diff options
author | Rogier-5 <rogier777@gmail.com> | 2016-11-16 17:56:05 +0100 |
---|---|---|
committer | Zeno- <kde.psych@gmail.com> | 2016-11-17 02:56:05 +1000 |
commit | 5f0dc8e78ad7e62959786efd5c7f72044aacb53a (patch) | |
tree | 18b0034ab284acd89d8e21deed02b0263246f349 /client/shaders | |
parent | 8e61c1dfd9c07abbea82b3acecf729c118d95793 (diff) | |
download | minetest-5f0dc8e78ad7e62959786efd5c7f72044aacb53a.tar.gz minetest-5f0dc8e78ad7e62959786efd5c7f72044aacb53a.tar.bz2 minetest-5f0dc8e78ad7e62959786efd5c7f72044aacb53a.zip |
Fix unexplained shader issue (glsl compiler bug??) (#4757)
Diffstat (limited to 'client/shaders')
-rw-r--r-- | client/shaders/nodes_shader/opengl_fragment.glsl | 16 | ||||
-rw-r--r-- | client/shaders/water_surface_shader/opengl_fragment.glsl | 16 | ||||
-rw-r--r-- | client/shaders/wielded_shader/opengl_fragment.glsl | 16 |
3 files changed, 42 insertions, 6 deletions
diff --git a/client/shaders/nodes_shader/opengl_fragment.glsl b/client/shaders/nodes_shader/opengl_fragment.glsl index 4d9ce1c12..149aa2bc5 100644 --- a/client/shaders/nodes_shader/opengl_fragment.glsl +++ b/client/shaders/nodes_shader/opengl_fragment.glsl @@ -19,6 +19,8 @@ bool normalTexturePresent = false; const float e = 2.718281828459; const float BS = 10.0; +const float fogStart = 0.4; +const float fogShadingParameter = 1 / ( 1 - fogStart); #ifdef ENABLE_TONE_MAPPING @@ -199,8 +201,18 @@ void main(void) #endif if (fogDistance != 0.0) { - float d = clamp((fogDistance - length(eyeVec)) / (fogDistance * 0.6), 0.0, 1.0); - col = mix(skyBgColor, col, 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); diff --git a/client/shaders/water_surface_shader/opengl_fragment.glsl b/client/shaders/water_surface_shader/opengl_fragment.glsl index b4c0cc4f8..4164870c7 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 = 0.4; +const float fogShadingParameter = 1 / ( 1 - fogStart); #ifdef ENABLE_TONE_MAPPING @@ -155,8 +157,18 @@ vec4 base = texture2D(baseTexture, uv).rgba; #endif if (fogDistance != 0.0) { - float d = clamp((fogDistance - length(eyeVec)) / (fogDistance * 0.6), 0.0, 1.0); - col = mix(skyBgColor, col, 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); diff --git a/client/shaders/wielded_shader/opengl_fragment.glsl b/client/shaders/wielded_shader/opengl_fragment.glsl index bd9741441..7c38b749a 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 = 0.4; +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 = clamp((fogDistance - length(eyeVec)) / (fogDistance * 0.6), 0.0, 1.0); - col = mix(skyBgColor, col, 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); } |