vertexIndex
Provides access to the unique index number of the current vertex in the vertex shader, forming a basis for procedural effects and efficient data lookups.
Core Advantages
It provides a unique, deterministic ID for each vertex, which can be used as a seed for pseudo-random number generators or for precise data lookups from textures/buffers (like in VAT), enabling rich visual variety or high-performance animations without extra vertex attributes.
Common Uses
Vertex Animation Textures (VAT)
Procedural Geometry Deformation & Patterns
Debugging & Visualizing Vertex Order
How to adjust
vertexIndex has no parameters itself. Its effect is changed by performing mathematical operations on it within the shader. For example, multiplying it by a small number and passing it to sin() creates waves, or using it as a seed for a rand() function generates a unique random value per vertex.
Code Examples
1// Check if the vertex index is even
2const isEven = eq( mod( vertexIndex, 2.0 ), 0.0 );
3
4// Switch between two colors based on the result
5const patternColor = cond( isEven, vec3( 1.0 ), vec3( 0.0 ) );