Adding Occlusion Culling to our URP project
What is Occlusion Culling?
Basically, if the game camera doesn’t see an object because other objects obscure that object, the non-visible object is not rendered on the GPU thus reducing GPU load and CPU overhead.
Occlusion culling is a process which prevents Unity from performing calculations for that are completely hidden from…
“Occlusion culling is a process which prevents Unity from performing rendering calculations for GameObjects that are completely hidden from view (occluded) by other GameObjects.
Every frame, Cameras perform culling operations that examine the Renderers in the Scene and exclude (cull) those that do not need to be drawn.
By default, Cameras perform frustum culling, which excludes all Renderers that do not fall within the Camera’s view frustum.
However, frustum culling does not check whether a Renderer is occluded by other GameObjects, and so Unity can still waste CPU and GPU time on rendering operations for Renderers that are not visible in the final frame.
Occlusion culling stops Unity from performing these wasted operations.”
This a great example of where Hierarchy organization makes your life easier.
I can select all of the relevant static objects very easily with this organization.
If we take a look at our Static dropdown in Unity for all of our static game objects, we can see that occlusion is already turned on in my case.
If not, this is where you could toggle it on.
We need to open our Occlusion Culling window by clicking Window > Rendering > Occlusion Culling.
Next, we want to open the Bake tab and click the Bake button.
If the Visualization tab doesn’t open automatically after baking, click the Visualization tab.
Our scene view should now show us the objects that are now being occluded.
It also gives us an Occlusion Culling interface in the bottom right of the scene view.
If we run our game and move the player, thus moving the camera, we can see a live visualization of all the objects being occluded.
That’s a lot rendering work that the player’s machine won’t have to do!
Remember, most players don’t have high priced PCs with top-of-the-line components.
We want our games to be as accessible to a broad variety of players as possible.
With URP, we are generally aiming at mobile game development or on that par of performance.
Anywhere we can reduce GPU and CPU usage will mean a smoother running game with a higher frame rate, a longer battery life while playing, and less heat generated which makes the player uncomfortable!
That’s it, see you in the next article.