PDA

View Full Version : double sided lighting on polygons



Structural
11-25-2002, 10:46 PM
I'm beginning to understand this OpenGL stuff now, but there are still a few things a tad blurry.
One of these is the use of normals. And how they SHOULD be implemented.
At the moment I read my objects from an object file, and while reading the object I calculate the normals of each polygon. For normals to point the right direction the points have to be defined COUNTER CLOCKWISE.
Firstly, I was wondering whether this is according the OBJ-file standard. I thought since texture mapping is counter-clockwise normal calculation also should be counter-clockwise.

Secondly, I have a very simple model now, and some polygons can be viewed from two sides. However, lighting is only CALCULATED on one side, and applied to both sides...
For example, when my normal points down, and the light is directly ABOVE the polygon, it appears black. While when the light is below the polygon (and normal pointing down), the polygon is bright-RED on both sides.
I'd like light to be calculated no matter the normal direction (0 degrees or 180 degrees). Even preferably each side of the poly seperately.

TY

jebus
11-26-2002, 03:33 AM
i think if you want a polygon/vertex lit on both sides, you need to make it 2 polygons/vertices, each with their own normal.

jebus

BBrown
11-26-2002, 06:37 AM
You can enable two-sided lighting in OpenGL.

glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);

This will flip the normals on the back side of the polygon and light it correctly. Note that the lighting calculation will be slower than the default one sided calcs.

jmg
11-26-2002, 07:00 AM
> For normals to point the right direction the points have
> to be defined COUNTER CLOCKWISE.

Right. The direction of the surface normal is defined
by the order the vertices are specified.

> Firstly, I was wondering whether this is according the
> OBJ-file standard.

It's sort of rooted in vector algebra. When you take the
cross product of two vectors, the direction of the result
is perpendicular to the plane of the two operands, and
which side it "points out of" is given by the right-hand-
rule.

Which side your surface normal points out of is determined
from the order of the verts using the right-hand-rule.

> [snip] However, lighting is only CALCULATED on one side,
> and applied to both sides...

You need to first tell OpenGL to render both front and back
sides of polys. Then, set the current normal "correctly",
draw the poly, set the normal to be reversed, draw the same
poly again. I think this is correct -- let me know.

> While when the light is below the polygon (and normal
> pointing down), the polygon is bright-RED on both sides.

This doesn't make any sense to me. If you're specifying
your vertices in the order consistent with the direction
you've chosen for the normal, and if OpenGL is using the
default assumption that "CCW verts face front" (ie. the
right hand rule holds), I would think that the backside
(the top) of the poly should be black.

Can anyone clarify?