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

Geometry drawn with Graphics.DrawMeshInstanced disappears at certain camera orientation?

Discussion in 'General Graphics' started by Bas-Smit, Jul 25, 2019.

  1. Bas-Smit

    Bas-Smit

    Joined:
    Dec 23, 2012
    Posts:
    272
    Hi, Im using Graphics.DrawMeshInstanced and Graphics.DrawMeshInstancedIndirect without much problems, but at certain camera orientations the geometry disappears. It is very reliable, I can trigger the issue by rotating the camera back and forth a tiny amount. I am really struggling to understand how this is even possible, there is no culling going on when using these calls right?

    Another, perhaps related question is why does Graphics.DrawMeshInstancedIndirect want a bounds as an argument?

    Cheers, Bas
     
  2. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    You need to add a bounds that cover all the geometry for all the instances. The entire drawcall is culled against that bounds. If that is not visible in the camera nothing will draw.
     
  3. Bas-Smit

    Bas-Smit

    Joined:
    Dec 23, 2012
    Posts:
    272
    Thanks, that works for Graphics.DrawMeshInstancedIndirect, my props are no longer disappearing \o/

    Graphics.DrawMeshInstanced does not have an overload accepting a bounds, and I compute vertex positions in the shader so the mesh bounds were incorrect. I set it to a large number now which works:

    var mesh = new Mesh
    {
    ...
    bounds = new Bounds(Vector3.zero, new Vector3(1000000, 1000000, 1000000))
    };


    I used float.Maxvalue previously which doesnt work :S I am also a bit puzzled by this line from the docs:

    Meshes are not further culled by the view frustum or baked occluders


    I guess they are trying to say _individual_ meshes are not culled, but the draw call as a whole is...

    Cheers, Bas
     
    Baggers_ likes this.
  4. Zyblade

    Zyblade

    Joined:
    Jul 1, 2014
    Posts:
    139
    I know this thread is old. But I want to recommend not to oversize the bounds. When I did this, my shadow quality was quite worse than setting the actual needed size. It might not happen to every project, since mine has a very special setting, like close fit shadows, an orthographic camera etc. But maybe to someone, this info is helpful.

    It helped me alot, visualize the bounds (google "Draw Bounds with Debug.DrawLine" for a git example).
    This way, I realized, the bounds draw from the center and I put in the wrong origin.