PDA

View Full Version : vbo,ibo + Normals



lobbel
09-09-2010, 11:29 PM
Hello,

drawing a Cube with vbo is not difficult. I define 8 vertices and
then create some indices to draw triangles with that given 8 vertices. But how to handle the normals ? When I wanted to have normales for each triangles, I created as much vertices I need for triangles.

For example, draw a cube with triangles need normally 36 triangles. 6 Faces and 2 triangles per face. When I create a cube with redundant vertices (36) and define a normal for each vertex, it's easy to understand how to use the normals. But how
to handle it, with just 8 vertices and an amount of 12 normnals, or 6 normals.

regards,
lobbel

Nicholas Matear
09-09-2010, 11:45 PM
It isn't possible; each vertex can only be associated with a single normal. In this case, you would have to use 24 separate vertexes.

lobbel
09-10-2010, 12:07 AM
Hi,
tanks for the fast answer.
regards,
lobbel

Pierre Boudier
09-10-2010, 12:44 AM
for a cube, all normals are directly orthogonal to the plane of the triangle.
so I believe that you could use a geometry shader which would compute the normal with a cross product for each triangle. in that case, you don't need to even allocate any normal array, or to duplicate any vertex.

another approach is to bind two additional texture buffers in your vertex shader:
- the first one will be indexed by gl_VertexID and will return the index of the normal (size == 36)
- the second one will return the float value of the normals, and will be indexed by the value of the first texbo (size==6)

lobbel
09-10-2010, 01:40 AM
Thanks Pierre,
I think you are talking about instancing, right? Also considered about this.

regards,
lobbel

Pierre Boudier
09-10-2010, 02:11 AM
this was not instancing, but you could use it to solve your problem as well.