Dynamic Lighting in the Compositor

Dynamic-Lighting-in-the-Compositor_BannerThis tutorial demonstrates how to dynamically alter the intensity and color of the lighting in a scene in Blender’s compositor, after rendering. I first read about this technique in Digital Lighting and Rendering byJeremy Birn (a book I highly recommend), and decided to see if I could figure out the particulars and do it in Blender. Essentially, by using pure red, green and blue lights, you can split the color channels of the image, adjust them independently, and recombine them.

It should be noted, the main body of this tutorial covers a three-point lighting system in the Blender Internal rendering engine. However, this can be used with more than three lights and can also be done in Cycles. These points will be covered at the end. Also, if you’re already experienced at using the compositor, after reading the “Setting Up the Scene” portion you can jump down to the full node tree image below to see the compositing setup.

Setting Up the Scene

In the example, I’ve set up three spot lamps (though you can use any lamp type). In the Lamp Settings panel for each lamp, set the colors of one to pure red, one to pure green and on one to pure blue, and set the energy of each to 1. Hexadecimal values for the colors are shown in the image.


Now, go to the Render Panel. Under Layers are listed Passes, these are the different render passes the renderer will deliver separately when checked. In the compositor, each checked pass appears as a socket on the Render Layers node. Check “color”, this will deliver an unshaded pass of just the scene colors. It is important not to check the “diffuse” pass, that will deliver a shaded color pass of the scene. The shading here will come from the split RGB channels. That’s it, now render and jump to the compositor (ctrl+left arrow, or select “compositing” from the screen layout drop menu at the top of the window).


 In the Compositor

As always, make sure you check “use nodes” in the toolbar at the bottom of the upper workspace. You will now have a Render Layers node with a “color” socket along with the usual “image”, “alpha” and “Z” sockets. Hit shift+a to add a node, select Converter -> Separate RGBA. Plug the “image” socket from the Render Layers node into the “image” socket on the Separate RGBA node. The “R”, “G” and “B” output sockets of the Separate RGBA node will now output grayscale images representing the red, green and blue channels of the rendered image. Since we set our three lamps to be pure red, green and blue, these images will represent the influence of each separate lamp.

Now add a Mix node (Color -> Mix). Change the mode in the drop down box from “mix” to “color” then plug the “R” output socket from the Separate RGBA node into the top “image” socket of the Mix node and the “color” output socket from the Render Layers node into the bottom “image” socket on the Mix node. This takes the grayscale image representing the red channel and colors it with the unshaded colors from the color pass, essentially giving what the render would look like with just that lamp.

Dynamic-Lighting-in-the-Compositor_Fig-03Now we can add two more Mix nodes set to “color” mode and do the same thing for the remaining “G” and “B” output sockets of the Separate RGBA node. At this point, we have the influence of the three lamps isolated and we can pretty much do whatever we want with each. You can add Brightness/Contrast nodes, Color Balance nodes, or anything to get all kinds of crazy effects. But we’re concerned with simply altering the intensity and color of each lamp and the best way to do that is with RGB Curve nodes. Add three RGB Curves node (Color -> RGB Curves) and plug the “image” output socket of each Mix node into one. (I’ve collapsed the lower two Mix and RGB Curves nodes in the image to save space.)


Then, to combine the whole image back together, add another Mix node, this time set to “add” mode, and plug the “image” output sockets of two of the RGB Curves nodes into each of the “image” input sockets of  the Mix node. Finally add another Mix node (set to “add”) and plug the “image” output of the previous mix node into the top “image” input of the sencond Mix node and the “image” ouptut of the remaining RGB Curves node into the bottom “image” input socket. Of course, then plug the “image” output of the final node into the “image” input of the Composite node. Here is the final node setup (click for larger view):

Dynamic-Lighting-in-the-Compositor_Fig-05Now, by adjusting the “C” channel of the RGB Curves nodes you can change the intensity of each lamp and by adjusting the “R”, “G” and “B” channels you can change the color. Here’s a comparison of the render ouput and the composited output with adjustments to the RGB Curves nodes:

Dynamic-Lighting-in-the-Compositor_Fig-06Notes on Using More Lamps and Cycles

So this works fine and dandy for three lamps, as there are three channels in an RGB image. But what if you want to use more lamps? Well, you can by using Light Groups.

Say, for example, you wanted to do this with five lamps. You can select three of those lamps (colors set to pure red, green and blue) and hit ctrl+g to create a group. Then name it something clever like “Group A”. Then, select the remaining two lamps (color set to pure red and green) and do the same thing and name that group something equally clever like “Group B”. Now go to the Render panel and under Layers, first add a new Render layer (hit the plus sign next to the Render Layer list). Again, clever name. Make sure to select “color” under the Passes for the new Render Layer.

A bit further down on the pane you will see “Light:” and a box. Click the box and up pop your Light Groups. Select one for one render layer and the other for the other render layer. This causes each render layer to only be influenced by the lights in the group assigned. (Note: it doesn’t matter to any of this which Scene Layer your lamps or any other object in the scene are located, provided they’re active for rendering, of course.)


Now you can just copy the node tree setup for three lamps and change the render layer on the the drop down box of the second Render Layers node to the new layer. Since we only have two more lamps you can delete everything coming ot of the “B” socket of the Separate RGB node. Finally just mix these two trees together at the end with another Mix node set to “add”. And, baby, you got a stew.

Dynamic-Lighting-in-the-Compositor_Fig-08So, what about Cycles? Well, you can apply this technique in Cycles as well. Everything is exactly the same except when using  the Render Passes. Instead of a single color pass option, Cycles allows you to choose to deliver Direct, Indirect and Color passes for Diffuse, Glossy and Transmission rays. Just select color for each.


Then in the compositor, use Mix nodes to add the three output sockets these passes create and continue from there with the same node setup described above.

Dynamic-Lighting-in-the-Compositor_Fig-10I have to note, I’ve only experimented briefly using this technique with Cycles. Some issues may arise, particularly with coloring reflections. Also, any environment lighting will obvioulsy change the whole dynamic. The example I used here has the world color set to absolute black. I’m sure there are ways to deal with these issues, however. If you come up with or know of any tips that can make this effective in Cycles, feel free to comment. I may explore this further in a later tutorial.

Anyway, that’s all for now. Hope you learned something and that I wasn’t too long-winded. Until next time…

Leave a Reply

Your email address will not be published. Required fields are marked *