Reputation: 77
I am using occlusion culling in Unity and it works well with the rotation of the camera. However, suppose a large wall is in front of the camera's view and behind the wall are many objects. Now because these objects are in direction of the camera, they do not get culled, even though they are not visible in camera's view. My question is, during such situation, can the occlusion culling work to even hide the object that are blocked in camera's view?
Upvotes: 1
Views: 3414
Reputation: 1
I had the same issue with unity 2017,2019 and 2020.
This happens when each axis of occluder's world position is on blue line and my smallest occluder setting is 2.
I solved this problem by making occluder not on the blue line.
Upvotes: 0
Reputation: 778
For a more thorough explanation, read through the following; if you want to get right to the point, jump to the conclusion at the end.
explanation: This is how occlusion culling works according to unity documentation:
Occlusion culling generates data about your Scene in the Unity Editor, and then uses that data at runtime to determine what a Camera can see. The process of generating data is known as baking.
When you bake occlusion culling data, Unity divides the Scene into cells and generates data that describes the geometry within cells, and the visibility between adjacent cells. Unity then merges cells where possible, to reduce the size of the generated data. To configure the baking process, you can change parameters in the Occlusion Culling window, and use Occlusion Areas in your Scene.
At runtime, Unity loads this baked data into memory, and for each Camera that has its Occlusion Culling property enabled, it performs queries against the data to determine what that Camera can see. Note that when occlusion culling is enabled, Cameras perform both frustum culling and occlusion culling.
More info on occlusion culling can be found here unity's doc on culling
So, basically, Unity uses these baked data to determine if the game object should be culled; but that is only for static game objects. Take a look at how unity can also cull dynamic game objects:
To determine whether a dynamic GameObject acts as a occludee, you can set the Dynamic Occlusion property on any type of Renderer component. When Dynamic Occlusion is enabled, Unity culls the Renderer when a Static Occluder blocks it from a Camera’s view. When Dynamic Occlusion is disabled, Unity does not cull the Renderer when a Static Occluder blocks it from a Camera’s view.
More information on how unity culls dynamic game objects can be found here: Using occlusion culling with dynamic GameObjects
Using the occlusion culling window, you should bake the data required by unity to enable Occlusion Culling occlusion culling window
Conclusion: So in order to cull your enemies which are behind the wall, the wall, the "Occluder", should be a static game object, your enemies, the "occluded"s should have Dynamic Occlusion
enabled on their renderer, the Occlusion culling
should be activated on your camera and Occlusion culling data should be baked for your scene.
Upvotes: 1