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

[SRP] MaterialPropertyBlock timing

Discussion in 'General Graphics' started by vp_unity778, Sep 24, 2020.

  1. vp_unity778

    vp_unity778

    Joined:
    Apr 26, 2019
    Posts:
    1
    Hi,

    We're using Unity 2019.3.3f1 and we're in the process of upgrading our project from 5.6. We are using SRP for our rendering.

    We noticed an odd timing issue in regards to MaterialPropertyBlock.
    First of all, there are three rendering callbacks that we use:
    1. OnPreCull
    2. OnWillRenderObject
    3. OnPreRender
    In 5.6 they arrive in that order. OnPreCull we render reflections into a RenderTexture. OnPreRender we set a material texture property via MaterialPropertyBlock to use the reflection RenderTexture. This works fine and we see the reflections in-game.

    In 2019.3 we try to emulate the 5.6 rendering technique - we have our custom OnPreCull and OnPreRender callbacks. OnWillRenderObject is called when ScriptableRenderContext.Cull is called.

    However, we noticed an issue - if we try to apply the MaterialPropertyBlock OnPreRender - it doesn't get applied. Specifically, the reflection texture isn't set. Instead, the game view is rendered using the default texture (UnityBlack).

    If we then move the OnPreRender callback to happen before OnWillRenderObject - the texture is applied just fine, but the callback order becomes different from 5.6:
    1. OnPreCull
    2. OnPreRender
    3. OnWillRenderObject
    This seems like some sort of bug/regression - in 5.6 you could apply the MaterialPropertyBlock in the OnPreRender callback just fine, whereas now you must apply all the properties before ScriptableRenderContext.Cull is called. Is this intentional? Is there a way to workaround this issue and retain the callback order as in 5.6?
     
  2. BattleAngelAlita

    BattleAngelAlita

    Joined:
    Nov 20, 2016
    Posts:
    400
    You use custom SRP or URP/HDRP?
     
  3. unity_LWr7nIFrIpNQ1w

    unity_LWr7nIFrIpNQ1w

    Joined:
    Sep 22, 2020
    Posts:
    1
    Custom SRP