Search Unity

Stock Unity UI Stencil usage?

Discussion in 'Shaders' started by chrismarch, May 10, 2019.

  1. chrismarch

    chrismarch

    Joined:
    Jul 24, 2013
    Posts:
    472
    Do the default UI & mask shaders write to the stencil buffer? If so, do they use a known WriteMask and ReadMask? I see a number of stencil properties in the default UI shader.
     
    Last edited: May 10, 2019
  2. KYL3R

    KYL3R

    Joined:
    Nov 16, 2012
    Posts:
    135
    I just found this for HDRP: There are 2 "User Bits":
    UserBit0: 64 (0b1000000)
    UserBit1: 128 (0b10000000)


    That information can be found here: https://docs.unity3d.com/Packages/c...endering.HighDefinition.UserStencilUsage.html
    or in an example here: https://github.com/alelievr/HDRP-Cu.../Assets/CustomPasses/SeeThrough/SeeThrough.cs

    The other bits are used by unity, which is listed here:
    https://github.com/Unity-Technologi...Runtime/RenderPipeline/HDStencilUsage.cs.hlsl

    Code (CSharp):
    1.  
    2. #define STENCILUSAGE_CLEAR (0)
    3. #define STENCILUSAGE_REQUIRES_DEFERRED_LIGHTING (2)
    4. #define STENCILUSAGE_SUBSURFACE_SCATTERING (4)
    5. #define STENCILUSAGE_TRACE_REFLECTION_RAY (8)
    6. #define STENCILUSAGE_DECALS (16)
    7. #define STENCILUSAGE_OBJECT_MOTION_VECTOR (32)
    8. #define STENCILUSAGE_EXCLUDE_FROM_TAA (2)
    9. #define STENCILUSAGE_DISTORTION_VECTORS (4)
    10. #define STENCILUSAGE_SMAA (4)
    11. #define STENCILUSAGE_WATER_SURFACE (16)
    12. #define STENCILUSAGE_AFTER_OPAQUE_RESERVED_BITS (56)
    13. #define STENCILUSAGE_USER_BIT0 (64)
    14. #define STENCILUSAGE_USER_BIT1 (128)
    15. #define STENCILUSAGE_HDRPRESERVED_BITS (63)
    16.  

    These values can also be found in the internal enum: "UnityEngine.Rendering.HighDefinition.StencilUsage" which you can decompile by ctrl-clicking the word "StencilUsage" in Visual Studio.