[SRP] MaterialPropertyBlock timing

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:

  • OnPreCull

  • OnWillRenderObject

  • 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:

  • OnPreCull
  • OnPreRender
  • 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?

You use custom SRP or URP/HDRP?

Custom SRP