Search Unity

"bounds" parameter in DrawMeshInstancedIndirect dictates world space position of mesh

Discussion in 'Documentation' started by OswaldHurlem, Sep 14, 2017.

  1. OswaldHurlem

    OswaldHurlem

    Joined:
    Jan 6, 2017
    Posts:
    40
    And not just frustum culling and other auxilary stuff. The documentation should note this.

    All the best,

    Ozzy
     
  2. bendf

    bendf

    Joined:
    Feb 28, 2017
    Posts:
    1
    Thanks for this. I was about ready to smash my head against my keyboard trying to figure out why my DrawMeshInstanced and DrawMeshInstancedIndirect calls were drawing at different locations.
     
    OswaldHurlem likes this.
  3. Pheck

    Pheck

    Joined:
    Jul 9, 2009
    Posts:
    225
    This is really frustrating and I dont fully get why unity is doing it this way, but this post helped me fix my issue.
    thanks
    I agree, the documentation should note that the bounds position is causing a render position offset. It made world space boids simulating relative to a moving object very difficult.
     
  4. leozzyzheng2

    leozzyzheng2

    Joined:
    Jul 2, 2021
    Posts:
    63
    I also found this, the bounds.center will be add to vertex's world position, so unity whats us always use bounds center at Vector3.zero, but If this affect the frustum culling, the bounds shouldn't be always center at Vector.zero, that's confused.
     
  5. owen_proto

    owen_proto

    Joined:
    Mar 18, 2018
    Posts:
    118
    thanks for posting this. i thought i was missing something.
     
  6. LazloBonin

    LazloBonin

    Joined:
    Mar 6, 2015
    Posts:
    812
    So, does the bounds parameter affect the frustum culling or not?

    If it does, as users, I'm assuming we're supposed to pass the bounds properly, but re-localize our matrices by the opposite of the bounds center?

    If it doesn't, as users, then I guess we should just pass default bounds (zero)?

    Can someone from Unity clarify this?
     
  7. leozzyzheng2

    leozzyzheng2

    Joined:
    Jul 2, 2021
    Posts:
    63
    I have done the test could make sure that this bounds is used for frustum culling.
    Cause I use GPU to do the whole culling so I just create a bounds with Vector.one size and put it in front of the camera every frame:

    Code (CSharp):
    1. new Bounds(camera.transform.poisition + camera.transform.forward * (camera.nearClipPlane + 1.0f), Vector.one);
    I plus 1.0f to nearClipPlane to make sure it won't intersect with near plane
     
  8. LazloBonin

    LazloBonin

    Joined:
    Mar 6, 2015
    Posts:
    812
    Thanks for chiming in, but I'm not sure I understand your reply.

    In your tests, for DrawMeshInstancedIndirect, is the bounds parameter used for frustum culling or not?
    What kind of test did you run to confirm?
     
  9. leozzyzheng2

    leozzyzheng2

    Joined:
    Jul 2, 2021
    Posts:
    63
    Yes for frustum culling.

    If the bounds you passed to DrawMeshInstancedIndirect it not inside the frustum, then Unity won't draw it.
    So I just create the bounds every frame and just make it always be the front of camera's direction. Then it will never be culled.
    But if you want the bounds is all instances' bounds, then you might need to calculate by you self.
     
    LazloBonin likes this.