PDA

View Full Version : Fade lights in a distance



LordFrost
03-14-2001, 12:32 PM
Hi all gurus in here http://www.opengl.org/discussion_boards/ubb/wink.gif
I want to have a light that fades with distance (illuminates closer objects, lets farther objects dark, e. g. moving a torch around). Of course I could first render the bright objects, disable the light, render the ones that are a bit darker, but there should be a better solution, or am I wrong?

Bob
03-14-2001, 01:47 PM
Use OpenGL's attenuation feature.

glLightf(GL_LIGHTn, GL_CONSTANT_ATTENUATION, kc);
glLightf(GL_LIGHTn, GL_LINEAR_ATTENUATION, kl);
glLightf(GL_LIGHTn, GL_QUADRATIC_ATTENUATION, kq);

Damping factor f = 1.0 / (kc + r*kl + r*r*kq).

r is the distance from the light to the vertex being lit.
kc/kl/kq is constant/linear/quadratic attenuation factors, controlling how much the light is dampend when you get further away.

LordFrost
03-14-2001, 02:24 PM
Thanx alot
It works great (a bit slow, though).