I’m having some major dramas with occlusion culling in a game that I thought would handle it really well (grid-based, 1x1 unit floortiles).
Every level has the same occlusion culling settings, 0.95 being just below the size of the wall, floor, and roof tiles… right? (I’ve tried a bunch of variations):
Some of the levels are perfect - no problems at all. But then I walk into a very simple rectangular room, and something like this happens (top-down view looking at the floor):
All of the floor tiles, walls, etc right in front of the player get culled.
Looking at the side views, you can see the visibility lines sometimes get “blocked” in front of the player, other times they make it to the roof, so you can see that, but no floor. Most of the time it’s even culling the enemy in the room which is non-static.
Any thoughts on what I’m doing wrong? I don’t get it.
I think I just figured something out that was probably obvious to everyone except me…
You need to turn off the camera occlusion culling if you’re using baked occlusion culling? Now that I’ve done that, everything seems to be working MUCH better.
EDIT: Actually according to the manual, that’s NOT the case. So I don’t understand why things work much better when I turn the camera setting off.
There’s still stuff I can’t explain though - like why when I’m standing right in front of a wall (that is bigger than the smallest occluder setting) is the game still rendering what’s behind that wall?
I also suspect that the “Stats” don’t properly take into account occlusion culling? Or at least I hope that’s the case. Either that or the visualisation doesn’t really work properly. Check out these two examples at opposite ends of the room. The visualisation shows that around the same amount of geometry is being rendered, but check out those stats!
For proper deductive reasoning we have to establish a ‘Baseline’. that is what he is asking.
Just for kicks, try even/larger numbers. it is that or something unique about those polygons/shaders, producing an inverse view matrix, which, I admit is bizarre… use whole numbers and always power of 2, please try it? p-
Obviously I’ve tried all the basic stuff - this isn’t my first 70’s themed disco.
I was looking for advice from someone who knows how the occlusion culling system works and might be able to tell me why my specific problems above would be occurring. e.g. regardless of the parameters, if they’re the same parameters on two levels which use the same geometry, then you would expect similar results, right? Not a level that works perfectly and another that’s completely broken.
If anyone has any advice specific to my issues described above, please let me know.
Still hopeful that someone might have some advice on this one? Another perfect example below - why is Unity rendering a bunch of stuff outside of the small, closed room that I’m in? There’s no possible “hole” in the geometry larger than 0.25 units (which is the setting on this example).
Alright… so I might have just found the answer to this, though I can’t get my head around it.
The walls in my game (for example) are imported with a scale factor of 1. Their local scale is also 1,1,1. Based on that, I concluded that my “Smallest Occluder” should be set to 1. Seemed logical based on my understanding of what “Smallest Occluder” meant, and based on the default setting of 5, that didn’t seem like a stretch.
I was then setting my “Smallest Hole” to 0.25 - assuming, given my scale of 1, that anything that large should definitely reveal the geometry behind it.
Anyway, for shits and giggles tonight I thought - Hey Steve! What if everything is just off by a huge factor for some unknown reason?!
So… I set my “Smallest Occluder” to 0.1 and my “Smallest Hole” to 0.025, rebaked, ran the game, and… everything now works PERFECTLY.
So what’s the story there?
This also now leads me to another question. In the doco there’s discussion about the tradeoff of the amount of occlusion data that must be parsed vs the saving that it gives. Using the old figures, the bake was super quick and resulting in about 50KB of data (but the occlusion was next to useless). Now it takes a minute to bake (no worries) and results in about 4MB of data for an average level. So, the question, how much occlusion data is considered “a lot” of occlusion data?
I don’t know the actual algorithm behind Occlusion Culling in Unity, but it will probably use some kind of tree data structure. Given a camera position, it will then need to go down the nodes till it finds the one with the appropriate PVS (potentially visible set). It will depend on your scene how much of that data is the actual tree, and how much of it is just PVS-lists.
If we just assume there are 100 references per node costing 4 bytes each, we could calculate 4MB of data = 4,000,000 / 400 = 40,000 nodes. If it’s a binary tree you will then need lg(40000)/lg(2) ≈ 16 steps to find the correct node. If it’s an oct tree it will be closer to lg(40000)/lg(8) ≈ 6. Either way that is not a lot, even if deciding which node to traverse is a bit costly (some vector math required).
I might of course be completely wrong with everything I just said, though, but you always can (and should) try to tweak your values to balance size and quality. You divided your values by a factor of 10. Maybe multiply by 2 again and see how that goes.
Turns out I spoke too soon. There are still levels that don’t work using the 0.1, 0.025 setting. Same geometry as the levels that do work, same sort of layout of walls, floors, roof tiles, etc… just completely different results. I’ve found one level where NOTHING but the floor tile directly under my feet gets rendered sometimes when I’m walking around.
Seriously over occlusion culling. Again, if anyone KNOWS how this should work, please advise (hint hint, someone from Unity who worked on occlusion culling would be nice).
Changed the smallest hole setting to 0.075 and NOW everything that I’ve been able to test seems to be working correctly. Again though, in the context of my scale, I can’t explain why 0.075 vs 0.025 would make any difference to the issues that were occurring, nor why it’s 0.075 and not 0.75, given a unit size of 1.0.
A related, but separate discussion - I’d love to hear people’s interpretations of what they understand an “Occlusion Area” to be, and how they would use them in a scene.
Mainly, I’m referring to the Unity docs lead you to believe you need an Occlusion area to occlude dynamic objects. This is not true. The true reason for Occlusion Areas aren’t mentioned in the Unity docs.
The Unity documentation is pretty abysmal for a lot of these key systems. It’s pretty slack.
What I find is missing is use case data - e.g. how MUCH should a level be carved up into Occlusion Areas, how many is too many, where should the demarcations be, same goes for Light Probes, same goes for Reflection Probes, etc etc.