Search Unity

Possible to retain functionality of sprite masks while also using a stencil-based texture?

Discussion in '2D' started by Cerzi, Jul 17, 2018.

  1. Cerzi

    Cerzi

    Joined:
    Dec 28, 2014
    Posts:
    12
    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?