Skip to main content
gamedev.net
🔒 Locked

Attenuation

Started by Greg K 2 replies 500+ views
Original Post
Greg K
Greg K
http://www.flipcode.com/tutorials/tut_dx8shaders.shtml I was looking through this tutorial on doing my own lighting with vertex shaders. Unfortunatly I don't know how the attenuation function works. Attenuation is the decay of the light over time. The function he uses here has three variables you can use to change the light. Does anyone know what they really are? I mean this is an excerpt from the tutorial: fatt = 1/(A0 + A1 * dl + A2 * dl * dl) (dl is distance to light) In the above equation, A0, A1 and A2 are known as the attenuation constants. As d goes to infinity, attenuation becomes very small but not zero. By varying the three constants A0, A1, A2, interesting effects can be achieved. Radial distance falloff: A1 = 0 and A2 > 0 Linear falloff: A1 > 0 and A2 = 0 If the light is too close to the surface, then, attenuation becomes very large, making the light too bright. To avoid this, set A0 to 1 or greater. I am writing an exporter for max so I can take the lights from max and display them in my game. I don't know how to change a float (farAtten in MAX) into these three constants. Any help clearing up this matter is greatly appreciated. -Greg [edited by - Greg K on December 23, 2002 3:42:24 AM]
Yann L
Yann L
I guess that''s a typo in your post, but attenuation is not the decay of light over time, but over distance.

Now, the A0, A1 and A2 are the attenuation factors: constant (A0), linear (A1), and quadratic (A2). The standard attenuation function allows for those three different types of light falloff functions, they may be used individually or combined. In the real world, light intensity decays with a quadratic function, this would be A2 in your equation. But in computer graphics, a quadratic attenuation might not look that good (the light will be attenuated too fast), due to the limited dynamic range of representable intensities.

3DS Max uses a very non-realistic (but easily adjustable) attenuation model: you explicitely specify the near and far ranges. The light stays at constant intensity withing the near range, and falls off in a linear way, until it reaches 0 at the far range. You cannot reproduce this behaviour with your per-pixel attenuation function, because Max''s way of doing attenuation has a fixed distance limit, whereas the more realistic perpixel function attenuates up to infinity. But you can try to approximate it, by using an appropriate value for the linear falloff, A1.

For more realistic lighting, you should use zero for A0, a medium value for A1, and a smaller value for A2. This will give you a basic linear attenuation, with a little touch of quadratic light-glow behaviour, without attenuating it too much. But this type of light will behave differently to 3DSMax lightsources.

/ Yann
Greg K
Greg K
Well thank you very much for your very helpful explanation. Very much appreciated.
-Greg

Topic Locked

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

Sign in to reply to this topic.