Jump to content
  • Advertisement


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


Lighting range !?!?! Attenuate

This topic is 5526 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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)


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"


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:


// 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.


Share this post

Link to post
Share on other sites
ya, but I know how to do it myself
I made a lightmap calculator so.

But this can take more CPU time than using OpenGL lighting.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!