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).
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.