top of page
Search
  • Writer's pictureFox Forge

Game Development - Occlusion Culling and Baking: Entry 4

Updated: Apr 25

With the final set dressing done by our environmental artists, the run-time performance of our game was drastically reduced due to the amount of rendering being done. To combat this, we can occlusion bake our scene. The guide on occlusion culling here is demonstrated in the Unity Game Engine.


What is Occlusion Culling and how does it work?


Occlusion culling simply means not rendering what cannot be seen by the camera. When this happens, the load on the GPU is dramatically reduced and performance improvements are clearly seen with increases in frames per second.


Fig 1. Here is a screen-shot from our game on a setting without occlusion culling

As you can see, our scene has many objects which are fairly detailed and rendering all of these at the same time makes our project run at 40fps - on my machine with a GTX 980ti graphics card! That's extremely bad!



Fig 2. The same shot from Fig 1. but with occlusion culling enabled

After enabling occlusion culling, you can see the visualisation of what the camera is rendering from the same setting - now running at around 90fps on the same PC. Much better! It is important to not that only the rendering is being filtered. All of the physics and other in-game systems are still present - meaning that if you have an rigidbodies or enemies present in non-visible parts of the scene, then they will not suddenly fall off the map!


When and Why to use or not use Occlusion Baking?


The term "Baking" comes into occlusion culling when you want to pre-compute the area's which cannot be seen be the camera. Therefore this means that only the objects in your scene which are STATIC and will not move can be baked for occlusion culling.


If you desire to perform occlusion culling on dynamic objects (objects which move or are instantiated at run-time) then you will have to mark their mesh renderer component to perform dynamic occlusion.



Fig 3. Shows the Mesh Component Inspector and outlines the area to check the dynamically occluded option

However, baked occlusion is a far better method than dynamic occlusion culling as it doesn't have to compute non-visible area's to the camera at run-time! Dynamic occlusion culling is still an option but it significantly outweighed. Moreover, occlusion culling in general, either dynamic or baked, should always be done regardless to gain performance improvements. There is not a scenario where occlusion culling is non-beneficial, so always make sure you do it!


How to perform Occlusion Baking with examples from our game project


As mentioned above, all objects for occlusion baking must be marked as static and must not move during run-time for the occlusion baking to be correct.


Fig 4. Shows the options in the Occlusion Window (Unity Game Engine) when selecting an object with a mesh in the scene. Note here, the two static options an object can have.

When marking objects as static for baking, there are two types of occlusion marks which can be toggled to get the result desired for a certain object with a mesh. You can select both, one or none per object. If you do not mark your objects with either static attribute, they will not be included in the occlusion bake.


Occluder Static - This means that the object can hide other objects from being seen.

Occludee Static - This mean that the object can be hidden by other objects


Once you have marked all the objects in your scene to the correct static types, you can go ahead to the bake tab in the occlusion window.


Fig. 5 This figure shows the bake tab with values used for our game development project. Note the three values here which can be changed in the inspector

Once here you have 3 editor defined values to achieve the occlusion bake which is best suited for your environment.


Smallest Occluder - This is the size of the smallest object that will be used to hide other objects when doing occlusion culling. For example, if a value of 4 is chosen, then all the objects that are higher or wider than 4 meters/units will block visibility and the objects that are smaller than that will not. This value is a trade-off between occlusion accuracy and storage size.


Smallest Hole - This means the smallest hole in the geometry through which the camera is supposed to see. The single float value of the parameter represents the diameter of the imaginary smallest hole, i.e. the maximum extent of a 3D object that fits through the hole.


Backface Threshold - The backface threshold is a size optimisation that reduces unnecessary details by testing backfaces. A value of 100 is robust and never removes any backfaces. A value of 5 aggressively reduces the data based on locations with visible backfaces. The idea is that typically valid camera positions cannot see many backfaces. For example geometry under terrain and inside solid objects can be removed.


With our project, a smaller value for the Smallest Occluder meant that we gained larger performance increases due to the high detail on the objects. For us, It was important that whatever could be occluded must be occluded as there was a lot of detail which went into the assets.


For the Smallest Hole, we kept the default value of 0.25 as it sufficed well for our current scene setting.


We decreased the Backface Threshold in our project to a value of 10 due to the camera view in our game. Our camera is never able to see the backfaces of most objects, so we could decrease their details a lot to gain further performance increases.


Once you have setup all your values, you can press the bake button!

Fig 6. A post-baked image of our game scene showing all the areas which have been defined in scene by occlusion baking

The occlusion data will be saved within a folder automatically created to match your scene's name. There is nothing more to be done and you can simply press play and see the performance increase you have just gained!


Regards to Future Development


With only 2 weeks left of development, the occlusion culling data will not change dramatically. However, we must be sure that if we are to add any more set dressing objects or final touches to the scene, that we re-bake the occlusion culling to make sure we are reducing as much rendering as possible.


162 views0 comments
bottom of page