Clamp vertex lighting before interpolation

Fixes a regression in which pass lighting was clamped after being passed
to fragment shader. For correct FFP emulation, we need to clamp the result
in vertex shader. When clamping after interpolation, negative lights in
particular have a much more drastic effect.
pull/593/head
glassmancody.info 4 years ago
parent 138d3b65a3
commit c48eee4eee

@ -73,12 +73,7 @@ void main()
vec3 diffuseLight, ambientLight; vec3 diffuseLight, ambientLight;
doLighting(passViewPos, normalize(viewNormal), shadowing, diffuseLight, ambientLight); doLighting(passViewPos, normalize(viewNormal), shadowing, diffuseLight, ambientLight);
lighting = diffuseLight + ambientLight; lighting = diffuseLight + ambientLight;
#endif clampLightingResult(lighting);
#if @clamp
lighting = clamp(lighting, vec3(0.0), vec3(1.0));
#else
lighting = max(lighting, 0.0);
#endif #endif
gl_FragData[0].xyz *= lighting; gl_FragData[0].xyz *= lighting;

@ -165,6 +165,7 @@ void main(void)
vec3 diffuseLight, ambientLight; vec3 diffuseLight, ambientLight;
doLighting(viewPos.xyz, viewNormal, diffuseLight, ambientLight, shadowDiffuseLighting); doLighting(viewPos.xyz, viewNormal, diffuseLight, ambientLight, shadowDiffuseLighting);
passLighting = diffuseLight + ambientLight; passLighting = diffuseLight + ambientLight;
clampLightingResult(passLighting);
#endif #endif
#if (@shadows_enabled) #if (@shadows_enabled)

@ -129,3 +129,12 @@ vec4 lcalcSpecular(int lightIndex)
return @getLight[lightIndex].specular; return @getLight[lightIndex].specular;
#endif #endif
} }
void clampLightingResult(inout vec3 lighting)
{
#if @clamp
lighting = clamp(lighting, vec3(0.0), vec3(1.0));
#else
lighting = max(lighting, 0.0);
#endif
}

@ -78,11 +78,7 @@ void main()
#endif #endif
vec3 lighting = diffuseColor.xyz * diffuseLight + getAmbientColor().xyz * ambientLight + emission; vec3 lighting = diffuseColor.xyz * diffuseLight + getAmbientColor().xyz * ambientLight + emission;
#if @clamp clampLightingResult(lighting);
lighting = clamp(lighting, vec3(0.0), vec3(1.0));
#else
lighting = max(lighting, 0.0);
#endif
gl_FragData[0].xyz *= lighting; gl_FragData[0].xyz *= lighting;

@ -176,12 +176,7 @@ void main()
doLighting(passViewPos, normalize(viewNormal), shadowing, diffuseLight, ambientLight); doLighting(passViewPos, normalize(viewNormal), shadowing, diffuseLight, ambientLight);
vec3 emission = getEmissionColor().xyz * emissiveMult; vec3 emission = getEmissionColor().xyz * emissiveMult;
lighting = diffuseColor.xyz * diffuseLight + getAmbientColor().xyz * ambientLight + emission; lighting = diffuseColor.xyz * diffuseLight + getAmbientColor().xyz * ambientLight + emission;
#endif clampLightingResult(lighting);
#if @clamp
lighting = clamp(lighting, vec3(0.0), vec3(1.0));
#else
lighting = max(lighting, 0.0);
#endif #endif
gl_FragData[0].xyz *= lighting; gl_FragData[0].xyz *= lighting;

@ -125,6 +125,7 @@ void main(void)
doLighting(viewPos.xyz, viewNormal, diffuseLight, ambientLight, shadowDiffuseLighting); doLighting(viewPos.xyz, viewNormal, diffuseLight, ambientLight, shadowDiffuseLighting);
vec3 emission = getEmissionColor().xyz * emissiveMult; vec3 emission = getEmissionColor().xyz * emissiveMult;
passLighting = getDiffuseColor().xyz * diffuseLight + getAmbientColor().xyz * ambientLight + emission; passLighting = getDiffuseColor().xyz * diffuseLight + getAmbientColor().xyz * ambientLight + emission;
clampLightingResult(passLighting);
shadowDiffuseLighting *= getDiffuseColor().xyz; shadowDiffuseLighting *= getDiffuseColor().xyz;
#endif #endif

@ -87,12 +87,7 @@ void main()
vec3 diffuseLight, ambientLight; vec3 diffuseLight, ambientLight;
doLighting(passViewPos, normalize(viewNormal), shadowing, diffuseLight, ambientLight); doLighting(passViewPos, normalize(viewNormal), shadowing, diffuseLight, ambientLight);
lighting = diffuseColor.xyz * diffuseLight + getAmbientColor().xyz * ambientLight + getEmissionColor().xyz; lighting = diffuseColor.xyz * diffuseLight + getAmbientColor().xyz * ambientLight + getEmissionColor().xyz;
#endif clampLightingResult(lighting);
#if @clamp
lighting = clamp(lighting, vec3(0.0), vec3(1.0));
#else
lighting = max(lighting, 0.0);
#endif #endif
gl_FragData[0].xyz *= lighting; gl_FragData[0].xyz *= lighting;

@ -47,6 +47,7 @@ void main(void)
vec3 diffuseLight, ambientLight; vec3 diffuseLight, ambientLight;
doLighting(viewPos.xyz, viewNormal, diffuseLight, ambientLight, shadowDiffuseLighting); doLighting(viewPos.xyz, viewNormal, diffuseLight, ambientLight, shadowDiffuseLighting);
passLighting = getDiffuseColor().xyz * diffuseLight + getAmbientColor().xyz * ambientLight + getEmissionColor().xyz; passLighting = getDiffuseColor().xyz * diffuseLight + getAmbientColor().xyz * ambientLight + getEmissionColor().xyz;
clampLightingResult(passLighting);
shadowDiffuseLighting *= getDiffuseColor().xyz; shadowDiffuseLighting *= getDiffuseColor().xyz;
#endif #endif

Loading…
Cancel
Save