How can I get a Depth of field render pass?
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.


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

In the Node Editor:


Add | Vector | Map Value (or Shift+A,V,M) and connect the Z-pass.
Right click on the Offset value and select Add Single Driver.


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.



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.