Hello,

I have a problem with setting Spine object as a mask for my sprites in Unity 2020.3.

My player has an extra sprite with Visible inside mask set, and there are object on the level which are regular sprites which are set to be masks (so I see player's silhouette if he walks behind them)

Now I want to have Spine objects to be those masks, but Sprite Mask doesnt work

any ideas?

Related Discussions
...

Basically mask interaction is implemented using the stencil buffer, masks writing (incrementing or setting a value other than 0) to the stencil buffer, masked objects reading the stencil value and only rendering when either equal to 0 with visibility set to Outside mask or larger than 0 (or == or >= a certain value to support nested mask-hierarchies) for Inside mask.

While we don't know a clean official way how to do this, you would need to write or use a shader which writes to the stencil buffer. Likely the write operation should increment the stencil buffer value (see the documentation page here) or set it to a constant value like 1 if on the first mask-level.

Just watch out for potential side effects when mixing your stencil shader with other Mask components, if perhaps other components rely on a certain stencil value to be set.

I've modified spine/skeleton shader and it seems to partially work - unfortunately it works only on a part of the object.
it looks like different parts of that object behave differently or are using different materials?
MeshRenderer on SkeletonAnimation object has single material and that material is using my shader

very confusing

ok the issue was related to sorting order of sprites and spine objects, setting correct layer and sorting order fixed it

@ghua Glad to hear you've figured it out.

One thing that came to my mind after having written the above posting is that you might want to write a fixed value to the stencil buffer and not increment it, since a Spine skeleton can easily have overlapping parts.