PDA

View Full Version : Lighting problem ...



Humus
03-30-2000, 09:57 PM
I have a scene with positional light in the middle and some ground built of about 2000 polys around it. The light works fine, but there is one little problem ... objects that are far away is lighted as much as those that is close to the light. What do i need to do to change this, obviously the following code wasn't enough:



glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 2.0);
glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 1.0);
glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0.5);


[This message has been edited by Humus (edited 03-30-2000).]

Bob
03-31-2000, 04:27 AM
Hello

OpenGL uses the dotproduct to determine the amount of light on each vertex/poygon. If you pass a normalized normalvector (length=1 unit), all objects will be lit with the same amount of light, independent of distance. What you have to do, is shorten the normal for objects further away from the lightsource. This will cause the dotproduct to "generate" a smaller amount of light.

Bob

Humus
03-31-2000, 05:16 AM
hmm ... but what about this that i have copied from the OpenGL programming guide?

"For real-world lights, the intensity of light decreases as distance from the light increases. Since a directional light is infinitely far away, it doesn't make sense to attenuate its intensity over distance, so attenuation is disabled for a directional light. However, you might want to attenuate the light from a positional light. OpenGL attenuates a light source by multiplying the contribution of that source by an attenuation factor:

http://heron.cc.ukans.edu/ebt-bin/nph-dweb/dynaweb/SGI_Developer/OpenGL_PG/@raster?scale=FALSE;filename=eq602.gif;target=1113 3

where

d = distance between the light's position and the vertex

kc = GL_CONSTANT_ATTENUATION

kl = GL_LINEAR_ATTENUATION

kq = GL_QUADRATIC_ATTENUATION

By default, kc is 1.0 and both kl and kq are zero, but you can give these parameters different values:

glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 2.0);
glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 1.0);
glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0.5);
Note that the ambient, diffuse, and specular contributions are all attenuated. Only the emission and global ambient values aren't attenuated. Also note that since attenuation requires an additional division (and possibly more math) for each calculated color, using attenuated lights may slow down application performance."

Shouldn't i use this, or am i misunderstanding something?

Bob
04-01-2000, 04:33 AM
Hello, me again

Grabbed my copy of the red book and read (well, you wrote it too): "...so attenuation is disabled for a directional light".

Make sure your light is a positional light. This means that w-coordinate (the fourth) has to be non-zero. You can set it to 1.

By the way, I made a small program, and it worked with attenuation.

Bob

Humus
04-01-2000, 06:19 AM
Hi!

My light is a positional light, i have tested to change the w to 0 to see if there was a difference, and it really was, and i can clearly see that the light is in the position i have set it so. But i just can't get the attenuation to work ...
I guess it could be my drivers, since matrox seams to prioritize incresing DirectX performace over enable some basic functionality in the OpenGL. There are still features in hardware that is not available in OpenGL but has been available in DirectKex all the time, for example the stencil buffer.

However, i would appreciate if you could send your little attenuation program to me please.