Point light shader question

This topic is 2632 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hey guys,

I am trying to implement a simple point light shader in glsl and not sure which equation calculates the right attenuation from the below two links:

1. XNA shader programming tutorials says attenuation = 1 - dot (L/r , L/r). I like this one because of the point light radius parameter we could pass in.
2. Now Lighthouse3d tutorials (and most text books) says: attenuation = 1 / (KC + (kL * D) + (KQ * D * D)).

Now which one do you guys think gives the right attenuation? If both are right what is the relation between them?

Share on other sites
Physically, lights will fall off based on the inverse of distance squared (similar to a magnetic field or a gravitational field). Of course games and other forms of computer graphics aren't usually physically-correct, and lighting attenuation is no exception. That second equation you listed is what all OpenGL/DirectX GPU's used in their fixed-function lighting pipelines, which is why you probably see it everywhere. With that it's possible to be physically-correct if you want to, or you can customize it to have a more linear or constant falloff. Falloffs like the first one you listed have become a lot more common now that people are using shaders for everything, and can therefore implement whatever attenuation function they like. Something simple that one can be nice because A) they're cheap, and B) they allow you to define a distance at which the light's influence reaches zero (which doesn't happen if you use an inverse square falloff, or the GL/DX falloff). This can be particularly important for determining which which lights affect a mesh, or for using bounding volumes for a light in a deferred renderer.

Share on other sites
Thanks for your Reply MJP .. that helped!
I found some explanations here : http://developer.dow...el_Lighting.pdf that was great as well!
I am going for the solution 1 because that meets all my needs for the application!
Thanks again!

1. 1
2. 2
Rutin
20
3. 3
khawk
17
4. 4
A4L
14
5. 5

• 12
• 16
• 26
• 10
• 44
• Forum Statistics

• Total Topics
633759
• Total Posts
3013719
×