Nodes/Photography Nodes/Depth of Field
ComfyUI Node

Depth of Field

Blur the background like a lens, mask or no mask

By TrophiHunter·Created about a year ago·Updated about a year ago· 5
Depth of Field
  • image
  • dof_mask
  • IMAGE
◄blur_strength0.500►
◄blur_sigma0.500►
◄dof_mask_size0.400►
◄falloff_size0.400►
◄sigma0.800►
◄modeeliptical dof►

AI renders famously nail the subject and then leave the background perfectly, unnaturally crisp. Depth of Field is the fix, and it gives you two ways in: feed it a mask (white = in focus) from a depth map, or let it fake an elliptical focal plane with zero extra inputs. For portraits, either path takes a flat render and makes it read like it was shot at f/1.8. The photorealism crowd calls out background blur that doesn't match lens optics as a top tell - this node is a direct answer to that.

How it works

The core is a separable gaussian blur applied to the whole frame, then blended back based on a mask. In use mask mode, the optional dof_mask (MASK input, white = in focus) controls exactly where sharpness survives - the natural pairing is a depth-estimation node (MiDaS-style) inverted so near subjects stay sharp and far ground blurs. In eliptical dof mode (the default), it generates an ellipse-shaped focus mask centered on the frame with dof_mask_size as the ellipse size, and blends to blur outside it - a one-shot, no-inputs-required faux bokeh for centered subjects.

blur_strength and blur_sigma together control how much and how soft the blur is, falloff_size shapes the transition from sharp to blurred (0.4 default is a soft gradient; higher gives a harder focus edge), and sigma tunes the mask falloff curve.

Inputs that matter

  • mode - "eliptical dof" (default, no mask needed) vs "use mask"
  • dof_mask - the optional MASK input; only needed for mask mode. White = keep sharp
  • blur_strength - how heavy the out-of-focus blur gets
  • dof_mask_size - the elliptical focus region size, 0–1

One IMAGE in, one IMAGE out (plus optional MASK).

Install

Part of Photography Nodes:

cd ComfyUI/custom_nodes
git clone https://github.com/TrophiHunter/ComfyUI_Photography_Nodes

Restart, find it under TrophiHunter/Photography (ComfyUI Manager: "Photography Nodes"). No requirements, no models.

Where people get burned

Switching to "use mask" without wiring a dof_mask in is the classic error - the node asserts and fails with a message telling you exactly that. And if the mask mode gives you a hard visible seam, your depth map is probably too high-contrast; the falloff is gaussian, so feed it a soft depth gradient, not a hard silhouette. The elliptical mode is honest about being fake - it centers focus on the frame, so off-center subjects will blur even if they're the subject. Also, heavy blur_strength with a big ellipse can feel like tilt-shift miniaturization rather than lens blur; keep it moderate for photorealism and reserve the extreme settings for the toy look.

CategoryTrophiHunter/Photography

Inputs (8)

NameTypeDefaultDescription
imageIMAGE—
blur_strengthFLOAT0.5000–10—
blur_sigmaFLOAT0.5000–10—
dof_mask_sizeFLOAT0.4000–1—
falloff_sizeFLOAT0.4000–1—
sigmaFLOAT0.8000–1—
modeCOMBOeliptical dof2 options: eliptical dof, use mask
dof_maskoptMASK—

Outputs (1)

NameTypeDescription
IMAGEIMAGE—