View Full Version : Lighting Problem

04-19-2009, 01:43 AM
I have a 3D maze right now and I want to add some lighting. But I can't get it work correctly. The front of the wall is lighted correctly but when I went to its back it's not..

Lighting in X works fine


Lighting in X doesn't work



Where: X = wall
0 = camera

Here's the coordinates.

glNormal3f( 0.0f, 0.0f, 1.0f);
X Y Z Texture coordinates
-4.0 1.0 -4.0 0.0 1.0
-4.0 0.0 -4.0 0.0 0.0
-1.0 0.0 -4.0 1.0 0.0

-4.0 1.0 -4.0 0.0 1.0
-1.0 1.0 -4.0 1.0 1.0
-1.0 0.0 -4.0 1.0 0.0

My question is. How to make the lighting works properly in the back?

04-19-2009, 01:53 AM
A wall with non-zero thickness is made of 6 rectangles, not just 1.

If really you want to stay with 1 rectangle per wall, you have to play with two-sided lighting and disable backface culling.

Search for "two-sided" on each of these pages :

04-19-2009, 08:33 AM
If you want a polygon to be visible from either side and also properly lit, do this:

// in your GL init code:
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); // ensures proper lighting for two-sided polygons

// in your scene draw code:
glDisable(GL_CULL_FACE); // disable backface culling so both sides of the wall are visible
// draw polygons
glEnable(GL_CULL_FACE); // enable backface culling again for other geometry

FYI: GL_LIGHT_MODEL_TWO_SIDE really just tells the GL renderer to invert the glNormal when it draws the back facing pixels.

04-20-2009, 01:53 AM
Ok thanks. I'll try it out.

Thanks again.