Search Unity

Question Problem with Stencil Buffer in Overlay Cutout Shader

Discussion in 'Shaders' started by Tobias3112, Oct 27, 2020.

  1. Tobias3112

    Tobias3112

    Joined:
    May 9, 2017
    Posts:
    16
    I tried to use the Stencil Buffer for an Effect like this, but the other way around: stencil.PNG

    So I want to see a xor instead of an Intersection between the two objects.

    Therefore I used this code in my Shader:
    Code (CSharp):
    1. Stencil{
    2.                 Ref 0
    3.                 Comp Equal
    4.                 Pass IncrSat
    5.             }
    The Stencil Buffer is initialized with a 0 so the first time an object arrives at the pixel it should be drawn and the Buffer should increase to 1. The next time an object that uses the same shader checks the buffer and should fail the comparison. Therefore it should be discarded

    So I try to use a single shader that solves the xor problem. But the effect is not like I want it to be: stencil 1.PNG

    Does someone know the solution for this problem?