Skip to main content
GameDev.net gamedev.net
🔒 Locked

Ligth range vs. attenuation

Started by nexuz May 12, 2003 at 9:46 AM 3 replies 850+ views
Original Post
nexuz
nexuz
I''m working on a high level API that will be able to incorporate both Direct3D and OpenGL. This has went fairly smoothly, but I have now stumbled over a small problem. We have decided to use a simple range value for lights in the engine (to simplify creation of bounding spheres etc...). The problem is that OpenGL uses an attenuation formula (constant, linear, quadratic) to represent distance attenuation. So my question is: how can I, given a simple range value calculate constant, linear and quadratic values that I can use in OpenGL but that will still visually correspond with Direct3D.
Kern
Kern
D3D uses the same attenuation formula. The same data should give the same result.
nexuz
nexuz
Ok, so what if I turn my question around. How do I calculate a range from the constant, linear and quadratic attenuation values? I realise that it''s a question of finding the 0 solution for the attenuation equation. But does anyone know this solution?
Kern
Kern
There are infinite posibility, you set it to what looks good. It can be attenuated to zero before, at, or after the range limit if you want.

If you have a range of 9...
If you set the constant at 0.9 you start at 90% light.
If you add to that a linear attenuation of 0.1 it will drop to zero at the range limit.
Brother Bob
Brother Bob
The attenuation factor in OpenGL will, mathematically, never reach zero. The attenuation factor is calculated as

f = 1/(kc + kl*d + kq*d^2)

kc = constant attenuation
kl = linear
kq = quadratic
d = distance

and the only time f is zero is when one or more values approaches infinity. That is, when the object is infinitely far away or when kc and/or kl and/or kq is infinity (in which case no light at all, no matter how close the object is, will reach the object, it will always be zero).

So in short, you can''t have zero atenuation.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.