#### Archived

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

# lighting is playing a mean trick on me

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

## Recommended Posts

The problem: The light's I'm positioning and enable are not where I put them Situation: I'm trying to shine a light on something that is centered around the origin and is on the YX plane (it's a square). I'm using gluLookAt, called in my DrawScene function (using the same window maker as NeHe). The position of the reference point (where I'm looking) is the origin, the position of eye point is ( 0,0,135 ). The light is positioned at ( 0,0,10,1 ), (the w value is a 1 making it positional) and it's direction is ( 0,0,-1 ). The square is textured, GL_TEXTURE_2D is enabled. Ambient is set to ( 0,0,0 ), diffuse and specular components are set to ( 0.6,0.6,0.6 ). The light is being positioned after gluLookAt in my drawscene function. The problem expanded: Only the top half (moving along positive y-axis) of the square gets light. If I translate the square upwards it gets more light. If I narrow the spot light cutoff I have to translate higher to keep the square lit. If I move my eyepoint up it has the same effect as translating down. I cannot, at any point, get the spot light to show up as a lit circle surrounded by less or no light on the table. My Cry For Help: I am floored by this. I have no clue what is wrong, or what is happening - let alone how to fix it. I've been messing around with this using Nehe, Gamedev and OpenGL: Programming Guide as references and I cannot figure this out. I appreciate you taking the time to read this essay, I appreciate even more if you extend your expense of time by givin' this problem a good think. _______________________ This post brought to you by the number 12...and Darren [edited by - cladinshadow on April 10, 2004 6:44:58 PM]

##### Share on other sites
I am not really sure what you see but just a note: OpenGL Lighting is per-vertex lighting, which means, the color of each vertex is multiplied with the light value at that position, as the colors are smoothed (GL_SMOOTH_SHADE) it looks like the quad is lighted in some way. If you have a quad located like this:

1-----------------2|                 ||                 ||                 ||        *        ||      Light      ||                 ||                 |4-----------------3

the vertices will all have about the same value (lets say (0.5,0.5,0.5). The point in the middle will be a combination of those values, result = (0.5,0.5,0.5), not the bright dot as it would be in real life. This can be solved by dividing the quad in smaller quads (even better, triangles) so the lighting will be measured at more places, therefore be more realistic. Anyway, you might have heard this a few times already but OGL Lighting SUCKS, you should check out lightmapping and such as soon as it doesn''t fit your needs anymore.

Another note: have you set the normals right?

WWW.TREEPENGUIN.TK

##### Share on other sites
Yea, I also think that OGL has a lot pf problems concerning lighting. To properly light an object, I have to specify an ambient light + the light source. Even this may not be enough sometimes.

I think its probably the coordinates specified for the light source and the direction.. dunno. am no expert!

One could use, maybe, shadows for adding realism on 3d objects...? I saw a few tutorials on the web, but don''t remember where...

##### Share on other sites
NeHe has a shadowing example too. Anyway, i really really reccommend lightmapping or some other technique that is not per-vertex (however, i think you should know how to use it so you can whenever you need it, it is a lot easier than other techniques).

1. 1
2. 2
3. 3
frob
15
4. 4
5. 5

• 20
• 12
• 13
• 14
• 80
• ### Forum Statistics

• Total Topics
632144
• Total Posts
3004405

×