- Home /
How do i do frustum culling in runtime
To frustum cull with objects created in runtime, in the editor you could
Change the script to execute in edit mode using [executeineditmode]
Click play
Click play again (To stop the game)
Bake
Click play
and then you would have frustum culling working with your generated objects in runtime. However, in a app it is not possible to do this. So i was thinking, if you could get the bake script that Unity uses, and then run it in runtime, it may work, however i am not sure. I doesn't matter if it takes a long time ( as long as its not over a minute) to work out all the geometry, as long in the end the game runs quickly. I have looked at some of the plugins that say that they can do frustum culling in runtime, but looking at the comments on these plugins shows me that all that they do is send rays all over where the camera is looking, and this results in only a slight optimization. If it is impossible to use the bake script in runtime, then is sending rays all over where the camera is viewing and then rendering what the rays hit the best way? Because that's what all the scripts i looked up were doing. Thanks!
You are probably confusing Occlusion culling and frustum culling.
frustum culling: Cull geometry that is outside of your camera's view frustum. occlusion culling: Culling geometry that is fully occluded by other geometry.
Unity does frustum culling for all geometry without baking based on their bounding boxes at runtime.
In theory it would be possible to build a script that can build occlusion data on request at runtime, but unity has non such script / function built in. The reason the moste runtime occlusion culling asset are just using raycast is that it can handle very dynamic changing geometry like destroyed walls or all type of dynamic geometry. The the performance benefits of occlusion culling depends on your scene layout.