What is and how to apply Occlusion Culling in Unity

Introduction — What is Occlusion Culling in Unity?

The Uni­ty engine has a sys­tem called "Occlu­sion Culling" that allows to auto­mat­i­cal­ly hide objects that the cam­era is not see­ing direct­ly. In this arti­cle we are going to see how to pre­pare a project in Uni­ty so that Occlu­sion Culling is applied, some details about its oper­a­tion and con­fig­u­ra­tion parameters.

Important Detail — Pre-calculations (BAKE) are made in Occlusion Culling

Occlu­sion Culling works with objects that are marked as "sta­t­ic" in the scene and it is nec­es­sary to pre-cal­cu­late all the data, this is known as "bake", this implies that every time you intro­duce a new object that should be turned off if the cam­era is not see­ing it, or if you change the posi­tion of one of these objects, you must pre­cal­cu­late again the data for Occlu­sion Culling, if you don't do it some objects that are behind the cam­era or behind some object may not dis­ap­pear or even worse, you could have objects that dis­ap­pear in front of the cam­era when they should remain visible.

Where is the Occlusion Culling configuration window in Unity?

The Occlu­sion Culling con­fig­u­ra­tion win­dow is locat­ed in Win­dow > Ren­der­ing > Occlu­sion Culling, in my case I usu­al­ly place it next to the inspec­tor win­dow for con­ve­nience, as shown in image 2.

Image 1: How to open the Occlu­sion Culling win­dow in Unity.
occlusion culling window in Unity
Image 2: Occlu­sion Culling win­dow next to the inspec­tor in Unity.

How to add objects to the Occlusion Culling system in Unity

For an object to belong to the Occlu­sion Culling cal­cu­la­tions and there­fore dis­ap­pear when the cam­era is not look­ing at it, each object must be marked with the "Sta­t­ic" para­me­ter in the inspec­tor, as shown in image 3. In gen­er­al, the impor­tant objects to mark as sta­t­ic are those that have some kind of Ren­der­er com­po­nent assigned to it, such as a Mesh Ren­der­er com­po­nent or a Sprite Ren­der­er com­po­nent, since these objects are the ones that have a visu­al rep­re­sen­ta­tion on the screen.

Image 3: "Sta­t­ic" prop­er­ty of any GameOb­ject that allows to include it in the Occlu­sion Culling system.

IMPORTANT: Objects that are part of the Occlu­sion Culling sys­tem must not change posi­tion at any time and if they do, the data must be recal­cu­lat­ed as we will see below.




How to apply Occlusion Culling in Unity

Once the pre­vi­ous step of mark­ing all the sta­t­ic objects we are going to make a "Bake" of the infor­ma­tion to apply Occlu­sion Culling, for this we go to the "Occlu­sion" win­dow that is observed in image 4, in case of not see­ing the win­dow con­sult above in this article.

In this win­dow basi­cal­ly we are going to con­fig­ure two para­me­ters, "Small­est Occlud­er" and "Small­est Hole", the first para­me­ter refers to the small­est object in the scene (in scene units) that can obstruct the cam­era and make every­thing behind it not to be ren­dered, the small­er this para­me­ter is the longer the cal­cu­la­tions will take so we will have to do some tests to deter­mine an appro­pri­ate val­ue, in prin­ci­ple we can con­sid­er the val­ues of the image 4.


Image 4: Occlu­sion win­dow to apply Occlu­sion Culling in Unity.

The "Small­est Hole" para­me­ter is used in case of hav­ing open spaces in a 3D mod­el, con­sid­er the exam­ple illus­trat­ed in image 5‑A, in which Occlu­sion Culling has been applied with the para­me­ters of image 4.

Image 5‑A: Scene set up to illus­trate Occlu­sion Culling.
Image 5‑B: Per­spec­tive of the cam­era in image 5‑A.

As we see in image 5‑B the cam­era can see through the hole, how­ev­er the cube that is select­ed in image 5‑A is not vis­i­ble, this is because the Occlu­sion Culling sys­tem is con­sid­er­ing that this cube should be hid­den, since the small­er hole is set to a size of 0.5 Uni­ty units (image 4), while the hole in image 5‑B has a size of 0.1 by 0.1 Uni­ty units.

Mod­i­fy­ing a bit the para­me­ters tak­ing into account these par­tic­u­lar mod­els and the fact that we should be able to see objects through that hole, we make a new Bake with the para­me­ters of image 6 and as seen in image 7 now the Occlu­sion Culling sys­tem does not hide that object because the cam­era could see it through that hole.

Image 6: New para­me­ters to cor­rect the prob­lem of objects not vis­i­ble through holes in Unity.
Image 7: With these new para­me­ters the cam­era can see the cube through the hole.

Scroll to Top
Secured By miniOrange