VertexArrays and three normals for triangle.

Hi All,

Yes, we have already discovered that it is not possible to use 3 normals for each triangles using vertex arrays.

The question is: does OpenGL provide a faster method than calling:


glNormal3f(...); // first
glVertex3f(...);
glNormal3f(...); // second
glVertex3f(...);
glNormal3f(...); // third
glVertex3f(...);

for each triangle?

Can vertex arrays be combined with a different approach to go faster than this?

Thanks,

Alberto

“not possible to use 3 normals for each triangles using vertex arrays”
You got that wrong, it is possible. However, 3 normals for a single vertex is indeed not possible, so you have to duplicate vertices whenever normal is not shared between adjacent triangles.

Thanks ZbuffeR,

I find it difficult to estimate the benefit of using vertex arrays if you need to duplicate some vertices even 100 times (in the case of a triangle fan with 100 triangles)…

Where is the break even point between the standard approach and vertex arrays?

I believed to use such a poor approach using the code above but now I am quite proud of it :slight_smile:

Thanks,

Alberto

For duplicated vertexes you use an indexed vertex array with glDrawElements. In any event, use of vertex arrays - even with duplicates - can often be faster than glBegin/glEnd purely because they allow for larger batch sizes which gives you more efficient use of bandwidth.

Using duplicated vertices means prepare a duplicate array from the one we use for geometry and to update it every time the first has changed.

I am really surprised that vertex array don’t support this so common drawign approach (more than one normal per vertex)

Regarding this issue, I submitted an “indexing per attribute” feature request in October 2009:

http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Main=51439&Number=265744

I cant see why you cant send any many normals per vertex as you want. To do this you can use upto the 16 (max) generic vertex attribute arrays - so this may rule out really old GL versions.
Additionally, if you have vertex texture lookup, you could supply normals via textures or per pixel in the pixel shader.

BionicBytes,

Can you please make an example of this approach?

Thanks,

Alberto

Let me check if I have understood well this approach:

  1. I need to specify my normals inside the glVertexAttribPointer, I can add a maximun of 16 values (5 normals)
  2. I need to use a shader that during vertex rendering applies this normals to the vertex

The question are:

  1. What happens if we have 100 triangles (triangle fan) meeting at the same vertex? We would need 100 normals…
  2. How can we get current triangle index to pick the proper normal for this vertex?

Thanks,

Alberto

I am really surprised that vertex array don’t support this so common drawign approach (more than one normal per vertex)

Your code doesn’t support more than 1 normal per vertex.

This is a triangle, as rendered with immediate mode:


glNormal3f(...); // first
glVertex3f(...);
glNormal3f(...); // second
glVertex3f(...);
glNormal3f(...); // third
glVertex3f(...);

This is a vertex of that triangle:


glNormal3f(...); // second
glVertex3f(...);

Do you see the one normal in that vertex? It’s no different for array rendering.

Alfonse,

You are right, but we have many triangles meeting at the same vertex and we need a different normal for each triangle. So we are doing:

glNormal3f(0,1,0); // only this changes
glVertex3f(3.32323, 4343.4343, 545.2323);

glNormal3f(0,1,1); // only this changes
glVertex3f(3.32323, 4343.4343, 545.2323);

glNormal3f(0,0,1); // only this changes
glVertex3f(3.32323, 4343.4343, 545.2323);

Thanks,

Alberto

Alfonse is right, it is the same thing to send several times the same vertex data with immediate mode OR vertex array.

The difference still being the high price of each immediate call, versus the almost-no-price on vertex array.

ZbuffeR,

Now I see the point. You think on the OpenGL side, while I think on the C++ programming side.

I mean, to use vertex arrays and specifing 3 normal for each triangle (one per vertex) we need to take our C++ vertex array (no duplicates) and make a new one for OpenGL (with duplicates) tu be used from OpenGL vertex arrays.

For huge meshes this means a busy machine for a while.

I was trying to understand if there was a way to avoid this array duplication in some way (mixed approaches, shaders, etc.). Is it possible?

Thanks,

Alberto