Merge
Merge allows you to layer multiple images together. When using this node, you need to select a compositing algorithm that determines how the pixel values from one input are calculated with the pixel values from the other to create the new pixel values that are output as the merged image. The operation dropdown menu houses a large number of different compositing algorithms, giving you great flexibility when building your composite.
When using most of the available merge algorithms, Nuke expects premultiplied input images. However, with the matte operation you should use unpremultiplied images.
You can also create this node by pressing M on the Node Graph.
Inputs and Controls
Connection Type |
Connection Name |
Function |
Input |
A |
The image sequence to merge with input B. When you connect the A input, a new input A1, A2, etc. is spawned allowing you to connect multiple image. |
B |
The image sequence to merge with input A. |
|
mask |
An optional image to use as a mask. By default, the merge is limited to the non-black areas of the mask. At first, the mask input appears as triangle on the right side of the node, but when you drag it, it turns into an arrow labeled mask. If you cannot see the mask input, ensure that the mask control isn’t disabled or set to none. |
Control (UI) |
Knob (Scripting) |
Default Value |
Function |
Merge Tab |
|||
operation |
operation |
over |
Sets the Merge algorithm to use: • atop - Shows the shape of image B, with A covering B where the images overlap. Algorithm: Ab+B(1-a) • average - The average of the two images. The result is darker than the original images. Algorithm: (A+B)/2 • color-burn - Image B gets darker based on the luminance of A. Algorithm: darken B towards A • color-dodge - Image B gets brighter based on the luminance of A. Algorithm: brighten B towards A • conjoint-over - Similar to the over operation, except that if a pixel is partially covered by both a and b, conjoint-over assumes a completely hides b. For instance, two polygons where a and b share some edges but a completely overlaps b. Normal over produces a slightly transparent seam here. Algorithm: A+B(1-a)/b, A if a>b • copy - Only shows image A. This is useful if you also set the mix or mask controls so that some of B can still be seen. Algorithm: A • difference - How much the pixels differ. See also Absminus. Algorithm: abs(A-B) • disjoint-over - Similar to the over operation, except that if a pixel is partially covered by both a and b, disjoint-over assumes the two objects do not overlap. For instance, two polygons that touch and share an edge. Normal over produces a slightly transparent seam here. Algorithm: A+B(1-a)/b, A+B if a+b<1 • divide - Divides the values but stops two negative values from becoming a positive number. Algorithm: A/B, 0 if A<0 and B<0 • exclusion - A more photographic form of difference. • from - Image A is subtracted from B. Algorithm: B-A • geometric - Another way of averaging two images. • hard-light - Image B is lit up by a very bright and sharp light in the shape of image A. Algorithm: multiply if A<.5, screen if A>.5 • hypot - Resembles the plus and screen operations. The result is not as bright as plus, but brighter than screen. Hypot works with values above 1. Algorithm: diagonal sqrt(A*A+B*B) • in - Only shows the areas of image A that overlap with the alpha of B. See also In. Algorithm: Ab • mask - This is the reverse of the in operation. Only shows the areas of image B that overlap with the alpha of A. Algorithm: Ba • matte - Premultiplied over. Use unpremultiplied images with this operation. See also Matte. • max - Takes the maximum values of both images. See also Max. Algorithm: max(A,B) • min - Takes the minimum values of both images. See also Min. Algorithm: min(A,B) • minus - Subtracts B from A. Algorithm: A-B • multiply - Multiplies the values but stops two negative values from becoming a positive number. See also Multiply. • out - Only shows the areas of image A that do not overlap with the alpha of B. See also Out. Algorithm: A(1-b) • over - This is the default operation. Layers image A over B according to the alpha of image A. Algorithm: A+B(1-a) • overlay - Image A brightens image B. • plus - The sum of image A and B. Note that the plus algorithm may result in pixel values higher than 1.0. See also Plus. Algorithm: A+B • screen - If A or B is less than or equal to 1 the screen, else use the maximum example. Similar to plus. See also Screen. Algorithm: A+B-AB if A and B between 0-1, else A if A>B else B • soft-light - Image B is lit up. Similar to hard-light, but not as extreme. Algorithm: B(2A+(B(1-AB))) if AB<1, 2AB otherwise • stencil - This is the reverse of the out operation. Only shows the areas of image B that do not overlap with the alpha of A. • under - This is the reverse of the over operation. Layers image B over A according to the matte of image B. Algorithm: A(1-b)+B • xor - Shows both image A and B where the images do not overlap. Algorithm: A(1-b)+B(1-a) |
Video colorspace |
sRGB |
disabled |
When enabled, colors are converted to the default 8-bit colorspace (ProjectSettings > LUT > 8-bit files) before doing the composite and results are converted back to linear afterwards. |
alpha masking |
screen_alpha |
disabled |
When enabled, the input images are unchanged where the other image has zero alpha, and the output alpha is set to a+b-a*b. When disabled, the same math is applied to the alpha as is applied to the other channels. Note: This option is disabled on operations where it makes no difference or PDF/SVG specifications says it should not apply. |
set bbox to |
bbox |
union |
Sets the output bounding box type and any data outside this region is clipped off: • union - Resize the output bbox to fit both input bboxes completely. • intersection - Use only those parts of the image where the input bboxes overlap. • A - Use input A’s bbox. • B - Use input B’s bbox. |
metadata from |
metainput |
B |
Sets which input’s metadata is passed down the node tree. Note: When metadata from is set to All and there are keys with the same name in both inputs, keys in B override keys in A. |
range from |
rangeinput |
B |
Sets which input's range is passed down the node tree. |
A channels |
Achannels |
rgba |
Sets the channels from the A input(s) to merge with the B channels, and which channel to treat as the A alpha. Note: Setting A channels to none is the same as black or zero. |
B channels |
Bchannels |
rgba |
Sets the channels to use from the B input, and which channel to treat as the B alpha. |
output |
output |
rgba |
Sets the channels to which the merge of the A and B channels are written. |
also merge |
also_merge |
none |
Sets the channels that are merged in addition to those specified in the A channels and B channels controls. |
mask |
N/A |
disabled |
Enables the associated mask channel to the right. Disabling this checkbox is the same as setting the channel to none. |
maskChannelInput |
none |
The channel to use as a mask. By default, the merge is limited to the non-black areas of this channel. |
|
inject |
inject |
disabled |
Copies the mask input to the predefined mask.a channel. Injecting the mask allows you to use the same mask further downstream. |
invert |
invert_mask |
disabled |
Inverts the use of the mask channel, so that the merge is limited to the non-white areas of the mask. |
fringe |
fringe |
disabled |
When enabled, only apply the effect to the edge of the mask. When disabled, the effect is applied to the entire mask. |
mix |
mix |
1 |
Dissolves between the original image at 0 and the full merge at 1. |
Step-by-Step Guides
Layering Images Together with the Merge Node
Video Tutorials
Constructing Node Networks from Foundry on Vimeo.
Now we have some of the basics out of the way, we can move on to making more complex node networks. This is where the difference between layer-based compositing and node-based compositing really becomes apparent. Just to save some time, I have already read in two pieces of footage: one is a still image of a canyon and the other is an image sequence that features a CG spaceship.
Let’s build a more complex network. I am going to go ahead and connect the Viewer to the canyon. Now, one common task of compositing is to apply effects or filters to alter the image. So, for example, I can blur this canyon. If there are no nodes selected in the Node Graph, and I make a new node - for example, I can go to Filter > Blur with the right-mouse menu - the new node comes in by itself, it’s not connected. There are actually several ways to make these connections between nodes. Of course, one is simply to click+drag a pipe and drop it on top of another node by connecting the Viewer. If you have a pre-existing connection line, for example, Viewer1 pipe is connected to Read1, I can simply click+drag my new node and drop it on the current connection. Now, before we go further, I want to talk about what these pipes mean. You can look at the pipes and see the arrow heads and from that you can determine which direction the information is flowing. So, I can tell the information is flowing out of Read1, through Blur1, and down into Viewer1.
Now, there are other ways to connect these together too. If I disconnect these pipes, click+drag the ends, and break them, you can also simply connect the inputs and outputs. For example, the Blur node has an input pipe. I can tell it’s an input pipe because it’s flowing towards the node on the top here. The Viewer also has an input pipe. Some nodes also have outputs. There is an output right here on Blur1 and an output pipe right here on Read1 - that means the information is flowing out of those nodes. So, I can connect the input of Blur1 to the output of Read1. Now let’s grab the input pipe and drop it on Read1, which means that Read1 is now sending information to Blur1. You can also grab the output of Blur1 and drop it on Viewer1, which means the input of Viewer1 is coming from Blur1. There is a third way to do that, if I disconnect these one more time. Connect the Viewer back up to the canyon and then select canyon. If a node is selected, and I create a new filter like Blur, it is automatically inserted downstream. Let me delete this other Blur, as I don’t need it right now. So, there is a little network. There is no blur happening right now, and one thing that happens with some of the filter nodes is they are off by default. If I increase the size property on the Blur, it becomes blurry.
Another important task of compositing is combining multiple images or pieces of footage. Now, in a layer-based system, you would simply stack layers. In a program like Nuke, you would have to use a special node to merge inputs. Let’s give that a try. I am going to delete the Blur node out. I am going to bring in a Merge node, and that’s under Merge > Merge or the M key. The Merge node has an A and B input, plus an output. You can relate this to layer-based compositing by thinking of the B input as the lower layer, and you can think of the A input as the upper layer. So, what you can do is connect the Viewer to the output of the Merge1. In this case, connect the B to the canyon and connect the A to the spaceship. If I zoom in, I can see my spaceship is now composited over the top of my canyon. Now, the reason that works is there’s alpha transparency around the spaceship. This was rendered in Maya. Nuke automatically recognizes the alpha channel, so this black is converted to transparency. You can tell that Nuke has recognized the alpha because of this little white line right here that’s right beside the red, green, and blue lines. These are channel lines. So, here it recognizes the rgb+alpha, whereas over on the canyon it just sees rgb. In that case, here's your basic merge. Now, there is a few things to know about the merge that are useful. One thing is you can have more than one A input. In fact, as soon as you connect A, the A2 appears on the left. If you connect A2, you will have A3, and so on. The highest A number is equivalent to the highest layer, so A3 is on top of A2, and so on, with B on the very bottom.
Now, there is a mask input on the right side, however, we will talk about that later on when we get to rotoscoping. The Merge node also has a mix slider at the very bottom here. The mix slider controls the influence of the A input. If I reduce that, A starts to fade out. Another important aspect of the Merge node is the operation up here at the top. In layer-based compositing, you may have something like a blending mode. Now, a blending mode determines how the upper layers combine with the lower layers - some type of mathematical formula. In Nuke, it’s the operation and that defaults to over. Over is similar to normal inside of After Effects. You can change this menu though to other styles, for example plus. Plus adds A and B together. In this case, it gives me a semi-transparent, brighter result in that area. I will turn that to over for now. If you are curious what these operations do, let your mouse hover over the menu. You will see all of the different mathematical formulas for all of the different operations. In this case, a capital A and B represents the rgb values of the A inputs and the B inputs, whereas the lower-case a and b indicates the alpha values of A and B inputs.
If you are working with CG renders, you might be concerned with premultiplication. For example, Maya premultiplies automatically and that affects the quality of the alpha edges. If you want to interpret something that is premultiplied, open up the Read node and there is a premultiplied checkbox right here - click that on.
We have now created a more complex network. We have also merged together two inputs. Now, we are ready to move on to working with transforms, and we will do that in the next video.