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)
The masking object has only one shader - transparent.

Solutions that don't fit and why:
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.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.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:
The masking object has only one shader - transparent.
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.


- not all objects can be used with the boolean modifier
- when you have a production scene with lost of objects it's really difficult to keep track of all the objects, masks and modifiers
- 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 03 '20 at 21:531 < depth < 2instead of just1 < depth? Shouldn't it make objects reappear if light rays go through multiple transparent layers? – Bruno Apr 03 '20 at 22:58