Archived

This topic is now archived and is closed to further replies.

Daivuk

Lighting range !?!?! Attenuate

Recommended Posts

OK, I got a problem here with the OpenGL lighting system. WHAT I WANT TO DO IS : I have a light, and its range is 200 meters. Mean that at 200 meters, the objet is dark. And at 0 meters, he's full bright. Simply a linear thing. So, I tried to play with : GL_CONSTANT_ATTENUATION GL_LINEAR_ATTENUATION GL_QUADRATIC_ATTENUATION But never got the simple result that I want. [edited by - daivuk on August 9, 2003 3:02:57 PM]

Share this post


Link to post
Share on other sites
It is impossible with standart OpenGL Lighting. The OpenGL Attenuation is defined as:

Attenuation = 1 / (AC + AL * ||V-L|| + AQ * ||V-L||^2)

where

AC...Constant Attenuation
AL...Linear Attenuation
AQ...Quadratic Attenuation
V...Vertex Position
L...Light Position
||..|| means the lenght of the Vector
^2 means squared

So if you want the attenuation to be 0 the component by which 1 has to be divided has to be infinity and that''s quite impossible. So you can never implement a lighting system as you want to. You can use vertex programs to code your own lighting.

Correct me if I''m wrong.

--------------------------------------------------------

"If it looks good, it is good computer graphics"
"If it looks like computer graphics, it is bad computer graphics"

Corrail
corrail@gmx.at
ICQ#59184081

Share this post


Link to post
Share on other sites
Hum, exactly like I think it is...
ok thanks.. I''ll keep these setting (with Linear attenuation of OpenGL)
It''s not PERFECT, but it''s look good, for a game made by my own just for fun !

Share this post


Link to post
Share on other sites
Sure, you might never get 0, but you''ll get a point that is completely dark... I''m sure it is possible to use the opengl lighting formula to calculate where 200m would be below a certain light level that appears entirely dark...

Vertex programs?? Surely that''s overcomplicating the issue? Unless you mean what I describe below...

If you did implement lighting yourself, basically by using glcolor3f, you could set a ''cutoff'' point of 200m. Or you could implement a simple lighting system using pythagoras'' theorem:


// PSEUDO CODE


// Calculate light level for the vertex

light_level = 1.0-(sqrt(sqr(x_distance)+sqr(y_distance))/200.0);

// If light level is lower than 0 (past the 200 metre point), make it 0

If light_level<0.0 light_level = 0.0;

// set the light level for the vertex

glcolor3f(light_level, light_level, light_level);

// The draw your vertex


This probably isn''t horribly clear, but hopefully it will give you some ideas. To implement your own system like this properly, however, you''ll need to take into account the lighting and vertex normals, something the OpenGL lighting system does automatically for you.

Jeff

Share this post


Link to post
Share on other sites