[UE4]Occlusion Culling
keywords: Occlusion Culling, 遮挡剔除, 场景优化, Scene Optimization
Working principle of Occlusion Culling
Unreal Engine 4 uses an automatic process for culling that uses Scene Depth and the bounds of an object.
When using the Wireframe viewmode, this is not a good method for testing if an object is occluded in UE4. You can use the (Editor only) console command r.visualizeOccludedPrimitives 1
to view the occluded objects. This will render a green bounds box for any objects that are occluded. Adjusting the bounds scale will increase the green bounding box and can cause the mesh to be rendered even when it’s not in view.
In the project settings you can disable Occlusion Culling completely if you need, but in most cases this is not needed.
There is an alternative method of occlusion in the engine that is not on by default. It’s less strict than the currently default method. You can enable this by using the console command r.HZBOcclusion 1
This uses an approximation with occlusion culling. It will occlude the mesh dependent more on size and bounds scale than strictly on bounds scale. This can be useful in some instances, but problematic in others where it would cause meshes to be rendered that you wouldn’t necessarily wan to be when hidden. This is largely why it’s not on by default at the moment.
Using the first console command above is the best solution right now for debugging what’s being occluded and what’s not for the time being.
Original Text: How does object occlusion and culling work in UE4?
https://answers.unrealengine.com/questions/312646/how-does-object-occlusion-and-culling-work-in-ue4.html
Occlusion Culling doesn’t work
Dynamic occlusion is on by default and does a pretty good job when given the opportunity. Unless all your static meshes are all one single mesh then occlusion is working.
You can test this by using the console command r.visualizeoccludedprimitives 1
. This will create a green bounding box around the actors that are occluded. This will work only while working in the editor and not while in PIE/standalone game modes. Alternatively, you can use the console command freezerendering
to toggle the current rendering state. Move the camera to outside of the are where it’s suppose to occlude the actors behind it. Use the console command and then you’ll see Rendering Frozen
in the top left of the screen. You can now freely move the camera around the scene and it will have frozen/paused the actors at their current rendering state. So if they were occluded and not being rendered they will not be visible when you move the camera behind you walls that were occluding them.
This is a good method to start troubleshooting your occlusion issues. You can also use the console command Stat Initviews
while in PIE/Standalone game and look at the counters at the bottom. Follow the stat for Visibile Satic Mesh Elements. This number should rise and lower depending on the number of Static Meshes that are visible in the viewing area.
Lastly, for Precomputed Visibility Volumes, this is a static, offline, way of handling occlusion. There are some caveats to using it, but overall it can be used. Before investigating adding it to your game I would instead troubleshoot and narrow down the issues regarding your issue with dynamic occlusion before moving to something else.
There is some documentation that is being worked on for Visibility Culling, Precomputed Visibility Volumes, and Cull Distance Volumes that will be available hopefully in the not too distant future.
If your still having issues or something I said doesn’t make sense feel free to post back here.
Occlusion Culling doesn’t work
https://answers.unrealengine.com/questions/458450/occlusion-culling-doesnt-work.html
Occlusion Culling switch
Global Switch(In Editor):
Project Settings -> Engine -> Rendering -> Culling -> Occlusion Culling
. It’s checked by default.
Local Switch(for single Primitive):
Details Panel of Mesh -> Rendering -> LOD -> Never Distance Cull
, false
by default.
This property in C++ is UPrimitiveComponent::bNeverDistanceCull
.
Reference
Visibility and Occlusion Culling
https://docs.unrealengine.com/en-US/Engine/Rendering/VisibilityCulling/index.html
Understanding Culling Methods | Live Training | Inside Unreal
https://www.youtube.com/watch?v=6WtE3CoFMXU
六盘山上高峰,红旗漫卷西风。今日长缨在手,何时缚住苍龙? ----毛泽东《清平乐· 六盘山》