Introduction to Composite Nodes in Blender
Composite with sky color, consisting of Combined, Modified Shadow, Reflection, and Specular passes

In Part 1 of this series, we started by looking at some of the key render passes that result in the final image as seen when we press F12 to render. We also reviewed how to set up for node editing, and we “built” a small part of the render pipeline by compositing diffuse and specular passes into a final image. Finally, we looked at the basics of pixel math, demonstrating some of the ways that Blender composites pixels internally – which can also be reproduced with a simple node setup…

In this installment, we’ll expand on the previous lessons by building a slightly more complex set of render passes. In addition, we’ll look at how to “exclude” passes as well as include them – this will help us build a composite that displays our background color, which was missing in last week’s exercise. Finally, we’ll look at some basic ways to make modifications to render passes before a final composite.

Assembling Additional Render Passes

Let’s begin by setting up our simple scene from last time, and preparing for node editing:

  1. Create a plane with a sphere on top, and assign the same material to both objects.

Simple scene setup with a sphere on top of a plane
Simple scene setup of a plane and sphere with the same material assigned to both.

  1. Configure a view pane to display the Node editor.
  2. From the Node editor header, activate the Composite Nodes and Use Nodes buttons.

Initial Composite Node Setup
Node editor with Composite Nodes and Use Nodes buttons active.

  1. From the Anim panel of the Scene buttons (F10) activate the Do Composite button.

Do Composite button active in Anim Panel
Scene buttons, Anim panel with Do Composite button active.

  1. Also from the Render panel, turn on the Ray button to enable Ray Tracing.
  2. Select the Render Layers panel and activate the passes for Combined, Diffuse, Specular, Shadow, and Reflection.

Render passes activated in Render Layers panel
Render Layers panel with necessary passes buttons active.

  1. For the material that was assigned to the plane and sphere, activate Ray Mirror from the Mirror Transp panel, and turn the RayMir value to 0.5.
  2. Make sure Traceable is activated in the Links and Pipeline panel.
  3. Render your scene with F12.

Beginning Node Setup Blend

Let’s wire up a composite, starting with the Diffuse and Shadow passes.

  1. In the Node editor, add a Mix node with Spacebar->Add->Color->Mix.
  2. Attach the Diffuse pass to the top RGB input of the Mix node, and attach the Shadow pass to the bottom input.
  3. Set the operation to Multiply, and the Factor to 1.0.
  4. Attach the Mix node’s output to the Image input of the Composite node.
  5. Press F11 to see the result. The F11 key shows the Render Buffer, but doesn’t re-render the scene. It will always reflect the result of whatever is attached to the Composite node’s Image input.

Diffuse pass and Shadow pass muliplied with Mix node
Diffuse pass multiplied with the Shadow pass

We get the Shadow pass’s effect by multiplying it with the Diffuse pass. Remember that in our Pixel Math lesson from Part 1, multiplying one pixel with another results in darkening the image, unless one of the pixels is pure white (1.0). Since shadows darken a scene, the multiply operation is perfect for compositing shadows.

Attach a Viewer node (Add->Output->Viewer) to the Shadow pass to see what it looks like. (If your Shadow pass looks rough, add a Subsurf modifier to the sphere at level 2.) All the shadow pixels are black, resulting in black pixels for those areas in the composite. The non-shadow pixels are white, resulting in no change to the composite on those areas. Multiplying black shadow pixels (0.0) always results in black pixels in the composite. Multiplying white shadow pixels (1.0) always results in unchanged pixel values in the destination composite.

Shadow pass multiplied by Diffuse pass
In the composite, black shadow pixels become black, and white pixels are unchanged.

Even in this simple node setup, we can make changes. By adjusting the Factor setting of the mix node, we can soften the effect of the shadow. This is because Factor controls how the values are combined, so a Fac setting of 0.5 will only apply 50% of the multiply effect.

Note: Since we’re using ray traced reflections, it’s better to leave this Mix node’s Factor setting above 0.5. This is because the Reflection pass takes shadows into account. If the shadow’s Factor is too low, reflections will brighten the shadow area when the pass is added to the composite.

Let’s add the Reflection pass to our composite:

  1. Add another Mix node to the editor with Spacebar->Add->Color->Mix.
  2. Attach the first Mix node’s Image output point to the new Mix node’s top Image Input point.
  3. Attach the Reflection pass output from the Render Layer node to the new Mix Node’s second Image input point.
  4. Attach the new Mix node’s output to the Composite node. You should be getting the hang of this by now.
  5. Set the Mix node’s operation to Add and the Factor to 1.0.

