Modify evalLightAttenuation to "fade" edges of lights.

This provides a more attractive light falloff around the bounds of a
light - removing harsh edges.

This also adds a new parameter to evalLightAttenuation - the
unnormalized light vector.
This commit is contained in:
Geenz 2016-05-19 20:03:05 -04:00
parent 9793f7ef36
commit 6ecbdc6b9a
3 changed files with 9 additions and 6 deletions

View file

@ -98,10 +98,13 @@ float getLightShowContour(Light l) {
return l._control.w;
}
float evalLightAttenuation(Light l, float d) {
float radius = getLightRadius(l);
float evalLightAttenuation(Light l, float d, vec3 ulightvec) {
float radius = getLightSquareRadius(l);
float denom = d / radius + 1.0;
float attenuation = min(1.0, 1.0 / (denom * denom));
float attenuation = 1.0 / (denom * denom);
// "Fade" the edges of light sources to make things look a bit more attractive.
// Note: this tends to look a bit odd at lower exponents.
attenuation *= clamp(0, 1, mix(0, 1, getLightCutoffSquareRadius(l) - dot(ulightvec, ulightvec)));
return attenuation;
}

View file

@ -66,8 +66,8 @@ void main(void) {
vec3 fragEyeDir = normalize(fragEyeVector.xyz);
vec4 shading = evalFragShading(fragNormal, fragLightDir, fragEyeDir, frag.metallic, frag.specular, frag.roughness);
// Eval attenuation
float radialAttenuation = evalLightAttenuation(light, fragLightDistance);
// Eval attenuation
float radialAttenuation = evalLightAttenuation(light, fragLightDistance, fragLightVec);
// Final Lighting color
vec3 fragColor = (shading.w * frag.diffuse + shading.xyz);

View file

@ -74,7 +74,7 @@ void main(void) {
vec4 shading = evalFragShading(fragNormal, fragLightDir, fragEyeDir, frag.metallic, frag.specular, frag.roughness);
// Eval attenuation
float radialAttenuation = evalLightAttenuation(light, fragLightDistance);
float radialAttenuation = evalLightAttenuation(light, fragLightDistance, fragLightVec);
float angularAttenuation = evalLightSpotAttenuation(light, cosSpotAngle);
// Final Lighting color