Open GL lights

BlitzMax Forums/BlitzMax OpenGL Programming/Open GL lights

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

The OpenGL Red Book says that the "attenuation factor" is calculated as:

a = 1.0/(c + l*d +q*d*d)

Where c, l and q are the constant, linear and quadratic factors and d is the distance from the light to the vertex in question. a is clamped so that it is always in the range 0.0 to 1.0. The vertex colour is multiplied by a in order to get the correct output colour (and the colours are smoothed across the polygon between vertices).

So what you want is a=1.0 when d=0.0 and you also want a=0.0 when d=(you maximum range). It's quite difficult to get a to be 0.0 when d is greater than some distance, but you can get it fairly dim. Setting c=0.0, l=(some small value) and q=(some very tiny value) tends to work OK. I think Direct3D allows you to specify a maximum range for a light, but all that's doing is just switching off the light if the surface is too far away, which you can test for yourself.