diff options
author | Lars Hofhansl <larsh@apache.org> | 2016-12-07 21:14:18 -0800 |
---|---|---|
committer | paramat <mat.gregory@virginmedia.com> | 2016-12-24 00:22:16 +0000 |
commit | 923a8f1983271f65c80cbbde7c46153ce58560b4 (patch) | |
tree | 61c3d459c9bc6f787d24e103b4ed7f7f8e2a464a /client/shaders/water_surface_shader | |
parent | a76e7698b21d51594d82e329d3825ee86e653295 (diff) | |
download | minetest-923a8f1983271f65c80cbbde7c46153ce58560b4.tar.gz minetest-923a8f1983271f65c80cbbde7c46153ce58560b4.tar.bz2 minetest-923a8f1983271f65c80cbbde7c46153ce58560b4.zip |
Shaders: Remove unnecessary 'if' statements
Pull if GENERATE_NORMALMAPS == 1 into the template to avoid evaluating
it for each fragment.
Remove if (fogDistance != 0.0).
Diffstat (limited to 'client/shaders/water_surface_shader')
-rw-r--r-- | client/shaders/water_surface_shader/opengl_fragment.glsl | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/client/shaders/water_surface_shader/opengl_fragment.glsl b/client/shaders/water_surface_shader/opengl_fragment.glsl index c4e78470d..19f6ac80f 100644 --- a/client/shaders/water_surface_shader/opengl_fragment.glsl +++ b/client/shaders/water_surface_shader/opengl_fragment.glsl @@ -114,7 +114,8 @@ void main(void) } #endif - if (GENERATE_NORMALMAPS == 1 && use_normalmap == false) { +#if GENERATE_NORMALMAPS == 1 + if (use_normalmap == false) { float tl = get_rgb_height (vec2(uv.x-SAMPLE_STEP,uv.y+SAMPLE_STEP)); float t = get_rgb_height (vec2(uv.x-SAMPLE_STEP,uv.y-SAMPLE_STEP)); float tr = get_rgb_height (vec2(uv.x+SAMPLE_STEP,uv.y+SAMPLE_STEP)); @@ -128,6 +129,7 @@ void main(void) bump = vec4 (normalize(vec3 (dX, -dY, NORMALMAPS_STRENGTH)),1.0); use_normalmap = true; } +#endif vec4 base = texture2D(baseTexture, uv).rgba; @@ -156,20 +158,18 @@ vec4 base = texture2D(baseTexture, uv).rgba; col = applyToneMapping(col); #endif - if (fogDistance != 0.0) { - // 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); - } + // 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); gl_FragColor = col; |