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.

2D Occlusion Culling

Discussion in '2D' started by Remiel, Mar 31, 2014.

  1. Remiel

    Remiel

    Joined:
    Oct 17, 2012
    Posts:
    103
    I am making a 2D game with an orthographic camera. There are no reflective surfaces, etc. so only things that are inside the camera's rectangular viewport need to be active.
    Since there are going to be many objects in the scene, there could be a large performance gain if objects that are outside of the viewport are deactivated (culled).

    Is there a way to achieve this through Unity's occlusion culling or do I need to write my own 2d occlusion culler? Could this be achieved effectively by unity's LOD system by specifying cull distance from the camera?
    What are your thoughts on this? Do you think the performance benefit could be large enough to outweigh the cost of culling?
    Are there any alternatives to achieve this?

    What if I didn't use an orthographic camera but a perspective one instead?
     
    Last edited: Mar 31, 2014
  2. mouurusai

    mouurusai

    Joined:
    Dec 2, 2011
    Posts:
    348
    You should do... you should do... nothing at all;)
    upd
    You can do not update some logic with "OnBecameVisible, "OnBecameInvisible" and boolean flag.
    if(!_isVisible)return;
    //some fancy stuff bellow
     
    Last edited: Mar 31, 2014
  3. Remiel

    Remiel

    Joined:
    Oct 17, 2012
    Posts:
    103
    Why?

    Update:
    The code for game logic/ai is mostly not the problem. The greatest performance impact goes to graphics.
     
    Last edited: Mar 31, 2014
  4. mouurusai

    mouurusai

    Joined:
    Dec 2, 2011
    Posts:
    348
    Objects outside camera frustum not rendered automatically. Occlusion culling? What kind of things can be occluded in 2D game?
     
    Last edited: Mar 31, 2014
  5. Remiel

    Remiel

    Joined:
    Oct 17, 2012
    Posts:
    103
    Documentation does mention that Unity disables renderers that are outside of camera view, but I never noticed it actually happening. Does it only happen at runtime and not in the editor?

    I used the term occlusion culling when I actually meant frustum culling -sorry for the confusion.
     
  6. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,352
    Unity doesn't disable the renderers of objects outside the camera view, instead it simply doesn't render them. That's what frustum culling does. It's impossible to see it happening, because they are outside of the camera view.... (You can turn the stats on, though, and see the effect that way, in terms of draw calls and stuff.)

    --Eric
     
  7. Remiel

    Remiel

    Joined:
    Oct 17, 2012
    Posts:
    103
    Ah, I see! Thank you for clearing that up.

    Thanks to you too mouurusai! I understand now what you meant when you said:
    I wasn't aware those two functions worked without manually turning the renderers on/off.
    Thank you for pointing them out to me!

    I'm marking the thread as resolved.