OGRE: Instancing

| OGRE 14.5 Object-Oriented Graphics Rendering Engine

Loading...
Searching...
No Matches
Instancing

Modern graphics cards (GPUs) prefer to receive geometry in large batches. It is orders of magnitude faster to render 10 batches of 10,000 triangles than it is to render 10,000 batches of 10 triangles, even though both result in the same number of on-screen triangles.

Therefore it is important when you are rendering a lot of geometry to batch things up into as few rendering calls as possible.

Ogre supports a variety of techniques to speed up the rendering of many objects in the Scene.

Static Geometry
  Pre-transforms and batches up meshes on the CPU for efficient use as static geometry in a scene.
Explicit Instance Manager
  Choose from different algorithms to batch up geometry and still be able to move & animate it. Requires manual setup and the algorithms have some limitations.
Auto-Instancing
  You can advertise instancing in you shaders and Ogre will batch the draw calls for you. Does not support animation.This is less efficient than the Explicit Instance Manager but requires no code changes and can be used with the RTSS.

# Static Geometry

This class allows you to build a batched object from a series of entities. Batching has implications of it's own though:

- Batched geometry cannot be subdivided; that means that the whole group will be displayed, or none of it will. This obivously has culling issues.
- A single world transform must apply to the entire batch. Therefore once you have batched things, you can't move them around relative to each other. That's why this class is most useful when dealing with static geometry (hence the name). In addition, geometry is effectively duplicated, so if you add 3 entities based on the same mesh in different positions, they will use 3 times the geometry space than the movable version (which re-uses the same geometry). So you trade memory and flexibility of movement for pure speed when using this class.
- A single material must apply for each batch. In fact this class allows you to use multiple materials, but you should be aware that internally this means that there is one batch per material. Therefore you won't gain as much benefit from the batching if you use many different materials; try to keep the number down.

In order to retain some sort of culling, this class will batch up meshes in localised regions. The size and shape of these blocks is controlled by the SceneManager which constructs this object, since it makes sense to batch things up in the most appropriate way given the existing partitioning of the scene.

The LOD settings of both the Mesh and the Materials used in constructing this static geometry will be respected. This means that if you use meshes/materials which have LOD, batches in the distance will have a lower polygon count or material detail to those in the foreground. Since each mesh might have different LOD distances, during build the furthest distance at each LOD level from all meshes
in that region is used. This means all the LOD levels change at the same time, but at the furthest distance of any of them (so quality is not degraded). Be aware that using Mesh LOD in this class will further increase the memory required. Only generated LOD is supported for meshes.

There are 2 ways you can add geometry to this class; you can add Entity objects directly with predetermined positions, scales and orientations, or you can add an entire SceneNode and it's subtree, including all the objects attached to it. Once you've added everything you need to, you have to call build() the fix the geometry in place.

Note
  This class is not a replacement for world geometry (Ogre::SceneManager::setWorldGeometry). The single most efficient way to render large amounts of static geometry is to use a SceneManager which is specialised for dealing with that particular world structure. However, this class does provide you with a good 'halfway house' between generalised movable geometry (Entity) which works with all SceneManagers but isn't efficient when using very large numbers, and highly specialised world geometry which is extremely fast but not generic and typically requires custom world editors.

Attention
  this class only works with indexed triangle lists at the moment, do not pass it triangle strips, fans or lines / points, or unindexed geometry.

See also
  Tutorial - Static Geometry

# Explicit Instance Manager

Instancing is a rendering technique to draw multiple instances of the same mesh using just one render call. There are two kinds of instancing:

Software
  Two larges vertex & index buffers are created and the mesh vertices/indices are duplicated N number of times. When rendering, invisible instances receive a transform matrix filled with 0s. This technique can take a lot of VRAM and has limited culling capabilities.

Hardware
  The hardware supports an extra param which allows Ogre to tell the GPU to repeat the drawing of vertices N number of times; thus taking considerably less VRAM. Because N can be controlled at runtime, individual instances can be culled before sending the data to the GPU. Hardware techniques are almost always superior to Software techniques, but Software are more compatible, where as Hardware techniques require D3D9 or GL3, and is not supported in GLES2

All instancing techniques require shaders. It is possible to have the RTSS (Realtime Shader System) generate the shaders for you.

See also
  Ogre::InstanceManager
  Instancing User-Guide

# Static Geometry vs Instancing

Static Geometry | Instancing
--- | ---
Any sort of mesh is grouped in a minimal number of meshes, and cannot be updated (each mesh cannot move independently, only all the static geometry would be able to do so.) | The same mesh used many times, so Instanced geometry can be updated (each mesh can move independently)
You have a scene with many unique meshes | Reuse the same mesh many times without the draw call cost.
Batches up small static detail fragments like grass without shaders. | One mesh is repeated many times without the performance hit of having them as individual meshes.
Geometry that doesn't move and has low in GPU requirements | Dynamic geometry (animated or moving) and better GPU (sm2.0+)
Batches separate sets of polygons together, as long as they have the same properties such as material. These batches are then automatically split into regions for better culling. You can control the region size. This is a good way to reduce batches for static elements. | Good for large numbers of the same exact object. You can have multiple instances of one object that can dynamically move but that are drawn in one draw call.