Nodes/Nukun_ComfyUI_Nodes/Regional Rect Masks (Nukun)
ComfyUI Node

Regional Rect Masks (Nukun)

Three rectangles, previewed before you queue

By OnekoSL·Created 3 months ago·Updated 11 days ago· 1
Regional Rect Masks (Nukun)
    • 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

    Every regional-conditioning workflow needs a mask, and most of the time the mask you need is "a rectangle here, a rectangle there." This node makes those rectangles - two or three of them, positioned by percentage coordinates, with optional edge blur - and hands you the masks so you can preview them before anything gets generated. It's the mask-only sibling of Native Regional Rect Conditioning (Nukun): that node builds masks and applies conditioning in one step; this one just builds masks, for when you want to wire the masks into something else (native ConditioningSetMask, RES4LYF regional conditioning, or a workflow that already has its own mask-handling).

    That separation is more useful than it sounds. Masks are the part you want to see; conditioning is the part you want to trust. Having the raw mask outputs means you can check your geometry without burning a generation on a typo'd coordinate.

    How it works

    width and height define the canvas. Each of the up to three regions has x, y, w, h in the 0.0–1.0 range - percentages, not pixels. x/y are the top-left corner, w/h the size. The defaults are three full-height columns (0.35 / 0.30 / 0.35), which is the right starting shape for a triptych.

    soft_edge (0–256 px) blurs the rectangle edges. Start at 0 to see the hard rectangle in preview, then raise it until seams disappear in the output - the value that works depends on your resolution, and since you can see the mask, you can judge directly.

    region_count is 2 or 3. At 2, region 3's controls are ignored and mask_3 comes back as an empty mask, so you don't need to clean up phantom inputs.

    Inputs and outputs

    Inputs: width, height, region_count, twelve rect coordinates (three × x/y/w/h), soft_edge. Outputs: mask_1, mask_2, mask_3. Wire the masks to a preview node (or the built-in rect editor) to see them, then to whatever consumes masks in your workflow.

    One genuinely nice detail: this node (like its rect-conditioning sibling and the DenseDiffusion rect variant) ships a browser-side rectangle editor - a draggable canvas where you position the boxes by mouse instead of typing coordinates. Right-click and look for the rectangle editor option. For the fiddly part of regional work - "slightly more to the right, a touch wider" - that's a big quality-of-life win.

    Installing it

    Same pack install as the rest:

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

    Restart ComfyUI, or install via Manager (search "Nukun"). No dependencies beyond the pack's own - this is pure tensor math.

    Common issues

    Coordinates are top-left anchored percentages, so y = 1.0 puts the top edge at the bottom of the canvas and the rectangle disappears below it - the most common "where did my mask go" moment. If a rectangle vanishes, check you're not placing it off-canvas. Overlapping rectangles are allowed and the later region draws on top when masks combine downstream - fine if intentional, confusing if not. And don't forget masks are single-channel geometry: they don't know which prompt goes with which rectangle. That wiring is the conditioning node's job, or yours if you're doing it by hand.

    CategoryNukun/Mask

    Inputs (16)

    NameTypeDefaultDescription
    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

    Outputs (3)

    NameTypeDescription
    mask_1MASK
    mask_2MASK
    mask_3MASK