From 688e804548861d3b12009ab414da05e58438aae7 Mon Sep 17 00:00:00 2001 From: Capostrophic Date: Fri, 24 Apr 2020 13:21:49 +0300 Subject: [PATCH] Fix simple water with radial fog enabled --- components/sceneutil/waterutil.cpp | 3 +++ files/shaders/objects_fragment.glsl | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/components/sceneutil/waterutil.cpp b/components/sceneutil/waterutil.cpp index 562b0ee73..b98a19ae8 100644 --- a/components/sceneutil/waterutil.cpp +++ b/components/sceneutil/waterutil.cpp @@ -74,6 +74,9 @@ namespace SceneUtil stateset->setRenderBinDetails(renderBin, "RenderBin"); + // Let the shader know we're dealing with simple water here. + stateset->addUniform(new osg::Uniform("simpleWater", true)); + return stateset; } } diff --git a/files/shaders/objects_fragment.glsl b/files/shaders/objects_fragment.glsl index 31e929a90..81884feac 100644 --- a/files/shaders/objects_fragment.glsl +++ b/files/shaders/objects_fragment.glsl @@ -49,6 +49,8 @@ uniform vec2 envMapLumaBias; uniform mat2 bumpMapMatrix; #endif +uniform bool simpleWater = false; + varying float euclideanDepth; varying float linearDepth; @@ -180,7 +182,11 @@ void main() gl_FragData[0].xyz += getSpecular(normalize(viewNormal), normalize(passViewPos.xyz), shininess, matSpec) * shadowing; #if @radialFog - float fogValue = clamp((euclideanDepth - gl_Fog.start) * gl_Fog.scale, 0.0, 1.0); + float depth = euclideanDepth; + // For the less detailed mesh of simple water we need to recalculate depth on per-pixel basis + if (simpleWater) + depth = length(passViewPos); + float fogValue = clamp((depth - gl_Fog.start) * gl_Fog.scale, 0.0, 1.0); #else float fogValue = clamp((linearDepth - gl_Fog.start) * gl_Fog.scale, 0.0, 1.0); #endif