Introduction to Composite Nodes in Blender
Viewer nodes showing Combined, Alpha, Diffuse, and Specular render passes.

I’ve been experimenting with compositing nodes lately; not so much for achieving specific results as for understanding how they work. The subject is also educational for increasing understanding of Blender’s rendering pipeline. Believe it or not, it’s possible to get a grasp on this without diving into the code…

Blender Underground’s focus thus far has been to deal more with the nuts and bolts of how things work than how to achieve this or that specific effect. This series will continue the tradition. I won’t rule out how-to’s on certain subjects, but I will try to focus more on theory and usage than on the end result – leaving that up to you, the artist, hobbyist, and/or professional. I’m aiming to help you understand the tools at your disposal and how they work, focusing less on how to obtain a specific result.

In this first installment, we’ll take a look at render passes, a basic node setup – which involves assembling some passes into a composite – and pixel math, for understanding how Blender combines passes into the final render.

Render Passes

Render passes in composite nodes - diffuse, specular, shadow, alpha
Left to Right, Top to Bottom: Combined, Alpha, Z Buffer, Color, Diffuse, Specular, Shadow, Ambient Occlusion, Reflection.

Blender’s composite nodes give the user access to data from its render passes. When Blender calculates things like shadows or specular highlights, it stores the results as pixel data – that is, images – to be combined later using pixel math. More on that later. The important part to understand right now is that with nodes, you can access each of these passes individually, modify them, and put them back together in whatever way you see fit. This is known as compositing.

The primary definition of a composite is something made up of differing parts, combined to make a whole. In Blender, when you press F12 and render your scene, what you’re seeing is a composite of render passes – a set of separate images combined together into one final, hopefully beautiful, picture. With CompositeNodes, you’re given control over how these render passes get assembled, and what happens to them along the way. Let’s grab a look at some of the component parts of a render.

Render pass Combined
Combined – This is the renderer’s composite of all the render passes.

Render pass Alpha
Alpha – This pass is an 8-bit graphic representing the combined render’s transparency information. White pixels represent full opacity and black pixels indicate full transparency.

Render pass Z-Buffer
Z-buffer – While you might not be able to see the data represented here, it’s all in there. Z-buffer information is stored as a 32 bit floating point number. So while all the values might look white, with some manipulation (such as in Photoshop or GIMP) the values become apparent.

Render pass Color
Color – This is an RGB color mask containing information for each object in the scene. Since the objects in this render have a material color of white, no color is present in this pass. The diffuse pass actually already incorporates this data.

Render pass Diffuse
Diffuse – This pass contains all shading and color information from lighting calculations in the scene.

Render pass Specular
Specular – The information generated from all materials’ specular shaders are contained in this pass.

Render pass Shadow
Shadow – For ray traced or buffered shadows, this pass stores the shadow data for the scene.

Render pass Ambient Occlusion
Ambient Occlusion (AO) – This pass is the result of a separate pass using the AO algorithm. It adds a simulation of dirt and shadows that occur for objects close to one another.

Render pass Reflection
Reflection – Data generated from ray traced reflections are stored in this pass. Much of the data has values close to black, and won’t show up well until this pass is added in the composite.

These aren’t all of the available render passes; and some of these – like reflect, shadows, and AO – won’t be available unless they’re configured to run. In addition, with few exceptions, only the passes you specify will be available for compositing.

In the Render Layers panel of the Scene buttons (F10) are buttons for activating the various passes.

Render layers panel - render passes buttons
Left: Render Layers panel with render passes selected. Right: Render Layer node with corresponding render pass points.

Keep in mind these buttons don’t activate or deactivate render functionality, but instead they tell Blender what passes to make available to the Node editor. Note that Alpha is available to the Node editor (Right) all the time – there is no corresponding Alpha selection in the Render Layers panel. Let’s quickly set up the Node editor to edit composite nodes.

Note: Anytime you add a render pass for access by a node, you’ll need to re-render in order for that pass’s data to be available to the node. However once this is done, you can make all sorts of changes to the node configuration without ever having to re-render your scene. This is one of the advantages of working with nodes.

Setting Up for Node Editing

Node Editor default setup
Node editor with composite nodes button selected and “Use Nodes” button active.

You can bring up the Node editor the same way you would any other window, by configuring a pane to display it. Once you have the Node editor active, you’ll need to select the Composite Nodes button at the bottom, and turn on the Use Nodes button. The last step is turning on “Do Composite” in the Anim panel of the Scene buttons – if you don’t, all the node editing in the world won’t affect your final render.

Anim Panel Do Composite setting
Anim panel with “Do Composite” active.

Let’s set up a scene and configure Blender to work with Composite nodes.

