tomster1996's picture

Cube made of Triangles shading problem

I have a cube made of triangles but when I apply lighting, the triangles that are next to each other seem to have opposite normals. However the normals of the triangles on the same face of the cube are the same.
What might the problem be?

Here's the file containing the coordinates of the vertexs.

SIDE1 
 
triangle1
v1
-5
-5
0
 
v2
5
-5
0
 
v3
-5
-5
10
 
triangle2
v1
5
-5
0
 
v2 
5
-5
10
 
v3
-5
-5
10
 
SIDE2
 
triangle1
v1
-5
5
0
 
v2
5
5
0
 
v3
-5
5
10
 
triangle2
v1
5
5
10
 
v2 
5
5
0
 
v3
-5
5
10
 
SIDE3
 
triangle1
v1
-5
-5
0
 
v2
-5
-5
10
 
v3
-5
5
0
 
triangle2
v1
-5
-5
10
 
v2 
-5
5
0
 
v3
-5
5
10
 
SIDE4
 
triangle1
v1
5
-5
0
 
v2
5
-5
10
 
v3
5
5
0
 
triangle2
v1
5
-5
10
 
v2 
5
5
0
 
v3
5
5
10
 
 
SIDE5
 
triangle1
v1
-5
-5
10
 
v2
5
-5
10
 
v3
5
5
10
 
triangle2
v1
5
5
10
 
v2 
-5
5
10
 
v3
-5
-5
10
 
SIDE6
 
triangle1
v1
-5
-5
0
 
v2
5
-5
0
 
v3
5
5
0
 
triangle2
v1
5
5
0
 
v2 
-5
5
0
 
v3
-5
-5
0

Here's the file containing the normals of each triangle.

SIDE1
 
n1
0
-1
0
 
n2
0
-1
0
 
SIDE2
 
n1
0
1
0
 
n2
0
1
0
 
SIDE3
 
n1
-1
0
0
 
n2
-1
0
0
 
SIDE4
 
n1
1
0
0
 
n2
1
0
0
 
SIDE3
 
n1
-1
0
0
 
n2
-1
0
0
 
SIDE4
 
n1
1
0
0
 
n2
1
0
0
 
SIDE5
 
n1
0
0
1
 
n2
0
0
1
 
SIDE6
 
n1
0
0
-1
 
n2
0
0
-1
Inline Images

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Inertia's picture

One easy way to debug this: grab a pencil and paper, choose a suitable coordinate system and plot your triangles one after the other. The errors will show quickly that way.

tomster1996's picture

Thanks, and can I quickly ask, how do you color the triangles? When i use GL.Color3(System.Drawing.Color.Red), it works fine with the lighting turned off, but if i turn on lighting the triangles stay grey.

c2woody's picture

The orientation of the triangles determines the front/back face, and the two triangles making up a quad face in your code have different orientation each. This only works if twosided lighting is enabled, otherwise assure that the orientation is equal.

tomster1996's picture

GL.LightModel(LightModelParameter.LightModelTwoSide, 1);
Does mean two sided lighting is enabled? Whatever the value is in the final parameter of this function, the problem still persists.

c2woody's picture
Quote:

Does mean two sided lighting is enabled?

Please check some OpenGL resources about what's needed. Usually LightModelTwoSide set to 1 as well as ColorMaterial set to FrontAndBack for the relevant material may be enough.

But, as already posted, get your orientations correct first unless you have a *serious* reason to use inconsistent ones.

Inertia's picture

Once you enable fixed-function lighting, you have to specify light and material parameters, otherwise defaults will be used.

http://www.glprogramming.com/red/chapter05.html