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.
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!
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.
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?
Edit:
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:
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!
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).