如何在不同情况下处理具有多个法线的顶点?

时间:2022-09-10 21:23:53

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:

大家!我目前正在开发一个使用OpenGL的项目。我知道使用索引顶点属性进行渲染可以节省大量内存。这要求每个顶点属性都应该是唯一的,否则索引渲染的优势将不会成立。所以,问题就出现了:

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.

假设我想从OBJ文件渲染具有立方基础的雕像。据我所知,对于OBJ格式,一个顶点可以由多个方面共享。这意味着顶点可以用几个不同的法线指定,这些法线是共享顶点的面的法线。

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.

情况1:对于雕像,我想平均每个顶点的法线以仅获得该顶点的一个法线,因此可以使用索引渲染。更重要的是,每个刻面内的插值法线赋予雕像更光滑的外观。

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.

情况2:对于立方基础,我想在渲染不同边时使用不同法线作为顶点,以使表面看起来像实际一样平坦。

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?

我是否必须将雕像及其底座分成不同的物体并以不同的方式对待它们?

1 个解决方案

#1


1  

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

OBJ文件格式使它不必要地混淆(正如许多其他资源一样):它们混淆了术语“顶点”和“位置”。

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.

顶点是位置,法线和其他属性的整个元组。如果只更改其中一个属性,则会获得不同的顶点。就OpenGL而言,它处理顶点。因此,如果单个位置由多个方面共享但在其他属性中存在差异,那么您将处理不同的顶点。

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).

如果您希望获得最佳性能,那么强烈建议将这些属性级别几何规范扩展为顶点级别规范,并重建索引列表以引用顶点而不是属性(而OBJ指的是属性)。

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.

使用现代OpenGL,实际上可以有多个索引缓冲区,并且在顶点着色器中使用顶点ID来访问索引缓冲区以将索引引入属性缓冲区。可行?是;有效?与其说,它引入了双重间接。

#1


1  

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

OBJ文件格式使它不必要地混淆(正如许多其他资源一样):它们混淆了术语“顶点”和“位置”。

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.

顶点是位置,法线和其他属性的整个元组。如果只更改其中一个属性,则会获得不同的顶点。就OpenGL而言,它处理顶点。因此,如果单个位置由多个方面共享但在其他属性中存在差异,那么您将处理不同的顶点。

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).

如果您希望获得最佳性能,那么强烈建议将这些属性级别几何规范扩展为顶点级别规范,并重建索引列表以引用顶点而不是属性(而OBJ指的是属性)。

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.

使用现代OpenGL,实际上可以有多个索引缓冲区,并且在顶点着色器中使用顶点ID来访问索引缓冲区以将索引引入属性缓冲区。可行?是;有效?与其说,它引入了双重间接。