GL light attenutation

I have probably read a dozen threads on light attenuation. Whenever someone asks about a light radius, I see two kinds of responses:

-“Use light attenation, using the glLightf GL_QUADRATIC blah blah blah to control lights. The function is an inverse of the cosine of the blah blah blah…”
This tells me nothing, excpe that this person doesn’t know the answer.

-“You can’t cut off the light. Write your own routine to calculate vertex lights.”
I’ve actually written vertex light calculations, lightmappers, and projection shadows. Understanding the 3D math is not an issue. The problem is that GL lights are much more highly optimized than anything I can write. I am using these lights on the “static meshes” in my maps, which are way too high-poly to let the CPU handle lights.

I want a nice, sharp cutoff of the light, with a definite radius. If GLlights have to attenuate forever, then I want the best estimation of a linear fade, and I’ll manually enable/disable lights that are out of range.

Come on, someone’s got to actually understand the lighting equation!

Thanks.

[This message has been edited by halo (edited 12-19-2003).]

The problem is that GL lights are much more highly optimized than anything I can write. I am using these lights on the “static meshes” in my maps, which are way too high-poly to let the CPU handle lights.

You could do it in a vertex shader.

Come on, someone’s got to actually understand the lighting equation!

I don’t need to. I’ve got vertex/fragment shaders.

The attenuation equation is 1 / (ad^2 + bd + c), where a, b and c are the quadratic, linear and constant factors. I would suggest trying to plot a few graphs with different values of a, b and c to see how it behaves. Compare it to the function y=1.0, which defines the point above which the light is at full brightness, and to y=0.0, which is the point where it’s fully dark.

Since the function is of the form y=1/x, it’s not possible to get an exact linear fade. If that’s what you want, either use a vertex shader like Korval said or burn a texture unit or two and use attenuation mapping (see http://www.ronfrazier.net/apparition/index.asp?appmain=research/per_pixel_lighting.html , the section titled “Calculating attenuation”).

– Tom

(Edit: wrong URL)

[This message has been edited by Tom Nuydens (edited 12-20-2003).]

Thanks. The equation actually makes sense.