How to mask sprite with more than 1 mask?

I thought about this for a while. Indeed you could use shaders for this. See this thread for a good, clear explanation of some of the required details: Shader stencil and Sprite Masks not working together

So the main idea is to replace Unity’s Sprite Mask with custom, own versions of the built-in sprite shader. It’s less complicated than it might seem. Basically you take the sprite shader from Unity sources, and add the stencil functionality. You can find the source code from the download archive:

Then you can render first a base mask and write to the stencil buffer, and after that a mask that cuts out from the base mask. Now you can move the masks independently.

And if you really need some complex mask that changes every frame (and it’s procedural or something like that) you probably have to render it to a RenderTexture, then read by using ReadPixels and store the result to a Texture2D and then make a Sprite out of that Texture2D using Sprite.Create() function. But that ReadPixels is pretty slow so I would definitely try to find better solution (maybe generate the mask procedurally inside the shader(s) if it would fit your use-case.

Here’s a quick test: