1
\$\begingroup\$

In the following code, I try to draw a mesh using 4 different methods:

Code:

private void Update()
{
    // ...

    var count = 0;

    Material.SetPass(0);

    Material.mainTexture = Textures[TextureIndex];

    var rotation = Camera.main!.transform.rotation * Quaternion.AngleAxis(90, Vector3.left);

    foreach (var effect in effects)
    {
        if (effect.count <= 0)
        {
            continue;
        }

        var position = Constants.Transform.MultiplyPoint(effect.pos);

        var matrix = Matrix4x4.TRS(position, rotation, new Vector3(Scale, Scale, Scale));

        Matrices[count++] = matrix;

        if (UseInstanced)
        {
            continue;
        }

        if (UseRenderMesh)
        {
            Graphics.RenderMesh(new RenderParams(Material), Mesh, 0, matrix); // works
        }
        else
        {
            Graphics.DrawMesh(Mesh, matrix, Material, 0); // works
        }
    }

    if (!UseInstanced)
    {
        return;
    }

    if (UseRenderMesh)
    {
        Graphics.RenderMeshInstanced(new RenderParams(Material), Mesh, 0, Matrices, count); // BUG not working
    }
    else
    {
        Graphics.DrawMeshInstanced(Mesh, 0, Material, Matrices, count); // BUG not working
    }
}

The material has enableInstancing set to true as explained in the docs.

There's no warning or error shown in the console but still nothing...

What's wrong?

\$\endgroup\$

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.