Curriculum
Course: How to develop 3D Games with Unity
Login
Video lesson

Occlusion Culling

Objectives

  • Understanding Occlusion Culling: Introduce the concept of occlusion culling, explaining its role in optimizing rendering by preventing off-camera GameObjects from being rendered in Unity.

  • Demonstration with Practical Example: Use a specific game (John Lemon project) to illustrate how occlusion culling functions in a real-world scenario.

  • Tutorial on Implementing Occlusion Culling: Guide users through the steps of implementing occlusion culling in Unity, including setting up GameObjects and adjusting camera settings.

  • Optimization Techniques: Provide insights into how occlusion culling contributes to game optimization by reducing unnecessary rendering, thus enhancing performance.

  • Hands-on Application: Encourage users to apply these techniques in the context of their game development projects, using the John Lemon project as a reference model.

  • Troubleshooting and Tips: Offer solutions and tips for common challenges encountered when implementing occlusion culling, ensuring users can effectively apply this technique in various scenarios.

Summary

Occlusion culling in Unity is a process designed to optimize rendering efficiency by preventing the rendering of GameObjects that are completely obscured (occluded) from the camera’s view by other GameObjects. It operates by having cameras in the scene perform culling operations each frame, evaluating Renderers and excluding those that do not need to be drawn. While the default frustum culling excludes Renderers outside the camera’s view frustum, it doesn’t account for objects occluded by others. Occlusion culling addresses this gap by eliminating unnecessary rendering operations for objects not visible in the final frame, thus saving CPU and GPU resources.

Steps

1. Open Your Unity Project:

  • Launch Unity and open the project where you want to implement occlusion culling.

2. Select the Objects for Occlusion Culling:

  • In the Unity Editor, navigate to the scene where you want to apply occlusion culling.

  • Identify and select the objects that you wish to include or exclude from the occlusion culling process.

3. Adjust Object Properties:

  • With an object selected, go to the Inspector window.

  • Find the ‘Static’ dropdown menu. This is usually located at the top right of the Inspector.

  • Here, you can choose whether an object is an ‘Occluder Static’ (blocks the view of other objects) or an ‘Occludee Static’ (can be blocked from view).

4. Configure Occlusion Culling Settings:

  • Go to the menu bar at the top, click on ‘Window’, navigate to ‘Rendering’, and select ‘Occlusion Culling’. This will open the Occlusion Culling window.

  • In the Occlusion Culling window, you will find settings like ‘Smallest Occluder’, ‘Smallest Hole’, and ‘Backface Threshold’. These settings help you fine-tune which objects should be culled.

5. Bake Occlusion Data:

  • In the Occlusion Culling window, click on the ‘Bake’ button. This process calculates which parts of your scene can be culled based on the camera’s perspective.

6. Testing Occlusion Culling in the Scene:

  • After baking, you can test the occlusion culling in your scene.

  • Move the camera around in your scene. You should notice that objects not in the camera’s view are not rendered, optimizing performance.

7. Adjusting Camera Settings:

  • Ensure your main camera is set up to utilize occlusion culling.

  • Select the main camera, go to the Inspector, and find the rendering section. There should be an option for occlusion culling which needs to be enabled.

8. Final Checks and Tweaks:

  • Play your scene to see occlusion culling in action.

  • You may need to adjust the properties of your objects and the occlusion culling settings to get the desired effect.

9. Optimization and Debugging:

  • As you test your scene, look for any performance improvements or potential issues that may arise from occluding objects.

  • Make necessary adjustments to optimize the balance between performance and visual fidelity.