PDA

View Full Version : how to set normal properly ..

jyoung77
04-03-2007, 11:10 PM
Hi,

I draw a triangle according to these vertices, respectively: (0, 0, 0), (0, 1, 0), (1, 0, 0). I hope to have two face to show the same color. When setting the vertices' normal, I find out that (0, 0, -1) shows darker, real color than (0, 0, 1). Could some one kindly explain this difference? It looks to me that something translucent covers the triangle when using (0, 0, 1), and hence it appears less pleasing.

Very sorry that I'm a newbie. Any help is much appreciated.

Tony

API
04-04-2007, 12:40 AM
As I understand you have the lighting on, right?

If you are using a clockwise order the correct normal for the triangle you are defining is the (0,0,-1). If you use the normal (0,0,1) the lighting isn't computed correctly. For example, the emissive component:

E = EmissiveTriangle*EmissiveLight*dot(N, L)

N is the normal vector
L is the light vector

So depending on the vector you use, the light component computed can be different.

Overmind
04-04-2007, 02:01 AM
E = EmissiveTriangle*EmissiveLight*dot(N, L)That's the formula of diffuse.

Could some one kindly explain this difference? The lighting is normally computed one-sided. That is, if the light comes from the front (that is, the side where the normal is pointing), you get normal light. When it comes from the back side of the polygon, you get only the ambient part of the light, so it's relatively dark. The diffuse part will be negative (because of the formula API posted), so it is clamped to zero.

You can switch lighting to two-sided with glLightModel(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE). Don't forget to specify the material for the back side when you do this (either seperately or with GL_FRONT_AND_BACK).

API
04-08-2007, 06:41 AM
That's the formula of diffuse. Ups, you are right, sorry stupid mistake :p