This topic is 2939 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
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!

• Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 9
• 11
• 15
• 21
• 26
×

Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!