Occlusion culling
- Game Development course
- Expert
- Lesson 5/47
- 4 min
Learn to cull out-of-view surfaces with Occlusion Culling.
Frustum culling vs Occlusion culling
By default, Unity does not render objects outside the camera view pyramid (Frustum Culling). However, objects that are inside the view field but completely hidden behind a massive wall or building are still rendered, wasting GPU power (Overdraw).
// Occlusion Culling:
// Even if inside the frustum, objects completely
// occluded by front obstacles are not rendered.Occlusion Culling discards objects obscured behind blockers, eliminating redundant rendering.
Occlusion bake and static flags
Occlusion Culling data is pre-baked for the scene. Large structures that block visibility are marked Occluder Static, while objects that can be hidden behind them are marked Occludee Static.
// Editor setting:
// Window -> Rendering -> Occlusion Culling -> Bake
// 'Smallest Occluder' controls the blocker precision.Once baking is complete, obscured objects are discarded instantaneously as the camera navigates between cells.
Practice Simulate culling status
Inspect the inFrustum and isOccluded flags: if outside the view (!inFrustum) print "Frustum Disi", if in frustum but hidden (isOccluded) print "Occlusion ile Elendi", otherwise print "Cizildi" using Console.WriteLine.
Starter code
using System;
class CullingTest
{
static void Main()
{
bool inFrustum = true;
bool isOccluded = true;
// Culling durumunu belirle ve ekrana yazdir
}
}Sample solution
using System;
class CullingTest
{
static void Main()
{
bool inFrustum = true;
bool isOccluded = true;
string status;
if (!inFrustum)
status = "Frustum Disi";
else if (isOccluded)
status = "Occlusion ile Elendi";
else
status = "Cizildi";
Console.WriteLine($"Durum: {status}");
}
}Expected output
Durum: Occlusion ile Elendi
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which system prevents rendering objects that are inside the camera frustum but hidden behind a wall?
- Occlusion Culling Correct answer
- Frustum Culling
- Dynamic Batching
- Post-processing Bloom
Explanation: Occlusion Culling detects and eliminates objects hidden behind other solid objects even if they reside inside the camera view.
2 Occluder static flag
StaticEditorFlags flags = StaticEditorFlags.____;
StaticEditorFlags flags = StaticEditorFlags.OccluderStatic;
Explanation: Static structures that obscure objects behind them are flagged as OccluderStatic.
3 Culling terms
| Term | Meaning |
|---|---|
Frustum Culling |
Doesn't render outside camera view |
Occlusion Culling |
Eliminates objects hidden behind |
Occluder |
Blocker that obscures objects behind it |
Occludee |
Object that can hide behind an obstacle |