FIXED: Something not right in GLSL attenuation function description

Trying to do some custom attenuation with lights in a deferred pass. I was referencing the attenuation function doc in the GLSL material doc here:

The code following the sentence “This function is essentially doing” seems incorrect and has a typo ( three L’s in in the second line re: attenScaleBiasRolll.y)

Can you confirm and correct?


Right, the 2nd line should be +=. I’ve updated it and fixed the typo, thanks!

Cool yeah I finally finagled that was would it should have been as well. On related note, is there a place to find how the scale/bias/roll is computed from the light’s atten parameters. They are pre-computed mainly because it requires some division right? Scale/X is 1/(atten far - atten near)? Bias/Y is the near as a fraction? Roll is still just the rolloff, or an inverse? Something like that?


I believe this is what the maths are:

attenScaleBiasRollX = 1 / - ( AttenFar - AttenNear )
attenScaleBiasRollY = AttenFar / ( AttenFar - AttenNear )
attenScaleBiasRollZ = AttenRolloff

Makes sense! Thanks Lucas!

1 Like

Yep that’s correct. The goal is to have near = 1 and far = 0, so we can multiply by PI/2 and plug it into sin(). I’ll update the docs with more info. Probably a cleaner way to do this but I think I was trying to work with the GL 1.2 fixed-function GL_ATTENUTATION back then, and then working this into shaders when they appeared (but really I forget, was done 15 years ago).

Malcolm interesting to know!

Just out of curiosity, what was the logic behind the attenuation start and attenuation end, and rolloff / falloff? I’ve always wondered what settings to enter to create lights default quadratic falloff. I realize that having artistic control over light radius means that falloff won’t necessarily falloff at the real life rate, but wondering what the correct settings might be for achieving something like that.

At the time we only had Phong which wasn’t realistic anyways, so we went with something a little more controllable. It likely is time we add a realistic attenuation mode though…