我试图通过动态计算顶点位置来创建一个点网格,基于它们在发送到着色器的顶点数组中的索引。我可以从我的着色器中调用一个等效的 gl_VertexID 变量吗?还是另一种无需向 GPU 发送更多数据即可访问它们在数组中的位置的方法?谢谢,乔希。
这是我的顶点着色器:
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;
}