How Occlusion Culling Improves Performance
Occlusion Culling is a great tool to save GPU on runtime; this tool is a process which prevents Unity from performing rendering calculations for GameObjects that are completely hidden from view (occluded) by other GameObjects. Only the objects that are baked in the Occluded Area according to the settings will be taken into account for this process, rendering the parts of the map that are only visible to the Game view’s camera.
- Preventing wasted rendering operations can save on both CPU and GPU time. Unity’s built-in occlusion culling performs runtime calculations on the CPU, which can offset the CPU time that it saves. Occlusion culling is therefore most likely to result in performance improvements when a Project is GPU-bound due to overdraw.
- Unity loads occlusion culling data into memory at runtime. You must ensure that you have sufficient memory to load this data.
- Occlusion culling works best in Scenes where small, well-defined areas are clearly separated from one another by solid GameObjects. A common example is rooms connected by corridors.
- You can use occlusion culling to occlude Dynamic GameObjects, but Dynamic GameObjects cannot occlude other GameObjects. If your Project generates Scene geometry at runtime, then Unity’s built-in occlusion culling is not suitable for your Project.
Occlusion culling generates data about your Scene in the Unity Editor, and then uses that data at runtime to determine what a Camera can see. The process of generating data is known as baking.
When you bake occlusion culling data, Unity divides the Scene into cells and generates data that describes the geometry within cells, and the visibility between adjacent cells. Unity then merges cells where possible, to reduce the size of the generated data. To configure the baking process, you can change parameters in the Occlusion Culling window, and use Occlusion Areas in your Scene.
At runtime, Unity loads this baked data into memory, and for each Camera that has its Occlusion Culling property enabled, it performs queries against the data to determine what that Camera can see. Note that when occlusion culling is enabled, Cameras perform both frustum culling and occlusion culling.
This is an example of how an environment is occluded at runtime, seen from the scene view.
To do this, the static game objects should be checked for this and the occluded areas must be baked.
Select all the static objects of the scene and check their Static properties as such:
The baked area should appear like this in the scene view once the baking process is done.
This process can be really helpful when rendering scenes for VR headsets since these games render the scene at least twice .