summaryrefslogtreecommitdiff
path: root/client/shaders/water_surface_shader/opengl_fragment.glsl
diff options
context:
space:
mode:
authorest31 <MTest31@outlook.com>2016-12-22 23:16:00 +0100
committerest31 <MTest31@outlook.com>2016-12-22 23:16:00 +0100
commit81d56b94919dceb7b2e51d70b21a7ca22f852bd5 (patch)
tree1e9ef1be1b3295a8673d6e4f0bdeb4c2d3a6015f /client/shaders/water_surface_shader/opengl_fragment.glsl
parent8077612dcb48221281e726a60eb97bf73fde462b (diff)
parent231ac33d34dfaaddf292c5f31b1eae43eeefba2d (diff)
downloadminetest-81d56b94919dceb7b2e51d70b21a7ca22f852bd5.tar.gz
minetest-81d56b94919dceb7b2e51d70b21a7ca22f852bd5.tar.bz2
minetest-81d56b94919dceb7b2e51d70b21a7ca22f852bd5.zip
Merge 0.4.15 changes into stable-0.4
0.4.15 release!
Diffstat (limited to 'client/shaders/water_surface_shader/opengl_fragment.glsl')
-rw-r--r--client/shaders/water_surface_shader/opengl_fragment.glsl33
1 files changed, 18 insertions, 15 deletions
diff --git a/client/shaders/water_surface_shader/opengl_fragment.glsl b/client/shaders/water_surface_shader/opengl_fragment.glsl
index 1fa669541..c4e78470d 100644
--- a/client/shaders/water_surface_shader/opengl_fragment.glsl
+++ b/client/shaders/water_surface_shader/opengl_fragment.glsl
@@ -21,6 +21,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);
#ifdef ENABLE_TONE_MAPPING
@@ -150,24 +152,25 @@ vec4 base = texture2D(baseTexture, uv).rgba;
vec4 col = vec4(color.rgb * gl_Color.rgb, 1.0);
-#if MATERIAL_TYPE == TILE_MATERIAL_LIQUID_TRANSPARENT || MATERIAL_TYPE == TILE_MATERIAL_LIQUID_OPAQUE
- float alpha = gl_Color.a;
- if (fogDistance != 0.0) {
- float d = max(0.0, min(vPosition.z / fogDistance * 1.5 - 0.6, 1.0));
- alpha = mix(alpha, 0.0, d);
- }
- col = vec4(col.rgb, alpha);
-#else
+#ifdef ENABLE_TONE_MAPPING
+ col = applyToneMapping(col);
+#endif
+
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);
}
col = vec4(col.rgb, base.a);
-#endif
-#ifdef ENABLE_TONE_MAPPING
- gl_FragColor = applyToneMapping(col);
-#else
gl_FragColor = col;
-#endif
}