Nodes/BrainDead Nodes/BD Mask Color Fill
ComfyUI Node

BD Mask Color Fill

Paint flat colors into mask regions — the fast path to flipbook UV textures

By BizaNator·Created 8 months ago·Updated 3 days ago· 15
BD Mask Color Fill
  • background
  • bg_mask
  • mask_1
  • mask_2
  • mask_3
  • mask_4
  • image
  • rgba
  • mask
  • status
bg_r0
bg_g0
bg_b0
bg_alpha0.00
bg_alpha_from_imagefalse
bg_alpha_invertfalse
r_1255
g_10
b_10
expand_10
feather_10
r_20
g_2255
b_20
expand_20
feather_20
r_30
g_30
b_3255
expand_30
feather_30
r_4255
g_4255
b_40
expand_40
feather_40

BD Mask Color Fill takes up to four masks and fills each with a solid color, then composites the whole thing over a background. That's the entire job, and the entire reason it exists is to build flat-color zone textures - most visibly the 2D flipbook UV textures in this pack's face pipeline, where you take BD Face Socket Infill mask outputs and turn them into clean, color-coded regions a game shader can read.

The mental model: each of the four slots is a colored rubber stamp. Wire a MASK into mask_1, pick its RGB with r_1/g_1/b_1, and the node stamps that color wherever the mask is white. Slots layer bottom-to-top - slot 1 is painted first, slot 4 last - so where two regions overlap, the higher-numbered slot wins. Leave a slot unwired and it's simply skipped, which means "up to four" is "however many you need."

The inputs that matter

  • expand_1expand_4 - dilate each mask before coloring. Grow the painted region outward by N pixels. This is how you close the little gaps between zones that the source masks left behind.
  • feather_1feather_4 - soften the stamp's edge. Positive feathers outward from the fill edge (interior stays opaque, boundary bleeds out); negative feathers inward (the fill fades toward its own edge); 0 is a hard binary edge. Per-slot, so a hard eye region can sit next to a soft hair region in the same pass.
  • background - if you connect an image here, it's used as the base instead of the bg_r/bg_g/bg_b solid color. This is where the composite gets real: paint your zones over the actual character render.

Then there are two clipping controls that turn "paint rectangles" into "paint the head":

  • bg_mask - a clip mask applied after all slot painting, ComfyUI convention (white = keep/opaque, black = transparent). Wire your head silhouette here and anything a slot painted outside the head gets cut away. This is the recommended way to clip by head shape - the README is explicit about it.
  • bg_alpha_from_image - when ON with a background image connected, the background's luminance drives the alpha channel: white background pixels become opaque, black become transparent. Pair with bg_alpha_invert if your image uses the opposite convention (white = background to cut out). This is your "background is already a cutout shape" mode.

Outputs

You get three views of the same result: image (RGB composite), rgba (filled regions opaque, background transparent unless you raised bg_alpha), and mask (the union of all active slots - handy if you want the total painted footprint as a mask for something downstream).

A usage note

The classic setup in this pack: BD Face Socket Infill outputs per-zone masks → four of them into BD Mask Color Fill with different colors → rgba out to a texture-save node. It's also a perfectly good general "colorize these regions" node for any mask set, and the per-slot expand/feather is what keeps hand-built masks from looking like hand-built masks.

Installing

Standard BrainDead pack install - ComfyUI Manager search "BrainDead", or clone + pip install -r requirements.txt + restart. All V3 API, so keep ComfyUI updated.

One habit worth picking up: when zones bleed where they shouldn't, the fix order is bg_mask first (clip by shape), then per-slot expand to close gaps, then feather to blend seams. Skip ahead to feathering before clipping and you'll just be softening the spill you meant to remove.

Category🧠BrainDead/Segmentation

Inputs (32)

