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_ATTENUATIONBy default, kc is 1.0 and both kl and kq are zero.
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.