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;
doLighting(passViewPos, normalize(viewNormal), shadowing, diffuseLight, ambientLight);
lighting = diffuseLight + ambientLight;
#endif
#if @clamp
lighting = clamp(lighting, vec3(0.0), vec3(1.0));
#else
lighting = max(lighting, 0.0);
clampLightingResult(lighting);
#endif
gl_FragData[0].xyz *= lighting;

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

@ -129,3 +129,12 @@ vec4 lcalcSpecular(int lightIndex)
return @getLight[lightIndex].specular;
#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
vec3 lighting = diffuseColor.xyz * diffuseLight + getAmbientColor().xyz * ambientLight + emission;
#if @clamp
lighting = clamp(lighting, vec3(0.0), vec3(1.0));
#else
lighting = max(lighting, 0.0);
#endif
clampLightingResult(lighting);
gl_FragData[0].xyz *= lighting;

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

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

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

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

Loading…
Cancel
Save