Use an object as a mask for a camera.

Does anyone know how to have a mask only draw stuff where an object is not present?

For example, I have a particles effect that cover all the screen, and i want to move a sphere around that will make the position and size of it be “cut” from the screen, as if the particles effect where transparent on that specific place.

Here is an explanation image to try to make it more clear:

Please notice that the “hole” is transparent, and only affects the effects layer, kind of like a peep hole.

You could do this with a Depthmask shader:

Shader "DepthMask"
{
    SubShader
	{
        Tags {"Queue" = "Geometry-1" }
        Lighting Off
        Pass
        {
            ZWrite On
            ZTest LEqual
            ColorMask 0     
        }
    }
}

Add it to your sphere

More here http://wiki.unity3d.com/index.php?title=DepthMask

This is super easy to accomplish with an extra camera and depth shader. Here’s what you need to do.

  1. Add a new “ClippingMask” layer
  2. On the main camera remove “ClippingMask” from “Culling Mask”
  3. Add a new camera that only renders “ClippingMask” in “Culling Mask”
  4. Put your see-through objects on the “ClippingMask” layer
  5. Add a depth shader to an object and apply the “ClippingMask” layer to it

Sprite style masking in 2D. Although you do have to sync the nested camera’s size in-case it changes.