Why Occlusion Culling Improves Performance
In the last article, I looked at Adding post processing profiles to my Universal Render Pipeline in Unity. Today, I’ll be delving into Occlusion culling, what it is, and why it can improve perfoemance in our games!
What is Occlusion Culling?
Occlusion Culling is a process in which items in a scene are removed from the final render if they are hidden from view by other objects. For example, a hallway that is hidden behind a closed door would not be rendered until the door is open and the hallway beyond is no longer hidden (or Occluded) by the door.
Using occlusion culling reduces the number of objects in a scene that need to be rendered which can improve the performance of the running game because Unity doesn’t have to waste CPU and GPU time rendering those objects. It’s important to note that Occlusion culling works best when used in environments where the areas are definitivly broken up by solid GameObjects. Scenes like the above example of two spaces separated by a solid door are good candidates.
How do I activate Occlusion Culling?
For occlusion culling to work in my scene all of my objects either need to be marked as Static, either by checking the Static checkbox next to each objects name in the inspector window, which sets all of the objects static options to on, or by setting their static individual properties via the drop down option next to the static option in the editor. The second method allows me to choose which operations the object is treated as static for. In my case I check Everything and then uncheck Contribute GI to make sure that the object isn’t treated as static when Global Illumination is calculated.
To activate Occlusion Culling in a scene, I open the Occlusion Culling window in the Unity Editor. This window is located at Windows > Rendering > Occlusion Culling.
With the Occlusion Culling window open, I then need to select Bake from the options at the top of the inspector window and click the bake Button.
After Unity generates the occlusion data during the Bake operation I can click on the Visualization tab in the Occlusion Culling inspector window and change the position and rotation of my camera to see how objects that are not visible either by exclusion from the camera’s viewing frustrum (this is actually called Frustrum culling and is done by default in Unity with or without Occlusion Culling) or by being completely obscured by another object (Occlusion Culling) are no longer rendered.
In this article, I looked at Occlusion Culling in Unity. Next time, I’ll be Reflection Probes in Unity! If you enjoyed this article, or want to come along with me as I progress on my journey, follow me at gamedevchris.medium.com.