Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question URP 2D Renderer stencil

Discussion in 'Universal Render Pipeline' started by noisetree, Oct 29, 2021.

  1. noisetree

    noisetree

    Joined:
    Apr 10, 2015
    Posts:
    51
    Hello! I'm a bit confused regarding URP 2D Renderer stencil workflow. I want to mask stuff using stencil. Here's my render feature setup for it.



    I can't exclude layers from "initial" rendering in 2D Renderer opposing to Universal Renderer. Can't find options like this are exposed in 2D Renderer.



    Because of this i assume get full sprite rendered first and stencil related part on top. Looks like this (black circle is "Entity" layer, grey "Default"). So can't really get mask "cut" done.


    When i put different override material in stencil "check" related render feature. There is another problem with sprites based shaders/materials. Cause it doesn't respect alpha. Here it writes whole texture into stencil buffer. Instead of cutting the circle part it cuts all texture square.


    The question is if i maybe doing something wrong, if not, is it even possible to use stencil this way in 2D Renderer? Thanks!
     
  2. noisetree

    noisetree

    Joined:
    Apr 10, 2015
    Posts:
    51
    @Chris_Chu Maybe someone from Unity can answer this?
     
  3. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    254
    I have a couple of questions. The first is are you trying to create a 'hole' using a sprite? If so you may want to consider using SpriteMask.

    If you are using the stencil for something else, are you asking how you can stencil using a sprite, and have the stenciled sprite render before everything else? Also, are you using normal maps, and will those need the same stencil pass?

    I will say for the second part of your question of why is alpha isn't respected, it's because there isn't any alpha clipping on the sprite shaders. So when it does the stenciling per pixel you will get stencil in the transparent parts because transparency is just a color. If you need it, you will need to modify whatever shader you are using to implement alpha clipping.
     
  4. noisetree

    noisetree

    Joined:
    Apr 10, 2015
    Posts:
    51
    Thanks for answer!

    Regarding SpriteMask, do i understand right that there is no way to put material for it? This circles i have in exampe are not based on actual "drawn" sprite, but ellipse node in shader graph (transparent sprite and material/shader drawing circle). I draw grey shapes and write them into stencil, then want to draw black shape using this stencil to cut off part that doesn't intersect with grey, but i can't cause i can't exclude (don't have filter settings as in universal renderer) black shape layer from default rendering. Don't use normal maps, but can you answer regarding them too cause maybe someone will find this info helpful.

    Regarding alpha clipping. Can alpha clipping options be exposed in shader graph and master node, like with non sprite shaders? Cause this way i assume if i use sprite shader i need to open generated code, copy/paste it to other shader and make alpha clipping change by hand each time i change the related shader in shader graph.