Home · Lab · Camera & Lens Lab

L3 Depth of field and bokeh

How big a blur disc gets is computable

Camera & Lens Lab · ~8 min · Free

1 The idea

A light that isn’t at the focus distance becomes a disc (the circle of confusion). Its size depends on focal length (f), f-stop (N), focus distance (S) and the light’s distance (D). Long lens, wide aperture, close focus = lots of blur.

In comp, defocus has to grow the blur like the real lens, not blur everything equally. Below are real Blender renders to compare, and bokeh traced through real lens prescriptions: a bright rim behind focus, a soft edge in front of it, and cat’s-eyes towards the frame edge.

CoC = f² / (N·(S − f)) · |D − S| / D

2 Hands-on

Focus on the robot (9 m), use a long lens and open the aperture

SkyVFX Lab · L3interactive · 1001

3 Deep dive

What makes the blur disc grow

CoC = f²/(N(S−f))·|D−S|/D. The first part depends on the lens and focus; the second on how far the point is from the focus distance. As D gets very large the second part approaches 1, so a far background has a ceiling: f²/(N(S−f)).

The near side has no ceiling: as D approaches the camera, |D−S|/D keeps growing. Things in front of the focus distance fall out of focus faster than things behind it.

ChangeFar background disc
Double the f-number (f/2.8 → f/5.6)Halves
Double the focal (distant focus)About 4× bigger
Focus at half the distance (9 → 4.5 m)About 2× bigger

From mm on the sensor to pixels

CoC comes out in mm on the sensor. To pixels: px = CoC ÷ sensor width × image width. Example: 50 mm at f/2.8 focused at 9 m gives about 0.10 mm for a far background; on a 36 mm full-frame sensor at 1920 px wide that is a disc about 5 px across.

Acceptable sharpness uses CoC = sensor diagonal ÷ 1500 (full frame ≈ 0.029 mm), a convention rather than a rule. The hyperfocal distance is H ≈ f²/(N·c) + f; for 35 mm at f/8 on full frame that is about 5.3 m. Focus there and everything from about H/2 to infinity reads sharp.

Think in pixels before touching a node: know how many px the background should blur.

Depth-driven defocus in comp

Render the CG sharp with a depth pass and defocus in comp. Don’t turn on DOF in both the render and the comp, or it doubles. Always sample the near and far depth values first, and never grade depth to "look nice": the distances are the data the defocus needs.

Nuke’s ScanlineRender depth is 1/Z (near = white), while most CG renders deliver real distance. Set ZDefocus’s math to match; with the wrong setting you get little or misplaced defocus.

  1. 1Sharp render + depth
  2. 2Sample near/far
  3. 3ZDefocus (right math)
  4. 4Bokeh shape
  5. 5Grain after

Bokeh shape and restraint

The number of aperture blades makes bokeh polygonal; some lenses turn discs into tilted ovals near the frame edges; anamorphic lenses give vertical ovals. Look at the highlights in the plate and copy that shape.

Depth of field that’s shallower than real makes a scene look like a miniature. Use numbers from the real lens, and give in-focus CG a touch of softness to match the plate’s sharpness.

On set: note the focus distance and f-stop for every take. Cine lenses are usually marked in T-stops, which are close to the f-stop but always a slightly higher number.

4 In real work

In Nuke

  1. ZDefocus: pick the depth channel and set math to match the depth type (real distance = depth; Nuke’s 1/Z = far = 0)
  2. Use the focal point picker on the robot, then set size / maximum from the pixel count you worked out
  3. Shape: filter type bladed or image, and the aspect ratio for anamorphic
  4. Defocus = one uniform blur; Convolve = blur with a kernel image you supply
  5. CG edges: expand colour and depth beyond the alpha once, then copy the original alpha back before the defocus

Common mistakes → the fix

  • ✗ Using a masked Blur as a depth defocus✓ A masked Blur only mixes sharp and blurred; it isn’t a variable blur. Use ZDefocus
  • ✗ Grading the depth pass to make it readable✓ Keep it raw; adjust the viewer if you need to see it
  • ✗ DOF in the render plus ZDefocus on top✓ Pick one place, usually comp
  • ✗ Math set for the wrong depth type✓ Sample near/far values before choosing the math
  • ✗ Over-shallow focus because it looks "cinematic"✓ Work from the real lens, or it reads as a miniature

Before you send the shot

  • Focal, f-stop, focus distance and film back of the plate are known
  • Near/far depth values are sampled and ungraded
  • Blur disc size (px) is close to the plate’s
  • No double DOF
  • No hard lines or cut-offs on CG edges after defocus

5 Check yourself

One question to check yourself

Going from f/2.8 to f/5.6, what happens to the blur discs?

What you learned

🔒 Answer the question above and this card opens

More questions

1. The background is very far. You pull focus from 9 m to 4.5 m. What happens to the background discs?

2. Depth comes from ScanlineRender (1/Z) but ZDefocus math is set for real distance. Result?

Where the numbers come from: Lens maths is the standard thin-lens model (FOV, CoC, hyperfocal), using CoC = sensor diagonal ÷ 1500, a common convention rather than a fixed rule. Distortion uses the Brown–Conrady model (k1, k2). The real DOF images are Blender Cycles renders. The real lens bokeh strip below is ray-traced through a published Double-Gauss prescription (Smith, Modern Lens Design) by our own tracer, plus an in-house Tessar-type design for contrast (not a commercial lens). Behind focus = a light at infinity with focus at 1.5 m; in front = a light at 0.8 m with focus at 3 m; round iris; the traced f-stop nearest yours is shown (f/2, f/2.8, f/5.6), each at matched exposure.