Strange question about compositing and masking

Hi folks,

This is probably weird and impossible, but please imagine the following:

I have a large cube and behind it, partly hidden by the cube, an icosphere.

Is it possible in the compositor (or some other way) to have blender treat the view from the camera as simply flat shapes, and let me choose if the icosphere is partly hidden, or if the cube is partly hidden. So i mean i’d like to be able to choose which object masks the other, regardless of their actual distance from the camera. So basically it’s letting me mask overlapping objects as if it’s a 2D composite.

Hmmm, clear as mud methinks!

Any ideas? … Thanks!

I would try rendering each object separately on a transparent background and then stacking the images using a Mix node. If you’re already comfortable with other image editing software you could load each image in as a layer and stack them there too.

Thanks, i tried the mix node but it won’t let me stack the render layers, it will only let me mix them together in weird and wonderful ways, see pic below!

Try a different blend mode.

I tried every blend mode, nothing works!

I did find a workaround (see below) but i’m hoping there’s a simpler way!

Have you tried clicking the “use alpha” or whatever it is just to the right of the blend mode in the mix node? I don’t remember exactly what the solution is in blender, the way alpha channels are handled have never been intuitive to me.

The alpha over node stacks images on top of each other, it places one image on top of the other using the alpha channel:

If you want to animate which one is on top you can double the alpha over setup (swapping the image order) then use a a mix node to swap the image order.

Great, many thanks, that works and good tip on using the mix node to swap the order!

Actually, one more quick one if you don’t mind!:

How can i use one shape to mask another one?

So, say i have a yellow circle and a blue square, and they partly overlap. I just want to see the blue square where they overlap, everything else should disappear. And as a variation, next i only want to see the blue square where it doesn’t overlap! …What’s the best way to go about that?

You should reply to my post so that the forum warns me there is a reply! :slightly_smiling_face:

To use the layers as masks you can use the “set alpha” node. You can invert the masks by inverting the alpha channel with an invert node.

I recommend you activate the backdrop and use the “node wrangler” addon and the viewer node.
Then by selecting a node and using Ctrl+Shift you can preview what each node is doing:

I million thanks man!

Just one more and i’lll leave you alone:

To get an object into the compositor you need to first put it in a collection, then create it’s own view layer.
Are there any shortcuts or addons that let you do this quickly? It’s quite a time consuming process and i don’t understand why blender doesn’t just let you put an object into the compositor without these extra steps!

Do not worry I enjoy the company! :slightly_smiling_face:

I am not sure if there are addons for this, I do not know.

In the render layers node, as you say, you can use view layers to separate the objects, but also you can use different scenes.
The main difference with using scenes is that each scene can have its own unique world settings, and render settings. You can even render one scene with eevee and another with cycles, this is very useful for example if you want to render smoke/volume in eevee (much faster) and composite it over a cycles render.

If you look closely at the render layers nodes of the first example I posted you will see that I had each object in a different scene (for no particular reason).

Great, didn’t know about that (render scenes), they could come in handy, thanks again!