1 The idea
A Gaussian blur turns bright points into soft fuzz, but a real lens turns out-of-focus bright points into crisp-edged discs (bokeh), especially strong lights like sparks.
Defocus needs linear values that aren’t clipped at 1, or the bokeh discs come out too faint. Click both nodes to compare.
2 Hands-on in the mini compositor
3 Deep dive
What a lens does to one point of light
When a point is out of focus, its light does not land on one spot of the sensor. It spreads into a disc shaped like the aperture, called the circle of confusion. The disc is evenly bright inside and has a clear edge. That is bokeh.
A Gaussian blur behaves differently: brightest in the middle, fading out with no edge, so a light turns into haze. On flat areas the two look alike. The moment there are hard lights, like sparks, the difference is obvious.
| Tool | Spread shape | Varies with depth | Use it for |
|---|---|---|---|
| Blur | Bell, no edge | No | Soft mattes, haze, diffusion |
| Defocus | Flat disc, clear edge | No (one size) | An element at one distance |
| ZDefocus | Disc, bladed, or your own image | Yes, from depth | CG or plates with depth |
| Convolve | Any image as the kernel | No | Real lens bokeh you photographed |
Why it needs linear values that are not clipped
Defocus creates no new light; it only shares out the light that is there. Example: a one-pixel spark at 62, spread into a 14 px disc (about 154 pixels), leaves about 0.40 in each pixel of the disc. It still reads as a bright disc over the desert plate.
If the same spark was clipped to 1 first, say it came from a JPEG or went through a Clamp, each pixel gets only about 0.0065, nearly invisible. 62 times less light. That is why defocus belongs in scene-linear float, with the values above 1 still there.
- 1Linear EXR, values above 1 intact
- 2Defocus each layer
- 3Merge back
- 4Grain last
In our lab, Defocus averages 64 samples inside a disc. Same idea as Nuke’s Defocus, which doesn’t read depth either; for blur that follows depth, use ZDefocus
Where the disc size comes from, and which depth you have
Depth of field gets shallower with a lower f-number (wider aperture), a longer lens, or a closer focus. There is more depth of field behind the focus point than in front. Too shallow and the scene reads as a miniature. Take the lens and camera values from the matchmove instead of guessing.
Depth comes in two main kinds. Nuke’s ScanlineRender gives 1/Z (near = high, far → 0). Most renderers give real distance in scene units (near = small, far = large). Tell ZDefocus the wrong kind and you get almost no blur, or blur in the wrong places.
| Depth type | Near | Far | ZDefocus math |
|---|---|---|---|
| 1/Z (ScanlineRender) | high | towards 0 | far = 0 |
| Distance (renderer) | small | large | depth |
Always sample the nearest and farthest thing first; you’ll know at once which kind it is
The edge between foreground and background
A CG robot stands sharp in front of a defocused desert plate. Run one ZDefocus over the merged image and the robot’s colours get smeared into the blurred background, leaving a ghost outline. A flat 2D image has no idea what is behind the robot.
The fix: split into depth layers, defocus each one with the focus linked to one master value, and merge back to front, or use deep if you have it. Know that even blur(FG) over blur(BG) is not physically exact where both layers are soft. It is an approximation people use because it is good enough in most shots.
Depth on an anti-aliased edge is an average of near and far, so it points at a distance where nothing exists. That shows up as a sharp outline inside something that should be soft. Extend the near depth a little past the edge, and do it exactly once.
- 1Split FG / BG
- 2Edge-extend depth once
- 3ZDefocus per layer
- 4Merge back to front
4 In real work
In Nuke
- Defocus: one disc size for the whole image. Good for an element at one distance, like a burst of sparks all about the same distance from camera.
- ZDefocus: set math to match the depth (1/Z = far = 0, real distance = depth), then switch output to focal plane setup to see the in-focus band.
- ZDefocus filter type: disc, bladed or image. For a specific bokeh shape feed your own kernel image, or use Convolve on an element at one distance.
- Turn depth of field off in the render and do it in comp, so you keep control and never blur twice.
- Defocus the degrained plate, then add grain once at the end of the comp (why grain goes last: O5).
Common mistakes → the fix
- ✗ Using Blur for out-of-focus lights✓ Use Defocus or ZDefocus. Lights must become discs with an edge, not haze.
- ✗ Defocusing an element already clipped at 1 (a JPEG, or after a Clamp)✓ Use a float EXR with the values above 1 intact. If all you have is clipped, push the hot cores back up before the defocus.
- ✗ ZDefocus does almost nothing because math doesn’t match the depth✓ Sample near and far first, then pick far = 0 for 1/Z or depth for real distance.
- ✗ Grading the depth channel so it “looks nice”✓ Depth is distance, not a picture. Never adjust it by eye, or every defocus calculation goes wrong.
- ✗ One ZDefocus over the already-merged robot and plate✓ Split by depth, defocus separately, merge back to front.
Before you send the shot
- Out-of-focus lights are discs with an edge, not haze
- Defocus runs in linear float with values above 1 intact
- You know whether depth is 1/Z or distance, and math matches
- No sharp outlines or ghost edges around soft foreground objects
- Depth of field fits the lens and doesn’t read as a miniature
- Defocused areas still carry grain as sharp as the rest
5 Check yourself
Why must defocus happen before clipping at 1?
🔒 Answer the question above and this card opens
1. You feed ScanlineRender depth into a ZDefocus set to math = depth and see almost no blur. Most likely cause?
2. A sharp robot stands in front of a defocused desert. Why defocus the desert separately from the robot?
Where the numbers come from: Computed in your browser. Saturation, Multiply, Clamp, Invert, Keymix, Copy and Grade match Nuke 17.0v2 (checked). Blur, Defocus, Glow, Sharpen, ChromaticAberration, Vignette, LensDistort, Grain, Erode, Toe, the Keyer and Despill are teaching versions, not identical to Nuke’s nodes. Transform here is also a teaching version: bilinear filtering, no concatenation, cropped at the frame edge. Images are our own Blender renders (the green screen is fully code-built; the desert scene uses Gaea 2.3 hills, a Poly Haven CC0 HDRI sky, Poly Haven CC0 rocks and grass, Quixel sand and cliff textures and a Mixamo rig for the robot, with Quixel and Mixamo used in the renders only).