How to Use Blender Defocus Node for Depth of Field
Using the Defocus node in Blender's Compositor allows you to apply realistic depth of field (DoF) effects during post-processing instead of calculating it in-camera. This guide covers how to enable the required depth pass, connect the Defocus node in the Compositor workspace, and fine-tune blur and bokeh settings to achieve clean, cinematic background and foreground separation without increasing 3D render times.
Step 1: Enable the Z (Depth) Pass
Before rendering, you must tell Blender to output depth information alongside the image:
- Open the View Layer Properties tab (the icon resembling stacked layers in the Properties panel).
- Expand the Passes section and go to Data.
- Check the box for Z (also known as the Depth pass).
- Render your image or animation frame (press F12).
Step 2: Set Up the Compositor
- Switch to the Compositing workspace at the top of the Blender interface.
- Check the Use Nodes checkbox at the top toolbar.
- You will see a Render Layers node connected to a Composite node.
- Press Shift + A, search for Defocus, and place the node between the Render Layers and Composite nodes.
- Press Shift + A, search for Viewer, and connect the Defocus node's Image output to the Viewer node to see real-time updates in the background (press V to zoom out the backdrop, Alt + V to zoom in).
Step 3: Connect the Node Inputs
Link the outputs from the Render Layers node to the Defocus node:
- Connect Render Layers (Image) to Defocus (Image).
- Connect Render Layers (Z) to Defocus (Z).
- Connect Defocus (Image) to both the Composite and Viewer nodes.
Step 4: Configure Node Parameters
Adjust the following key settings inside the Defocus node:
- Use Z-Buffer: Check this option to instruct the node to use the depth pass connected to the Z input.
- Z-Scale: Leave this at
0.000to automatically read the camera's focus distance set in the 3D scene. If you uncheck "Use Z-Buffer", you can manually control the focal distance using this value. - f-Stop: Controls the depth of field aperture size. Lower values (e.g., 1.4 to 2.8) produce a shallow depth of field with heavy blur, while higher values (e.g., 8.0 to 16.0) keep more of the scene sharp.
- Max Blur: Limits the maximum pixel radius of the blur. Setting this too high can cause artifacting, while setting a cap (e.g., 16 to 32 pixels) maintains smooth performance and avoids fringing.
- Threshold: Helps eliminate aliasing artifacts along high-contrast depth edges. Adjust this slightly if you see sharp outlines around blurred objects.
- Bokeh Type: Choose the shape of out-of-focus highlights (e.g., Octagonal, Hexagonal, Circular) to match real-world camera lens characteristics.
Step 5: Adjust Focus Distance
To change what is in focus:
- Select your Camera in the 3D viewport or Outliner.
- Go to the Camera Properties tab.
- Expand Depth of Field and set your Focus Object or adjust the Focus Distance metric manually.
- The Defocus node in the Compositor will automatically update the in-focus area according to these camera settings.