From BlenderWiki

Jump to: navigation, search

We can easily use Blender's compositing nodes to blur the background of our scene. The concept is to take information about our scene, specifically how far away objects are from the camera, and route that information to a blur node that only blurs objects that are beyond a certain distance from the camera.

You will hopefully recall that the RenderLayer node, as well as an Image node with an OpenEXR format picture loaded, puts out a Z depth map. This map specifies how far each image pixel is from the camera. The vector Map Value node is the key here. Ultimately we want to route our Z information into map node that produces a scale from 0.00 to 1.00; the more an object is in the background, the higher its value. If you were to look at this as a picture, you would see that an object in the background gets grayer (the farther back it is). We combine that with a blur factor to blur our original image.

[edit] Blurring the Background of a Scene

To blur the background, simply set up the compositing node map shown below:

Background Blur Node Map

This node map shows you the degree of blurriness as a black and white (BW) image in the viewer, and the composite effect on the image in the composite output node. The RenderLayer, which is showing all six monkeys, puts out the image to a blur node. The Z map is routed to a Map Value node, which feeds the Size socket of the Blur and a ColorRamp. The ColorRamp enables you to see the z values in the viewer, and can be deleted along with the viewer.

In the Map Value node, use the Offset to specify that all objects closer than x (in this case, 10) blender units from the camera will get black and thus will not be blurred (recall that black is zero, and zero times any blur is zero). Everything else is therefore the background. Change the offset to move the focal plane. From there (10 units away) back to infinity, the Size value says how fast the background objects will fade away and thus be blurred.

[edit] Controlling the Amount of Blur

To calculate Size, subtract the Z-value of the object in your focal plane from the Z-value of the farthest object. This result is the depth of your blurring. Invert this number (divide 1 by X, or 1/x) to yield the Size. The farthest object away will get the full blur effect. Objects in between will get some percentage blur, depending on how far back they go.

The Blur node X & Y offsets say in effect what your f-stop is; namely, how much the most blurry background object is. The sampling filter says how fast they fall off, and which one you choose is a personal preference based on the dramatic impact you want to achieve, much like choosing between lens manufacturers. The Cubic sampling filter may be the most realistic, the Mitch sampling filter gives a nice smooth falloff while preserving crisp highlights, and the flat is dramatic and thus suitable for commercials.

[edit] Shutter Speed Effect

While X and Y are normally set equal to each other, you can achieve a shutter speed effect by setting Y to half of X (for capturing horizontal motion like a runner) or the inverse for a jumper (vertical motion). This effect mimics what happens when a photographer tracks the runner (in focus) as they run. The background is not only out of focus, but smeared as the shutter was open while the camera was moved laterally. The example above has the normal blur set to 10, but X is doubled to achieve the shutter speed effect. Obviously, to mimic a faster runner or slower shutter speed, increase the proportion of X to Y.

Good enough?
Most animations and stage productions have the actors up front against a background. So, the node setup that you have so far is good enough for most animations.

[edit] Blurring a Photograph's Background

When working with still images (e.g. pictures in JPEG or PNG formats), you can still blur the background using Blender. The original photo taken (below, left) shows all objects in focus, even the distracting ones in the background. Using Blender to create a mask allows you to achive the special effect shown next to it.

Original
Using a Blur Mask

Use Blender's mesh modeling tools to construct a mask and a backdrop. In the example below, the mask was constructed using a cyclic bezier curve, and the backdrop was a subdivided plane bulged by using the "To Sphere" manipulator at 50%. In this way, the Blender Scene is used to supply a set of Z depth values which, when used as the Blur factor on the photograph, yields exceptional results. A partial screen capture of Blender in action is shown below. In this picture, you can see a node map very similar to the previous one, except that the RenderLayer input supplies the Z values and an Image input node supplies the picture. The black and white image in the UV/Image editor window shows you the Z values as shades of gray. The mask is flat and exactly 10 units from the camera; hence the Offset value. The bulge is just behind it and curves backward and away from the camera, giving a nice smooth falloff.

Blender windows to Construct and Use a Mask and Backdrop

Traditionally, the edges are problematic since the mask invariably has some background pixels. Using a flat backdrop provides uniform blurring of the background, but some of the blurring bleeds into the edges of the mask, resulting in a very blurry edge. The bulged plane allows some blending of the pixels at the edge of the mask, and more as the background expands outward. The mask's edge pixels are smoothed out and blurred into the background to make them unnoticeable. The increasing blurriness as you move out of center of frame is also more realistic and heightens the focus and impact of the crisp center.







Redirects to fix

  • Manual/Compositing Nodes Input → Doc:Manual/Composite Nodes/Types/Input
  • Manual/Compositing Nodes Vector → Doc:Manual/Composite Nodes/Types/Vector
  • Manual/Curves → Doc:Manual/Modelling/Curves
  • Manual/Depth Of Field → Doc:Tutorials/Composite Nodes/Depth Of Field
  • Manual/Vector Blur → Doc:Tutorials/Composite Nodes/Vector Blur