Working with Occlusion Culling

Tutorial

·

intermediate

·

+10XP

·

20 mins

·

(130)

Unity Technologies

Working with Occlusion Culling

In this tutorial, you’ll learn to use occlusion culling to optimize rendering and performance of your 3D Unity projects.

Languages available:

1. Working with Occlusion Culling

Verified with: 2019.4LTS


In this tutorial, you’ll learn to use Occlusion Culling to optimize rendering and performance of your 3D Unity projects. Occlusion Culling disables GameObjects that are fully hidden (occluded) by other GameObjects. This means CPU and GPU time isn’t wasted rendering objects that will never be seen by the Camera.


Because Occlusion Culling is calculated in a pre-pass, it’s not a good fit for projects where Scene geometry is instantiated or generated at runtime. An ideal use case for Occlusion Culling is a Scene with distinct zones or areas that are hidden from each other by corridors, walls, mountains, or buildings.


2. Preparing for Occlusion Culling

1. Identify GameObjects in your Scene that should be considered Static Occluders (GameObjects that can block other GameObjects) and/or Static Occludees (GameObjects that can be blocked by other GameObjects).


Static Occluders have either a Mesh or Terrain Renderer, are opaque, and do not move at runtime. Examples include walls, buildings, and mountains. If using LOD groups with a GameObject designated as a Static Occluder, the base LOD (LOD0) is used in the calculation.

Static Occludees have any type of Renderer and do not move at runtime. Examples include level decor, like shrubs, or any GameObject that is likely to be occluded.

A GameObject can be both. Dynamic GameObjects can be occluded but can’t occlude other GameObjects.


2. Select all GameObjects that you wish to be Static Occluders. Using the Static Editor Flags drop-down in the upper right, set the Occluder Static property (Figure 01).


Figure 01: Setting SouthWall to be a Static Occluder

Figure 01: Setting SouthWall to be a Static Occluder


3. Repeat the process for Static Occludees. For GameObjects that are Occluders and Occludees, set both flags.


4. For each Camera in the Scene, ensure Occlusion Culling is enabled in its Inspector (Figure 02).


Figure 02: Enabling Occlusion Culling for a Camera

Figure 02: Enabling Occlusion Culling for a Camera


3. Baking Occlusion Culling Data

1. To open the Occlusion Culling window, use the Window drop-down and select Rendering > Occlusion Culling.


2. The Occlusion Culling window has three views: Object, Bake, and Visualization.


Object view allows you to quickly filter the Hierarchy view to show only relevant GameObjects or Occlusion Areas, as well as create Occlusion Areas (Figure 03). By default, the entire Scene is treated as a global Occlusion Area. Depending on the layout of your Scene, it may make sense to have individual Occlusion Areas.


Figure 03: Creating a new Occlusion Area

Figure 03: Creating a new Occlusion Area


Bake view allows the user to set default values for Occlusion Culling calculation (Figure 04).


Smallest Occluder is the minimum size an object should be to be considered a possible occluder.


Smallest Hole is the minimum diameter that’s considered a possible space between occluders. Holes and gaps smaller than this setting are ignored.


Backface Threshold determines the degree to which backfaces are tested and removed. The default value of 100 leaves all backfaces, and the ideal value for this setting will vary from project to project.


Figure 04: Setting default parameters for Occlusion Culling

Figure 04: Setting default parameters for Occlusion Culling


Visualization allows the user to see Camera Volumes, Visibility Lines, and Portals to better understand how the occlusion data is calculated (Figure 05).


Figure 05: Visualizing the occlusion data based on the selected Camera

Figure 05: Visualizing the occlusion data based on the selected Camera


3. Available in all views is the option to Clear or Bake the Occlusion Culling data.


4. Click Bake. The amount of time it takes to prepare the occlusion data depends on the complexity of your Scene and your Occlusion Culling settings.


4. Visualizing Overdraw

The 3D rendering process starts with the geometry farthest from the camera. This is known as Overdraw. In the Scene view, the user can enable Overdraw mode to visualize this (Figure 06).


Figure 06: Visualizing Overdraw

Figure 06: Visualizing Overdraw


5. Conclusion

Occlusion Culling is an easy way to optimize performance by limiting rendering to only GameObjects in Camera view. With this being just one way to optimize performance, check out our Optimizing for Performance project to learn about additional ways that you can optimize your project.


Complete this tutorial