Update: I’ve rewritten this tutorial for Blender 2.6 at Blender Quicktips.
Here’s how to do depth of field in Blender. What’s depth of field, you ask? Go read the Wikipedia article for the details, but the layman’s summary is that it’s how you blur the out-of-focus parts of an image. (The blur is called bokeh, by the way.) The shallower the depth of field (or the lower the f-stop), the blurrier the out-of-focus parts get. I like it because it looks better and feels more professional, and it also focuses the viewer’s attention right where you want it. (But it’s not something you should use in every shot by default. Don’t leave artistic judgment behind. :))
The good news is that Blender can do depth of field. The bad news is that it’s only possible via postprocessing (using compositing nodes), which isn’t perfect. But it mostly works.
I’m visual—show me what it looks like
Here’s the sample scene before adding depth of field:
And here it is afterward:
As you can see, both the foreground and the background are now blurry, leaving only the center thingie in focus.
Overview (Microwave Edition)
All you have to do is give the camera a focus point (Dof Dist or Dof Ob), add a Defocus node, and render with Do Composite.
The Gritty Details, Please (With Pictures!)
1. Set up the scene. Here we’ve got a pretty basic setup with cubes (using some array modifiers and a path to spiral them out), lights, a thingie in the middle (made by extruding a cube), and a camera.
2. Select the camera and go to the edit buttons. Click on the Limits button (under “Show:” in the upper right). You’ll now see a line pointing out from the camera, with a yellow line through the camera itself to show you where the camera’s focus will be.
3. Now to set the focus. You can either give the camera a set distance (Dof Dist) or an object to focus on (Dof Ob, which we set here to MainCube, but you could just as easily use an empty to have finer control over where the camera focuses).
4. Open up the node editor, click on the face (the middle of those three buttons), then click on Use Nodes.
5. Add a Defocus node (Add->Filter->Defocus). And ignore the fact that there’s nothing in the RenderLayer on the left — I’m pretty sure it’s a bug in Blender 2.49.
6. Drag the RenderLayer node’s Z output to the Defocus node’s Z input, the RenderLayer node’s image output to the Defocus node’s image input, and the Defocus node’s image output to the Composite node’s input. (Just follow the diagram. :))
7. Uncheck No zbuffer. This way it’ll look at the depth data from the scene, which is exactly what we want. Also set the fStop down to something low (lower is blurrier) — try 8 or 12 for starters. Note: when you do the final render, deselect the Preview button here.
8. Select the Do Composite button. (If you don’t, it won’t use the nodes we just set up and you’ll get an ordinary render.)
9. Render. You’ll notice the sharp artifacts on the far left and center bottom. To be honest, I don’t know how to get rid of these. My guess is that they appear because Blender’s depth-of-field isn’t actual DOF but is just a postprocessing illusion. If any of you know how to fix this, let me know.
This tutorial was made using Blender 2.49.