Nodes/Nukun_ComfyUI_Nodes/DenseDiffusion Rect Apply (Nukun)
ComfyUI Node

DenseDiffusion Rect Apply (Nukun)

Rectangular regional prompts with DenseDiffusion, in one node

By OnekoSL·Created 3 months ago·Updated 11 days ago· 1
DenseDiffusion Rect Apply (Nukun)
  • model
  • conditioning_1
  • conditioning_2
  • conditioning_3
  • model
  • conditioning
  • mask_1
  • mask_2
  • mask_3
width1024
height1024
region_count3
x_10.00
y_10.00
w_10.35
h_11.00
x_20.35
y_20.00
w_20.30
h_21.00
x_30.65
y_30.00
w_30.35
h_31.00
soft_edge0
strength_11.00
strength_21.00
strength_31.00

Regional prompting - giving different parts of the canvas different prompts - is the standing answer to two characters whose attributes bleed into each other. It works, but it's fiddly: to get it going with DenseDiffusion you'd normally wire up mask creation, then a DenseDiffusion "Add Cond" node per region, then the DenseDiffusion Apply node, keeping every mask and every strength straight. NukunDenseDiffusionRectApply collapses that whole chain into one node with a draggable rectangle editor.

It's the "freely placed rectangles" flavor. The sibling DenseDiffusionSplitApply does full-width/full-height splits; this one lets each region be its own rectangle anywhere on the canvas.

What it wraps

Under the hood it builds 2 or 3 rectangular masks from percentage coordinates, adds one DenseDiffusion region conditioning per mask, and runs the DenseDiffusion Apply - all internally. You give it:

  • model - your patched/unpatched base model.
  • conditioning_1, conditioning_2 (and optional conditioning_3) - the per-region prompts, already CLIP-encoded.
  • width / height - the canvas size.
  • region_count - 2 or 3. At 2, conditioning_3 is ignored.
  • x_n/y_n/w_n/h_n - each region's rectangle in 0.0–1.0 image coordinates. The defaults tile three vertical bands, which is a fine place to start.
  • soft_edge - blur the rectangle edges so region boundaries aren't hard cuts.
  • strength_1..3 - per-region influence.

Outputs: the patched model (into your sampler), the combined conditioning (into the positive path), and mask_1 through mask_3 so you can preview exactly what each region covers.

The draggable editor

The pack ships a browser-side rectangle editor that attaches to this node (and its split/rect siblings) - you drag the region rectangles directly on a canvas in the node UI instead of typing coordinates. That's the feature that makes this usable: you can see where region 2 ends before you burn a run.

The safety detail worth knowing

DenseDiffusion has a known failure mode: pixels not covered by any region can end up with empty attention and produce black or NaN images. This node handles that internally - uncovered pixels are assigned to all active region masks so every pixel has attention. That's the kind of gotcha that eats an hour when you wire DenseDiffusion by hand, and it's handled for you here.

Installing it - the one extra step

This node needs the actual DenseDiffusion package, which is not bundled:

cd ComfyUI/custom_nodes
git clone https://github.com/OnekoSL/Nukun_ComfyUI_Nodes.git
cd ComfyUI/custom_nodes
git clone https://github.com/huchenlei/ComfyUI_densediffusion.git

Restart ComfyUI (or use ComfyUI Manager for both - search "Nukun" and "densediffusion"). The import is lazy, so the rest of the Nukun pack works fine even without it; only these two DenseDiffusion nodes need the companion.

The honest take

This is the node to reach for when your regional layout is genuinely rectangular - a subject left, a companion right, a background band. If your regions are actually full-height or full-width strips, the Split variant is simpler. And if you don't need DenseDiffusion's model patching at all (it's the heavier hammer), the pack's Native Regional Rect Conditioning gives you core-only regional conditioning without the extra package. Rect-apply is the right tool when you want DenseDiffusion's per-region strength control with rectangles - and the editor makes placement painless.

CategoryNukun/Conditioning

Inputs (23)

NameTypeDefaultDescription
modelMODEL
conditioning_1CONDITIONING
conditioning_2CONDITIONING
widthINT10248–16384
heightINT10248–16384
region_countINT32–3
x_1FLOAT0.000–1
y_1FLOAT0.000–1
w_1FLOAT0.350–1
h_1FLOAT1.000–1
x_2FLOAT0.350–1
y_2FLOAT0.000–1
w_2FLOAT0.300–1
h_2FLOAT1.000–1
x_3FLOAT0.650–1
y_3FLOAT0.000–1
w_3FLOAT0.350–1
h_3FLOAT1.000–1
soft_edgeINT00–256
strength_1FLOAT1.000–2
strength_2FLOAT1.000–2
strength_3FLOAT1.000–2
conditioning_3optCONDITIONING

Outputs (5)

NameTypeDescription
modelMODEL
conditioningCONDITIONING
mask_1MASK
mask_2MASK
mask_3MASK