Attenuating light
Light attenuation, also known as gradual loss in intensity, is what we're going to use when creating the effect of a light source that is slowly bleeding away. It essentially comes down to using yet another formula inside the light pass shader. There are many variations of attenuating light that work for different purposes. Let's take a look:
uniform sampler2D texture; uniform vec3 AmbientLight; uniform vec3 LightPosition; uniform vec3 LightColor; uniform float LightRadius; uniform float LightFalloff; void main() { vec4 pixel = texture2D(texture, gl_TexCoord[0].xy); // Nornalized light vector and distance to the light surface. vec3 L = LightPosition - gl_FragCoord.xyz; float distance = length(L); float d = max(distance - LightRadius, 0); L /= distance; // calculate basic attenuation float attenuation = 1 / pow(d/LightRadius + 1, 2); attenuation = (attenuation - LightFalloff) / (1 - LightFalloff); attenuation = max(attenuation, 0...