4

I'm looking for a way to render a mesh that resides inside another mesh, here is an image of what I mean:
enter image description here
I want the part of the monkey that is inside the cube to be rendered, so the result would look like this:
enter image description here
I know, I could achieve this using boolean operators, but this is prone to error due to not closed meshes, also because I will have cases, where multiple objects will lie inside the boundaries.

Is there any other way I could achieve this?

lukasz1985
  • 41
  • 3
  • related: http://blender.stackexchange.com/questions/8600/how-can-i-easily-animate-cutaway-views-on-multiple-objects/8636#8636 and http://blender.stackexchange.com/questions/6550/cutting-with-boolean-modifiers –  Sep 03 '15 at 14:55

1 Answers1

4

You can achieve this by using render layers: Object ID and Transparent color

  1. Give the cube a transparent material.
  2. Give each object a different object index for masking with the object ID mask in the node editor (Properties Window --> Object tab --> Relations --> Pass Index).
  3. Render, go to the node editor and set up a node tree as in the attached image or blend file.
TLousky
  • 16,043
  • 1
  • 40
  • 72
  • Could you share a blend file of that? – lukasz1985 Sep 03 '15 at 12:56
  • Oh, I see the result in the background. That's certainly not what I want. – lukasz1985 Sep 03 '15 at 13:22
  • Sorry, my bad, didn't see the 2nd image you posted. This is still attainable with render layers, will update my answer in a bit to show how. – TLousky Sep 03 '15 at 14:11
  • Edited, have a look and see if this works for you. – TLousky Sep 03 '15 at 14:24
  • Yup, exactly what I wanted, now I'll have to figure out what you did there :). Sorry for posting this comment from a different accout, I'm having some serious problems tracking my SO accounts. I would certainly accept this answer if I could... Nevertheless, really, thanks a lot! :D – luke1985 Sep 03 '15 at 14:33
  • No prob. Added some links to help you get into grips with each individual step. – TLousky Sep 03 '15 at 14:38
  • @TLousky Unfortunately I was too fast saying it was working. Problem is, when I put the monkey behind the cube (relative to the camera), the monkey still renders while not being in the cube. Nevertheless, thanks for your efforts. :) – luke1985 Sep 03 '15 at 15:49
  • @spectre I know you don't need this anymore, but for academic purposes: you can use a copy of that cube with its normals flipped, and do a depth masking of the monkey on top of the object-index masking (so when behind the flipped cube, the moneky gets masked). – R. Navega Dec 04 '17 at 06:05