Nodes Composite of Diffuse, Shadow, and Reflection passes
Composite of Diffuse, Shadow, and Reflection passes.

As you can see from the result, Reflection passes are “added” to the composite. Any pixel in the Reflection pass that is brighter than black will brighten the destination composite. Note also that the Factor setting of this second Mix node can also be tweaked to enhance or reduce the reflective effect. Just keep in mind that if you set the Reflection mix factor higher than 1.0, you’ll need to bump up the shadow’s mix as well to compensate, because the Reflection pass is “shadow aware.”

Last but not least, add another Mix node to add in the Specular pass. This should be elementary at this point, and with a little practice, you’ll be doing this level of compositing without much thought at all. You may want to tinker with the Factor setting for this node as well, taking note of how the Specular pass can be enhanced or muted with settings greater than, or less than, 1.0.

Specular pass is added to the Diffuse, Shadow and Specular passes
Diffuse, Shadow, Reflection, and Specular passes mixed together with Factor settings of 1.0.

Render of four combined passes
Combined render with all four passes.

Note: One advantage to tuning shadow, reflection, and specular intensities in the composite is that it requires no additional rendering time. If you were to make these changes to the scene itself, you would need to re-render the scene to see the results. Composite nodes give you a great way to make moderate enhancements with real-time results.

Excluding Render Passes

In the render above, we don’t see our sky color. Actually, that’s not entirely true. In the reflection pass, we see the sky color just fine. However we don’t see it in the background where we would expect it. Now you might be wondering how we’re going to add sky in a section about “excluding” passes. Let the magic happen.

In the Render Layers panel of the Scene buttons (F10) take note of the “Combined” pass. This pass corresponds directly to the “Image” attach point of the Render Layers node.

Combined pass equates to the Image point on the Render Layer
Left: The Combined render pass is the same as the Image connection point of the Render Layer (Right).

By default, the Combined (Image) pass is Blender’s internal composite for the entire render. Everything is in there: Diffuse, Specular, Shadow, Reflection, AO, Refraction, etc., regardless of whether or not that pass is included on the Render Layer node (but only if it’s configured to run, such as with Ambient Occlusion). However you can tell Blender to excludea pass from that Combined composite.

This is accomplished by using the CTRL key when clicking on the pass buttons. When this is done, a black dot appears on the button, indicating that this pass will not be included in combined. Note that this is independent of whether or not the pass is included on the Render Layer node.

Excluded render passes marked with black dot
Render passes excluded from the Combined pass (Left) are marked with a black dot – Render passes included on the Render Layer node (Right) have their buttons selected.

Let’s decode the above screen shot. First, note that not all the passes have the potential of being excluded. In the case of the Diffuse pass, it’s the minimum requirement of the Combined pass: it has to be included no matter what, so you’re not given the option of exclusion. The other passes are extra data, such as Z buffer, Vector, Normal, UV, Index, and Color. They are not actually a part of the composite, but are data passes used by Blender internally, and made available to the user for convenience and advanced effects. The Color pass is a subset of the Diffuse pass, so it’s always included as well. One additional piece of the puzzle, included in the Combined pass by default, is the sky background color.

So the above configuration gives us a Combined pass that will contain diffuse information, along with our background sky color. Our Combined pass is now configured to replace our Diffuse pass, which is why Diffuse is not selected. We don’t need it as a separate pass because we already have it in Combined. We’ve told Blender to exclude the Specular, Shadow, and Reflection passes from the Combined pass, but we’ve specified that they should definitely be included on the Render Layer node instead.

If you haven’t done so already, configure your own scene as shown above, with the Combined, Specular, Shadow, and Reflection passes selected. Using the CTRL key, select Specular, Shadow, and Reflection passes for exclusion from the Combined pass. We’re not concerned with AO, Refraction, or Radiosity because they’re not configured to affect our scene. If they were, we’d take them into account.

Here’s the new node setup:

Combined with sky color using Alpha channel
Composite with sky: the Combined node is connected to the Multiply Mix node’s first Image input; additionally, the Alpha output is connected to the Factor input.

In the above node diagram, everything’s the same as before except for two connections: 1) The Render Layer’s Image (Combined) point is connected to the first Mix node’s top Image input (because it’s replacing our Diffuse pass); 2) The Alpha output is connected to the Mix node’s Factor input. The Factor setting can take an image input – in this case, the Alpha channel.

Why did we need the Alpha channel and how is it affecting Factor? Let’s take a look at both the Alpha and Shadow passes:

