Search Unity

[FIX] Broken SSR in old custom shaders with latest HDRP 7.2+

Discussion in 'High Definition Render Pipeline' started by iceb_, Feb 18, 2020.

  1. iceb_

    iceb_

    Joined:
    Nov 10, 2015
    Posts:
    95
    Based on my testing, I am assuming that it is the latest HDRP 7.2+ that broke old materials' SSR. The automated HDRP upgrade process seems to fix the built-in unity HDRP shaders, but the custom shaders such as from Amplify Shader Editor gets broken. (If the materials were made prior to upgrading to latest HDRP)

    Here's my fix for it, I used Notepad++ to REGEX batch replace my affected *.mat files. Adjust the small details as needed.
    ---------------
    Fix materials with SSR:

    Replace this with NotePad++ REGEX and Newline turned ON:
    \- _StencilRef[^*]+\- _StencilWriteMaskMV: 176

    Replace With:
    - _StencilRef: 0
    - _StencilRefDepth: 8
    - _StencilRefDistortionVec: 4
    - _StencilRefGBuffer: 10
    - _StencilRefMV: 40
    - _StencilWriteMask: 6
    - _StencilWriteMaskDepth: 8
    - _StencilWriteMaskDistortionVec: 4
    - _StencilWriteMaskGBuffer: 14
    - _StencilWriteMaskMV: 40
    - _SubsurfaceMask: 1
    - _SupportDecals: 1
    -------------------

    The above REGEX searches for this old broken code in the shader file:
    - _StencilRef: 2
    - _StencilRefDepth: 0
    - _StencilRefDistortionVec: 64
    - _StencilRefGBuffer: 2
    - _StencilRefMV: 128
    - _StencilWriteMask: 3
    - _StencilWriteMaskDepth: 48
    - _StencilWriteMaskDistortionVec: 64
    - _StencilWriteMaskGBuffer: 51
    - _StencilWriteMaskMV: 176
     
  2. SebLagarde

    SebLagarde

    Unity Technologies

    Joined:
    Dec 30, 2015
    Posts:
    934
    Hi,

    you are right, our upgrade only work with built in HDRP shader.
    We have change our stencil usage which explain why you get error.
    The automatic upgrader call HDShaderUtils.ResetMaterialKeywords(material); on all our built-in material for the stencil update which call: static public void SetupStencil(Material material, bool receivesSSR, bool useSplitLighting)
    This is where all the bits change that your regexp setup is coming from.
     
  3. iceb_

    iceb_

    Joined:
    Nov 10, 2015
    Posts:
    95
    hi! Is there any way to include a tool that works for other shaders too, where it just rewrites some of the material code to fix it? I am assuming that it must be breaking it for other people too.
     
  4. SebLagarde

    SebLagarde

    Unity Technologies

    Joined:
    Dec 30, 2015
    Posts:
    934
    Hi, sadly we can't patch materials that we aren't aware off... We can't blindly patch all materials either as it could corrupt material. Guess what we need to do is a way to register your custom materials as a HDRP Material. We will work on something like this to help in the future.
     
  5. iceb_

    iceb_

    Joined:
    Nov 10, 2015
    Posts:
    95
    ahh that's a good idea if it can just detect it as custom HDRP and then it'll just run the fix! Thanks!!