7

I'm trying to create a grid of points by calculating vertex positions dynamically, based on their index in the array of vertices sent to the shader. Is there an equivalent of the gl_VertexID variable that I can call from within my shader? Or another way of accessing their position in the array without having to send more data to the GPU? Thank, Josh.

Here's my vertex shader:

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;
}
Josh
  • 331
  • 2
  • 10
  • 4
    Not an answer to your original question, but this was added in GLES 3.0. http://www.khronos.org/registry/gles/specs/3.0/es_spec_3.0.0.pdf – nullspace Nov 12 '12 at 08:54

1 Answers1

14

Unfortunately there is no gl_VertexID equivalent in GLES2. You must create and pass additional data yourself.

Mārtiņš Možeiko
  • 12,733
  • 2
  • 45
  • 45