Alpha pass and Shadow pass
Left: Alpha Render Pass – Right: Shadow Render Pass

Earlier we composited the Shadow pass by multiplying it with the Diffuse pass. This most recent time we multiplied it with the Combined pass, which we used to replace Diffuse. However the Shadow pass has an entire area of black pixels around the border of our objects, very much like the Alpha channel. When we multiply black pixels by any other value the result is black, so it ends up setting our sky color to all black.

However we have the Alpha channel to rescue us. When we add it as an input to Factor, it tells the Mix node to only apply the effect where the pixels are white. This means that where the pixels are black, no multiplication is taking place. The result is that our sky background color is preserved. If this isn’t making sense, remember that the Pixel Math operations are performed on a per pixel basis. The Alpha channel pixels tell the Mix node to take into account the per pixel value of the Factor input. So instead of setting Factor globally and manually, we’re using an image (the Alpha channel) to apply it per pixel.

Here’s the rendered result:

Composite render complete with sky color
Composite render with sky color visible (Specular Mix node’s Factor is 2.0)

You might notice a faint black line around the outside pixels, where the objects border the sky color. This is an artifact of the Shadow pass being multiplied with the Combined pass, and results because of edge anti-aliasing. We’ll deal with this at the end of the lesson.

Modifying Passes Before the Final Composite

Let’s touch on some quick ways to make modifications to the render passes before assembling them into the final composite. We’ve already looked at making adjustments to the Factor setting of the Mix nodes, which is very handy, but there are other ways to modify passes as well.

One of the things you might want to apply for your renders is color correction. We’ll simplify our node setup since we’ll be adding nodes for color adjustments.

Specular pass exluded in Combined pass
Simple node setup with the Specular pass included for the Render Layer, but excluded for the Combined pass.

The above node setup is very much like the one we did in Part 1 of this series. It simply adds the Specular pass to the Diffuse. There are two differences however: 1) We’re using the Combined pass instead of the Diffuse pass; 2) We’ve excluded the Specular pass from the Combined pass so that we can work on each individually. I’ve also turned off ray tracing, because we won’t be using any Shadow or Reflection passes in this example.

Let’s expand our setup to make modifications to the Combined pass, then we’ll add the Specular pass back on at the end.

  1. Add an RGB Curves node with Spacebar->Add->Color->RGB Curves.
  2. Attach the Image output of the Render Layer to the Image input of the RGB Curves node.
  3. Attach the Image output of the RGB Curves node to the Image input of the Composite Node.
  4. On the RGB Curves node, press the R button near the top (Red channel). You’ll see buttons for R, G, B, and C (Combined). This is similar to other color curves widgets you may have used in image applications.
  5. Click in the RGB Curves window to add a curve point, and drag it toward the upper left corner, as shown below.
  6. Press F11 to see the result.

Combined pass with modified RGB curves
Node setup with Combined pass being piped through an RGB Curves node.

What we’ve accomplished here is to add a red cast to our Diffuse pass by piping it through an RGB Curves node, and modifying the Red channel’s gamma. As with the Mix node, we can adjust how much of the effect is applied with the Factor setting.

One of the problems you may have noticed with this effect is that we’re not just adjusting the red channel of the scene objects, but we’re effecting the entire image, sky and all. The solution is simple. We can use the Alpha channel as the RGB Curve’s Factor input. This will signal the RGB node to only apply the effect where the Factor input sees white pixels. When we attach the Alpha to the Factor, the RGB Curve node’s effect on the sky color goes away.

The last step is using a Mix node to add the specular channel back in. This is why we excluded it from the Combined pass, so that we could deal with the Diffuse color separately.

Diffuse modified by RGB Curve node with Specular pass added
RGB modified Diffuse pass with Specular pass added on, and the Alpha channel used as Factor input for the RGB node.

Render of RGB modified Diffuse channel
Render of RGB modified Diffuse channel – the RGB node’s combined gamma has been reduced, and the Mix node’s Factor set to 2.0 for Specular.

Since we had the Diffuse and Specular passes separate, we could have chosen to make modifications to the Specular pass as well. You might want to experiment with this on your own, and take note of some other node types as well, such as the HSV node for color modification on Hue, Saturation, and Value levels.

Addressing the Shadow Pass’s Multiply Artifacts

Earlier when we composited shadows, there was a faint black line that appeared around the border of the scene objects and the background.

Black line on edge of Alpha from multiplied Shadow pass
Composite render showing faint black line resulting from the multiplication of the Shadow pass.

