Occlusion Culling
Object culling allows you not to render objects which are not presented in the viewing frustum. The particular cases of occlusion culling are the following:
- Occluders: world, mesh, terrain.
- Sectors and Portals.
- Hardware occlusion queries for objects with heavy shaders.
Occluders#
Occluders allow culling geometry that isn't visible behind them. There are 3 types of occluders:
The type of occluder to be used is defined by geometry to be culled.
Occluders can be highly effective in case of complex environments where there are many objects that occlude each other and are costly to render (they have a lot of polygons and/or heavy shaders).
Before using occluders, check the following:
- Rendering of occluders is enabled: in the Menu Bar, Rendering -> Occlusion Culling -> Occluders is toggled on.
- Rendering of shadows from the occluded objects is disabled: in the Menu Bar, choose Windows -> Settings -> Occlusion Culling and toggle Shadows Culling on.
You can leave shadows rendering enabled, if necessary.
Usage of occluders is shown in the Content Optimization video tutorial.
Using a Box-Shaped Occluder#
An occluder is a box-shaped occluder that culls objects' surfaces, bounds of which aren't visible behind it. This is a simpliest type of occluders that should be used together with the box-shaped objects that occlude the other ones. For example, you can add an occluder that coincides bounds of a building to avoid rendering of objects behind this building.
To create a box-shaped occluder, perform the following:
- In the Menu Bar, choose Create -> Optimization -> Occluder and add the occluder as a child to the target node (that should occlude the other objects).
- In the Node tab of the Parameters window, set the position of the occluder to the parent one.
- In the World Occluder tab of the Parameters window, click Edit Size to enable the editing mode for the occluder. Resize it by using the colored rectangles on the occluder box sides, so that it coincides the parent node size.
You can also use the Size parameter to set the size along the axes.
- Specify the Distance between the camera and the occluder, at which the occluder doesn't occlude anything and, therefore, should be disabled to avoid negative impact on the performance.
To check how the occluder works, disable the parent node and then try to toggle the occluder on and off:
By default, the front faces of the occluder are used to cull objects. However, if the camera is inside the occluder (e.g. inside the building), occlusion culling won't be performed. To avoid such situation, enable the Back Face parameter in the World Occluder tab of the Parameters window.
Using a Mesh-Based Occluder#
An occluder mesh is based on an arbitrary mesh that culls objects' surfaces, bounds of which aren't visible behind it. It is used together with the geometry that cannot be approximated with a box.
To create a mesh-based occluder, perform the following:
- Prepare a low-poly mesh to be used for the occluder.
It isn't recommended to use the same detailed mesh that is used for the target node (that should occlude the other objects): the mesh for the occluder should be as simple as possible to avoid performance loss.
- In the Menu Bar, choose Create -> Optimization -> Occluder and specify the prepared mesh.
You can load a new mesh for the occluder any time, if necessary.
- Add the occluder as a child to the target node.
- In the Node tab of the Parameters window, set the position of the occluder to the parent one.
- Specify the Distance between the camera and the occluder, at which the occluder doesn't occlude anything and, therefore, should be disabled to avoid negative impact on the performance.
Using a Terrain Occluder#
An occluder terrain culls objects' surfaces, bounds of which aren't visible behind the terrain geometry. The terrain occluder repeats the shape of the terrain. It is highly effective on scenes containing:
- A terrain with fluctuating heights.
- A lot of objects with complex geometry that can be occluded by the terrain geometry. However, such objects shouldn't be too large in order to be successfully culled by the terrain occluder (since if any part of their surface is seen, it cannot be culled).
It is not recommended to use the occluder terrain in the following cases:
- If the terrain is flat: the occluder will decrease the performance as there will be no surfaces to be culled.
- If the terrain relief is changed in runtime.
- If the terrain is observed from above (e.g., in case of flight simulators).
If the camera can go below in such scenarios, set up the occluder terrain that is enabled/disabled at a certain distance to improve the performance.
To create an occluder terrain, perform the following:
- In the Menu Bar, choose Create -> Optimization -> Occluder Terrain and place it in the center of the terrain.
- In the World Occluder Terrain tab of the Parameters window, set the Size of the occluder so that it coincides with the the terrain size. The whole terrain should be covered with the occluder.
- In the Heights parameter of the World Occluder Terrain tab, specify the same height map that was used for the terrain generation, but downscaled for optimization purposes.
Check the result: look through the terrain geometry to the occluded objects and try to toggle the occluders rendering on/off.
Sectors and Portals#
For large indoor scenes with several rooms and passages, sectors and portals should be used to optimize performance. Sectors and portals allow to skip all objects outside the current interior (e.g., outdoor objects, another rooms and environments).
Usage of sectors and portals is also shown in the Content Optimization video tutorial.
Using Sectors#
A sector allows culling all objects outside its volume. Sectors are used to split the world into 2 areas: inside and outside it. They can significantly improve the performance in the combined scenes with large indoor and outdoor parts: when you are inside some room, objects outside this room aren't rendered.
To create and set up a sector, perform the following:
- In the Menu Bar, choose Create -> Optimization -> Sector and add the sector to the world.
- In the World Sector tab of the Parameters window, specify the size of the sector, so that it coincides with the room size.
- Move the sector to match the position of the room. You can also add the sector node as a child to the room node and set the sector's position to the parent one.
In the result, the interior won't be visible, when the camera is outside the room and vice versa.
Connecting Adjacent Sectors#
A portal allows connecting sectors: it provides an opening through which an interior of one sector is visible from another one. Portals haven't any positive impact on the performance: they only make the scene more realistic.
To create a portal, perform the following:
- In the Menu Bar, choose Create -> Optimization -> Portal and place it on a face of a sector. The portal must become green: it means that the interior of the sector will be visible through the portal.
- In the World Portal tab of the Parameters window, set the Width and the Height of the portal. Also you can adjust the size in the editing mode that is activated by pressing Edit Size.
Hardware Occlusion Queries#
Another way to cull geometry that is not visible in the camera viewport is to use a hardware occlusion query. It allows skipping rendering of objects, the bounding boxes of which are covered by another solid geometry. In the result, the number of the rendered polygons is reduced and the performance grows.
To run the hardware occlusion test for the scene before sending data to the GPU, toggle the Rendering -> Occlusion Culling -> Occlusion Query flag on in the Menu Bar.
To run the hardware occlusion test, perform the following:
- In the Menu Bar, toggle the Rendering -> Occlusion Culling -> Occlusion Query flag on to enable testing for the scene before sending data to the GPU.
- For all objects, that should be culled, enable the Culled by Occlusion Query flag in the Node tab of the Parameters window.
Only nodes with this flag set are tested on the hardware occlusion culling.
When culling is enabled for the object, an occlusion query box is rendered for it.
Occlusion Query Test Passed |
Occlusion Query Test Failed, Material Ball Isn't Rendered |
You can check the effect of this technique by enabling the second wireframe mode to see all the triangles in the scene. Type render_show_triangles 2 in the console and check the way the occluded polygons act.
An example of using hardware occlusion queries is also available in the Content Optimization video tutorial.