mirror of
https://github.com/overte-org/overte.git
synced 2025-04-19 15:03:53 +02:00
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:
parent
9793f7ef36
commit
6ecbdc6b9a
3 changed files with 9 additions and 6 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue