Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Problems With Occlusion Culling

Discussion in 'General Graphics' started by JeanFinley, Dec 23, 2021.

  1. JeanFinley

    JeanFinley

    Joined:
    Aug 12, 2017
    Posts:
    6
    I'm trying to implement Unity's standard occlusion culling but I'm having trouble getting good results. A lot of objects that seem like they should be occluded are still being drawn.

    Some info about the project/scene:
    • I'm using URP.
    • I have one camera in the scene and it has Occlusion Culling enabled and set to Everything.
    • All of my objects are static occluders and occludees (and all the other static flags are also enabled on them).
    • The walls, floors and other structural geometry are mostly modular, so there are very few large meshes that would be occluded poorly in that regard.
    • Most of the geometry that's not occluding is opaque (and has an opaque material)

    What I've tried:
    • I turned off static batching, SRP batcher and GPU instancing in case that was causing problems but there was no change.
    • I've tried various occlusion baking settings which did change the output but no combination gave good results.
    • I turned off dynamic occlusion on objects, that had no effect.

    Occlusion culling is definitely working in some capacity but it's not working properly, or at least not well enough. The visibility lines pass through a bunch of geometry and end up drawing objects that are on the other side of the level with many objects in between.

    This is what the scene looks like without occlusion:
    upload_2021-12-23_15-16-0.png

    Here it is with occlusion, with the camera to the left. You can see on the top right there's a section of the level that's behind multiple layers of walls and yet is still drawing:
    upload_2021-12-23_15-15-39.png

    Here's the previous image with visibility lines enabled. Honestly I'm not entirely sure how these work but it seems strange to me that they're going as far as they are:
    upload_2021-12-23_15-15-23.png

    This is the camera view:
    upload_2021-12-23_15-30-35.png

    Here's an example of a visibility line just straight up going through solid geometry:
    upload_2021-12-23_15-19-39.png


    Any insight on why the results aren't great would be appreciated. Am I doing something wrong? Or am I just hitting engine limitations?

    Thanks
     
  2. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,008
  3. JeanFinley

    JeanFinley

    Joined:
    Aug 12, 2017
    Posts:
    6
    I tried setting smallest hole to be quite large - certainly much larger than any gap between modular geometry would be - so the camera shouldn't be able to see between the modular pieces.

    I tried your suggestion with an occluding cube and these are the results. It's still failing to occlude everything behind it, but interestingly, it is occluding more than before. That giant cube should definitely be hiding everything behind it as far as I understand and I'm really not sure of the logic behind why it's only hiding certain things.

     
  4. Deleted User

    Deleted User

    Guest

    It maybe because u have the whole room as one mesh???
     
    bealion likes this.
  5. sameng

    sameng

    Joined:
    Oct 1, 2014
    Posts:
    172
    I've had this issue since forever. Occlusion culling sadly never worked for me, even in cases where there are huge huge colliders like cubes, and many small objects that SHOULD be occluded. Just like your scene.

    I would even have massive 50x50 cubes and a tiny 0.1x0.1 object still being rendered on the other side of it.

    It also costs quite a bit of CPU on modern consoles. The fact that it barely works, and it costs so much in terms of memory and CPU usage, I gave up on it and created my own basic zone-based system.

    It sucks cause I would love to use occlusion culling instead of my basic dumb system.

    Would love to see a response from Unity on this, or at least an example scene with best practices. I know that Umbra is a black box so I doubt it's still being supported. I have a feeling it will never be fixed, and stay in this broken state until replaced with a new solution.
     
  6. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,008
    No I have a lot of objects, houses etc.

    What I find strange with your screenshots is that you are showing only camera lines, like there is no occlusion tree objects that are shown during debugging.


    Occlusion culling works for me, mostly, with some caveats.

    I'm using metric system for my level , human is about 2 m in size.
    Objects are set to static, material must be opaque, transparent materials are ignored.
     
  7. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,008
    For the beginning test with default values, smallest hole 0.25

    But you might set smallest occluder for something small, default is 5, it might be to big for your case.
     
  8. JeanFinley

    JeanFinley

    Joined:
    Aug 12, 2017
    Posts:
    6
    There are like 16k meshes lol

    I tried the default values, I tried making each value smaller, making each value larger, and various values in between. Even if there was a problem with the smallest hole value, there's no hole in that giant cube in the last screenshot I posted so that couldn't be the problem.
    Yeah I ended up buying an asset that uses a totally different method for occlusion culling. I'm getting much better results with it, at least good enough, hopefully. Maybe we'll get a better system in future!
     
  9. Neto_Kokku

    Neto_Kokku

    Joined:
    Feb 15, 2018
    Posts:
    1,751
    The default occlusion culling system is rubbish, sorry. AFAIK Unity uses a very ancient version of Umbra and the integration has been basically left to rot, so it only works in very narrow use cases.
     
  10. sameng

    sameng

    Joined:
    Oct 1, 2014
    Posts:
    172
    Which asset are you using? Would you mind sharing a review of it? I'd love to hear your thoughts.
     
  11. burgee

    burgee

    Joined:
    Feb 28, 2016
    Posts:
    14
    The freakin' classic "nvm guys i fixed it" but offers literally no explanation or details of how.

    Love it. Having the same issue, would love to know his asset that worked well.
     
  12. sameng

    sameng

    Joined:
    Oct 1, 2014
    Posts:
    172
    Yep. I've also since tried Perfect Culling, which is decent.

    It's better than umbra for sure. It requires some setup. It's much "dumber" than umbra, but I think it makes it better.
    The downside is the bake process, but if you can get a handle on it, perfect culling works really well.
     
  13. nait23

    nait23

    Joined:
    Dec 13, 2018
    Posts:
    1
    Same problem. Fixed by seting up Occlusion Area.