This happens in part because the Shadow pass not only has black pixels representing shadows, but it has black pixels around the boundary of the scene objects as well. When the Shadow pass is multiplied with the Diffuse pass, it darkens the very outside pixels of that pass.

We need a better way to deal with this than we did previously: by using Alpha as a factor to control the Mix node. Pixel anti-aliasing occurs on the edges of the Alpha channel as well as the Diffuse pass. The result is a very faint overlap of pixels between those passes at the edges. Let’s use the Alpha channel again, but in a different way.

Here’s another look at the Alpha and Shadow passes:

Alpha and Shadow passes
Alpha and Shadow passes: Almost identical except for the shadow pixels of the sphere object.

These passes are nearly identical at their edges. So identical in fact, that we can use the Alpha channel to get rid of the Shadow pass’s outer black pixels altogether. However, first we need to invert the alpha channel, then add it to the Shadow pass. The result will be a Shadow pass that only contains black shadow pixels, no black boundary.

Shadow pass excluded from Combined
Node setup with Shadow both excluded from Combined, and included in the Render Layer.

Make sure you turn on ray tracing for this example, but you can turn off Ray Transparency for the material, as we’ll only be dealing with the Shadow pass separately. The Combined pass includes Specular, but excludes Shadow. We’ve made Shadow available as a separate point on the Render Layers node.

The next step is to invert the Alpha channel.

  1. Add a ColorRamp node with Spacebar->Add->Converter->ColorRamp.
  2. Attach the Render Layer’s Alpha point to the input of the ColorRamp.
  3. Attach the ColorRamp’s output to the Composite node so that you can see the result.
  4. Render the scene (F12).
  5. On the ColorRamp node, switch the places of the black and white points on the color band.

Inverted Alpha channel with ColorRamp node
ColorRamp node is used here to invert the values of the Alpha Channel.

The ColorRamp node works like any color ramp, in that it allows you to map the luminosity values of the input to entirely new luminosity values. In this case, we’ve inverted the ramp entirely, making the white pixels black, and the black pixels white. Note from the output that the result has inverted our Alpha channel.

Back to Pixel Math for a moment: when we add the Alpha channel to the Shadow pass with a Mix node, the white pixels will combine with the black ones to give us white pixels (0.0 + 1.0 = 1.0).

Since there are no white pixels anywhere else in the inverted Alpha channel, only black pixels, those parts of the pass will remain unchanged (0.0 + x = x). Let’s do that now with the following node setup:

Inverted Alpha added to Shadow pass
Node setup adding inverted Alpha channel to Shadow pass.

Remember to set your Factor to 1.0.

The result here is a modified Shadow pass that has no black values except for the shadowed area itself. Let’s now Multiply this Shadow pass and see the result. We need to set up the Render Layer like we did before, and re-enable Ray Mirror in the Material settings.

Specular, Shadow, and Alpha excluded from Combined pass
Combined pass excludes Specular, Shadow, and Reflection – these are included in the Render Layers node.

Here’s the final wiring diagram for our completed node setup:

Final node setup with corrected Shadow pass
Corrected Shadow pass combined with Diffuse+sky, Reflections, and Specular.

Final Node Setup Blend

If you can’t tell the relationships by the diagram, here’s a rundown:

  1. The Combined pass (Diffuse + sky) is multiplied by the corrected Shadow pass, which consists of the inverted Alpha channel added to the original Shadow.
  2. The Reflection pass is added to the result with another Mix node.
  3. The Specular pass is added to the result with a final Mix node.
  4. The resulting output is piped into the Composite node.

Let’s look at the output render of the above node setup:

Final render with corrected Shadow pass
Final render with no darkened edge artifacts

In this render there is no black pixel influence on the edges of our scene objects. Our treatment of the Shadow pass has completely eliminated them, and we’ve managed to build a Composite node setup that’s ready to be modified in a number of ways on a per-pass basis. Now that you know how to assemble this type of composite, you can use this as a starting point for all sorts of node-based modifications.

Note that our earlier solution of using the Alpha channel to modulate the Factor of the first Mix node no longer applies, since we have completely reworked the Shadow pass; however you will find that the Alpha channel (or an inverted Alpha) will often serve a beneficial purpose as Factor input, to limit the effects of a variety of nodes to specific areas of your scene.

Conclusion

By understanding just a few basic node types, you gain control over how your scene is composited. You obtain the ability to modify the appearance of your scene on a pass by pass basis, and gain all sorts of interesting possibilities for creativity.

