9
$\begingroup$

I have a picture of a room including the floor and I want it to look like there is, for example, a cube going through the floor. Is there a way to do this, maybe by making it go through a plane that is transparent to the photograph but not to the cube?

If anyone knows how to do this, as I'm not very good at doing things from text, would you be able to explain with pictures or something? Is there is a tutorial for this sort of thing?

$\endgroup$
  • 2
    $\begingroup$ Maybe Blenderguru's camera tracking tutorial will help. He creates a hole in the ground and has to mask out part of the hole geometry for that. Otherwise you could probably just use a boolean modifier that 'cuts away' the part of your object that is in the ground. $\endgroup$ – maddin45 May 23 '14 at 23:11
  • $\begingroup$ Is the final result a static picture or an animation? $\endgroup$ – invicente May 24 '14 at 10:03
  • $\begingroup$ I was thinking of the Blender gurus camera mapping tutorial blenderguru.com/videos/camera-mapping-tutorial-v2 $\endgroup$ – MarcClintDion May 25 '14 at 18:08
14
$\begingroup$

Update for posterity: An archive of this answer can be found at https://bvisness.me/2017/04/25/blender-masking-layers.html.


Blender has a feature called Masking Layers, which nicely accomplish exactly what you're trying to do. Put your content cube on one layer and your masking plane on another, then set the Masking Layer for the plane's layer. I got my result to look like this:

Final render of a cube set into the floor

Here's how to accomplish that effect:

1. Set up your layers

Start by turning on transparent film. This makes your Cycles render layers use transparency instead of a background color. Go to the Render panel in the Properties window, scroll down to Film, and check Transparent.

Put your cube (or other content) on one layer and your masking plane on another. I had my cube on layer layer 1 and my plane on layer layer 2

Make sure that both your cube and your plane are visible, then go over to the Render Layers tab and set the mask layer to the layer with your plane.

The correct setup for the render layers

To overlay the render on your image, you can use a compositing setup like this:

Simple composite setup to overlay the render on the image

Give it a render, and you'll get something like this:

First render, with pretty bad lighting

This technically answers your question, but it looks really bad, so I'm gonna keep going.

2. Add shadows and AO

You can use your masking plane to capture shadows and AO as well. First add another render layer for just your masking plane. Go down into the "Passes" tab and make sure that Shadows and AO are checked.

Shadows and AO must be checked on the new render layer

Then, use a composite setup like this to mix the shadows and apply them to the original image:

A complicated composite setup

This will result in a render like this:

A much better render

Just one more step, if you want the lighting to be more accurate:

3. Make the floor material match the picture

You can improve the lighting accuracy if you make the floor material match the picture. This will change the color of the light bounces, even though the plane itself is not actually visible.

Create a material with a node setup like this and assign it to the floor:

A good material node setup

This material will use the coordinates of the window to apply the picture to the floor. This means that there will be no distortion of the texture when it is rendered. This change will result in a subtly improved render:

The final render


This technique works for other objects too. Just replace the cube with whatever object you actually want in your scene.

A monkey!


Anyway, I hope that helps. Let me know if you want me to clarify anything.

$\endgroup$

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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