In a tutorial published a couple of weeks ago, I showed how to enable Depth of Field in Blender, both in the 3D Viewport and during rendering, to keep one object in focus while blurring the rest of the scene....



Video Transcript

Hello everyone! In a tutorial published a couple of weeks ago, I showed how to enable Depth of Field in Blender, both in the 3D Viewport and during rendering, to keep one object in focus while blurring the rest of the scene.

The blur effect produced by Depth of Field allows for interesting results. However, it doesn’t focus solely on the selected object, because all other elements at the same distance from the virtual camera will also remain in focus.

On screen, I am showing an animation where the White Queen has been set as the focus object. As you can see, other pieces and parts of the chessboard are also in focus during the animation. Additionally, the White Queen is not always perfectly in focus because it is quite tall, and depending on the camera angles, some parts may fall at different distances from the focus point.

Now I am showing you the render we will achieve by the end of this tutorial. As you can see, the pieces located at different distances from the White Queen are blurred using the Depth of Field effect. This isn’t a simple uniform blur applied across all areas; instead, all other objects are blurred except for the White Queen, which is perfectly in focus.

As with many of my other video tutorials, the PDF version of this tutorial is available for free download via the link in the description. This is also a great time to subscribe to the channel and turn on notifications so you won’t miss future tutorials!

Let’s see how to achieve the result shown in the second animation. First, we need to enable Depth of Field for the Camera object and set the focus object, which in our case is the White Queen.

At this point, however, we disable the Depth of Field effect of the virtual camera.

Now, when starting the rendering, we will get the entire image in focus. We have disabled the camera's Depth of Field because, in this case, we don’t want to blur the scene during rendering. Instead, we only want to extract the distance information of the White Queen to apply the Defocus effect during Compositing.

Before proceeding, let's enable the Z Render Pass in the View Layers panel to obtain this information during the Compositing phase.

To isolate the White Queen's mask from the rest of the rendering in Compositing, first assign a Pass Index value other than 0 to this object, for example, 1, in the Object Data Properties tab under the Relations section.

Only the White Queen should have this Pass Index value. Otherwise, other objects would be included in the Compositing mask.

To use this information in Compositing, we also need to enable the Object Index Render Pass in the View Layer Properties panel before starting the rendering.

Let's start a render with this information and move on to Compositing to set up the required node scheme for the final result.

Let's pass the Object Index information to an ID Mask node with the Index set to 1 to isolate the mask of the White Queen.

Let's multiply this mask with the original image using a Color Mix node in Multiply mode, with Factor set to 1 and Clamp enabled, to obtain a render of the White Queen alone on a black background.

To overlay this image onto the original render, we need to make all the black areas of the image transparent. For this purpose, a Set Alpha node works well. However, there’s a problem: using Alpha would make the White Queen semi-transparent because, in the final image, it inherits its colors from the render.

Fortunately, we already have a white mask on a black background for the White Queen, thanks to the output of the ID Mask node! Connect the output of the Multiply node to the Image input of the Set Alpha node. Then, connect the Alpha output of the ID Mask node to the Alpha input of the Set Alpha node.

Now, we have the render of the White Queen on a transparent background, ready to be overlaid onto the blurred scene using an Alpha Over node.

Let's add an Alpha Over node to the setup, setting the Factor to 1. Connect the render output from Render Layers to the first Image input of the Alpha Over node. Then, connect the output image from the Set Alpha node to the second Image input of the Alpha Over node.

Right now, all objects are perfectly in focus because the initial render was not blurred.

Let's add a Defocus node between Render Layers and Alpha Over, enabling the Z Buffer and connecting the Depth output from Render Layers to the Z input of the Defocus node.

Lower the F-Stop value enough to introduce the desired Depth of Field blur effect.

At this point, the White Queen is fully in focus, along with other objects at the correct distance from the camera. However, I’d like to draw your attention to something noticeable when the F-Stop value is set very low.

In fact, the result implemented by our node setup differs from what can be achieved using the Depth of Field of the Camera object. Since the White Queen is a very tall object, not all of its parts would remain in focus when using a low F-Stop value.

With our node setup, we are isolating the in focus render of the White Queen and applying it to the blurred version of the original render.

We now need to add an additional blur to all other elements that are at the correct distance from the virtual camera, excluding, of course, the White Queen.

This can be easily achieved by further blurring the output from the Defocus node using a Blur node with appropriate blur values.

The Defocus node applies an initial blur based on the depth of field, making objects farther from the White Queen blurrier than others. Then, the Blur node adds an additional layer of blur to the entire image, affecting all remaining elements.

Finally, the render of the White Queen, perfectly in focus, is overlaid onto the blurred image, creating the final result.

That’s all for this tutorial! I hope you found it helpful. See you next time!

Search Tutorials

Enter a phrase or multiple comma-separated keywords to search.

This is a personal website and does not constitute a sales channel. The pages dedicated to 3D models document a selection of my work and do not contain offers, prices, purchasing procedures, or commercial links. I am not currently accepting requests for custom work, consulting, or other professional collaborations.


EXTENDED PRIVACY AND COOKIE USAGE POLICY