MX_LensBokeh
Shaped bokeh blur — pentagon, hexagon, whatever you want
- images
- IMAGE
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-3and up, default5. Aperture blades; 5 gives the classic cheap-lens pentagon, 6 is rounder.blades_radius-1and up, default10. Size of the aperture - effectively the size of the bokeh discs.blades_rotation-0–360degrees, default0. How the polygon is rotated, which matters for the highlight shape orientation.blur_size-1and up (step 2), default10. Strength of the pre-blur.blur_type-bilateral,stack, ornone.method-dilateorfilter.
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.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| images | IMAGE | — | |
| blades_shape | INT | 5 | — |
| blades_radius | INT | 10 | — |
| blades_rotation | FLOAT | 0.000–360 | — |
| blur_size | INT | 10 | — |
| blur_type | COMBO | 3 options: bilateral, stack, none | |
| method | COMBO | 2 options: dilate, filter |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |