O'Reilly logo

Mastering SFML Game Development by Raimondas Pupius

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required