diff options
Diffstat (limited to 'indra/newview/app_settings/shaders/class1/environment/waterFogF.glsl')
-rw-r--r-- | indra/newview/app_settings/shaders/class1/environment/waterFogF.glsl | 50 |
1 files changed, 42 insertions, 8 deletions
diff --git a/indra/newview/app_settings/shaders/class1/environment/waterFogF.glsl b/indra/newview/app_settings/shaders/class1/environment/waterFogF.glsl index d44690d1fb..4bdfce9260 100644 --- a/indra/newview/app_settings/shaders/class1/environment/waterFogF.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/waterFogF.glsl @@ -25,16 +25,50 @@ +uniform vec4 lightnorm; +uniform vec4 waterPlane; +uniform vec4 waterFogColor; +uniform float waterFogDensity; +uniform float waterFogKS; + +vec3 getPositionEye(); + vec4 applyWaterFog(vec4 color) { - // GL_EXP2 Fog - //float fog = exp(-gl_Fog.density * gl_Fog.density * gl_FogFragCoord * gl_FogFragCoord); - // GL_EXP Fog - // float fog = exp(-gl_Fog.density * gl_FogFragCoord); - // GL_LINEAR Fog - float fog = (gl_Fog.end - gl_FogFragCoord) * gl_Fog.scale; - fog = clamp(fog, 0.0, 1.0); - color.rgb = mix(gl_Fog.color.rgb, color.rgb, fog); + //normalize view vector + vec3 view = normalize(getPositionEye()); + float es = -(dot(view, waterPlane.xyz)); + + //find intersection point with water plane and eye vector + + //get eye depth + float e0 = max(-waterPlane.w, 0.0); + + vec3 int_v = waterPlane.w > 0.0 ? view * waterPlane.w/es : vec3(0.0, 0.0, 0.0); + + //get object depth + float depth = length(getPositionEye() - int_v); + + //get "thickness" of water + float l = max(depth, 0.1); + + float kd = waterFogDensity; + float ks = waterFogKS; + vec4 kc = waterFogColor; + + float F = 0.98; + + float t1 = -kd * pow(F, ks * e0); + float t2 = kd + ks * es; + float t3 = pow(F, t2*l) - 1.0; + + float L = min(t1/t2*t3, 1.0); + + float D = pow(0.98, l*kd); + + color.rgb = color.rgb * D + kc.rgb * L; + color.a = kc.a + color.a; + return color; } |