Course contentsShow
← Unity Game Development
Lesson 704 of 82810. VFX and Post-ProcessingFree lesson

Applying Occlusion Culling for Rendering Efficiency

You will learn to set up occlusion culling to prevent the engine from rendering objects hidden behind static walls and geometry.

In this lesson, you will learn how to configure occlusion culling to prevent the GPU from wasting resources on objects hidden behind opaque, static geometry.

The Core Concept

Rendering is often bottlenecked by draw calls—the commands sent from the CPU to the GPU. Even if an object is behind a massive, solid wall, the engine might still try to draw it, wasting processing power. Occlusion culling solves this by analyzing your scene layout in the editor to create a "visibility map." At runtime, if an object is completely obstructed by a designated "Occluder," Unity skips the draw call entirely, significantly reducing the burden on your GPU.

Implementing Occlusion Culling

To set this up, you must differentiate between objects that block view (Occluders) and objects that can be hidden (Occludees):

  1. Tagging Objects: Select your static environment geometry (like walls or large buildings) and in the Inspector, check the Static toggle. Specifically, ensure Occluder Static is enabled. For smaller objects that can be hidden, ensure they are marked as Occludee Static.
  2. The Occlusion Window: Go to Window > Rendering > Occlusion Culling. Switch to the Bake tab.
  3. Baking: Adjust the parameters:
    • Smallest Occluder: Controls the size of the smallest hole that can block view. Lower values are more precise but increase baking time.
    • Smallest Hole: The size of gaps (like door frames) that the culling system should ignore.
  4. Click Bake: Unity will pre-calculate the potential visibility from various camera positions.

Once baked, your scene will automatically perform visibility checks. You can verify this by opening the Scene View and changing the dropdown from Shaded to Overdraw or by toggling the Occlusion view mode in the Rendering Debugger to see what is currently being culled from the camera's perspective.

Note: Occlusion culling is only effective for static geometry. Dynamic objects (like moving enemies) cannot act as occluders, though they can be culled if they move behind baked static occluders.

Key Takeaway: By marking static geometry as Occluder Static and baking the scene, you offload processing from the GPU by ensuring that invisible, hidden objects never reach the rendering pipeline.