1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-16 15:29:55 +00:00

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.
This commit is contained in:
glassmancody.info 2021-04-22 16:49:06 -07:00
parent 138d3b65a3
commit c48eee4eee
8 changed files with 16 additions and 23 deletions

View file

@ -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;

View file

@ -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)

View file

@ -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
}

View file

@ -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;

View file

@ -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;

View file

@ -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

View file

@ -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;

View file

@ -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