简体   繁体   English

消除“顶点着色器”中的“顶点”歧义

[英]Disambiguate "vertex" in "vertex shader"

https://www.khronos.org/opengl/wiki/Vertex_Shader says that "The vertex shader will be executed roughly once for every vertex in the stream." https://www.khronos.org/opengl/wiki/Vertex_Shader说“顶点着色器将对 stream 中的每个顶点大致执行一次。”

If we are rendering a cube, vertex could refer to the 8 vertexes of the entire shape (meaning One).如果我们正在渲染一个立方体,顶点可以指整个形状的 8 个顶点(意思是一个)。 Or, it could refer to the 24 vertexes of the 6 squares with 4 corners each (meaning Two).或者,它可以指 6 个正方形的 24 个顶点,每个顶点有 4 个角(意思是两个)。

As I understand it, if a cube is being rendered, the 8 corners of the cube have to be converted into the coordinate system of the viewer.据我了解,如果正在渲染立方体,则必须将立方体的 8 个角转换为查看器的坐标系。 But also there are texture coordinates that have to be calculated based on the individual textures associate with each face of the cube.但也有一些纹理坐标必须根据与立方体每个面关联的各个纹理进行计算。

So if "vertex" is intended by meaning One, then why are textures being supplied to a shader which is a per face concept?因此,如果“顶点”的意思是“一”,那么为什么要将纹理提供给每个面概念的着色器? Or if "vertexes" are being fed to the shader by meaning two, does that mean that the coordinate transforms and projections are all being done redundantly?或者,如果“顶点”通过意义二被馈送到着色器,这是否意味着坐标变换和投影都是冗余完成的? Or is something else going on?还是发生了其他事情? These guides seem to have an allergy to actually saying what is going on.这些指南似乎对实际说出正在发生的事情过敏。

The page on Vertex Specification could be a bit more clear on this, but a vertex is just a single index in the set of vertex arrays as requested by a rendering operation. Vertex Specification 页面对此可能更清楚一些,但顶点只是渲染操作请求的顶点集合 arrays 中的单个索引。

That is, you render some number of vertices from your vertex arrays. You could be specifying these vertices as a range of indices from a given start index to an end index ( glDrawArrays ), or you could specify a set of indices in order to use ( glDrawElements ).也就是说,您从顶点 arrays 渲染一些顶点。您可以将这些顶点指定为从给定起始索引到结束索引 ( glDrawArrays ) 的索引范围,或者您可以指定一组索引以便使用( glDrawElements )。 Regardless of how you do it, you get one vertex for each datum specified by your rendering command.无论您如何操作,您都会为渲染命令指定的每个数据获得一个顶点。 If you render 10 indices with indexed rendering, you get 10 vertices.如果您使用索引渲染渲染 10 个索引,您将获得 10 个顶点。

Each vertex is composed of data fetched from the active vertex arrays in the currently bound VAO.每个顶点由从当前绑定的 VAO 中的活动顶点 arrays 获取的数据组成。 Given the index for that vertex, a value is fetched from each active array at that index.给定该顶点的索引,从该索引处的每个活动数组中获取一个值。 Each individual array feeds a vertex attribute, which is passed to the vertex shader.每个单独的数组提供一个顶点属性,该属性传递给顶点着色器。

A vertex shader operates on the attributes of a vertex (passed as in qualified variables).顶点着色器对顶点的属性进行操作( in限定变量传递)。

The relationship between a "vertex" and your geometry's vertices is entirely up to you. “顶点”与几何体顶点之间的关系完全取决于您。 Vertices usually include positions as part of their vertex attributes, but they usually also include other stuff.顶点通常包括位置作为其顶点属性的一部分,但它们通常还包括其他内容。 The only limitation is that the value fetched for each attribute of a particular vertex always uses the same vertex index.唯一的限制是为特定顶点的每个属性获取的值始终使用相同的顶点索引。

How you live within those rules is up to you and your data.您如何遵守这些规则取决于您和您的数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM