1

Suppose i have triangulated mesh, then i have a lot of repeated positions between triangles, and index buffer may become very handy in this case.

But if i also need normals, then no gain, because all triangles have different normals. So tuple { position, normal } is unique. If add texture coordinates and other features, then i don't understand for what purpose index buffer is needed?

Yola
  • 18,496
  • 11
  • 65
  • 106

1 Answers1

6

Normals are often stored per-vertex, and not per-face (face being a triangle). If you have a number of triangles sharing a single vertex, you can average all the normals of all the faces to get the normal of the vertex. Now you just interpolate those normals when rendering and you have a smooth surface. Some file types are even designed this way, in that you cannot store a normal for each triangle, only a normal for each vertex. It is a very common way of storing and interpreting normals, especially in real time graphics.

Texture coordinates are most of the time per vertex as well. If you have some smooth surface, you most likely will not need to have the texture suddenly change. To get seems on the surface you simply put them on the texture but keep the coordinates the same. Thus you can store texture coordinates per vertex perfectly fine.

Moral of the story is that there are very very very few things that actually needs to be stored per-face. Most of the data you need can be converted to a per-vertex representation. Normals and texture coordinates in particular are often wanted per vertex instead of per face.

Also on a side note, if you don't want smooth surfaces, but want flat surfaces (so you can see the triangles), you can actually pick one vertex for each face and only use its extra data for the surface. So for example, the first vertex of each triangle will store the normal, texture coordinates and so on for said triangle. This will leave you with a number of vertices at the end with extra data you don't need, but that's a lot better than a lot more duplicated vertices. In OpenGL this technique can be achieved through flat interpolation in the shaders, I'm not sure what the Direct3D equivalent is.

Invalid
  • 1,870
  • 1
  • 16
  • 22
  • (+1) I have triangles, usually every vertex participates in more than 3 (6) triangles. So, some triangles will share the same normal though not in one plane. – Yola Jul 30 '14 at 15:04
  • 2
    As explained in my first section, this is actually wanted if you want smooth shading and pretend the surface is smooth instead of triangulated. If you want actual flat shading you would apply the technique from my last section. It can happen you need a few duplicates to achieve this, but that's _still_ better than the amount of duplicates you'd have without an index buffer. – Invalid Jul 30 '14 at 15:07
  • Thank you Invalid for sharing your very helpful answer. Please could you elaborate on the suggestion in your last paragraph, as to how this might be implemented with the vbos and ebos of modern OpenGL, if that's what you intended ? My use case is for a flat-shaded mesh in modern OpenGL, in which adjacent triangles are almost never coplanar. – Simon Sep 27 '22 at 14:15