GLSL gl_VertexID Variable

Label each vertex with an index

Equilateral Triangle

Notes

A helpful concept we’ll use is called the vertex ID. I you think of ordering your collection of vertices, it’s merely the index (zero-based) of each vertex in the list. That is, the first vertex is zero, and so on.

For our equilateral triangle, we’ll specify the first vertex as the one along the x-axis and proceed counter-clockwise around the triangle (this decision isn’t arbitrary, and we’ll see the rationale a bit later).

As mentioned, each vertex will be processed by a unique instance of the vertex shader, which will be provided the vertex ID, which will allow us to make per-vertex decisions. Each shading language contains this concept, however, the name of the variable in the shader will differ by language. For WebGL (and all of the GLSL-based shaders), the vertex ID is available in the shader as the gl_VertexID variable.