Without a doubt, compositing is currently one of the hot topics in 3D computer graphics creation, particularly because it enables efficient management and creative control of complex scenes and images. A typical 3D graphic can consist of many individual layers, each having a special filter or effect applied and combined into the final result. By pre-rendering such layers an artist can work much faster on fine-tuning the final lresult of an image.

 

In Blender, the Compositor is tightly integrated and aligned with the rendering pipeline. For this reason it is part of the Blender Scene, meaning there's only one "Composite" possible per Scene (but each file can have unlimited Scenes).

Compositing can also be used 'stand-alone; with only images read from disk as input, allowing you to render the Composite without having a 3D rendering invoked.

 

Read here about general implementation notes for Nodes

Examples

Shot from Elephants Dream, comped by Matt Ebb (Comp breakdown: QuickTime H.264 / XviD AVI
Node setup
Shot from Elephants Dream, comped by Matt Ebb (Comp breakdown: QuickTime H.264 / XviD AVI
Node setup
Rose by 'teyrak', with node setup
Casualties by Sander 'Roger' Wit. Rendered in YafRay, Z-blur in Blender compositor.

Getting started

If using Blender Nodes for the first time, check the general editing information on the Nodes UI page.

 

First setup a good workspace:

- split the Blender Screen a couple of times (mouse over edge, RMB).

- use the leftmost button in the headers to assign one window a Node Editor, and another window a UV/Image Editor

 

Then enable Compositing:

- In the Node Editor header, press the small icon with the face, the Scene icon. This makes the Node Editor display Composite nodes, and will add a default setup with three Nodes.

- Also press "Use Nodes" in the Node Editor header, this will enable live updates while editing

- Finally, set the "Do Composite" button in the Scene Context buttons. This tells the render pipeline to include compositing.

 

Now if you press "Render" or F12, you can see something resembling the screenshot above.

Examples

Agua, by zanQdo ( 2.25 MB AVI )
Node setup
Hell background by Nathan Vegdahl ( 500KB MPEG4 / .blend file )

Compositing

To use Compositing Nodes, you can use two different Output Nodes. The "Composite Node" defines the output for the rendering pipeline, the "Viewer Node" allows results to be displayed in the UV/Image Editor. The latter is facilitated by a built-in (generated) Image with the name "Compositor". To view this image to it with the menu in the header.

 

Only one Viewer and one Composite Node is active, which is indicated with a red sphere icon in the Node header. Clicking on Viewer Nodes makes them active. The active Composite Node is always the first, typically you only use one anyway.

 

The UV/Image Editor also has three additional options in its header to view Images with or without Alpha, or to view the Alpha or Z itself. Holding LMB in the Image display allows you to sample the values.

 

Internally, the Compositor uses float buffers only (4 x 32 bits), regular 24 or 32 bits images used as input get converted to float first before compositing. Images are saved in the format as defined in the "Format" panel in the Scene context buttons. Only OpenEXR and Radiance images can store the full floating point range. DPX and Cineon formats will map the colors to 16 or 10 bits per component, clamped to a 0.0-1.0 range. All other formats save as regular 24 or 32 bits.

Sockets and links

 

Input and output sockets are available in three types:

- RGBA (4 channels), yellow. When images or operations only have or use RGB, the Alpha channel is set to 1.0 by default.

- Vector (3 channels), blue.

- Value (1 channel), grey.

 

A socket can store both an Image buffer or just a fixed value (for example one value or an RGBA color). Blender's compositor allows the use of values or buffers as inputs transparently, and internally sorts out what will happen in a Node execution as follows:

- when all inputs are values, the operation occurs on the values only

- when all inputs are buffers, the operation occurs on the buffers

- when one input is an image, and another a value, the operation tries to define an image size (typically the first/top Image socket) and uses this image to operate on, with the value.

 

Most Color operations or Filter nodes have a "Fac" input, defining how much of an effect the operation has. By default the first/top Image (or color) input is always passed on, and the "Fac" defines how much the operation with other input(s) contributes to the end result, with 0.0 defined as "no operation".

 

Any "Fac" input can be used in three ways:

- As a constant, with a button for manual input

- Linked from another Node, passing on a value (like from a Time Node).

- Or as a buffer, when linked to an output having a buffer, to define a per-pixel influence of the operation.

 

The compositor also allows you to link different socket types, in which case a default conversion will occur as follows:

- value from vector: the average (X+Y+Z)/3.0

- value from color: the BW average (0.35*R + 0.45*G + 0.2*B)

- vector or color from value: copies value to each channel

- vector from color: copies RGB to XYZ

- color from vector: copies XYZ to RGB and sets A to 1.0

 

Almost all Node operations support this conversion, with some exceptions, such as the Vector-Blur node, which really requires the proper inputs.

 

Image size

 

The compositor can mix images with any size, and will only perform operations on pixels where images have an overlap. When Nodes receive inputs with differently sized Images, these rules apply:

- the first/top Image input socket defines the output size.

- the composite is centered by default, unless a translation has been assigned to a buffer with the "Translate Node".

 

So each Node in a composite can operate on different sized images, as defined by its inputs. Only the Composite Output node has a fixed size, as defined by the Scene buttons (Format Panel). The Viewer node always shows the size from its input, but when not linked (or linked to a value) it shows a small 320x256 pixel image.

 

Note: when using the Preview option (see below), it is important a fixed size is known in advance, to be able to define the preview cut-out. In this case the render output size is used by default.

 

(NB: currently no scaling or cropping node exists yet).

Executing a composite

On each Node editing event (like dragging links or changing Node settings) the composite tree is called to execute again. It then goes over the following stages:

 

- Initializing the stack

Each used input and output socket will get a stack entry assigned, this happens in such a way that linked inputs will use the same stack entry as the output it is linked to.

To enable faster editing, the resulting buffers from a previous composite were stored in the output sockets, and will get copied to this stack as well.

(NB: this does not happen for nodes inside of a Group, only the Group Node itself will store outputs).

 

- Dependency check

The Blender Node system internally already sorts Nodes based on linked dependencies. While editing, the nodes that were changed received a tag. This enables to 'flush' changes easily through the node tree and detect which nodes require a recalculation, and in which order.

 

- Threading setup

A composite happens by default in a separate thread, and when "Threads render" was chosen it accepts to use multiple threads as well (only 2 threads implemented now, but more threads is easy to add).

 

- Threaded composite processor

This is a loop continuously polling for available Nodes to execute. Based on the amount of available threads it runs the execute callback for Nodes. Nodes get each executed in its entirety, which can be scanline based or (for blur) based on specific filter masks. Only when a node is fully finished, the thread is freed and the main loop is allowed to execute another node.

Group Nodes are treated as a single Node, thus allowing Groups to be executed in parallel too.

 

- Cleanup

The (finished) output buffers get copied from the stack to the Node's output sockets. The stack then gets freed.

 

For rendering, the Render Result nodes, the Time Node and optionally the Image Node (when animated) get tagged as "changed" too, ensuring the dependency system to execute the composite correctly. On a background render, the compositor skips making previews in Nodes and skips executing the Preview Nodes themselves.

 

Memory usage

While a composite executes, it doesn't free image buffers as created fror the Output sockets. Only when executing a Group Node, the internally used buffers are all freed in the end.

This feature allows only recalculating the changes while editing, however memory consumption can quickly grow into 100s of MB.

 

You can disable this option with the "Free Unused" option in the header, this will immediately free all output buffers when not needed anymore (with as exception the Image, Render Layer and Viewer/Composite nodes).

 

You can quickly estimate memory requirements by adding up the amount of used outputs, and multiply that with the size of an Image. Note that Blender uses float buffers, so a single HD frame (1920x1080) will be 32 MB (2 megapixel x 4 colors x 4 bytes).

 

The render pipeline will always free up all composite buffers before a render starts, and will free up all 3d render data before a composite starts.

 

Two ideas exist to optimize memory usage further, which is still in development.

- Execute a composite tile-based, so only a relative small amount of memory is required. (Is quite hard to do for large filters though)

- Using a smart image disk-cache, to save buffers when not needed.

Editing hints

Using a Preview Panel for fast compositing.

Executing a full composite can take a while, especially for larger images. Here's some hints to make working more interactive.

 

- ESC

Pressing Escape will stop the composite, note that it will always end the currently being composited Node.

 

- Disable "Use Nodes".

This button, in the Composite Editor header, will disable execution on editing Nodes. A Composite then is still executed on a Render.

 

- Set a Preview Panel

In the UV/Image editor, press SHIFT+P to add a preview panel. This panel can be dragged around or scaled to display the portion of interest.

A composite then only happens on this part, also only allocating memory for this. Zooming in or out works too.

Because this can only work with an image output size in advance, it only works when the render output size is set correctly (see Image Size above).

 

- Use the "Save Buffers" option

When compositing multiple render-layers, you can save the layers while rendering with this option (in Scene buttons, "Output" Panel).

This option writes a temporal OpenEXR file which can be read later on, like after restarting Blender, with the hotkey R. Blender then reads back the buffer for the selected "Render Result" nodes and invokes a composite.

Nodes

Viewer

The Viewer Node can be used anywhere in a network, and offers a preview render at the linked location. Only the active Viewer is displayed in the UV/Image editor (browse Image named "Compositor"), this has a red sphere icon to indicate that.

Composite

The Composite Node defines the output for Rendering. Only one can be active at a time. The Image size of a Composite is defined by the Scene settings for rendering.

 

Render Result

This Node gives access to the results of a rendering. It can indicate the result for any render-layer as defined in the current Scene. You can also include RenderResult Nodes for other Scenes. On a render, it then also (fully) renders that Scene.

When you don't include any RenderResult Node in a Composite, a 3D rendering won't happen, but compositing still gets executed (also on a F12 render).

The little "scene" icon on the bottom/right of the Node allows to only re-render that specific layer.

Image

Images are always used as float buffers, and get converted if needed.

The bottom/right icon button allows to indicate an animated sequence of images. On rendering animations, this Node then will reload the Image on each frame step. Check the tooltips for these buttons for more info.

Texture

The Texture Node allows to use Blender textures, to make effects based on normalized pixel coordinates (ranging from -1 to 1). Use it to create blend ranges for example.

 

Group

When you group Nodes (CTRL+G), this Group becomes a new Node Tree in the Blender Library, which then can be linked by a "Group Node" to be re-used anywhere you want to. More about Groups here.

 

RGB Curves

This Node shows a new UI widget, the "Curves". You can use it to adjust overall brightness or the individual RGB channels. Note that by default this Node clamps values between 0 and 1.. More about Curves widget.

Mix

The Mix Node always passes on the first (top) Image input, and uses the "Fac" value to define the amount of operation with the second input. With "Fac" set to zero, no operation happens.

Hue Saturation

A Hue and saturation value are included as a preset, the "Fac" value defines the amount of the effect. Note that "Fac" can be an image too.

Alpha Over

The first (top) image input is the background, the second input gets alpha-overed. Note that "Fac" can be an image too.

Z Combine

Use this Node to combine 2 images based on Z values. It then only shows the closest Z. Currently this happens without filtering or anti-aliasing still.

 

Normal

This UI widget allows to input a Normal, or to perform a dot product. You can use it for quick re-lighting of a RenderLayer, when it has a Normal pass.

Vector Curves

Although this Node operates similar to the RGB Curves Node, it is initialized properly for 1:1 mapping and clamping values between -1 and 1. More about Curves widget.

Map value

This Node can be used to clamp/translate/scale a value.

 

Filter

This Node offers a range of 3x3 pixel filter kernels. The "Fac" input can be an Image too.

Blur

The Blur Node has a variable filter kernel size, offering a wide range of filter settings. Use the "Gamma" option to enable a gamma corrected filtering (this gives brighter values an advance over darker values). The default Blur options are calculated in two passes, with filtering in X and Y direction, so it performs relatively fast.

The "Bokeh" option uses a 'real' filter image, meaning it averages for each pixel in a result all surrounding pixels from the input. Now only a circular bokeh is implemented; try a "flat" filter for best results. On the todo is more filter shapes, like pentagon or hexagon or star shaped.

Vector Blur

This is the new motion blur option in Blender, in more detail described on this page.

 

Color Ramp

This Node converts a value to a RGBA using a Ramp. The ramp editing works like for the regular ramps in the Blender UI (CTRL+click to add new key positions).

RGB to BW

A simple color to value convertor

Separate RGBA

Separate HSVA

These Nodes separate an Image into 4 components.

Set Alpha

Use this Node to set the Alpha of in Image.

Translate

Any composite can happen with any offset, which can be set using this Node.

 

Value

This Node generates a Value

RGB

This Node generates a Color

Time

The time node generates a value, based on indicated start/end frame, and a curve mapping this to (default) a range of 0 to 1.