Search Unity

  1. Unity wants to learn about your experiences working on a Unity project today. We'd like to hear from you via this survey.
    Dismiss Notice
  2. Read here for Unity's latest plans on OpenXR.
    Dismiss Notice
  3. All Pro and Enterprise subscribers: find helpful & inspiring creative, tech, and business know-how in the new Unity Success Hub. Sign in to stay up to date.
    Dismiss Notice
  4. Dismiss Notice

Help Wanted Adding Stencil Buffer to URP Shader

Discussion in 'Unity MARS' started by wickedwaring, May 10, 2021.

  1. wickedwaring

    wickedwaring

    Joined:
    Feb 5, 2014
    Posts:
    15
    Hi,

    I have posted this in general shaders (https://forum.unity.com/threads/adding-stencil-buffer-to-urp-shader.1096291/), but sadly no reply, we are using MARS to create an AR project and this would really help us move along if someone could help.

    --------

    I am new to shader coding, but have managed to get a basic shader to work with a stencil buffer as I need to for our project.

    I have a stencil write shader, and simply read it within my stencil read shader as follows

    [IntRange] _StencilRef ("Stencil Reference Value", Range(0,255)) = 0

    ...

    Stencil {
    Ref [_StencilRef]
    Comp Equal
    }

    A couple of questions -

    a) How would I get hold of the Unity Source for the URP shaders (currently using Lit for starters), so I can add my Stencil code to it? (I will just leave the rest of the code as is as, just want to control the stencil buffer)
    b) Is there another method to do this that I am not aware of?

    Thanks for your help,
    Matt
     
  2. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    27,209
    You can do visually via the render features in the URP configuration asset file. You can define which layers draw and read stencil data and when.
     
    wickedwaring and jmunozarUTech like this.
  3. wickedwaring

    wickedwaring

    Joined:
    Feb 5, 2014
    Posts:
    15
    Thanks HippoCoder, I will look into that, can I assume the URP shader code is not open source then like the standard shaders to modify like I thought?
     
unityunity