I was trying to mask a sprite using a stencil buffer and it works fine untill I add some transparency to it. The mask works using the whole texture, but I want it to work only where the quad is drawn. Here's a picture to illustrate what I'm saying:
The black sprite is the sprite I want to mask and as you can see the quad that is acting as the mask isn't masking where there's transparency in the texture
I'm just passing Unity's default quad mesh to the Mesh Filter
Is this normal behaviour? Is there anything I can do to make it work only where the quad is being drawn?
The mask shader code:
Tags { "RenderType" = "Transparent" }
Pass
{
Stencil
{
Ref 1
Comp Always
Pass Replace
}
ColorMask 0 // Don't write to any colour channels
ZWrite Off // Don't write to the Depth buffer
}
The mask interaction code:
Tags
{
"RenderType" = "Transparent"
"Queue" = "Transparent"
}
Pass
{
Name "Sprite Lit"
Tags
{
"LightMode" = "Universal2D"
}
// Render State
Stencil
{
Ref 1
Comp Equal
}
Blend SrcAlpha OneMinusSrcAlpha, One OneMinusSrcAlpha
Cull Off
ZTest LEqual
ZWrite Off
}