Occlusion
Information about setting up occlusion in Flora.
GPU Occlusion
Flora employs a hi-z implementation for GPU occlusion culling, utilizing the depth buffer from the previous frame to cull occluded objects. This technique involves down-scaling the depth buffer from a Unity camera, allowing Flora to determine whether instances are obscured by other GameObjects or instances in the scene.
The process works as follows:
Depth Buffer Down-Scaling: Flora captures and down-scales the depth buffer from the Unity camera each frame.
Occlusion Testing: The GPU uses the down-scaled depth textures from the previous frame to perform occlusion tests on objects in the current frame.
Culling: Objects that are determined to be occluded (i.e., behind other objects) are culled, meaning they are not rendered. Only objects that were un-occluded in the previous frame are rendered.
Rendering: Flora then proceeds to render the remaining un-occluded objects.
Performance Considerations
The effectiveness of GPU occlusion culling in enhancing rendering performance is highly dependent on the specific characteristics of your scene. Here are the scenarios where GPU occlusion culling is most beneficial:
Homogeneous Objects: When multiple objects share the same mesh and material, Flora can batch these objects into a single draw call, optimizing rendering performance.
High Occlusion Scenes: In scenes with significant occlusion, particularly where occluded objects have a high vertex count, occlusion culling can substantially reduce the rendering workload by eliminating unnecessary draw calls.
Potential Performance Overhead
While GPU occlusion culling can significantly speed up rendering in occlusion-heavy scenes, it may also introduce additional GPU overhead in scenarios where occlusion is minimal. This is because the GPU must perform extra work to set up and execute the occlusion culling process. If occlusion culling does not substantially reduce the number of objects being rendered, the overhead may result in an overall increase in rendering time.
Enabling
To enable GPU occlusion in Flora, follow these steps:
Add the
InstancingCameraSettings
Component:Select the camera you wish to enable GPU occlusion for.
Add the
InstancingCameraSettings
component to the camera.
Set
InstancingOcclusionMode
toGPU Hi-Z
:Within the
InstancingCameraSettings
component, locate theInstancingOcclusionMode
setting.Change the
InstancingOcclusionMode
toGPU Hi-Z
to activate GPU occlusion culling.
Enable GPU Occlusion in SceneView Camera:
Open the SceneView window in Unity.
Go to the view options toolbar, typically located at the top right corner of the SceneView.
Access the scene view camera settings and enable GPU occlusion from there.
Debugging
Flora provides robust debugging tools to help you fine-tune and analyze the effectiveness of GPU occlusion culling.
Accessing the Instance Debugger
Navigate to the top menu bar in Unity.
Go to Flora -> Instance Debugger to open the instance debugger window.
GPU Occlusion Debugging Options
Within the instance debugger, you’ll find several options specifically for debugging GPU occlusion:
Occlusion Overlay:
Locate the GPU Occlusion section in the instance debugger.
Enable the Occlusion Overlay toggle to activate a colored visualization. This overlay displays a gradient of colors based on the number of instances occluded, helping you visualize which parts of your scene are being culled.
Dispatch Counter:
Near the end of the debugger display options, find the Dispatch Counter toggle.
Enable this toggle to show the exact number of instances that are occluded vs drawn when GPU occlusion is active.
CPU Occlusion
Flora can query Unity's baked occlusion data when it is built for a scene, leveraging this information to enhance culling performance.
Unity's Occlusion Culling Baking
Unity provides a built-in system for occlusion culling, which involves baking occlusion data for your scenes. This data helps determine which objects are visible and which are hidden behind other objects, thus improving rendering performance.
For more information on how to bake occlusion data in Unity, refer to the Unity Occlusion Culling Documentation.
Culling Groups
Instead of culling individual instances based on Unity's occlusion data, Flora groups instances into clusters within the BVH. Flora creates a Unity CullingGroup
and uses this group to receive notifications when a group of instances is occluded. This method reduces the number of occlusion queries needed and efficiently handles large numbers of instances.
Optimized for Lower-End Platforms
This CPU-based occlusion culling method is particularly beneficial for lower-end platforms, such as mobile devices, where GPU occlusion may be too resource-intensive. By utilizing CPU occlusion culling, Flora ensures efficient rendering performance without overburdening the sys
Last updated