- Home /
How to use Stencil shaders alongside Sprite Masks in 2D games?
I'm generating a mesh each frame based on raycasts that represents the player's line of sight. As mesh cannot be used as a sprite mask, I've had to instead create a stencil shader for the mesh to use, with another stencil shader on the "fog" for the mesh to cut through. This all works great.
The problem is that, in doing this, all the sprite masks I use with custom sorting layer ranges have become essentially useless. There doesn't seem to be any way for the Stencil material to have functionality akin to the "Custom Range" option of built-in Sprite Masks. This means that any objects with "Mask Interaction" set to something besides None are always affected by the stencil shader.
Is there any way around this? Ideally I'd like to just use a regular sprite mask for the dynamically created mesh, but this doesn't seem to be possible. Right now it feels like the only option is to completely discard all usage of Sprite Masks, and instead rely entirely on custom-made stencil shaders. This feels a bit frustrating considering how much more work it is compared to just using sprite masks.
Any thoughts?
Your answer
Follow this Question
Related Questions
Hiding a sprite partially (shader? masking?) 0 Answers
Deform sprite using SkinnedMeshRenderer 0 Answers
How to clear the stencil buffer? 1 Answer
2d lighting effect 1 Answer
2D Animation does not start 1 Answer