Polygon display of a box with normals showing strange lighting / coloring

Basically, I have two triangles that are slightly different in color (looks like a lighting problem due to incorrect normals). But I do not think so ...

More details

I have a simple cube (field) where each face consists of 6 vertices using the vertex buffer (I do not currently use the index buffer).

In addition to my vertices, I determined the normal values ​​for each face.

However, it seems that something is a little wrong with the normals (which I don't think there is a problem) and / or lighting.

enter image description here

Each face is drawn using WebGl.drawArrays using TRIANGLE_STRIP. The image shows the front face of the cube. Its vertices are listed below (note that the origin is the upper left corner of the front surface):

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 first triangle is lighter in color than the second triangle?

+6
source share
1 answer

The trick with a triangular strip is that each additional triangle receives one additional vertex, but three normal vectors. I would suggest that you did not specify enough normal vectors or indicate too many vertices.

+1
source

Source: https://habr.com/ru/post/971087/


All Articles