ComfyUI Node

MX_LensBokeh

Shaped bokeh blur — pentagon, hexagon, whatever you want

By Intersection98·Created 2 years ago·Updated 2 years ago· 13
MX_LensBokeh
  • images
  • IMAGE
blades_shape5
blades_radius10
blades_rotation0.00
blur_size10
blur_type
method

LensBokeh is the pack's shallow-depth-of-field node, but with a twist: the bokeh circles are shaped. Real lenses render out-of-focus highlights as polygons matching their aperture blades - pentagons on cheap lenses, rounded hexagons on nicer ones. This node lets you pick the blade count and rotation, so you can blur a background into pentagonal or hexagonal light discs instead of generic round smears.

It's part of Intersection98/ComfyUI-MX-post-processing-nodes, and it's the most "photographic" of the pack's three lens nodes. The effect it's chasing - background blur with shaped highlights - is one of the strongest realism tells in the photorealism playbook, because most generative models just don't render it.

How it works

The node builds a polygon "aperture" mask from blades_shape, blades_radius, and blades_rotation, then uses that polygon as a convolution kernel. Two method options apply it differently:

  • filter - a true convolution of the image with the shaped kernel. Smooth, correct, and slower.
  • dilate - a morphological dilation with the kernel. Chunky and fast; more of a stylized punch than an optical simulation.

Before the shaped blur runs, a blur_type pass (bilateral or stack blur) pre-softens the image - that's what actually creates the out-of-focus look; the shaped kernel then turns bright highlights into aperture-shaped discs. blur_type = none skips that pre-pass entirely.

The inputs that matter

  • images - your IMAGE tensor.
  • blades_shape - 3 and up, default 5. Aperture blades; 5 gives the classic cheap-lens pentagon, 6 is rounder.
  • blades_radius - 1 and up, default 10. Size of the aperture - effectively the size of the bokeh discs.
  • blades_rotation - 0–360 degrees, default 0. How the polygon is rotated, which matters for the highlight shape orientation.
  • blur_size - 1 and up (step 2), default 10. Strength of the pre-blur.
  • blur_type - bilateral, stack, or none.
  • method - dilate or filter.

Output is a single IMAGE at the original resolution.

Install

Standard MX pack install. ComfyUI Manager (search MX or ComfyUI-MX-post-processing-nodes), or:

cd ComfyUI/custom_nodes
git clone https://github.com/Intersection98/ComfyUI_MX_post_processing-nodes
cd ComfyUI_MX_post_processing-nodes
pip install -r requirements.txt

Restart ComfyUI; it's under postprocessing/lens. No model downloads - OpenCV does the polygon masking and filtering.

Where people get burned

The big one: this node blurs the entire frame. It has no depth map and no mask, so it can't keep a subject sharp while blurring the background - if you need real shallow depth of field, that's a depth-based blur (or a mask-driven one, e.g. MX_AlphaBlend with a depth mask) and this node isn't it. Its job is the look of bokeh on a whole image or a masked region. Second, shaped bokeh only becomes visible where there are bright highlights - on a dark, low-detail image the effect is subtle to invisible, so judge it on highlights, not shadows. Third, the filter method at large blades_radius is slow; use dilate for previews. And there's a small input quirk to be aware of: blur_size is decremented by 1 internally, so don't obsess over exact values. For the classic "city lights through a window" shot, blades_shape 5, blur_size ~20, method filter is the starting recipe.

Categorypostprocessing/lens

Inputs (7)

NameTypeDefaultDescription
imagesIMAGE
blades_shapeINT5
blades_radiusINT10
blades_rotationFLOAT0.000–360
blur_sizeINT10
blur_typeCOMBO3 options: bilateral, stack, none
methodCOMBO2 options: dilate, filter

Outputs (1)

NameTypeDescription
IMAGEIMAGE