Open GL lights

BlitzMax Forums/OpenGL Module/Open GL lights

AdrianT(Posted 2005) [#1]
Currently I'm mwssing around with openGL and 3D, working on an art path and .B3D compatibility.

Having a few problems with lights, each light in the scene has these parameters:

Ambient ( r,g,b,1 )
Diffuse ( r,g,b,1 )
Specular ( r,g,b,1 )

The above are pretty straight forward, just like blitz only local to each light


Constant( % )
Linear( % )
Quadratic( % )

change light range and falloff, but I'm totaly lost in regards to how they work, being used to simply stating a range and having a linear fall off.

how do I go about getting a simple linear falloff with user defined range? Messing around with these last numbers cause a lot of confusion.

stil lgot to learn about materials in order to get brush shinyness right, but thats looking to be more difficult than I imagined, since the lighting and material properties work together in GL.

Paret of the reason I'm posting is to get any suggestions in regards to how to get blitz like lighting, naturally with proper falloff that ends at a specific range rather than being infinite ;)


teamonkey(Posted 2005) [#2]
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.


Chris C(Posted 2005) [#3]
this any use?

c#=0
l#=0.01
q#=0.000001
For d#=0 To 500 Step 10
a# = 1.0/(c# + l#*d# +q#*d#*d#)
If a#<0 Then a#=0
If a#>1 Then a#=1
Print "distance D="+Int(d#)+" colour 255="+int(255*a#)
next