- Home /
Occlusion Culling still rendering hidden gameobjects.
Hello, I'm trying to learn C# coding and Unity so I'm having fun and recreating some of the mechanics from Minecraft.
I'm trying to get some Occlusion Culling working properly so I can boost performance and FPS. However, even tho I am only viewing a small portion of game objects (blocks) it still renders A LOT of blocks that aren't even visible. I would prefer it to simply hide any blocks that are not visible at all and only render ones the player can see (if a block is hidden behind 1 block that is visible, I would like that hidden block to not render.)
I've tried messing around with the OC Bake parameters but nothing seems to change and I don't fully understand what they do. I'm a big newb and still learning so any help would be appreciated. Thanks!
EDIT: I should have probably mentioned I already set all my blocks in the static drop-down to "Occluder" and "Occludee". And these blocks are generated at runtime not in pre-scene, therefore I baked 1 block beforehand to get occlusion culling working in the first place. Also my blocks are made of 6 quads, not primitive cubes or a custom script-made mesh.
Answer by RendrWyre · Jan 14, 2020 at 04:12 PM
You don't really provide any information so I'm going to take a stab in the dark.
1) Unity needs to know if an object is an "Occludee Static" or an "Occluder Static". For example, any blocks that could potentially occlude another block should be marked as an "Occluder" and, subsequently, any blocks that could potentially be occluded by another block need to be marked as "Occludee".
Marking all of your blocks as both "Occluder" and "Occludee" should solve your issue.
2) For performance reasons I would suggest looking into GPU instancing. For example, the material used for each block should be marked as "GPU Instance" (this means the blocks can not be marked as "Batching Static").
https://docs.unity3d.com/Manual/GPUInstancing.html
3) https://docs.unity3d.com/Manual/OcclusionCulling.html is the best place to understand what is happening. For example
Smallest Occluder - The size of the smallest object that will be used to hide other objects when doing occlusion culling.
So if you're smallest block is 1 meter x 1 meter, your smallest occluder needs to be set appropriately.
I don't know if this will suit your problem 100% depending on what you are trying to do (are you generating and destroying blocks at runtime?).
Apologies, I should have explained or given more information. The picture shown is result of "Occluder" and "Occludee" already being set. (I have everything turned off in static drop-down except those 2).
As I said I have default parameters, so Smallest Occluder is set to 0.25. I'm guessing for a 1x1 cube, the correct setting would be 1 ins$$anonymous$$d of 0.25?
And yes, the blocks are generated at runtime.
$$anonymous$$y blocks are made of 6 quads and then prefabbed ins$$anonymous$$d of the primitive cube or a script-made mesh. This is my lazy way of adding multiple textures to a cube without UV mapping. I've made sure the parent gameobject and all the children (quads) have the Occluder and Occludee set on them, but could the way I've made my cubes be effecting the occlusion results here?