if you have the unity free version is there any way of creating a simple occlusion cull with say raycast?
Occlusion culling, ie. not rendering objects that are infront of the camera but are not seen is not available in Unity Free.
I had done something like a custom Occlusion Culling before.
STEPS:
-
Identify objects that can be seen only from certain places. This maybe anything - a high polymesh behind a building that can be seen only when you go behind the building. Or maybe objects that are inside a room and can be seen only when you are infront of the door of the room etc. disabling the renderer of high poly assets in the scene can lead to an increase in performance.
-
Identify all the places ( which I called ‘cells’ ) from which the object can be seen. Only when the player/camera comes in the cell the object which can be seen only from that cell is rendered. Renderer can be switch on by using :
renderer.enabled = true;
What I did was I placed box colliders in all such places with their trigger on. These trigger colliders had a javascript called “OC.js”.
I don’t have the script now, but it was easy to comprehend and was something like this :
var objThatCanBeCulled : Renderer[]; //array of objects that can be culled when the player/camera come to this cell
function OnTriggerEnter(other : collider){
if(other.gameObject.tag == "player"){
for(i = 0 ; i < objThatCanBeCulled.size ; i ++){
objThatCanBeCulled*.enabled = true; //turn off the renderer of all the objects*
}
}
}
//similarly use OnTriggerExit to turn off the renderers
If I am not wrong, then Occlusion Culling in Unity is done using grids. Here, I did it using block triggers. This way is explicit and a bit manual, so you have to use it more carefully other wise it might give you unfavorable results. However if used well, it can give you results you would expect with occlusion culling (only a little less ) - example if you are making something like the good old Wolfenstein3D ( the old FPS with a lot of rooms to be opened ), then you can turn off the renderer of the objects in the room that hasn’t been opened yet. For that you would need a different script system, but the concept is the same, if you can’t see it, don’t draw it.
There are also other ways to improve frame rate by different kinds of culling processes. Unity automatically applies frustum culling. Apart from that you can use distance fog, or layerCullDistances, both of which are explained in the Unity manual and can be really usefull. You can also use LOD ( level of detail ) method.
I hope this helped!
Yes there is indeed,
InstantOC
it’s a ray-based dynamic occlusion culling and LOD system for Unity, compatible with all versions of Unity. You can grab it on the Asset Store for 15$