Contents / Previous / Next


Attenuation of Light

For real-world lights, the intensity of light decreases as distance from the light increases.

Since a directional light is infinitely far away, it doesn't make sense to attenuate its intensity over distance,
so attenuation is disabled for a directional light.

However, you might want to attenuate the light from a positional light.
OpenGL attenuates a light source by multiplying the contribution of that source by an attenuation factor:



where

d = distance between the light's position and the vertex
kc = GL_CONSTANT_ATTENUATION
kl = GL_LINEAR_ATTENUATION
kq = GL_QUADRATIC_ATTENUATION
By default, kc is 1.0 and both kl and kq are zero.
Example, you can give these parameters different values:
glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 2.0);
glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 1.0);
glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0.5);
Note that the ambient, diffuse, and specular contributions are all attenuated. Only the emission and global ambient values are not attenuated.