I recently decided to switch to an other Attenuation formula for the lights in my engines. The formula I've had before didn't support different falloffs but only straight linear ones.
When I started to implement my lighting-system I've used the D3D10-Book here at GDNet, this Article to be exact: http://wiki.gamedev....t_Light_Sources
This is their code:
float Attenuation
(
float distance,
float range,
float a,
float b,
float c
)
{
float Atten = 1 / ( a * distance * distance + b * distance + c );
// Use the step() intrinsic to clamp light to
// zero out of its defined range
return step(distance, range) * saturate( Atten );
}
Only problem is that the attenuation-formula doesn't seem to work correctly. So I used another one I've found somewhere back then.
Now that I am back at the problem I'd like to know what's wrong with the formula suggested in the article.
Here are the results I get with all 3 parameters set to 1:
When I change the light-radius to something bigger I see that the falloff doesn't change with the Radius. Did I maybe miss something? Or did the writers of the Book?
I've noticed that their code doesn't compile out of the box:
They declare the attenuation as "float Atten", but use "atten" in that saturate in the last line.
Probably they forgot something other as well...
Or maybe one of you got another, working, formula for me. That would be great as well