Calculate viewNormal only when needed

pull/578/head
Andrei Kortunov 5 years ago
parent 0d1b7fd3f0
commit f30cb9f8bc

@ -83,7 +83,9 @@ void main()
mat3 tbnTranspose = mat3(normalizedTangent, binormal, normalizedNormal);
vec3 viewNormal = gl_NormalMatrix * normalize(tbnTranspose * (normalTex.xyz * 2.0 - 1.0));
#else
#endif
#if (!@normalMap && (@parallax || @forcePPL))
vec3 viewNormal = gl_NormalMatrix * normalize(passNormal);
#endif
@ -184,7 +186,12 @@ void main()
#endif
if (matSpec != vec3(0.0))
{
#if (!normalMap && !@parallax && !forcePPL)
vec3 viewNormal = gl_NormalMatrix * normalize(passNormal);
#endif
gl_FragData[0].xyz += getSpecular(normalize(viewNormal), normalize(passViewPos.xyz), shininess, matSpec) * shadowing;
}
#if @radialFog
float depth;
// For the less detailed mesh of simple water we need to recalculate depth on per-pixel basis

@ -63,7 +63,9 @@ void main(void)
euclideanDepth = length(viewPos.xyz);
linearDepth = gl_Position.z;
#if (@envMap || !PER_PIXEL_LIGHTING || @shadows_enabled)
vec3 viewNormal = normalize((gl_NormalMatrix * gl_Normal).xyz);
#endif
#if @envMap
vec3 viewVec = normalize(viewPos.xyz);
@ -112,5 +114,7 @@ void main(void)
passViewPos = viewPos.xyz;
passNormal = gl_Normal.xyz;
#if (@shadows_enabled)
setupShadowCoords(viewPos, viewNormal);
#endif
}

@ -43,8 +43,10 @@ void main()
mat3 tbnTranspose = mat3(tangent, binormal, normalizedNormal);
vec3 viewNormal = normalize(gl_NormalMatrix * (tbnTranspose * (normalTex.xyz * 2.0 - 1.0)));
#else
vec3 viewNormal = normalize(gl_NormalMatrix * passNormal);
#endif
#if (!@normalMap && (@parallax || @forcePPL))
vec3 viewNormal = gl_NormalMatrix * normalize(passNormal);
#endif
#if @parallax
@ -93,7 +95,12 @@ void main()
#endif
if (matSpec != vec3(0.0))
{
#if (!normalMap && !@parallax && !forcePPL)
vec3 viewNormal = gl_NormalMatrix * normalize(passNormal);
#endif
gl_FragData[0].xyz += getSpecular(normalize(viewNormal), normalize(passViewPos), shininess, matSpec) * shadowing;
}
#if @radialFog
float fogValue = clamp((euclideanDepth - gl_Fog.start) * gl_Fog.scale, 0.0, 1.0);

@ -26,8 +26,10 @@ void main(void)
gl_ClipVertex = viewPos;
euclideanDepth = length(viewPos.xyz);
linearDepth = gl_Position.z;
#if (!PER_PIXEL_LIGHTING || @shadows_enabled)
vec3 viewNormal = normalize((gl_NormalMatrix * gl_Normal).xyz);
#endif
#if !PER_PIXEL_LIGHTING
lighting = doLighting(viewPos.xyz, viewNormal, gl_Color, shadowDiffuseLighting);
@ -38,5 +40,7 @@ void main(void)
uv = gl_MultiTexCoord0.xy;
#if (@shadows_enabled)
setupShadowCoords(viewPos, viewNormal);
#endif
}

Loading…
Cancel
Save