◄ Wiki / Graphics
gl_PrimitiveID
gl_PrimitiveID is a shader built-in giving the index number of the primitive currently being processed.
As the GPU draws triangles (or other primitives), it numbers them in order, and gl_PrimitiveID exposes that number inside the shader. This lets a shader treat different primitives differently — picking a per-triangle color, texture, or material without extra vertex data. It is a lightweight way to give each primitive its own identity.
See also
- gl_Layergl_Layer is a shader built-in variable that selects which layer of a layered render target to draw into.
- gl_PrimitiveID / gl_LayerA pair of shader built-ins: one identifies the current primitive, the other picks which render-target layer to write to.
- fragment shaderA fragment shader is a small program the GPU runs for every fragment to decide its final color.