1
\$\begingroup\$

my custom shader works like a charm for what I wanted it, but if it is referenced in the scene, Unity built-in masking stops working (both the Sprite Mask component and the rect-based Mask stop masking).

What I needed is a 2D unlit shader that would combat overlapping semi-transparency for 2D non-light based shadows. In other words, instead of this: enter image description here I want this: enter image description here

Since I don't know the first thing about shaders, I've copied the shader (like a clueless monkey) from here. It works but, as I mentioned it breaks other stuff (masking). As soon as I change the shader of the referenced material to any other shader, the masks start working without problems, so I know the shader is the culprit. I found out the problem has to do with the stencil. Trying different shaders that use the stencil and expose stencil properties shows that stencil ID, Comparison and Operation values that help achieve the required effect always break Unity built-in masking. This leads me to the conclusion stencil is "shared" between shaders and masking effects. I've also tried different Stencil Write/Read Mask values, but that didn't help. Please keep in mind my understanding of the stencil topic is super-shallow.

\$\endgroup\$
2
  • \$\begingroup\$ Can you show us how specifically the masking "breaks"? What happens? \$\endgroup\$
    – DMGregory
    May 2, 2020 at 20:01
  • \$\begingroup\$ By "breaks" I mean "stops working". Objects/sprites that were masked are no longer masked. Just as if the Mask or SpriteMask component was switched off. \$\endgroup\$
    – Jan Mysior
    May 3, 2020 at 21:26

0

You must log in to answer this question.

Browse other questions tagged .