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)
[ExecuteInEditMode]
public class TestComponent : MonoBehaviour
{
public Mesh mesh;
public Material material;
void Update()
{
if( mesh != null && material != null )
{
// Ignores reflection probes
Graphics.DrawMesh( mesh, transform.localToWorldMatrix, material, 0 );
// Ignores reflection probes
Graphics.DrawMesh( mesh, transform.localToWorldMatrix, material, 0, null, 0, null, UnityEngine.Rendering.ShadowCastingMode.On, true );
// Uses reflection probes
Graphics.DrawMesh( mesh, transform.position, transform.rotation, material, 0, null, 0, null, UnityEngine.Rendering.ShadowCastingMode.On, true, transform );
}
}
}
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?
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