ComfyUI Node

Nuke Defocus

Simulate depth of field with bokeh, not just blur

By sumitchatterjee13·Created about a year ago·Updated 9 days ago· 59
Nuke Defocus
  • image
  • depth_map
  • IMAGE
defocus1.0
aspect_ratio1.00
qualitymedium
methoddisk
mix1.00
focus_distance0.50

Plain blur smears. Depth of field looks like a camera. The difference is the shape and the intent - out-of-focus areas take on the shape of the lens aperture, and which areas are soft depends on what's in focus. NukeDefocus is the ComfyUI port of Nuke's Defocus node, and it's the one that produces bokeh that reads as photography rather than a filter. If you want the background of a generated scene to feel like it was shot at f/1.8, this is the tool.

How it works

Instead of one blur amount across the whole frame, the blur is shaped. You pick a method - gaussian, disk, or hexagon - and that shape becomes the kernel, so highlights spread into visible bokeh discs (or hexagons, like a six-blade lens) instead of washing out symmetrically. aspect_ratio stretches the shape to simulate an anamorphic lens if you want that look.

Where it gets properly interesting: there's an optional depth_map input. Feed it a depth/grayscale image where the value encodes distance, and focus_distance picks the plane in focus. Pixels closer to that plane stay sharp; pixels farther away blur proportionally more. That's the difference between "blurred background" and "actual depth of field." No depth map and it just applies the blur uniformly, which is fine for a subtle defocus on a single plane.

The inputs that matter

  • defocus - blur amount, 0 to 20.
  • aspect_ratio - stretch of the bokeh shape, 0.1 to 3; 1 is round.
  • method - gaussian, disk (round bokeh), or hexagon.
  • quality - low / medium / high, kernel resolution vs speed.
  • depth_map - optional IMAGE grayscale depth to drive focal falloff.
  • focus_distance - where the in-focus plane sits in the depth map, 0 to 1 (default 0.5). Only meaningful with a depth map.
  • mix - blend the defocus back into the original.

Output is a single IMAGE at the input resolution.

Installing it

It's part of the Nuke Nodes pack:

cd ComfyUI/custom_nodes
git clone https://github.com/sumitchatterjee13/nuke-nodes-comfyui.git nuke-nodes
cd nuke-nodes
pip install -r requirements.txt

Or search "Nuke Nodes" in ComfyUI Manager and restart. It's under the Nuke category, pure PyTorch, no special dependencies.

Common issues

  • It just looks like blur, no bokeh - check the method: gaussian will read as a plain soft focus; switch to disk or hexagon for visible bokeh shapes, especially on bright highlights.
  • Depth map does nothing - if you didn't wire one in, there's nothing driving the falloff, so the blur is uniform. Also confirm your depth map has contrast - a flat depth image can't produce falloff.
  • Everything is blurry - focus_distance may be far from where the actual depth values sit, or defocus is large. Lower the amount or move the focus plane.
  • Edges get hard and weird - large defocus values on a small image can produce chunky kernels; drop defocus or raise quality.

For making a generated scene feel photographed rather than rendered, defocus with a depth map is the honest shortcut.

CategoryNuke/Filter

Inputs (8)

NameTypeDefaultDescription
imageIMAGE
defocusFLOAT1.00–20
aspect_ratioFLOAT1.000.1–3
qualityCOMBOmedium3 options: low, medium, high
methodCOMBOdisk3 options: gaussian, disk, hexagon
mixFLOAT1.000–1
depth_mapoptMASK
focus_distanceoptFLOAT0.500–1

Outputs (1)

NameTypeDescription
IMAGEIMAGE