When it comes to game optimization, camera culling is one of the important aspects to improve game performance. But What culling actually is? And how does Unity use it?
To understand unity camera culling system, you should need to understand unity camera component first. Unity Camera is a specific Unity3d built-in component that renders 3D or 2D world to the display. The camera component can be attached to a game object which means it has position and rotation properties. With the camera 📸 component you can adjust its field of view(FoV) and viewport rectangle. So, essentially its viewport rectangle defines the output. And the output is the actual image of your scene or game that shows on a display or maybe on a render texture.
So the 🎥 camera's responsibility is to render a game object(s) on the screen but here comes the culling: actually camera's responsibility is to determine which objects should be rendered on the screen? And for this reason, three types of processes or culling systems/types/techniques are adopted:
Frustum Culling:
Camera clipping Plane in unity. |
Layers Culling:
Layer culling is one of the most used optimization ways in our projects. As you have learned that unity camera renders those objects that lie within the camera view frustum but within the view frustum of camera, you can also apply layers culling.
By default, a camera in Unity will not render objects that are further away than its "far clip plane" distance. However, you can set up specific layers in your project to use smaller culling distances by adjusting the "layer cull distances" parameter. This can be especially useful for culling small objects early on in the rendering process, as long as they are assigned to the correct layers.
Here is one of the free assets which provide you an easy way to apply layers culling in unity. But the process of layer culling implementation is straightforward you have to assign layer to your object than with the code you can set it culling distance.
Occlusion Culling:
According to OpenAI's language model (ChatGPT) Occlusion culling is another optimization technique that you can use to improve the performance of your game. This technique involves not rendering objects that are occluded or hidden behind other objects in the scene. This is done by using occlusion probes which are placed in the scene and determine if an object is visible or not. When an object is not visible, it is not rendered which saves computational power and improves performance. Below screenshot display that how occlusion culling is works.
Without occlusion Culling (left) vs with occlusion Culling (right) |
Like you can see on the left side your camera is rendering all the object which lies within the camera view frustum but on the right side, after applying the occlusion culling it only renders those object which are visible to the camera
In Unity, you can use the Occlusion Culling window to set up occlusion probes in your scene. You can adjust the size, shape, and placement of the probes to control what is visible and what is occluded. Additionally, you can control the level of detail for objects that are visible, as well as what is rendered in the background. Here is the detailed tutorial available on the Unity website which you can follow to learn about occlusion culling.
Overall, occlusion culling is a useful optimization technique for games where objects are frequently occluded from view. It can greatly improve performance by reducing the number of objects that need to be rendered and allowing you to control the level of detail for objects that are visible.
In conclusion, a unity culling system is a crucial aspect of game optimization and includes frustum culling, layer culling, and occlusion culling. Frustum culling is the default behavior of the unity camera and eliminates the rendering of objects beyond the view frustum. Layer culling allows you to control what objects are rendered by using layers. Occlusion culling optimizes performance by not rendering objects that are occluded by other objects in the scene. By using these techniques, you can improve the performance of your game and ensure that your game runs smoothly and efficiently.
0 Comments