How to render invisible objects casting their z-depth alongside other visible objects I've been looking for some sort of way of rendering invisible objects as transparent pixels depending if they're in front or back of visible objects in the scene.

For example, I have a clothed character like this:



And my goal is to render every clothing attached to the character independently, this is for making a spritesheet I can use in a 2D game but I have a problem with that and is that when I try to snap a single clothing, some parts that should be hidden by the character body itself are being renderer.

IE: let's say I want to render the character's hair only, when I take the snapshot I get something like this:



As you can see, there is a part of the hair I wouldn't like to be rendered after all, like the part where the character's face should be:



I've been thinking of simple hacks like making some sort of chroma by using a green background and a green texture in the head, so then I can use a tool like Photoshop or Gimp for replacing the green part with transparency, but I'd like to make it in a simple and faster way if possible.

The sprites are going to be produced in a automated way by using a Python script, I also use Cycles as my rendering engine for this purpose.

Thank you...
Using render layers might help you.
I have created these two planes, and put them in seperate layers. The light grey in layer 1, and the blue in layer 2. In the render layer tab settings there is a "mask layer" where I chose layer 2 as a mask layer.



Please note that the shadows of layer 1 still render, you can remove these by unchecking the "shadow" box in the "cycles settings" under the object tab

finished result, a masked grey plane in all its glory

If the blue plane on top is moved below the grey plane. It will not mask the plane.