Search Unity

Graphics.DrawMeshInstanced Doesn't work with transparent materials

Discussion in 'Scripting' started by Voltonik_, Mar 15, 2021.

  1. Voltonik_

    Voltonik_

    Joined:
    Jan 21, 2018
    Posts:
    22
    Im trying to render multiple quads using Graphics.DrawMeshInstanced. It works fine with opaque materials but when I change the surface type to transparent it doesn't render. (using HDRP btw)
    Here are some screenshots demonstrating the issue. Note the cube above the quad using the same material.
    Opaque:


    Transparent:


    Here is the code:

    Code (CSharp):
    1.  private void RenderClouds() {
    2.          cloudMaterial.SetFloat(cloudsWorldPosName, transform.position.y);
    3.          cloudMaterial.SetFloat(cloudsHeightName, cloudsHeight);
    4.          _offset = cloudsHeight / cloudsResolution / 2f;
    5.          var initPos = transform.position + (Vector3.up * (_offset * cloudsResolution / 2f));
    6.          for (var i = 0; i < cloudsResolution; i++) {
    7.              _cloudsPosMatrix = Matrix4x4.TRS(initPos - (Vector3.up * _offset * i), transform.rotation, transform.localScale);
    8.              _cloudMatrices.Add(_cloudsPosMatrix);
    9.          }
    10.          Graphics.DrawMeshInstanced(cloudMesh, 0, cloudMaterial, _cloudMatrices.ToArray(), cloudsResolution);
    11.          _cloudMatrices.Clear();
    12.      }
    13.  
    Is this a bug or am I missing something?
    Thank you.
     
    amisner2k likes this.
  2. amisner2k

    amisner2k

    Joined:
    Jan 9, 2017
    Posts:
    43
    Voltonik_ likes this.