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

Stencil on HDRP

Discussion in 'Graphics Experimental Previews' started by alexanderkudryavy, Nov 7, 2021.

  1. alexanderkudryavy

    alexanderkudryavy

    Joined:
    Sep 20, 2019
    Posts:
    13
    Hello, finally I got working stencil on HDRP Lit with light and shadows but this solution have one strange bug, maybe you can understand why it happening because I really dont know how fix this.

    View attachment 950842

    Here is repo with modificated lit shader: https://github.com/mirgorodalexander/Stencil-HDRP

    What I've done:
    - Remove string to got custom settings in shader
    Code (CSharp):
    1. CustomEditor "Rendering.HighDefinition.LitGUI"
    - Add this strings in properties section
    Code (CSharp):
    1. _StencilMask("Stencil Mask", Int) = 0
    2. _StencilWriteMask("Stencil Write Mask", Int) = 0
    3. [Enum(UnityEngine.Rendering.CompareFunction)] _Compare("Compare", Int) = 0
    4. [Enum(UnityEngine.Rendering.StencilOp)] _Pass("Pass", Int) = 0
    - In "GBuffer" pass replace Stencil with this
    Code (CSharp):
    1. Stencil
    2. {
    3.     WriteMask [_StencilWriteMask]
    4.     Ref [_StencilMask]
    5.     Comp [_Compare]
    6.     Pass [_Pass]
    7. }
    - In "MotionVectors" pass replace Stencil with this
    Code (CSharp):
    1. Stencil
    2. {
    3.     WriteMask [_StencilWriteMask]
    4.     Ref [_StencilMask]
    5.     Comp [_Compare]
    6.     Pass [_Pass]
    7. }
    Next I create two materials "Inside" and "Outside"
    Inside properties:
    View attachment 950827
    Outside propeties:
    View attachment 950830

    And that's it, it working, but have strange bug, at some positions of "Camera" and "Editor Camera" inside objects disappeard, I don't know why, maybe you can understand how fix this?

    Here is the BUG:
    View attachment 950851