Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

URP - Transparency mask

Discussion in 'Shaders' started by bibloc, Nov 2, 2020.

  1. bibloc

    bibloc

    Joined:
    Jan 31, 2018
    Posts:
    17
    Hello everyone,

    We would like to use MaterialPropertyBlock to increase performance but we got some problems with a ForwardRenderer feature (Transparency mask).

    Here is the expected result, which works without MaterialPropertyBlock.
    The transparent elements (sphere, cylinder and cube) masks the other transparent objects and you can still see through them (strictly speaking, they aren't opaque objects) :
    WithoutMaterialPropertyBlock.png

    But when we use MaterialPropertyBlock, the ForwardRenderer feature seems to be ignored :
    WithMaterialPropertyBlock.png

    The forward render feature we use :
    ForwardRenderer.png

    The transparency mask material :
    TransparencyMask.png

    Code (CSharp):
    1. public class MaterialPB : MonoBehaviour {
    2.     public Renderer[] transparentObjects;
    3.     public Color targetColor;
    4.     public bool useMaterialPropertyBlock = true;
    5.  
    6.     private MaterialPropertyBlock _materialPropertyBlock;
    7.  
    8.     void Start () {
    9.         _materialPropertyBlock = new MaterialPropertyBlock ();
    10.  
    11.         foreach (Renderer renderer in transparentObjects) {
    12.             if (useMaterialPropertyBlock) {
    13.                 renderer.GetPropertyBlock (_materialPropertyBlock);
    14.                 _materialPropertyBlock.SetColor ("_BaseColor", targetColor);
    15.                 renderer.SetPropertyBlock (_materialPropertyBlock);
    16.             } else {
    17.                 renderer.material.color = targetColor;
    18.             }
    19.         }
    20.     }
    21. }
    We use unity 2019.4.13f1 with URP 7.3.1.

    Does anyone have any ideas on how to fix the problem ?
     
    Last edited: Nov 2, 2020
  2. bibloc

    bibloc

    Joined:
    Jan 31, 2018
    Posts:
    17
    We got a response from QA Team, we forgot to set the 'Pass Index' to 2.
    In this way only the depth pass is rendered and we dont pay the cost of rendering the LitForward pass and it gives us the desired effect with MPB.
     
  3. bibloc

    bibloc

    Joined:
    Jan 31, 2018
    Posts:
    17
    If you use URP > 7.6, ou need to set the 'Pass Index' to 3.

    Because in 8.0.1:
    "Drawing order of SRPDefaultUnlit is now the same as the Built-in Render Pipline"