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
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:
The question at the first link
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
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
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.