Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Stencil buffer overlays

Discussion in 'Shaders' started by Everest1986, Mar 20, 2017.

  1. Everest1986

    Everest1986

    Joined:
    Nov 21, 2015
    Posts:
    2
    Hi all,

    Could somebody help me. I try to understand stencil buffer. I have put in shader something like this:

    For moving object:
    Properties
    {
    _Ref("Layer", int) = 0
    _Comp("ComparitionEnum", Int) = 6
    }
    Stencil
    {
    Ref [_Ref]
    Comp [_Comp] //notequal
    Pass Keep
    }

    For walls:
    Properties
    {
    _Ref("Layer", int) = 0
    }
    Stencil
    {
    Ref [_Ref]
    Comp Always
    Pass replace
    }

    Unfortunately stencils sometimes are overlay and I have situation like below:


    Somebody know how to achieve That with stencils.
     
  2. faren

    faren

    Joined:
    Sep 10, 2015
    Posts:
    60
    You must set the geometry queue of the moving objects after the wall. It's just a tag "Queue"="Geometry+1"
     
  3. Everest1986

    Everest1986

    Joined:
    Nov 21, 2015
    Posts:
    2
    Ok, but then it cause another issue. I have some objects that I would like to be rendered under moving object. This all is in 2D. Please find picture below:

    I want that object with higher Y position will be under moving object.