Search Unity

Question RenderMeshInstanced: transparent material not working on Quest 3

Discussion in 'VR' started by mw2357, Jan 20, 2024.

  1. mw2357

    mw2357

    Joined:
    Jul 12, 2020
    Posts:
    16
    Hi all,

    I stumbled upon the following issue: I want to draw several objects by RenderMeshInstanced in my Update()-routine. For this, I set up a material. The material can be transparent in some cases. When running the game in Unity, the transparent objects are shown transparent as they should, but on the Quest 3 they are always solid.
    Does anyone know what to change for transparent colors to work on the Quest? I set up my material as follows:

    Code (CSharp):
    1.  
    2. //clr is my color which can be transparent
    3. //mymat is the material to be rendered
    4.  
    5. mymat = new Material(Shader.Find("Standard"));
    6.  
    7. if(clr.a < 1)  //transparent
    8. {
    9.     mymat.SetOverrideTag("RenderType", "Transparent");
    10.     mymat.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
    11.     mymat.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
    12.     mymat.SetInt("_ZWrite", 0);
    13.     mymat.DisableKeyword("_ALPHATEST_ON");
    14.     mymat.EnableKeyword("_ALPHABLEND_ON");
    15.     mymat.DisableKeyword("_ALPHAPREMULTIPLY_ON");
    16.     mymat.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent;
    17.  
    18.     MaterialMarker.SetFloat("_Mode", 3.0f); //transparent
    19. }
    20. //else not transparent, nothing to change
    21.        
    22. //always: assign color and enable instancing
    23. mymat.SetColor("_Color", clr);
    24. mymat.enableInstancing = true;
    25.  
    26. rp = new RenderParams(mymat);
    Thanks a lot and best regards!
     
  2. mw2357

    mw2357

    Joined:
    Jul 12, 2020
    Posts:
    16
    Nevermind, I created two materials in the editor: one transparent and one opaque. And I switch between those two in the code instead of adjusting one material. That works :)
     
    DevDunk likes this.