Compositing CG and Live Action in Blender
Written for use in Blender 2.33, may not be accurate for different versions


Okay, let's start with this simple picture I took of my room.



Open Blender, and delete the default cube. Go to front view by pressing 1 (on the numpad), and add a plane. Move this back away from the camera quite a bit, then go to the camera view by pressing 0 (on the numpad), and increase the size of the plane until it fills the camera view. Now select the plane, Shift+select the camera, and press Ctrl+P to make the camera the parent of the plane.



Select the plane, go to the Material buttons, and add a new material. You can call it "Background" if you want. Go to the Texture buttons, and add a new texture. You can call this texture "Background" if you want. Make it an image texture. Use my picture as the image. Then go back to the Material buttons. Press "Shadeless" in the Material panel, and "Win" in the Map Input panel. This will make it so that light won't affect the plane, and the texture will fill the camera view exactly, even if the camera is at a different angle. And disable "Traceable" and "Shadow" in the Shaders panel, so that it won't cast shadows.



Now go to the Render buttons, and make sure "SizeX" and "SizeY" in the Format panel are set to 640 and 480, respectively, since that's the size of my picture. The effect of all this should be that if you render now, you'll get a duplicate of that picture.

Now, go to the View menu on the bottom of the 3d window, and click Background Image. Click "Use Background Image" in the panel that pops up, then select your image texture from the dropdown menu that says "Texture" next to it. You can close this panel now.



You should now be able to see the background picture if you go to the camera view and press Z to show everything as wireframe.

From top view, add another plane. Make it fairly big. Select the camera, and go back to camera view. Move it around with G and R (try pressing the middle mouse button while moving or rotating to move or rotate along a different axis) until it looks like the new plane lines up reasonably well with the floor in the background picture.



Select the floor plane, and go to the Material buttons. Add a new material, you can call it "Floor". Reduce the alpha of the object to about 0.500, and in the Mirror Transp panel, press "OnlyShadow" and "ZTransp". This will make it so when you render, you'll only be able to see the plane in the places where shadows are being cast on it, and the rest will be transparent.



Add a Monkey. Set Smooth it, and set the SubSurf level to 2, just to make it look nicer. This is just a testing object, so you can use something else if you want.

Select the default lamp, and change it to an Area light. Turn Ray shadows on. I had to set Size to about 7, Energy to about 0.1, and Samples to 6 to get it to look good, but different settings may work better for you depending on how you set up the scene. Set the color of the lamp to a slightly yellow tint to match the lighting in the background.



Move the lamp to the right of the scene, since that's where the light was coming from when I took the picture. Add a Hemi light, and put it on the other side of the scene, with a low Energy value, to lighten up the dark parts a bit. Go to the Render buttons and press Ray, so that the raytraced shadows will be rendered.



You should probably save the .blend file now if you haven't already. If you render it now, you should get this:



It's a decent picture, but there are several problems with it. The CG monkey doesn't blend very well with the background picture, for several reasons. I'll deal with that later.



First, animation. If you're not making a video, just a still picture, you might be able to skip over this part, though there are parts of it that are relevant to still pictures as well. Here's a simple video I made, the picture I've been using is a frame from that video, so you won't have to change the camera angle or anything:

in.avi - 1.8 MB, 2 seconds long, compressed with DivX.

Open the .blend file you made earlier, if it's not already open. You may want to save it as a different file in case you want to use the old one again. Select the plane with the background image texture, and go to the Texture buttons. Press the Movie button, then load my video as the image, and then press the arrow button next to the "Frames" button. Since the video is 60 frames long, like it says there, go to the Render buttons, and make sure that "Sta" is set to 1, and that "End" is set to 60.

This video was deinterlacd with VirtualDub, by the way. If you don't deinterlace, you get ugly horizontal lines like here:



This is a good explanation of how interlacing works.

Back to Blender. As you can see, in the video I am waving my hand around in front of where the monkey should be. If you just render the video without doing anything, of course the monkey will show up in front of my hand, because it's in front of the background video. So, we'll have to fix this. First, put the 3d cursor very close to the camera:



Make sure you're still on frame 1. Now, from camera view, add a plane. You might want to do this on layer 2 so none of the objects in the scene obscure your view of the background video. Extrude and subdivide and whatnot to get your new object in the shape of my hand and arm.



Now, in edit mode, press I, and choose Mesh, then Absolute keys, to add a vertex key. Open up an IPO window, and from the pulldown menu set to "Object" choose "Vertex":



