Lighting GLSL library: use inverse square falloff for lighting in sRGB mode

- It is a slightly modified equation that actually terminates the light's influence at the light radius
This commit is contained in:
shadowislord 2015-02-21 22:50:29 -05:00
parent 4e7d7fd2f1
commit 9d715cdd2b

View File

@ -11,7 +11,12 @@ void lightComputeDir(in vec3 worldPos, in float ligthType, in vec4 position, out
vec3 tempVec = position.xyz * sign(posLight - 0.5) - (worldPos * posLight);
lightVec = tempVec;
float dist = length(tempVec);
#ifdef SRGB
lightDir.w = (1.0 - position.w * dist) / (1.0 + position.w * dist * dist);
lightDir.w = clamp(lightDir.w, 0.0, 1.0);
#else
lightDir.w = clamp(1.0 - position.w * dist * posLight, 0.0, 1.0);
#endif
lightDir.xyz = tempVec / vec3(dist);
}