From BlenderWiki

Jump to: navigation, search

Node Compositing System

The new compositing system in Blender allows for some very cool effects to be created fairly quick and easily. To use the garbage matte that we created in the previous tutorial with our green screen hero footage, we will use the composite node system. Open up a new blend and make the main view the node editor. Select the compositing nodes and be sure to turn the compositing on in the render panel. You are now ready to do some compositing.

Screen Layout

Go into the node window and create an 3 image input nodes and select garbage mask we created, the raw footage, and the background image an inputs for each node. Be sure to select the movie button and the read from disk buttons in the raw footage input node so that it animates as we render out the output. you will also need to set the number of frames that it should use (192 frames). Also be sure to set the output resolution and frame rate to match the input raw video source.

I like to build my node trees from left to right with all my inputs flowing into the various nodes to change their appearance, with the final output going into the composite node on the far right. You can see the compositor output in an image window by setting the render output to Image Editor. I also like to have a viewer node attached at various parts of my composite to check my progress. You can also view the viewer node in the image editor, so I have another image editor window open with it set to the viewer node.

Using the Mask

Screen Layout

Create a new node from the Node Converter menu called “Set Alpha” and connect the output of the raw footage to the top input of the Set Alpha node and connect the output of the mask to the bottom input of the Set Alpha node. This assigns our mask as the alpha channel of our raw footage.

Create an alpha over node and connect the output of the background node to the top input of the Alpha over node and connect the output of the Set Alpha node to the bottom input of the set Alpha node. Connect the output of the Alpha Over node to the input of the composite node. Now press F12 to render the current frame. You should see our hero (sitting in a green circle) in the desert. That’s great and all, but we need to get rid of that green circle, it just doesn’t fit in with the rest of the scene. Lucky for use there is a technique, funny enough, called green screening that will help us with this.

Green Screen

Green screening is a process that separates a foreground object from the background. In our case, Super Wu-Man is the foreground object and the green screen (minus the stuff we already masked out) is the background. I will present two different nodes that separate the foreground objects from the background in different manners, but we will end up with the same result: Super Wu-Man all by himself. The chroma key and color difference nodes each have two outputs. The first is the matte that is generated and the second is the image with the matte applied (as its alpha channel). The reason for splitting it out into the matte and pre-multiplied image is that you may want to do some blurring or use the erode/dilate node on the matte to make it fit better to give a more realistic final result. You could also mix it with other mattes to combine them into a final matte for the image, which we will do.

Color space

Just a quick word about color space. Think of color space as 3 dimensional Cartesian space except instead of the XYZ axis that you are familiar with, the axis are labeled RGB. Internally Blender’s image format is a 32bit floating point value per channel that is clamped from 0 to 1. So a pure red pixel has a value of (1.0, 0.0, 0.0). All colors are actually points in this color space. There are other types of color spaces. Instead of representing a color by its red, green, and blue components, you can represent it with a Hue, Saturation, and Value, (HSV color space), a Luminance, U, V (YUV) color space, or a Luminance, Chroma Blue, Chroma Red) (YCbCr color space-remember this one). To get an idea of why this may be important for keying, use the break out to channel nodes for each of the color spaces with the same image to view how each component contributes to your key. When broken out by channel you should see that your key does not have a lot of variance in it in a particular channel and there is a very clear difference between the foreground and the background.

Color Difference Method

Basic Setup

Create a color difference matte node from the matte menu. Connect the output for the raw footage video to the input and then click on the key color to bring up the color selection window. Press the sample button in the color selector window and then pick a color from green screen area that isn’t too bright and isn’t too dark, but very middle of the road (very Goldilocks-ish). You need to connect up the outputs of the node for it work, so lets use the viewer node (which is also being shown in an image editor to watch our work) to look at the matte that is being produced. Let’s also connect the matte output to a mix node. The Set Alpha node can be moved down the node chain (or to the right) as we build it to the composite since we will use it again.

Difference Matting

Now that we have our color selected for our key, and our difference node all hooked up, you can pick any color space to use. I would recommend RGB or YCC. You should see some of the green pixels become transparent. These pixels are very close to the key color in that 3 dimensional color space. Since nothing is perfect, we need to allow a range of pixels around that key to be considered the key; that’s what the tolerance sliders are for. You can adjust the tolerance of each axis individually so that you can have more red variance or blue variance in what you would allow to be transparent. I find that about .15 (or 15%) is plenty of variance if the background is evenly lit. We will cover what to do if it is not evenly lit (such as our raw footage in a moment).


You can adjust the amount of transparency that a pixel has by the distance that it is from the actual key location. So that pixels that are closer to the key are more transparent that ones that are further away. This is called falloff. If you want pixels that are far away to be considered very transparent, then use a high falloff value.

Mixing nodes together

Chain of Nodes

With a bit of tweaking you should be able to quickly find the point where you are able to get rid of almost all of the green without getting rid of any of Super Wu-Man. If there is a section of green that you just can’t get rid of without losing some of the ship, you can chain color difference nodes together, each focusing on a specific shade of green to cover all of the background. What we want to do now is combine the garbage matte that we created with the matte that we pulled from the color difference node. We do this using a mix node using the multiply method of mixing. We’ll have to create one from the color menu. In the mix node, select the multiply type of mix. What this will do will multiply each pixel from our masks together, which is a good way to combine them since black (0) times anything becomes black (or 0). The other input to the mix node should be the mask that we created in the previous tutorial. This is our final mask for our raw footage.

Chroma Key Node Method

The other method of pulling a key from an image based on its background is done using the chroma key node. It works solely in the YCbCr color space for the simple reason that a green screen or blue screen have very little chroma variance in the Cb and Cr channels, which makes it easier to determine if a given pixel part of the background or part of the foreground.

Where’s the key?

If you look at the chroma key node you’ll notice there isn’t a place to select a color as a key. Right now there are two sliders for each channel (the channels are Cb and Cr). The sliders are slope and position. Position is technically the key color and they help define the cutoff point for what is background and what is foreground. The slope adjusts the tolerance of the colors that are just before and just after the position point.

What is this slope thing

The slope adjusts the mathematical function’s slope that determines the which way the pixel gets clamped. For most backgrounds it is possible to just set it at the max and be done with it. Only with very uneven backgrounds do you need to adjust the slope to allow for some slop in the background.

alpha threshold=shadows?

When using the chroma key node, if you have a transparent object, or wish to keep a shadow from a foreground on the background, The alpha threshold will use the luminance channel difference to determine if the transparent pixel needs to be shaded rather than fully transparent. You can adjust the slider to get more or less shadows. If you want to get the foreground object and nothing but the foreground object slide this up to the max.