NameTypeDefaultDescription
backgroundoptIMAGEBase image. If not connected, bg_r/g/b solid color is used as background.
bg_roptINT00–255Background red (used when no background image).
bg_goptINT00–255Background green.
bg_boptINT00–255Background blue.
bg_alphaoptFLOAT0.000–1Alpha of the background in the RGBA output. 0 = transparent background (default). 1 = fully opaque.
bg_maskoptMASKClip mask applied AFTER all slot painting. Uses ComfyUI mask convention: 1.0 (white) = keep/opaque, 0.0 (black) = transparent. Wire your head silhouette mask here — areas outside the head (mask=0) become transparent even if a slot bleeds there. This is the recommended way to clip by head shape. bg_alpha controls the non-slot base: 0=only slot zones show, 1=whole masked region is opaque showing background pixels.
bg_alpha_from_imageoptBOOLEANfalseWhen ON and a background image is connected, the background image's luminance is also used as a clip (in addition to bg_mask if wired). White=opaque, black=transparent. Enable bg_alpha_invert if your background image has the opposite convention (white=background, dark=head).
bg_alpha_invertoptBOOLEANfalseInvert the bg_alpha_from_image clip. Use when your background image has white=background (to be clipped out) and dark=head (to be kept). Has no effect when bg_alpha_from_image is OFF.
mask_1optMASKMask slot 1. Leave unconnected to skip.
r_1optINT2550–255Red channel for slot 1.
g_1optINT00–255Green channel for slot 1.
b_1optINT00–255Blue channel for slot 1.
expand_1optINT00–60Dilate mask slot 1 by this many pixels before coloring. Grows the painted region outward.
feather_1optINT0-200–200Edge feather for mask slot 1. Applied after expand. Positive: soft ramp extends OUTWARD from the fill edge — interior stays fully opaque, only the boundary bleeds out. Negative: soft ramp goes INWARD — fill fades toward its own edge. 0 = hard binary edge.
mask_2optMASKMask slot 2. Leave unconnected to skip.
r_2optINT00–255Red channel for slot 2.
g_2optINT2550–255Green channel for slot 2.
b_2optINT00–255Blue channel for slot 2.
expand_2optINT00–60Dilate mask slot 2 by this many pixels before coloring. Grows the painted region outward.
feather_2optINT0-200–200Edge feather for mask slot 2. Applied after expand. Positive: soft ramp extends OUTWARD from the fill edge — interior stays fully opaque, only the boundary bleeds out. Negative: soft ramp goes INWARD — fill fades toward its own edge. 0 = hard binary edge.
mask_3optMASKMask slot 3. Leave unconnected to skip.
r_3optINT00–255Red channel for slot 3.
g_3optINT00–255Green channel for slot 3.
b_3optINT2550–255Blue channel for slot 3.
expand_3optINT00–60Dilate mask slot 3 by this many pixels before coloring. Grows the painted region outward.
feather_3optINT0-200–200Edge feather for mask slot 3. Applied after expand. Positive: soft ramp extends OUTWARD from the fill edge — interior stays fully opaque, only the boundary bleeds out. Negative: soft ramp goes INWARD — fill fades toward its own edge. 0 = hard binary edge.
mask_4optMASKMask slot 4. Leave unconnected to skip.
r_4optINT2550–255Red channel for slot 4.
g_4optINT2550–255Green channel for slot 4.
b_4optINT00–255Blue channel for slot 4.
expand_4optINT00–60Dilate mask slot 4 by this many pixels before coloring. Grows the painted region outward.
feather_4optINT0-200–200Edge feather for mask slot 4. Applied after expand. Positive: soft ramp extends OUTWARD from the fill edge — interior stays fully opaque, only the boundary bleeds out. Negative: soft ramp goes INWARD — fill fades toward its own edge. 0 = hard binary edge.

Outputs (4)

NameTypeDescription
imageIMAGERGB composite.
rgbaIMAGERGBA — filled regions opaque, background transparent (unless bg_alpha > 0).
maskMASKUnion of all active mask slots.
statusSTRING