Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Material property block for Path tracer

Discussion in 'HDRP Ray Tracing' started by stevenMoonen, Jan 11, 2021.

  1. stevenMoonen

    stevenMoonen

    Joined:
    Oct 19, 2020
    Posts:
    6
    I need to change some properties of a material for an object. When using the rasterization pipeline this works fine with the setPropertyBlock function of the renderer of that object. But these changes are ignored when I switch from the rasterization pipeline to the path tracer. Is there a similar feature to set material properties for the path tracer or is the only solution to make a copy of my material and directly changing this?

    Code (CSharp):
    1. Renderer renderer = GameObject.Find("myObject").GetComponent<Renderer>();
    2. MaterialPropertyBlock newProperties = new MaterialPropertyBlock();
    3. renderer.GetPropertyBlock(newProperties);
    4. newProperties.SetColor("_Color", new Color(0.3f, 0.4f, 0.6f));
    5. renderer.SetPropertyBlock(newProperties); // works for the rasterization pipeline but not for path tracer
     
  2. INedelcu

    INedelcu

    Unity Technologies

    Joined:
    Jul 14, 2015
    Posts:
    173
    This should work fine starting with 2020.2.
    The support for SetPropertyBlock in ray tracing was added in 2020.2.
     
    stevenMoonen likes this.
  3. INedelcu

    INedelcu

    Unity Technologies

    Joined:
    Jul 14, 2015
    Posts:
    173
    I tested your code in 2020.2.0f1 and works as expected.
     
    stevenMoonen likes this.
  4. stevenMoonen

    stevenMoonen

    Joined:
    Oct 19, 2020
    Posts:
    6
    This indeed got fixed in version 2020.2.0f1 but I noticed this behavior has reappeared as of version 2022.2.0b1 (it might have happened sooner version 2021.2.0b1 is the last version I tested where it still worked.) I also tested on version 2023.3.0b7 and here its still broken.

    So to reiterate: when using the property block to override the BaseColor of the lit shader (see script below) the new value is ignored when enabling the Path Tracing volume override but it is used when disabling this.
    Code (CSharp):
    1. Renderer renderer = this.gameObject.GetComponent<Renderer>();
    2. MaterialPropertyBlock newProperties = new MaterialPropertyBlock();
    3. renderer.GetPropertyBlock(newProperties);
    4. newProperties.SetColor("_BaseColor", new Color(1.0f, 0.0f, 0.0f));
    5. renderer.SetPropertyBlock(newProperties);
     
  5. INedelcu

    INedelcu

    Unity Technologies

    Joined:
    Jul 14, 2015
    Posts:
    173
    Hi! Thanks for reporting the issue. It will be fixed ASAP and backported.
     
    stevenMoonen likes this.
  6. stevenMoonen

    stevenMoonen

    Joined:
    Oct 19, 2020
    Posts:
    6
    I just tested version 2023.3.0b10 and it works again!
    Thanks for the support.