24
$\begingroup$

How can one make a render pass with black and white data to display depth of field based on the Settings > Camera dof settings?
I want to blur or defocus in the compositor, similar to the way it is done with the Z pass but with a more accurate dof information that is based on a target, as opposed to distance away from the camera.

I tried to fiddle with the settings in a new Render layer, overwriting the material, but I have been unable to achieve a render pass effect that outputs something useful.

$\endgroup$
0

3 Answers 3

24
$\begingroup$

Defocus node

There's build-in support for focusing on objects using this node.

  • In the Properties editor under Object data (with the camera selected):
  • In the Depth of Field panel, add your Focus object.

Camera Object Data, Depth of Field settings

  • When setting up your Defocus node, enable Use Z-Buffer.

Defocus node setup

Cycles DoF

Cycles also has built-in support for DoF. Again in Depth of Field panel, set your Focus object and now increase the Size.

Aperture Size

Also called lens radius. If this is zero, all objects will appear in focus, while larger values will make objects farther than the focal distance appear out of focus.

Creating a black and white depth image

  1. In the Node Editor:
  1. In the Properties shelf (N) of the Driver section of the Graph Editor:
  • Change the variable type to Distance and set the two object to the camera and your target object.
  • Set the script expression to -var. Driver setup
  1. Back to the Node Editor:
  • Adjust the Size setting in the Map Value node.
  • Add | Converter | Math(Shift+A,N,M), set to Multiply and the values to -1 and the Map Value node.
  • Add | Color | Mix (Shift+A,C,M), set to Screen and connect the Map Value and Math nodes.

Node setup

$\endgroup$
2
  • $\begingroup$ Wow, sometimes, some things are so simple that I wouldn't believe it :) Thanks. I wasn't aware that z depth works in relationship to a target setup in the depth of field section, hence the reason I was looking for a way to achieve another zdepth map. But now, that I just did a simple test, one with defocus node, and one with dof settings adjusted in the camera, i see that the results are comparable. I was previously trying to use the normalize node in between the z depth output and the defocus node z input. $\endgroup$
    – dimitarsp
    Commented Jul 1, 2013 at 12:12
  • $\begingroup$ @Aldrik any idea why I still get a white image after using the "Creating a black and white depth image" technique? $\endgroup$ Commented Nov 17, 2015 at 22:39
13
$\begingroup$

This is because the Z-Depth pass outputs values greater than 1 for distance. You will need to use a Normalize node to convert those values to a 0-1 scale:

Normalize

$\endgroup$
9
  • $\begingroup$ I think it could be helpful to link this answer with this answer, right? $\endgroup$
    – p2or
    Commented Dec 14, 2015 at 13:34
  • $\begingroup$ Absolutely, I didn't see that one. Good find. $\endgroup$
    – J Sargent
    Commented Dec 14, 2015 at 14:01
  • $\begingroup$ This is the only thing thats missing in Aldriks answer. I'm not sure, should we ask the mod-team for merging this answer? $\endgroup$
    – p2or
    Commented Dec 14, 2015 at 14:17
  • $\begingroup$ Maybe, we can ask their opinion $\endgroup$
    – J Sargent
    Commented Dec 14, 2015 at 14:18
  • 1
    $\begingroup$ Use "Map Range" vector node if you are interested in preserving more depth information over an animation and also convert it to 0~1. For example if you do From 0~100 To 0~1 then you will lose everything further from camera than 100, but anything lower will be black to white in your zpass render. If you use Normalize in animation the relationship between 2 zpass renders will not be comparable. (One image's white might be really far, but other might be close) $\endgroup$
    – 5argon
    Commented Sep 5, 2017 at 15:01
10
$\begingroup$

You can also hijack the Mist Pass. This works for both BI and Cycles.

Enable it in Properties > Render Layers > Passes:

Cycles

And tweak the start/depth settings in Properties > World. If you are using BI, adjust the settings without enabling it, so that the combined pass is not affected:

enter image description here

Enable Mist in Camera Settings > Display to draw guides in the 3D view which make setting the values in Properties > World easier:

enter image description here

Result:

enter image description here

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .