one would like to render many instances of the same object.
- Blades of grass
- Forest of trees
the client program, one could loop over each object and render it:for (int
= 0; i < N; i++) glDrawArrays(GL_TRIANGLES, 0,
each call to glDrawArrays
carries some overhead. Instead, one can
render the entire set with a single call:
the vertex shader, there is a built-in variable called gl_InstanceID
variable allows the programmer to treat each instance differently, for example,
by applying a transformation.
Vertex shader:Example: A herd of 1000 horses!
horse: 1581 triangles
rendering: 60 FPS
Non-instanced: 40 FPS