Search Unity

Using Graphics.DrawMesh to Draw a Combined Mesh from Static Batching

Discussion in 'General Graphics' started by ruj, Jan 27, 2015.

  1. ruj

    ruj

    Joined:
    Feb 28, 2013
    Posts:
    113
    A visual effect I am trying to create requires that I draw a number of the objects in the scene a second time, and I am trying to avoid having to do this as a second camera pass as that comes with quite a bit of overhead.

    When I try and draw the meshes using Graphics.DrawMesh() if doesn't work correctly, not surprisingly, since I don't know the matrix I should be passing in. Can anyone suggest a proper way to do this? Or maybe an alternate solution? Thanks!

    In addition, when I do try this, I would assume that the original mesh would be unaffected and should render normally before being rendered via this method, but that is not the case. It also breaks the primary rendering of the mesh, any ideas on why that would be the case??
     
    Last edited: Jan 27, 2015
  2. ruj

    ruj

    Joined:
    Feb 28, 2013
    Posts:
    113
    Partial solution, apparently passing in the identity matrix for a combined mesh gets it to draw in the correct place! However, the normal rendering of the combined object is somehow broken by this. The mesh is rendered in the correct place with my replacement material, but the normal material version is all scrambled up objects are all in seemingly random places, Thoughts?
     
  3. ruj

    ruj

    Joined:
    Feb 28, 2013
    Posts:
    113
    Solution: for anyone in the future who tries something like this, I was able to get it to work by specifically using the sharedMesh and rendering with the identity matrix. I'm not sure why using the regular mesh caused the objects to render incorrectly outside my DrawMesh() call, but it went back to normal once I switched to sharedMesh.

    IMPORTANT: even accessing the mesh, like assigning it to a variable, will break the whole render.
     
    Last edited: Jan 27, 2015
  4. migueltuliompg

    migueltuliompg

    Joined:
    Feb 12, 2018
    Posts:
    63
    Sorry to necro but this is exactly what I was looking for, thanks