Select the big curvy Speed IPO, and go to the Curve menu, choose Extend mode, then Extrapolation. Then select the flat orange line (that's the vertex key), press N, and set "Key Y" to 0.01 (the frame it should be on divided by 100). If you've done this right, you should now be able to create more vertex keys and they'll automatically be in the right place along the Speed IPO.



Now just go forward, a frame at a time, on each frame repositioning the vertices in the hand object to match the background video and adding another vertex key. Sometimes on slower movements you don't have to put a key on every frame, you can put them at intervals and the computer will inbetween it for you.

Since I was moving my hand pretty fast, it would be a good idea to turn motion blur on. So press the MBLUR button in the Render buttons, and then move the Speed IPO to the right a bit (0.3 of a frame worked for me) to compensate for the fact that Blender's motion blur renders stuff ahead of the frame you're on.



You could render it now, and again, it would look decent, but there are still some problems, and besides, doing it this way takes a very long time to render because of the area light and the motion blur, even though it's a pretty simple scene. So how do we fix this?



First, select the background plane, and go to the Material buttons. Press "Env" in the Mirror Transp panel. This makes it so that the background plane will render transparent to the background color, but still obscure anything behind it. Go to the World buttons and set HoR, HoG, and HoB to 0.

Make sure you only have layer 1 activated, so you can see everything except the arm object. Press Key in the Render buttons. Render a still picture, with no motion blur. You can do this because the monkey isn't going to move at any point during the video, so you can just use a still frame. Press RGBA in the Render buttons and save as a PNG. (If the monkey was moving and you were rendering an animation, you would render to a sequence of PNGs.)



Now go to layer 2, where the arm object is. Select it and go to the Material buttons. Turn off Env, and turn off Col in the Map To panel. Set R, G, and B to 1. Turn motion blur back on, and render the animation to an AVI. The arm should render as white against a black background.

The next part you could probably do in a program like After Effects, but After Effects costs a lot of money and I don't have it, so I'll explain how to do it in Blender.

Make a new file. The first bit of this is going to be pretty similar to what you've done before. Delete the default cube and lamp, you don't need them. Again make sure that in the Render buttons, "SizeX" is set to 640, "SizeY" to 480, "Sta" to 1, and "End" to 60. From camera view, add a plane, and increase the size of the plane until it fills the camera view. Go to the Material buttons, and add a new material. Go to the Texture buttons, and add a new texture. Use my video as the texture, like before. Then go back to the Material buttons. Press "Shadeless" in the Material panel, and "Win" in the Map Input panel.

Press 3 to go to side view. Duplicate the plane and move it slightly in front of the old plane. Go to the Material buttons, and add a new material (based on the one you were using already). Go to the Texture buttons, and add a new texture. Use the monkey PNG as the image. (If you were using a sequence of PNGs for a video, you would choose the first one, and set "Frames" to the number of frames there are.) Press "UseAlpha". Then go back to the Material buttons. Decrease the Alpha of the material to 0, and press "Alpha" in the Map To panel. Press "ZTransp" in the Mirror Transp panel.

Now we're going to degrade the quality of the monkey image to match the crappy quality of my DV video. Open the still picture I used at the beginning of the tutorial in Photoshop, or GIMP, or any other image editing program, as long as it has a blur feature. Blur this image a HUGE amount, we want to wind up with almost a solid color that's just the most common color in the image. Save it as blur.jpg or something.



Back to Blender, add the blurred picture as another texture on the monkey plane (and set it to Win in the Map Input panel). In the Material buttons, set the Col slider in the Map To panel to about 0.2 or 0.3. This is to make the monkey tinted a bit more like the rest of the picture.

Go back to the Texture buttons for the texture with the monkey PNG, set "Filter" to about 10. This is to blur the monkey, since the background video is pretty blurry relative to the perfect looking CG render. Press "Fields" to simulate the deinterlacing effect.

Now add one more texture. Set it to Win in the Map Input panel as usual. Now for this texture you're going to need a video from your video camera of just noise. What I did for this is aimed the camera at a white card, and just filmed for a little while.



noise.avi - 984 KB, 2 seconds long, compressed with DivX.

(The reason this video is 2 seconds long is just to save space on my website, if you're making a longer video, looping a 2 second long noise video won't work, you'll need something about 10 seconds long at least.)
Press "Mul" in the Map To panel of the Material buttons. You may have to adjust the brightness and contrast in the Colors panel of the Texture buttons to get it to be visible enough. Render.



It should be sufficiently crappy looking now. Compare to the earlier render:



Okay, now for the arm. Duplicate the background plane and move the duplicate closer to the camera than both the old planes. Add a new material (again, based on the one you were using already). Add the AVI of the white on black arm as another texture. Set "Win" in the Map Input panel again. Disable "Col" and enable "Alpha" in the Map To panel, set the Alpha of the material to 0 and press ZTransp in the Mirror Transp panel. Set "Filter" to 10 on this texture too.



done.avi - 690 KB, 2 seconds long, compressed with DivX.

If you've done everything right you should be finished now. Render, and watch the coolness. If you have any problems, email me at weirdhat@weirdhat.com.