From 1465baede1f1a511e97f33edce0576b2ff6a766d Mon Sep 17 00:00:00 2001 From: Xonk Date: Mon, 17 Mar 2025 22:40:55 -0400 Subject: [PATCH] add water caustics and sunlight absorbtion to translucent stuff when underwater. small NdotL tweak for translucent rendering --- shaders/dimensions/all_translucent.fsh | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/shaders/dimensions/all_translucent.fsh b/shaders/dimensions/all_translucent.fsh index e109c40..b7b85ae 100644 --- a/shaders/dimensions/all_translucent.fsh +++ b/shaders/dimensions/all_translucent.fsh @@ -568,12 +568,15 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 ) #ifdef OVERWORLD_SHADER vec3 DirectLightColor = lightCol.rgb/2400.0; - if(isEyeInWater == 1){ - float distanceFromWaterSurface = max(-(feetPlayerPos.y + (cameraPosition.y - waterEnteredAltitude)),0.0) ; - DirectLightColor *= exp(-vec3(Water_Absorb_R, Water_Absorb_G, Water_Absorb_B) * distanceFromWaterSurface); + if(!isWater && isEyeInWater == 1){ + float distanceFromWaterSurface = cameraPosition.y - waterEnteredAltitude; + float waterdepth = max(-(feetPlayerPos.y + distanceFromWaterSurface),0.0); + + DirectLightColor *= exp(-vec3(Water_Absorb_R, Water_Absorb_G, Water_Absorb_B) * (waterdepth/abs(WsunVec.y))); + DirectLightColor *= pow(waterCaustics(feetPlayerPos + cameraPosition, WsunVec)*WATER_CAUSTICS_BRIGHTNESS, WATER_CAUSTICS_POWER); } - float NdotL = clamp(dot(normal, normalize(WsunVec*mat3(gbufferModelViewInverse))),0.0,1.0); NdotL = clamp((-15 + NdotL*255.0) / 240.0 ,0.0,1.0); + float NdotL = clamp((-15 + dot(normal, normalize(WsunVec*mat3(gbufferModelViewInverse)))*255.0) / 240.0 ,0.0,1.0); float Shadows = 1.0; float shadowMapFalloff = smoothstep(0.0, 1.0, min(max(1.0 - length(feetPlayerPos) / (shadowDistance+16),0.0)*5.0,1.0)); @@ -686,7 +689,6 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 ) float f0 = isReflective ? max(specularValues.g, harcodedF0) : specularValues.g; bool isHand = false; - #ifdef HAND isHand = true; f0 = max(specularValues.g, harcodedF0); @@ -708,7 +710,7 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 ) #endif - vec3 specularReflections = specularReflections(viewPos, normalize(feetPlayerPos), WsunVec, vec3(blueNoise(), vec2(interleaved_gradientNoise_temporal())), worldSpaceNormal, roughness, f0, Albedo, FinalColor*gl_FragData[0].a, DirectLightColor * Shadows, lightmap.y, isHand, reflectance, flashLightSpecularData); + vec3 specularReflections = specularReflections(viewPos, normalize(feetPlayerPos), WsunVec, vec3(blueNoise(), vec2(interleaved_gradientNoise_temporal())), worldSpaceNormal, roughness, f0, Albedo, FinalColor*gl_FragData[0].a, DirectLightColor * Shadows, lightmap.y, isHand, isWater, reflectance, flashLightSpecularData); gl_FragData[0].a = gl_FragData[0].a + (1.0-gl_FragData[0].a) * reflectance;