Discovered various interesting things in the process of solving the masking issue, thought it would be good to circulate.
Masking in Unity
So the way masking works in Unity is by doing the following:
- Each object contains a mask object (child) and then a bunch of other child objects
- Mask object is given a masking shader
- At render time, the mask "draws", but doesn't write color to the output buffer, it only writes depth. Another way to visualize this is that it creates an invisible 3D object that still blocks other objects behind it
- When the other objects render, the parts that are behind the invisible objects get masked because the Z-buffer compare fails
- Why can't you have two on the screen at once?