March 2013
Intermediate to advanced
984 pages
26h 18m
English
In addition to instanced vertex attributes, the index of the current instance is available to the vertex shader in the built-in variable gl_InstanceID. This variable is implicitly declared as an integer. It starts counting from zero and counts up one each time an instance is rendered. gl_InstanceID is always present in the vertex shader, even when the current drawing command is not one of the instanced ones. In those cases, it will just be zero. The value in gl_InstanceID may be used to index into uniform arrays, perform texture lookups, as the input to an analytic function, or for any other purpose.
In the following example, the functionality of Examples 3.9 through 3.12 is replicated by using gl_InstanceID ...
Read now
Unlock full access