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).master
parent
a76e7698b2
commit
923a8f1983
|
@ -163,7 +163,8 @@ void main(void)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (GENERATE_NORMALMAPS == 1 && normalTexturePresent == false) {
|
#if GENERATE_NORMALMAPS == 1
|
||||||
|
if (normalTexturePresent == false) {
|
||||||
float tl = get_rgb_height(vec2(uv.x - SAMPLE_STEP, uv.y + SAMPLE_STEP));
|
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 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));
|
float tr = get_rgb_height(vec2(uv.x + SAMPLE_STEP, uv.y + SAMPLE_STEP));
|
||||||
|
@ -177,7 +178,7 @@ void main(void)
|
||||||
bump = vec4(normalize(vec3 (dX, dY, NORMALMAPS_STRENGTH)), 1.0);
|
bump = vec4(normalize(vec3 (dX, dY, NORMALMAPS_STRENGTH)), 1.0);
|
||||||
use_normalmap = true;
|
use_normalmap = true;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
vec4 base = texture2D(baseTexture, uv).rgba;
|
vec4 base = texture2D(baseTexture, uv).rgba;
|
||||||
|
|
||||||
#ifdef ENABLE_BUMPMAPPING
|
#ifdef ENABLE_BUMPMAPPING
|
||||||
|
@ -200,7 +201,6 @@ void main(void)
|
||||||
col = applyToneMapping(col);
|
col = applyToneMapping(col);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (fogDistance != 0.0) {
|
|
||||||
// Due to a bug in some (older ?) graphics stacks (possibly in the glsl compiler ?),
|
// 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
|
// the fog will only be rendered correctly if the last operation before the
|
||||||
// clamp() is an addition. Else, the clamp() seems to be ignored.
|
// clamp() is an addition. Else, the clamp() seems to be ignored.
|
||||||
|
@ -213,7 +213,6 @@ void main(void)
|
||||||
float clarity = clamp(fogShadingParameter
|
float clarity = clamp(fogShadingParameter
|
||||||
- fogShadingParameter * length(eyeVec) / fogDistance, 0.0, 1.0);
|
- fogShadingParameter * length(eyeVec) / fogDistance, 0.0, 1.0);
|
||||||
col = mix(skyBgColor, col, clarity);
|
col = mix(skyBgColor, col, clarity);
|
||||||
}
|
|
||||||
col = vec4(col.rgb, base.a);
|
col = vec4(col.rgb, base.a);
|
||||||
|
|
||||||
gl_FragColor = col;
|
gl_FragColor = col;
|
||||||
|
|
|
@ -114,7 +114,8 @@ void main(void)
|
||||||
}
|
}
|
||||||
#endif
|
#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 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 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));
|
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);
|
bump = vec4 (normalize(vec3 (dX, -dY, NORMALMAPS_STRENGTH)),1.0);
|
||||||
use_normalmap = true;
|
use_normalmap = true;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
vec4 base = texture2D(baseTexture, uv).rgba;
|
vec4 base = texture2D(baseTexture, uv).rgba;
|
||||||
|
|
||||||
|
@ -156,7 +158,6 @@ vec4 base = texture2D(baseTexture, uv).rgba;
|
||||||
col = applyToneMapping(col);
|
col = applyToneMapping(col);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (fogDistance != 0.0) {
|
|
||||||
// Due to a bug in some (older ?) graphics stacks (possibly in the glsl compiler ?),
|
// 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
|
// the fog will only be rendered correctly if the last operation before the
|
||||||
// clamp() is an addition. Else, the clamp() seems to be ignored.
|
// clamp() is an addition. Else, the clamp() seems to be ignored.
|
||||||
|
@ -169,7 +170,6 @@ vec4 base = texture2D(baseTexture, uv).rgba;
|
||||||
float clarity = clamp(fogShadingParameter
|
float clarity = clamp(fogShadingParameter
|
||||||
- fogShadingParameter * length(eyeVec) / fogDistance, 0.0, 1.0);
|
- fogShadingParameter * length(eyeVec) / fogDistance, 0.0, 1.0);
|
||||||
col = mix(skyBgColor, col, clarity);
|
col = mix(skyBgColor, col, clarity);
|
||||||
}
|
|
||||||
col = vec4(col.rgb, base.a);
|
col = vec4(col.rgb, base.a);
|
||||||
|
|
||||||
gl_FragColor = col;
|
gl_FragColor = col;
|
||||||
|
|
|
@ -75,7 +75,8 @@ void main(void)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (GENERATE_NORMALMAPS == 1 && normalTexturePresent == false) {
|
#if GENERATE_NORMALMAPS == 1
|
||||||
|
if (normalTexturePresent == false) {
|
||||||
float tl = get_rgb_height(vec2(uv.x - SAMPLE_STEP, uv.y + SAMPLE_STEP));
|
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 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));
|
float tr = get_rgb_height(vec2(uv.x + SAMPLE_STEP, uv.y + SAMPLE_STEP));
|
||||||
|
@ -89,6 +90,7 @@ void main(void)
|
||||||
bump = vec4(normalize(vec3 (dX, dY, NORMALMAPS_STRENGTH)), 1.0);
|
bump = vec4(normalize(vec3 (dX, dY, NORMALMAPS_STRENGTH)), 1.0);
|
||||||
use_normalmap = true;
|
use_normalmap = true;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
vec4 base = texture2D(baseTexture, uv).rgba;
|
vec4 base = texture2D(baseTexture, uv).rgba;
|
||||||
|
|
||||||
|
@ -108,7 +110,6 @@ void main(void)
|
||||||
|
|
||||||
vec4 col = vec4(color.rgb, base.a);
|
vec4 col = vec4(color.rgb, base.a);
|
||||||
col *= gl_Color;
|
col *= gl_Color;
|
||||||
if (fogDistance != 0.0) {
|
|
||||||
// Due to a bug in some (older ?) graphics stacks (possibly in the glsl compiler ?),
|
// 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
|
// the fog will only be rendered correctly if the last operation before the
|
||||||
// clamp() is an addition. Else, the clamp() seems to be ignored.
|
// clamp() is an addition. Else, the clamp() seems to be ignored.
|
||||||
|
@ -121,6 +122,6 @@ void main(void)
|
||||||
float clarity = clamp(fogShadingParameter
|
float clarity = clamp(fogShadingParameter
|
||||||
- fogShadingParameter * length(eyeVec) / fogDistance, 0.0, 1.0);
|
- fogShadingParameter * length(eyeVec) / fogDistance, 0.0, 1.0);
|
||||||
col = mix(skyBgColor, col, clarity);
|
col = mix(skyBgColor, col, clarity);
|
||||||
}
|
|
||||||
gl_FragColor = vec4(col.rgb, base.a);
|
gl_FragColor = vec4(col.rgb, base.a);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue