0

everyone! I'm currently working on a project with OpenGL. I know that rendering with indexed vertex attributes could save a lot of memory. That requires that every vertex attribute should be unique, or else the advantage of indexed rendering will not be true. So, here comes the question:

Say I want to render a statue with a cubic base from an OBJ file. As far as I know, for OBJ format, one vertex could be shared by several facets. That means the vertex could be specified with several different normals which are normals of the facets sharing the vertex.

Situation 1: For the statue, I want to average the normals of each vertex to get only one normal for this vertex, so indexed rendering could be used. What's more, the interpolated normals inside each facet gives the statue a more smooth appearance.

Situation 2: For the cubic base, I want use different normals for the vertex when rendering different sides to make the surface looks flat as it actually is.

Is there an universal way to handle the preceding situations?

Do I have to separate the statue and its base into different objects and treat them differently?

SilverX
  • 13
  • 3

1 Answers1

1

The OBJ file format makes it unnecessarily confusing (as do so many other resources): They mix up the terms "vertex" and "position".

A vertex is the whole tuple of position, normal and other attributes. If you change only one of the attributes you get a different vertex. As far as OpenGL is concerned it deals with vertices. So if a single position is shared by multiple facets but with differences in other attributes you're dealing with a different vertex.

If you want the best performance, then it's strongly advisably to expand those attribute level geometry specification into vertex level specification and rebuild the index list to refer to vertices instead of attributes (and OBJ refers to attributes).

With modern OpenGL it's actually possible to have multiple index buffers and in a vertex shader use the vertex ID to access the index buffers to get the indices into the attribute buffers. Doable? yes; efficient? Not so much, it introduces a double indirection.

datenwolf
  • 159,371
  • 13
  • 185
  • 298