Starting off I want to clear it out that it may be a duplicate question, but in fact it is not.
1. Here's my previous question Cycles. Masking shader. How to make objects disappear in plain sight.
2. Here's the one using the compositor Mask out certain objects?
3. This one uses Blender Render Mask single object

Problem description:
I need to be able to mask out (make it completely transparent) certain objects in a 3d scene. An object placed inside another object's volume (masking objects are closed mesh, water tight, manifolds) should be transparent. If only a potion of an object is inside the mask (masking object) then only that portion is transparent (invisible on the render).

The main use of this is for motion graphic designs.
Demonstrations of what is needed: (imitated with booleans)

Solutions that don't fit and why:

1. The question at the first link[1] was by me, and the answer was to use Transparent Depth as a factor.
The problem with that solution is that it doesn't care whether an object is inside something or not, it just renders transparent everything that comes after the transparent surface (the surface of the masking object) As you can see, from one side it's fine but when rotate the view so that all our objects are behind the masking one, everything that has that shader setup is transparent.

2. The answer that is given at the second link[2] uses render layers and as a consequence requires compositing. When you work in 3d and have a production scene with many objects that grow out control, that approach is simply not suitable.

3. At the third link [3] the solution is provided only for the Blender Render and also uses fixed coordinates for a "faked plane" which is done in nodes, not taking into account any real geometry at all.

My thoughts and commentary:
Maybe there is a way to input the geometry of other meshes through pynodes and somehow use it as a factor in mixing emission and transparency.

• Why are boolean operations not working for you for that purpose? – Bruno Apr 3 '20 at 18:46
• @Bruno 3 things: 1. not all objects can be used with the boolean modifier 2. when you have a production scene with lost of objects it's really difficult to keep track of all the objects, masks and modifiers 3. sometimes there is a need to use not a "shadeless" material and booleans tend to create bad normals from time to time which can halt the whole project – BlenderSpot Apr 3 '20 at 21:53
• right about boolean. Regarding Transparent depth, have your tried playing around using 1 < depth < 2 instead of just 1 < depth? Shouldn't it make objects reappear if light rays go through multiple transparent layers? – Bruno Apr 3 '20 at 22:58
• @Bruno i think lemon's answer provided just the approach that you're taking about, if i understood you correctly – BlenderSpot Apr 5 '20 at 16:16

Using Cycles, you can achieve this by combining transparent depth of the light path node and backfacing of the geometry node.

We want to be transparent what has a depth modulo 2 equal to 1, as we want to be visible what is behind the transparent object (all are considered manifold).

But back faces have an additional transparency depth because they can be behind its own transparent front face.

So we add the two (backface + transparency depth) and set transparent what is modulo 2 = 1.

Here is an example:

Note that in the provided blend file, if the two transparent cubes overlap (intersect), the blue one will reappear. But the two transparent cubes together are no more manifold when overlapping.

• do you think there's a way to make the masks interact in a manner of a logical OR gate (inclusive OR)? so just overlapping wouldn't cause the masked mesh to reappear. – BlenderSpot Apr 4 '20 at 21:22
• You mean when the two transparent cubes are intersecting? I don't think it is possible as the shader does not know (and can't know) about the geometry that is masking it. – lemon Apr 5 '20 at 5:52