Although so far we’ve only toyed around with rebuilding Blender’s existing render composite capability, in the next lesson we’ll look at additional node types, and consider some ways to create effects that aren’t possible without Composite nodes. We’ll also take a closer look at the Z buffer.

<< Part 1

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

This entry was posted on Thursday, April 10th, 2008 at 12:10 am and is filed under Tutorials. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

13 Responses

  1. MasterDomino says

    I just registered to let you know how great I think this introduction is.

    Tutorials about compositing normally explain you how to achieve a certain thing which results basically in you following exactly some instructions how to connect something to a noodle without having any idea what is going on.

    This here is completely different and so much better, it explains you *what* is happening and *why* it is happening in a very understandable way and very well explained. I was understanding the principles behind compositing for the first time thanks to this tutorial.

    Very well written and a perfect amount of information, enough to follow, but also not too much, so you also have to try things out yourself and learn something by doing that.

    Great, thank you so much for this! I am looking forward to the third part.

    MD

  2. Apollos says

    MasterDomino, Thank you!! That was exactly my intention, so I’m really glad to hear your comments. I’ll try to get Part 3 out soon. Welcome to Blender Underground. 8)

  3. lewarcher says

    Great tutorial, as always! This is the first tutorial that I found on the internet that explains compositing from the basics. Thanks!

  4. Apollos says

    You’re welcome Lew!

  5. KrisBerg says

    Exactly as the other people points out! Great tutorials, Blender Underground! You really make my transition smoothly being a 3DSMAX guy and all, and also the great VideoTuts “BlenderBasics”. Can’t wait for more Apollos. BTW: Love the dramatic quest of hiding from “The man”. haha. Keep it up! Thanks.

  6. blend3d says

    Just logged in to say thanks, A very clear and for me a much needed tutorial. Thanks also for making this a static (non-video) tutorial. It allows me to take my time and try out experiments with what you are showing us.

    Also a thank you for all the other stuff you have presented to date…It is all very, very good!

    Blend3d (aka David)

  7. ChrisHav says

    You call this a node tutorial? It’s more like a part of a blender-node course! (which is a good thing). I’m pretty un-unique from every one else who commented, namely, that I joined the underground to show that your hard work is appriciated. I’m still going to have to study nodes a lot more to really grasp hold of what I’m doing, but this was a great help.

  8. Apollos says

    Hi Chris! Welcome to Blender Underground. 8)

    Glad you enjoyed it, and I hope to do another one in the future.

    @blend3d, thanks for dropping by, and letting me know how it helped. :o

    @KrisBerg, great to hear you made the transition, and I’m glad I could be a small part of it.

    Welcome to the Underground, all! 8)

  9. Haytch says

    Ditto to above ..Just signed up to register my appreciation for your efforts and to encourage you to continue with this node stuff as its finally starting to make sense to me.
    H

  10. Jamin3D says

    Yet another amazingly useful and excellent tutorial. Through other ‘tutorials’ I tried to figure out how to combine render layers to achieve vector blur for just 1 object… and the answer was as simple as learning the basics that you teach right here. Thanks Apollos!

  11. lalamax3d says

    thanks for such a nice effort
    suggestions for part3:

    for simple scenes / renders, this approach is good, comping before rendering and all modifications will be part of it after final render
    issue: if shot / scene is bit and been divided into few layers. comping each layer and then rendering final shot, scares me a bit
    like typical approach, i want to render each layer with elements (diffuse,alpha,spec, shadow,reflection etc) so they can be loaded into compositor and have no dependency in scene 3d data. how to setup this.
    currently confusions in my mind are
    1- when i typically hit “render” key >> blender shows me composite view (where all elements are combined), how can i write each element to disk in jpg / tga / exr??
    so they can be loaded in compositer??
    btw, thanks again in advance

  12. Apollos says

    lalamax3d,

    You can use the file output node to save individual passes (Add->Output->File Output). This is what you want I think. Then you can load the separate images into any program you choose for compositing (After Effects, GIMP, Photoshop, etc).

    You can even load them back to the Blender compositor with the Image node.

    Hope this helps. ;-)

  13. Apollos says

    lalamax3d,

    1) Not that I know of. It would be nice if every node were also a viewer node, which would save some time and hassle. As it stands, you’ll need to hook an output node to each output that you want to examine. I usually hook up several and leave them in place while I’m creating the group.

    2) The best you can do here is hook an output node to each output you want to compare and click back and forth between them. You can have as many output nodes as you want, and whichever one is selected will show up on the background.