summaryrefslogtreecommitdiff
path: root/client/shaders/wielded_shader/opengl_fragment.glsl
diff options
context:
space:
mode:
Diffstat (limited to 'client/shaders/wielded_shader/opengl_fragment.glsl')
-rw-r--r--client/shaders/wielded_shader/opengl_fragment.glsl16
1 files changed, 14 insertions, 2 deletions
diff --git a/client/shaders/wielded_shader/opengl_fragment.glsl b/client/shaders/wielded_shader/opengl_fragment.glsl
index 75dd1b674..ba7a8f12d 100644
--- a/client/shaders/wielded_shader/opengl_fragment.glsl
+++ b/client/shaders/wielded_shader/opengl_fragment.glsl
@@ -19,6 +19,8 @@ bool texSeamless = false;
const float e = 2.718281828459;
const float BS = 10.0;
+const float fogStart = FOG_START;
+const float fogShadingParameter = 1 / ( 1 - fogStart);
void get_texture_flags()
{
@@ -107,8 +109,18 @@ void main(void)
vec4 col = vec4(color.rgb, base.a);
col *= gl_Color;
if (fogDistance != 0.0) {
- float d = max(0.0, min(vPosition.z / fogDistance * 1.5 - 0.6, 1.0));
- col = mix(col, skyBgColor, d);
+ // Due to a bug in some (older ?) graphics stacks (possibly in the glsl compiler ?),
+ // the fog will only be rendered correctly if the last operation before the
+ // clamp() is an addition. Else, the clamp() seems to be ignored.
+ // E.g. the following won't work:
+ // float clarity = clamp(fogShadingParameter
+ // * (fogDistance - length(eyeVec)) / fogDistance), 0.0, 1.0);
+ // As additions usually come for free following a multiplication, the new formula
+ // should be more efficient as well.
+ // Note: clarity = (1 - fogginess)
+ float clarity = clamp(fogShadingParameter
+ - fogShadingParameter * length(eyeVec) / fogDistance, 0.0, 1.0);
+ col = mix(skyBgColor, col, clarity);
}
gl_FragColor = vec4(col.rgb, base.a);
}