diff --git a/leenkx/Shaders/water_pass/water_pass.frag.glsl b/leenkx/Shaders/water_pass/water_pass.frag.glsl index 2c21f25c..efe72a37 100644 --- a/leenkx/Shaders/water_pass/water_pass.frag.glsl +++ b/leenkx/Shaders/water_pass/water_pass.frag.glsl @@ -151,6 +151,7 @@ void main() { } // Displace surface + float geomZ = p.z; // undisplaced depth for foam/fog tests p.z += (sin(p.x * 10.0 / waterDisplace + speed) * cos(p.y * 10.0 / waterDisplace + speed) + sin(p.x * 20.0 / waterDisplace + speed * 1.3) * cos(p.y * 20.0 / waterDisplace + speed * 1.3) * 0.5) / 50.0 * waterDisplace; @@ -229,13 +230,13 @@ void main() { float specAmount = pow(max(dot(n2, h), 0.0), 200.0) * (200.0 + 8.0) / (PI * 8.0); fragColor.rgb += specAmount * (isSky ? 0.3 : 1.0) * horizonFactor; // Depth fog - blend toward waterColor with depth, faded at horizon - float depthFog = clamp(-(p.z - waterLevel) * waterDensity, 0.0, 0.9); + float depthFog = clamp(-(geomZ - waterLevel) * waterDensity, 0.0, 0.9); fragColor.rgb = mix(fragColor.rgb, waterColor, depthFog * horizonFactor); // Alpha fades smoothly at horizon instead of hard cut - fragColor.a = isSky ? horizonFactor : clamp(abs(p.z - waterLevel) * 5.0, 0.0, 1.0); + fragColor.a = isSky ? horizonFactor : clamp(abs(geomZ - waterLevel) * 5.0, 0.0, 1.0); // Foam - based on actual geometry depth below water surface - float fd = isSky ? 1.0 : abs(p.z - waterLevel); + float fd = isSky ? 1.0 : abs(geomZ - waterLevel); if (fd < 0.1) { // Based on foam by Owen Deery // http://fire-face.com/personal/water