Search Unity

GPU Instancing Sorting Limitation

Discussion in 'General Graphics' started by BPR, Aug 30, 2018.

  1. BPR

    BPR

    Joined:
    Jan 4, 2013
    Posts:
    56
    Hi,

    when I made some experiments with GPU instancing I came across some undocumented limitation of GPU Instancing. Besides meshes requiering to share same geometry, material, lights (in forward pass), reflection probe and lightmap (if any) - it seems only meshes can be instanced in the same draw call if they can be intersected by any single plane that is parallel to the camera image plane (I added a pink transparent plane to my screenshot to illustrate that). The chair contains 3 instanced materials (plus some draw calls for shadow depth calculations):
    noInstancingDepth.png activeInstancingDepth.png

    This is not exactly unexpected as I guess it is required for correct sorting, in fact I was doing the experiments in order to check for this... but I think it is odd that it is never mentioned in the documentation, so someone with no technical knowledge would expect to render a room full of objects that fullfill the above mentioned requirements in one draw call.

    Or am I missing an important setting here?
    Can the new scriptable renderpipelines maybe overcome that depth sorting limitation for GPU Instancing?
     
  2. BPR

    BPR

    Joined:
    Jan 4, 2013
    Posts:
    56
    Okay after some more testing it seems like there are some kind of zones (painted into the screenshot) in relative distance to the camera (so it is no parallel plane either), all objects that fullfill the above criteria and are in the same zone can be drawn with a single drawcall. If one instance is in a different zone then you have to draw it once more. The zone seem to get larger the further away from the camera they are (20 units from camera starts a zone that is about 20 units broad).

    InstancingDepthZones.png

    So to get maximum efffect out of instancing you want your objects clustered in depth and far away from the camera.
    btw the HDRP behaves the same way.
    Still would be nice if this was documented somewhere or even configurable.
     
  3. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    Try to turn of shadow cascades and see if that changes your zones.

    This is probably done to not drawing more objects than needed when rendering shadows. If you batched all of them they would all render 4 times to do 4 cascades.
     
    bgolus likes this.
  4. BPR

    BPR

    Joined:
    Jan 4, 2013
    Posts:
    56
    Hi,

    Shadow Cascades was already set to none, but even with 2 or 4 it does not affect these zones...
     
  5. FahmyEldeeb

    FahmyEldeeb

    Joined:
    May 11, 2021
    Posts:
    4
    Hello,
    2022 at the moment, we've ran into these limitations on URP 2020.3. We had no idea about them because any documentation that mentions them is non-exisistant at least none we could find.

    What we tested was simple distance, so a bunch of chairs, when they are near each other they are instanced, a bit far away they are not instanced, only like 20-30 units away not that far.

    It might be the distance from camera affecting them as mentioned here and we mistook it from distance to each other.

    But there's definitly lots of merit here
     
  6. joshuacwilde

    joshuacwilde

    Joined:
    Feb 4, 2018
    Posts:
    727
    Try turning turning off opaque sorting nice on the camera (through script). Also try setting a non-default value for the render order of the material.