Set up your scene as follows:

  1. UVSphere object on top of a Plane object.
  2. Basic material assigned to both objects.
  3. Turn off Ray Tracing if it’s active (Scene panel, F10).
  4. From the Render Layers panel (F10) turn on Combined, Diffuse and Specular passes.
  5. Configure a pane to display the Node editor, and activate the Composite Nodes button and the Use Nodes button.
  6. Activate the Do Composite button in the Anim panel of the Scene context (F10).
  7. Render your scene.

Simple Node Scene Blend File

Your node setup should now look like this, minus the callouts:

Node setup with callouts
Default node setup, with Combined Image output point of the Render Layer node connected to the Image input point of the Composite node.

A. Render Layer node – this node contains all the render passes.
B. Composite node – this node represents the render buffer (F11). Whatever is attached to this node gets displayed as the final render, and will get saved as an image when F3 is pressed.
C. View Configuration buttons – these control what elements get displayed in a node. Just play around with them and you’ll get the idea.
D. Node Connection Points – attachment points for input and output of a node’s data. Input points are present on the left side of the node, and output on the right.
E. Render button – re-renders the current Render Layer.
F. Mode Selector – these buttons determine whether the node editor is working with Material or Composite nodes.
G. Use Nodes button – Needs to be active to make use of Composite nodes.

Note: The Image connection point of the Render Layer node represents the combined, or composited, data from each render pass.

The above node configuration (sometimes referred to as a “noodle”) does nothing special. The Render Layer node’s Image (Combined) output point is connected to the Composite node’s Image input point. This configuration performs the same task as if we weren’t using nodes at all.

Rebuilding the Render Pipeline

Now that we’re set up to work with Composite Nodes, let’s use them to rebuild a small part of the render pipeline.

  1. With your mouse over the Node editor, add a Mix node with Spacebar->Add->Color->Mix.
  2. Attach the Render Layer node’s Diffuse point to the Mix node’s top RGB (yellow) connection point.
  3. Attach the Render Layer node’s Specular point to the Mix node’s bottom RGB connection point.
  4. Set the operation to Add instead of Mix, and set the Fac (Factor) to 1.0.
  5. Connect the Mix node’s Image output point to the Composite node’s Image input point.

Mix node combining specular and diffuse render passes
Composite using the Mix node to add the specular channel to the diffuse channel.

Press F11 to see the result.

Render result for diffuse and specular mix
Render result for the composite of Diffuse and Specular render passes.

If you’re not seeing a result, press F12 to re-render and re-check your connections. What we’ve just accomplished is using the Mix node to combine the Diffuse and Specular passes in the same way the renderer does. We’ve taken control of the compositing element of the render pipeline. The only difference is that the sky color is missing, which we’ll deal with in an upcoming installment.

Let’s check our results by using viewer nodes to inspect each of our passes.

  1. Add a Viewer node by pressing Spacebar->Add->Output->Viewer, and place it above the Render Layer node.
  2. Connect the Render Layer node’s Image point to the Viewer node’s Image input point.
  3. Turn on the “Backdrop” button from the Node editor header.
  4. Select the newly added Viewer node. You should now see that viewer node displayed as the backdrop image for the node editor.
  5. With the Viewer node selected, press SHIFT+D to duplicate it and place the new Viewer node above the Mix node.
  6. Duplicate it again and place the new node below the Mix node. To make things easier, you can collapse the Viewer nodes with the triangle button on the top left corner of the node.
  7. From the Render Layer node, connect the Diffuse point to one of the Viewer nodes and the Specular to the other. As you select each of them, you should get a full resolution view on the Node editor’s backdrop.
  8. Finally, duplicate one of the Viewer nodes one more time and place it above the Composite node. Connect the Mix node’s Image output to the viewer node.

Finished node setup with Viewer nodes
Finished node setup combining Diffuse and Specular channels, with Viewer nodes and backdrop.

As you select the different viewer nodes, the backdrop changes to reflect the node’s input. This lets you see each individual pass and result to help you keep track of what’s going on. You can reposition the backdrop with SHIFT+MMB, and the nodes with MMB.

When you click on the Viewer node above the Render Layer node, you should see the combined composite as it is assembled by the renderer. When you click on the Viewer node above the Composite node, you should see the composite as you’ve assembled it. The only difference should be the presence of the sky color. As mentioned earlier, we’ll deal with that in an upcoming installment. As you click on the Viewer nodes above and below the Mix node, you should see the Diffuse and Specular passes that are being assembled in the Mix node.

Finished Node Setup Blend

Pixel Math

Why did we “add” the specular channel to the diffuse? The term “add” is more than a literary convenience, it describes the math that is used to combine the channels together. We need to briefly discuss how basic pixel math works. Don’t worry, it’s simple but illuminating stuff.

