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:
- Create a plane with a sphere on top, and assign the same material to both objects.
Simple scene setup of a plane and sphere with the same material assigned to both.
- Configure a view pane to display the Node editor.
- From the Node editor header, activate the Composite Nodes and Use Nodes buttons.
Node editor with Composite Nodes and Use Nodes buttons active.
- From the Anim panel of the Scene buttons (F10) activate the Do Composite button.
Scene buttons, Anim panel with Do Composite button active.
- Also from the Render panel, turn on the Ray button to enable Ray Tracing.
- Select the Render Layers panel and activate the passes for Combined, Diffuse, Specular, Shadow, and Reflection.
Render Layers panel with necessary passes buttons active.
- 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.
- Make sure Traceable is activated in the Links and Pipeline panel.
- Render your scene with F12.
Let’s wire up a composite, starting with the Diffuse and Shadow passes.
- In the Node editor, add a Mix node with Spacebar->Add->Color->Mix.
- Attach the Diffuse pass to the top RGB input of the Mix node, and attach the Shadow pass to the bottom input.
- Set the operation to Multiply, and the Factor to 1.0.
- Attach the Mix node’s output to the Image input of the Composite node.
- 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 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.
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:
- Add another Mix node to the editor with Spacebar->Add->Color->Mix.
- Attach the first Mix node’s Image output point to the new Mix node’s top Image Input point.
- Attach the Reflection pass output from the Render Layer node to the new Mix Node’s second Image input point.
- Attach the new Mix node’s output to the Composite node. You should be getting the hang of this by now.
- Set the Mix node’s operation to Add and the Factor to 1.0.
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.
Diffuse, Shadow, Reflection, and Specular passes mixed together with Factor settings of 1.0.
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.
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.
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:
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:
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 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.
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.
- Add an RGB Curves node with Spacebar->Add->Color->RGB Curves.
- Attach the Image output of the Render Layer to the Image input of the RGB Curves node.
- Attach the Image output of the RGB Curves node to the Image input of the Composite Node.
- 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.
- Click in the RGB Curves window to add a curve point, and drag it toward the upper left corner, as shown below.
- Press F11 to see the result.
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.
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 – 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.
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: 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.
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.
- Add a ColorRamp node with Spacebar->Add->Converter->ColorRamp.
- Attach the Render Layer’s Alpha point to the input of the ColorRamp.
- Attach the ColorRamp’s output to the Composite node so that you can see the result.
- Render the scene (F12).
- On the ColorRamp node, switch the places of the black and white points on the color band.
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:
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.
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:
Corrected Shadow pass combined with Diffuse+sky, Reflections, and Specular.
If you can’t tell the relationships by the diagram, here’s a rundown:
- The Combined pass (Diffuse + sky) is multiplied by the corrected Shadow pass, which consists of the inverted Alpha channel added to the original Shadow.
- The Reflection pass is added to the result with another Mix node.
- The Specular pass is added to the result with a final Mix node.
- The resulting output is piped into the Composite node.
Let’s look at the output render of the above node setup:
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.
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.
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.