fix SSS with colored shadows. FIX VPS not working.

This commit is contained in:
Xonk 2024-03-21 19:52:55 -04:00
parent 1cfb3f2f8c
commit 4bd3510497
8 changed files with 117 additions and 80 deletions

View File

@ -356,7 +356,6 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
vec4 COLORTEST = vec4(Albedo, UnchangedAlpha);
if (iswater > 0.95) COLORTEST = vec4(0.0);
#ifdef BIOME_TINT_WATER
if (iswater > 0.95) COLORTEST.rgb = color.rgb;

View File

@ -15,7 +15,16 @@ uniform sampler2D colortex6; // Noise
uniform sampler2D colortex8; // Noise
uniform sampler2D colortex14; // Noise
uniform sampler2D colortex15; // Noise
uniform sampler2D shadow;
// #ifdef TRANSLUCENT_COLORED_SHADOWS
uniform sampler2D shadowcolor0;
uniform sampler2D shadowtex0;
uniform sampler2D shadowtex1;
// #endif
uniform sampler2D noisetex;
uniform vec3 sunVec;
uniform vec2 texelSize;
@ -416,7 +425,7 @@ void main() {
float weight = 3.0 + (i+noise) *rdMul/SHADOW_FILTER_SAMPLE_COUNT*shadowMapResolution*distortFactor/2.7;
// float d = texelFetch2D( shadow, ivec2((projectedShadowPosition.xy+offsetS*rdMul)*shadowMapResolution),0).x;
float d = texelFetch2D( shadow, ivec2((projectedShadowPosition.xy+offsetS*rdMul)*shadowMapResolution),0).x;
float d = texelFetch2D(shadowtex1, ivec2((projectedShadowPosition.xy+offsetS*rdMul)*shadowMapResolution),0).x;
float b = smoothstep(weight*diffthresh/2.0, weight*diffthresh, projectedShadowPosition.z - d);

View File

@ -721,7 +721,16 @@ void BilateralUpscale_REUSE_Z(sampler2D tex1, sampler2D tex2, sampler2D depth, v
ambientEffects = ssao_RESULT/SUM;
#endif
}
vec3 ColorBoost(vec3 COLOR, float saturation){
float luminance = luma(COLOR);
COLOR = normalize(COLOR+0.0001);
vec3 difference = COLOR - luminance;
return COLOR + difference*(-luminance + saturation);
}
void main() {
vec3 DEBUG = vec3(1.0);
@ -964,37 +973,6 @@ void main() {
feetPlayerPos += gbufferModelViewInverse[3].xyz;
////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////// UNDER WATER SHADING ////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
if ((isEyeInWater == 0 && iswater) || (isEyeInWater == 1 && !iswater)){
#ifdef DISTANT_HORIZONS
vec3 viewPos0 = toScreenSpace_DH(texcoord/RENDER_SCALE-TAA_Offset*texelSize*0.5, z0, DH_depth0);
#else
vec3 viewPos0 = toScreenSpace(vec3(texcoord/RENDER_SCALE-TAA_Offset*texelSize*0.5,z0));
#endif
float Vdiff = distance(viewPos, viewPos0)*2.0;
float estimatedDepth = Vdiff * abs(feetPlayerPos_normalized.y); //assuming water plane
// make it such that the estimated depth flips to be correct when entering water.
if (isEyeInWater == 1){
estimatedDepth = 40.0 * pow(max(1.0-lightmap.y,0.0),2.0);
MinimumLightColor = vec3(10.0);
}
float depthfalloff = 1.0 - clamp(exp(-0.1*estimatedDepth),0.0,1.0);
float estimatedSunDepth = Vdiff; //assuming water plane
Absorbtion = mix(exp(-2.0 * totEpsilon * estimatedDepth), exp(-8.0 * totEpsilon), depthfalloff);
DirectLightColor *= Absorbtion;
AmbientLightColor *= Absorbtion;
// apply caustics to the lighting, and make sure they dont look weird
DirectLightColor *= mix(1.0, waterCaustics(feetPlayerPos + cameraPosition, WsunVec)*WATER_CAUSTICS_BRIGHTNESS + 0.25, clamp(estimatedDepth,0,1));
}
////////////////////////////////////////////////////////////////////////////////////
///////////////////////////// MAJOR LIGHTSOURCE STUFF ////////////////////////
////////////////////////////////////////////////////////////////////////////////////
@ -1036,6 +1014,7 @@ void main() {
if(shadowMapFalloff > 0.0){
shadowMap = vec3(0.0);
vec3 ShadowColor = vec3(0.0);
vec3 COLOR = vec3(1.0) ;
projectedShadowPosition = projectedShadowPosition * vec3(0.5,0.5,0.5/6.0) + vec3(0.5);
@ -1049,42 +1028,56 @@ void main() {
vec2 offsetS = tapLocation_simple(i, 7, 9, noise_2) * 0.5;
projectedShadowPosition += vec3(rdMul*offsetS, biasOffset);
#ifdef TRANSLUCENT_COLORED_SHADOWS
float opaqueShadow = shadow2D(shadowtex0, projectedShadowPosition).x;
ShadowColor += vec3(opaqueShadow/SHADOW_FILTER_SAMPLE_COUNT);
shadowMap += opaqueShadow / SHADOW_FILTER_SAMPLE_COUNT;
vec4 translucentShadow = texture2D(shadowcolor0, projectedShadowPosition.xy);
float shadowAlpha = clamp(1.0 - pow(translucentShadow.a,5.0),0.0,1.0);
#if SSS_TYPE != 0
if(LabSSS > 0.0) ShadowColor += (DirectLightColor * clamp(pow(1.0-shadowAlpha,5.0),0.0,1.0) + DirectLightColor * translucentShadow.rgb * shadowAlpha * (1.0 - opaqueShadow)) / SHADOW_FILTER_SAMPLE_COUNT;
else ShadowColor = DirectLightColor;
#endif
if(shadow2D(shadowtex1, projectedShadowPosition).x > projectedShadowPosition.z) shadowMap += (translucentShadow.rgb * shadowAlpha * (1.0 - opaqueShadow)) / SHADOW_FILTER_SAMPLE_COUNT;
if(shadow2D(shadowtex1, projectedShadowPosition).x > projectedShadowPosition.z){
vec4 translucentShadow = texture2D(shadowcolor0, projectedShadowPosition.xy);
if(translucentShadow.a < 0.9) ShadowColor += (normalize(translucentShadow.rgb+0.0001) * clamp(1.0-opaqueShadow,0.0,1.0)) / SHADOW_FILTER_SAMPLE_COUNT;
}
#else
ShadowColor += vec3(shadow2D(shadow, projectedShadowPosition).x/SHADOW_FILTER_SAMPLE_COUNT);
shadowMap += vec3(shadow2D(shadow, projectedShadowPosition).x / SHADOW_FILTER_SAMPLE_COUNT);
#endif
}
shadowMap = ShadowColor;
#else
#ifdef TRANSLUCENT_COLORED_SHADOWS
float OPAQUESHADOW = shadow2D(shadowtex0, projectedShadowPosition).x;
shadowMap += vec3(OPAQUESHADOW);
DirectLightColor = ShadowColor;
#endif
#else
#ifdef TRANSLUCENT_COLORED_SHADOWS
float opaqueShadow = shadow2D(shadowtex0, projectedShadowPosition).x;
shadowMap += opaqueShadow;
vec4 translucentShadow = texture2D(shadowcolor0, projectedShadowPosition.xy);
float shadowAlpha = clamp(1.0 - pow(translucentShadow.a,5.0),0.0,1.0);
#if SSS_TYPE != 0
if(LabSSS > 0.0) ShadowColor += DirectLightColor * (1.0 - shadowAlpha) + DirectLightColor * translucentShadow.rgb * shadowAlpha * (1.0 - opaqueShadow);
else ShadowColor = DirectLightColor;
#endif
if(shadow2D(shadowtex1, projectedShadowPosition).x > projectedShadowPosition.z) shadowMap += translucentShadow.rgb * shadowAlpha * (1.0 - opaqueShadow);
if(shadow2D(shadowtex1, projectedShadowPosition).x > projectedShadowPosition.z){
vec4 shadowLightColor = texture2D(shadowcolor0, projectedShadowPosition.xy);
if(shadowLightColor.a < 0.9) shadowMap += normalize(shadowLightColor.rgb+0.0001) * (1.0-OPAQUESHADOW);
}
#else
shadowMap += vec3(shadow2D(shadow, projectedShadowPosition).x);
shadowMap += shadow2D(shadow, projectedShadowPosition).x;
#endif
#endif
Shadows = shadowMap;
#ifdef TRANSLUCENT_COLORED_SHADOWS
DirectLightColor = ShadowColor;
#endif
// if(shadow2D(shadowtex0, projectedShadowPosition).x < projectedShadowPosition.z) DirectLightColor *= shadow2D(shadowtex1, projectedShadowPosition).x * waterCaustics(feetPlayerPos + cameraPosition, WsunVec)*WATER_CAUSTICS_BRIGHTNESS + 0.25;
Shadows = shadowMap;
}
if(!iswater) Shadows = mix(vec3(LM_shadowMapFallback), Shadows, shadowMapFalloff2);
@ -1094,6 +1087,38 @@ void main() {
#endif
// }
////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////// UNDER WATER SHADING ////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
if ((isEyeInWater == 0 && iswater) || (isEyeInWater == 1 && !iswater)){
#ifdef DISTANT_HORIZONS
vec3 viewPos0 = toScreenSpace_DH(texcoord/RENDER_SCALE-TAA_Offset*texelSize*0.5, z0, DH_depth0);
#else
vec3 viewPos0 = toScreenSpace(vec3(texcoord/RENDER_SCALE-TAA_Offset*texelSize*0.5,z0));
#endif
float Vdiff = distance(viewPos, viewPos0)*2.0;
float estimatedDepth = Vdiff * abs(feetPlayerPos_normalized.y); //assuming water plane
// make it such that the estimated depth flips to be correct when entering water.
if (isEyeInWater == 1){
estimatedDepth = 40.0 * pow(max(1.0-lightmap.y,0.0),2.0);
MinimumLightColor = vec3(10.0);
}
float depthfalloff = 1.0 - clamp(exp(-0.1*estimatedDepth),0.0,1.0);
float estimatedSunDepth = Vdiff; //assuming water plane
Absorbtion = mix(exp(-2.0 * totEpsilon * estimatedDepth), exp(-8.0 * totEpsilon), depthfalloff);
DirectLightColor *= Absorbtion;
AmbientLightColor *= Absorbtion;
// apply caustics to the lighting, and make sure they dont look weird
DirectLightColor *= mix(1.0, waterCaustics(feetPlayerPos + cameraPosition, WsunVec)*WATER_CAUSTICS_BRIGHTNESS + 0.25, clamp(estimatedDepth,0,1));
}
////////////////////////////////////////////////////////////////////////////////
//////////////////////////////// SUN SSS ////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
@ -1110,7 +1135,7 @@ void main() {
#endif
#if !defined Variable_Penumbra_Shadows
ShadowBlockerDepth = pow(1.0 - clamp(dot(Shadows,vec3(0.33333)),0,1),2.0);
ShadowBlockerDepth = pow(1.0 - clamp(Shadows.x,0,1),2.0);
#endif
@ -1296,14 +1321,16 @@ void main() {
gl_FragData[0].rgb = (Indirect_lighting + Direct_lighting) * albedo;
#ifdef Specular_Reflections
vec2 specularNoises = vec2(noise, R2_dither());
DoSpecularReflections(gl_FragData[0].rgb, viewPos, feetPlayerPos_normalized, WsunVec, specularNoises, normal, SpecularTex.r, SpecularTex.g, albedo, DirectLightColor*Shadows*NdotL, lightmap.y, hand);
#endif
// gl_FragData[0].rgb = Direct_lighting;
Emission(gl_FragData[0].rgb, albedo, SpecularTex.a);
// #ifdef Specular_Reflections
// vec2 specularNoises = vec2(noise, R2_dither());
// DoSpecularReflections(gl_FragData[0].rgb, viewPos, feetPlayerPos_normalized, WsunVec, specularNoises, normal, SpecularTex.r, SpecularTex.g, albedo, DirectLightColor*Shadows*NdotL, lightmap.y, hand);
// #endif
// Emission(gl_FragData[0].rgb, albedo, SpecularTex.a);
if(lightningBolt) gl_FragData[0].rgb = vec3(77.0, 153.0, 255.0);
// if(lightningBolt) gl_FragData[0].rgb = vec3(77.0, 153.0, 255.0);
}
@ -1318,12 +1345,12 @@ void main() {
}
//////// DEBUG VIEW STUFF
// #if DEBUG_VIEW == debug_SHADOWMAP
// vec3 OutsideShadowMap_and_DH_shadow = (shadowMapFalloff > 0.0 && z >= 1.0) ? vec3(0.25,1.0,0.25) : vec3(1.0,0.25,0.25);
// vec3 Normal_Shadowmap = z < 1.0 ? vec3(0.25,0.25,1.0) : OutsideShadowMap_and_DH_shadow;
// gl_FragData[0].rgb = mix(vec3(0.1) * (normal.y * 0.1 +0.9), Normal_Shadowmap, shadowMap) * 30.0;
// #endif
////// DEBUG VIEW STUFF
#if DEBUG_VIEW == debug_SHADOWMAP
vec3 OutsideShadowMap_and_DH_shadow = (shadowMapFalloff > 0.0 && z >= 1.0) ? vec3(0.25,1.0,0.25) : vec3(1.0,0.25,0.25);
vec3 Normal_Shadowmap = z < 1.0 ? vec3(1.0,1.0,1.0) : OutsideShadowMap_and_DH_shadow;
gl_FragData[0].rgb = mix(vec3(0.1) * (normal.y * 0.1 +0.9), Normal_Shadowmap, shadowMap) * 30.0;
#endif
#if DEBUG_VIEW == debug_NORMALS
gl_FragData[0].rgb = FlatNormals;
#endif
@ -1340,9 +1367,9 @@ void main() {
gl_FragData[0].rgb = viewPos * 0.001;
#endif
#if DEBUG_VIEW == debug_FILTERED_STUFF
vec3 FilteredDebug = vec3(15.0) * exp(-1.0 * vec3(1.0,0.5,1.0) * filteredShadow.y);
FilteredDebug += vec3(15.0) * exp(-7.0 * vec3(1.0,1.0,0.5) * pow(SSAO_SSS.x,2));
FilteredDebug += vec3(15.0) * exp(-7.0 * vec3(0.5,1.0,1.0) * pow(SSAO_SSS.y,2));
vec3 FilteredDebug = vec3(15.0) * exp(-7.0 * vec3(1.0,0.5,1.0) * filteredShadow.y);
// FilteredDebug += vec3(15.0) * exp(-7.0 * vec3(1.0,1.0,0.5) * pow(SSAO_SSS.x,2));
// FilteredDebug += vec3(15.0) * exp(-7.0 * vec3(0.5,1.0,1.0) * pow(SSAO_SSS.y,2));
gl_FragData[0].rgb = FilteredDebug;
#endif

View File

@ -159,18 +159,18 @@ void main() {
vec3 FINAL_COLOR = clamp(int8Dither(col,texcoord),0.0,1.0);
#ifdef TONE_CURVE
FINAL_COLOR = toneCurve(FINAL_COLOR);
FINAL_COLOR = toneCurve(FINAL_COLOR);
#endif
#ifdef COLOR_GRADING_ENABLED
FINAL_COLOR = colorGrading(FINAL_COLOR);
FINAL_COLOR = colorGrading(FINAL_COLOR);
#endif
applyContrast(FINAL_COLOR, CONTRAST); // for fun
gl_FragColor.rgb = FINAL_COLOR;
// if(texcoord.x > 0.5) gl_FragColor.rgb = texture2D(shadowcolor0, texcoord * vec2(2.0, 1.0) - vec2(1.0, 0.0)).rgb * vec3(1.0);
#if DEBUG_VIEW == debug_SHADOWMAP
if(texcoord.x < 0.25 && texcoord.y < 0.5) gl_FragColor.rgb = texture2D(shadowcolor0, (texcoord * vec2(2.0, 1.0) * 2 - vec2(0.0, 0.0)) ).rgb * vec3(1.0);
#endif
}

View File

@ -211,7 +211,7 @@ vec4 GetVolumetricFog(
#endif
}
// float sh2 = sh;
vec3 sh2 = sh;
#ifdef VL_CLOUDS_SHADOWS
// if(clamp(progressW.y - CloudLayer1_height,0.0,1.0) < 1.0 && clamp(progressW.y-50,0.0,1.0) > 0.0)

View File

@ -186,7 +186,7 @@ void DoSpecularReflections(
vec3 Lightsource_Reflection = vec3(0.0);
vec4 SS_Reflections = vec4(0.0);
Lightmap = clamp((Lightmap-0.6)*5.0, 0.0,1.0);
Lightmap = clamp((Lightmap-0.8)*7.0, 0.0,1.0);
Roughness = 1.0 - Roughness; Roughness *= Roughness;
F0 = F0 == 0.0 ? 0.02 : F0;

View File

@ -44,7 +44,7 @@ float blueNoise(){
void main() {
gl_FragData[0] = vec4(1);
gl_FragData[0] = texture2D(tex,texcoord.xy) * color;

View File

@ -123,8 +123,8 @@ void main() {
color = gl_Color;
vec3 position = mat3(gl_ModelViewMatrix) * vec3(gl_Vertex) + gl_ModelViewMatrix[3].xyz;
playerpos = vec4(0.0);
playerpos = gbufferModelViewInverse * (gl_ModelViewMatrix * gl_Vertex);
// playerpos = vec4(0.0);
// playerpos = gbufferModelViewInverse * (gl_ModelViewMatrix * gl_Vertex);
// mat4 Custom_ViewMatrix = BuildShadowViewMatrix(LightDir);
// mat4 Custom_ProjectionMatrix = BuildShadowProjectionMatrix();
@ -197,6 +197,8 @@ void main() {
if(mc_Entity.x == 8 ) gl_Position.w = -1.0;
// color.a = 1.0;
// if(mc_Entity.x != 10002) color.a = 0.0;
// materials = 0.0;