For RGBA color, there are 8 bits per channel for a total of 32 bits (Red, Green, Blue, Alpha). Each 8 bits of data is 1 byte, with a possible range of values from 0 to 255. For the renderer’s math operations, the values are “normalized.” That is, they are represented by the values 0.0 to 1.0 instead.

R = 0 to 255 | 0.0 to 1.0
G = 0 to 255 | 0.0 to 1.0
B = 0 to 255 | 0.0 to 1.0
A = 0 to 255 | 0.0 to 1.0

When we look at any of these channels individually, they are actually values ranging from 0.0 (black) to 1.0 (white). When RGB color math takes place, it happens on a per-pixel and per-channel basis. Let’s try to wrap our head around this by looking at a couple of 1-pixel math examples.

Pixel Math Addition 1
When two medium gray pixels are added together, the result is a white pixel.

Pixel Math Addition 2
When a black pixel and a medium gray pixel are added together, the result is a medium gray pixel.

Pixel Math Addition 3
When a dark gray and a medium gray pixel are added together, the result is a light gray pixel.

Notice that for Add operations, the result is always lighter than either of the two source pixels, unless one of them is black (0.0). Add operations effectively always brighten the result. For Specular passes, this makes perfect sense, considering that specular highlights are always brighter than their diffuse counterparts.

Also remember that these operations take place individually for every pixel in the pass, which is why diffuse plus specular equals shiny.

Pixel Math per pixel diffuse specular example
The Add operation works on each pixel in the pass. When the Specular pass is added to the Diffuse pass, the result is a bright specular spot, simulating shininess.

Note: When the values of two pixels are added together, the result is often greater than 1.0. In this case the renderer will often “clamp” any value greater than 1.0 to 1.0.

Some render passes, such as the Shadow pass, aren’t added – they’re multiplied. When numbers less than 1.0 are multiplied together, the result is always a smaller number – a darker value – unless one of the values is exactly 1.0. Let’s look at a few pixel multiplication equations:

Pixel Math Multiplication 1
Two medium gray pixels multiplied together results in a dark gray pixel.

Pixel Math Multiplication 2
A light gray pixel multiplied with a medium gray pixel results in a dark gray pixel.

Pixel Math Multiplication 3
When any pixel (in this case, medium gray) is multiplied by a white pixel (1.0) the result is unchanged.

The net result of our examination of pixel math should help you to understand a little more of what goes on under the hood of Blender. By examining Add and Multiply pixel math, we’ve gained an understanding of how many render passes are combined in the pipeline, on a per-pixel basis.

Conclusion

Understanding the basics of pixel math, along with having a knowledge of how render passes are assembled in the pipeline, will make understanding composite nodes much easier. This primer served as part 1 of a multipart series on using Composite Nodes.

In the next part of the series, we’ll assemble a more complex set of passes, and make some modifications to them along the way. We’ll introduce additional Node types and examine how they’re used to make modifications to the render passes before assembling them into the final composite.

Part 2 >>

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

This entry was posted on Monday, March 31st, 2008 at 2:16 am and is filed under Tutorials. You can follow any responses to this entry through the RSS 2.0 feed. You can skip to the end and leave a response. Pinging is currently not allowed.

9 Responses

  1. yoyo says

    [@$*&] it’s not a video i have to read,
    I’m block with this nodes,i don’t understand anything.
    Now i hope everything will be ok.
    so thanks again blenderunderground team
    cheers
    Yo

  2. kernond says

    Good start on a challenging subject.

  3. teasel says

    This compositing series is a great idea. A lot of 3D shots integrated with live action fall apart because of poor compositing. Keep up the good work!

  4. Goliath says

    Tanks for that first tutorial

    Extremely goods explanations as well as for the examples.

    Hope its the first of a long serie explaining all of us how to finaly make a better render than just by pressing F12 after had spent 5 hours on a scene !!!

  5. 555 Blender Tutorials | FilmmakerIQ.com says

    [...] Introduction to Composite Nodes, Part 1 [...]

  6. Ad3m says

    very nice Blog. Hope its the first of a long serie explaining all of us how to finaly make a better render than just by pressing F12 after had spent 5 hours on a scene !!!

    __________________________
    Muhabbet , mirc , sohbet

  7. yunsky says

    Thanks a lot. keep it up.

    ___________________________________
    TV studio film lighting -HD video camera battery -HD LCD monitor

  8. dandymac says

    great! can you give a tutorial on basics of animation?

  9. lenniez says

    Great intro to nodes……
    Mo stuff like this needed 4 noobies like me…..

Leave a Reply

You must be logged in to post a comment.