Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Box polygon rendering w/ normals showing weird lighting/coloring

Basically, I have 2 triangles that appear slightly different in color (looks like a lighting issue due to incorrect normals). But I don't think this is the case...

Details

I have a simple cube (box), where each face is composed of 6 vertices using a vertex buffer (I am not using an index buffer at the moment).

In addition to my vertices I have defined the normal values for each face.

However, it appears that something is slightly wrong with either the normals (which I don't think there is an issue with) and/or the lighting.

enter image description here

Each face is drawn using WebGl.drawArrays using TRIANGLE_STRIP. The image is showing the front face of the cube. The following are its vertices (note that the origin is the top-left corner of the front face):

            0, 1, 0,
            0, 0, 0,
            1, 0, 0,

            1, 0, 0,
            1, 1, 0,
            0, 1, 0

The following are its normals:

            0, 0, 1,
            0, 0, 1,
            0, 0, 1,

            0, 0, 1,
            0, 0, 1,
            0, 0, 1

Question

Any ideas why the 1st triangle is lighter in color than the 2nd triangle?

like image 420
AlvinfromDiaspar Avatar asked Jun 20 '14 06:06

AlvinfromDiaspar


1 Answers

The trick with triangle strip is that each additional triangle gets one additional vertex but three normal vectors. I would guess you are not specifying enough normal vectors or specifying too many vertices.

like image 75
Adam McCormick Avatar answered Oct 19 '22 11:10

Adam McCormick