I have a problem that I want to solve if possible.

I have 2 objects (Boxes), Obj2 is above Obj1 (almost touching each other on Obj1's Z+ face). I want to draw Obj2 only in where Obj1 is visible to camera ray. So if I can see Obj1 through X-Ray the Obj2 is drawn. I know that OpenGL has stencils, this is what I want, but I didn't find it in Blender.


Example Viewport is what I have in Blender.

Mask Passed is what I will have in the render (after shading).

Mask Failed is what will not be drawn (This is what failed the comparison inside the stencil, like a inverse mask)

I think Booleans won't work here because it has nothing to intersect with.

So my question is: Is this possible without hardcoding them both in Eevee and Cycles? If I change the Loc/Rot/Scale of the camera the stencil must be calculated automatically.


  • $\begingroup$ docs.blender.org/manual/en/latest/compositing/types/converter/… $\endgroup$ – user1853 Dec 30 '19 at 22:53
  • $\begingroup$ @cegaton Thank you for this page. Some notes why I didn't find this: 1. I searched in Inputs 2. I searched in Shading not Compositing 3. Google doesn't show me Mask ID page $\endgroup$ – Spar Dec 30 '19 at 23:01
  • $\begingroup$ Sadly Eevee doesn't have this ID function. I found some walkaround with layers, I will try to use them $\endgroup$ – Spar Dec 30 '19 at 23:03


The mask effect can be achieved with rendering objects in different scenes and combining them in compositor after.

Compositing with Eevee:

Compositor with Eevee

Compositing with Cycles:

Compositor Nodes Cycles

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.