Light Attenuation

In the real world, the amount of light a surface receives from a light source decreases the further it gets from the light source. (The amount of light is inversely proportional to the square of the distance.)

In OpenGL, by default, the light from a light source is the same, no matter how far you are from it.

Attenuation simulates the falloff of light with distance.

It uses a formula with 3 adjustable coefficients, so that you can vary light realistically, or semi-realistically:

                           1
illumination = -----------------------
                Kc + Kl * d + Kq * d^2

These coefficients are controlled by the following calls:

glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, Kc);
glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, Kl);
glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, Kq);


Example code: attenuate.c



next