我正在尝试通过动态计算顶点在数组中的索引位置来创建点网格。是否有类似于gl_VertexID变量可以从着色器中调用的等效物?或者其他不需要发送更多数据到GPU即可访问它们在数组中位置的方法?谢谢,Josh。
以下是我的顶点着色器:
以下是我的顶点着色器:
attribute vec4 vertexPosition;
uniform mat4 modelViewProjectionMatrix;
vec4 temp;
uniform float width;
void main()
{
temp = vertexPosition;
// Calculate x and y values based on index:
temp.y = floor(gl_VertexID/width);
temp.x = gl_VertexID - width*temp.y;
gl_Position = modelViewProjectionMatrix * temp;
}