Search Unity

[Unity5] Graphics.DrawMesh with reflection probes

Discussion in 'General Graphics' started by Hyunkell, May 5, 2015.

  1. Hyunkell

    Hyunkell

    Joined:
    Apr 1, 2013
    Posts:
    2
    I'm trying to render a large stack of items using Graphics.DrawMesh in order to avoid creating a GameObject for each item.
    I have found that by default, meshes rendered using Graphics.DrawMesh ignore all reflection probes. (They use the skybox as a reflection source instead)
    The only overload of Graphics.DrawMesh that does use reflection probes is the one taking an anchorProbe parameter. Unfortunately the only version of this overload does not take a transform matrix. It only supports position and rotation (but not scale)

    Here's a small code snippet illustrating the issue: (disable all but one Graphics.DrawMesh call)
    Code (CSharp):
    1. [ExecuteInEditMode]
    2. public class TestComponent : MonoBehaviour
    3. {
    4.     public Mesh mesh;
    5.     public Material material;
    6.     void Update()
    7.     {
    8.         if( mesh != null && material != null )
    9.         {
    10.             // Ignores reflection probes
    11.             Graphics.DrawMesh( mesh, transform.localToWorldMatrix, material, 0 );
    12.             // Ignores reflection probes
    13.             Graphics.DrawMesh( mesh, transform.localToWorldMatrix, material, 0, null, 0, null, UnityEngine.Rendering.ShadowCastingMode.On, true );
    14.             // Uses reflection probes
    15.             Graphics.DrawMesh( mesh, transform.position, transform.rotation, material, 0, null, 0, null, UnityEngine.Rendering.ShadowCastingMode.On, true, transform );
    16.         }
    17.     }
    18. }
    Is this intended behaviour or is it a bug? If it is intended to work like this, is there any chance we can get an overload of Graphics.DrawMesh that takes both a transform matrix and a probe anchor as parameters?
    Code (CSharp):
    1. public static void DrawMesh(Mesh mesh, Matrix4x4 matrix, Material material, int layer, Camera camera, int submeshIndex, MaterialPropertyBlock properties, Rendering.ShadowCastingMode castShadows, bool receiveShadows = true, Transform probeAnchor = null);
    Cheers,
    Hyu
     
  2. sloopidoopi

    sloopidoopi

    Joined:
    Jan 2, 2010
    Posts:
    244
    This seems to be a bug.(Have the same issue) But thanks for the workaround with the right method call .
     
  3. SeriousBusinessFace

    SeriousBusinessFace

    Joined:
    May 10, 2014
    Posts:
    127
    Perhaps there's an ancillary problem that could be solved - What problems are you seeing with having one game object per mesh?
     
  4. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Graphics.DrawMesh is not necessarily going to be faster than one game object per mesh. From my understanding, every call to Graphics.DrawMesh is a separate draw call - where as separate game objects will be dynamically batched if they are under ~300 vertices. I was doing some work with asteroid fields a while ago and found that Graphics.DrawMesh was actually many times slower than just making lots of game objects.
     
  5. RosieGarden

    RosieGarden

    Joined:
    May 4, 2013
    Posts:
    33
    Actually, from my experience, Graphics.DrawMesh uses the same dynamic batching that separate gameobjects uses.