Hi everyone, I am making a top-down 2D game and I'd like to be able to display elements under those conditions. I am using stencil masks to block elements. I'd like to be able to cutout a stencil mask before applying it. Another way to put it is : Mesh A and Mesh B are stencil masks and a Mesh C. Mesh A displays whatever is under it (usual stencil mask) Mesh B displays what is under it ONLY where Mesh C and Mesh B intersects. (and it doesn't interfere with Mesh A, Mesh A still displays no matter what) I was thinking of cutting out Mesh B through some intermediary stencil shader but I don't know how to do it. My code is the default Stencil Mask/Object shader Mask : Code (CSharp): Tags { "RenderType"="Opaque" "Queue"="Geometry-100" } ColorMask 0 ZWrite off LOD 200 Stencil { Ref 1 Pass replace } Object : Code (CSharp): Tags { "RenderType"="Opaque" } LOD 200 Stencil { Ref 1 Comp equal } Would really appreciate some help Thanks !
Stencils take some mind bending to realize their full utility. The stencil buffer is a byte per pixel buffer, and you can use it either as the straight byte value (0-255) or as a bit wise operation where you’re setting and checking the bits. The reason why this is useful is you can have one stencil use Ref 1, and a second use Ref 2 with both using Pass Replace. With no other stencil settings whichever is the last of those two to render is what the stencil buffer has. But if you use WriteMask 1 (00000001) and WriteMask 2 (00000010) respectively each shader will only write to the first and second bit of the byte. This means any anywhere both of them render both meshes render the stencil will hold the value 3 (00000011). Then you can have your object check Ref 3 an Comp Equal and it’ll only show in those area where both overlap.