Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Setting Camera.main.opaqueSortMode to NoDistanceSort doesn't work!

Discussion in 'General Graphics' started by BrightBit, Mar 7, 2017.

  1. BrightBit

    BrightBit

    Joined:
    Jan 22, 2013
    Posts:
    264
    According to the documentation NoDistanceSort should disable the distance based sorting of opaque objects. Assuming that "opaque objects" means objects in the "Opaque" render queue it doesn't seem to work.
    I've added a script to the camera with a method like this:

    Code (CSharp):
    1. void Start()
    2. {
    3.     camera.opaqueSortMode = OpaqueSortMode.NoDistanceSort;
    4. }
    ...but the Frame Debugger reveals in my small test scenario that the camera still does some distance based sorting:


    Moving "Cube (2)" further into the background will make it be rendered later, too.​

    I've attached the small test scene to my post that I've used to examine this feature. Did I do something wrong or is this feature broken?
     

    Attached Files:

  2. BrightBit

    BrightBit

    Joined:
    Jan 22, 2013
    Posts:
    264
    No one? Is this the wrong forum? Can at least someone test the scene that I've attached, please?
     
  3. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    Right forum, just no one with any answers. It's probably broken as a I doubt people use that feature often. I would report it.
     
    BrightBit and richardkettlewell like this.
  4. BrightBit

    BrightBit

    Joined:
    Jan 22, 2013
    Posts:
    264
    I've reported it in the meantime and the devs wrote back "We are currently investigating this problem and we will inform about our progress." :)
     
  5. Mariusj

    Mariusj

    Unity Technologies

    Joined:
    Oct 27, 2016
    Posts:
    8
    Hello everyone,

    There is an answer from our developers, so I will post it here in case anyone will need this information:

    "Thanks for raising this. Looking at your scene the simplicity kind of hides what is really happening in the batcher. I've made the code available here: https://hastebin.com/jeqemuqiqi.cpp

    So whats happening is that that flag controls the option 'doOpaqueDistanceSort'. This buckets things for nice material batching in terms of distance along the view frustum. You have disabled this. Afterwards it then falls through and tries to batch on shader, material, pass type and other things.

    At the very end if there is still no preferred draw order it does still order by depth (to help with overdraw). The name of the flag is slightly misleading, I will admit.

    As it stands now we have had an internal discussion and will not be modifying the current flow. The reason is that it could change how older scene batch / work, as well as make peoples scene slower (due to less z-culling)."

    We are aware that it is not documented very well since it can change pretty drastically between releases.

    To conclude, "OpaqueSortMode.NoDistanceSort" works as expected and it does not seem to be broken.
     
  6. hungtaikei

    hungtaikei

    Joined:
    Mar 31, 2017
    Posts:
    3
  7. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    About NoDistanceSort... I've noticed I pass from 1400 to 1100 draw call when using NoDistanceSort.

    I'm looking into this because I found out the normal GPU Instancing/Static batching is generally rather dumb and easily break a batch the moment a different mesh shows in between 2 batchable one.

    I assume NoDistanceSort might be bad with overdraw, as it pretty much render stuff without any distance check.

    However, I would really like a better batching algo that is a bit more tolerant to object order.
     
  8. lmartellmc

    lmartellmc

    Joined:
    Aug 3, 2018
    Posts:
    23
    Just tried this myself and NoDistanceSort cut the draw calls in half... mobile game with a lot of opaque objects but all atlased onto a single shared material/texture. Seems to be the same thing LightStriker said... batching algorithm isn't very smart and this might just shake things up enough that it can be more efficient.
     
  9. tinyant

    tinyant

    Joined:
    Aug 28, 2015
    Posts:
    127
    hi,the link is broken now.
     
    dev1_unity835 likes this.