Nodes/ComfyUI-DAELab-Custom-Nodes-Library/Badge Height Patch (DAELab)
ComfyUI Node

Badge Height Patch (DAELab)

Change one region's height without touching the rest by one bit

By TeutonicMepheles·Created 4 months ago·Updated 2 days ago· 0
Badge Height Patch (DAELab)
  • current_height
  • current_foreground_mask
  • edit_mask
  • target_layer
  • patched_height
  • patched_height_image
  • patched_foreground_mask
  • change_preview
  • difference_report
◄apply_patchfalse►

What it is and why you'd reach for it

"Make this lettering raised instead of flat" is a geometric instruction, and if you send it to an image model you get a picture of raised lettering plus a new material and slightly different letters. The DAELab approach is to split the job: change the height data deterministically, then ask the model to render the change you already made.

Badge Height Patch is the deterministic half. You hand it the current height map, the foreground mask, the region you want to change, and a target tier. It writes the new value into that region - wholly, absolutely, not blended - updates the foreground topology if you cut something out, and proves that nothing outside your mask moved.

How it works

The operation is a straight select: patched = mask * target + (1 - mask) * height. The target_layer comes in as a typed BADGE_HEIGHT_LAYER value, one of Cut Out (0.0) through Layer 5 (1.0), which is why you can wire it from Badge Local Edit Prompt Builder and have the prompt text and the data mutation agree by construction. There's no feathering and no averaging - a masked pixel becomes exactly that tier.

Foreground follows the geometry, which is the subtle part:

  • Target 0.0 (cut out): foreground is multiplied by 1 - mask, so masked pixels leave the silhouette. This is how you punch a hole through a badge.
  • Any nonzero target: foreground becomes max(foreground, mask), so a tier applied to background fills that area into the badge.

Then the contract check, same paranoid style as the composite node: height and foreground differences outside the mask are computed and any nonzero value raises Height patch violated the zero-difference outside-mask contract. With a binary mask this can't fire; it exists to catch a future code change, and it also catches an upstream mask that isn't actually binary.

apply_patch defaults to false, and that's a routing switch, not an accident. Leave it off and the node passes height and foreground through unchanged with action pass_through_non_height_operation - which is exactly what you want on a colour or material edit, where the height branch should be inert. Wire apply_height_patch from the local edit builder and it flips automatically for height operations only.

Inputs and outputs that matter

current_height, current_foreground_mask, edit_mask (all three must match in dimensions and batch - no broadcast of the mask batch, unlike some siblings), apply_patch, target_layer. The mask must be binary and the foreground too; both are checked.

Outputs: patched_height is the new mask to feed back into shading or the next stage. patched_height_image is the same data as a viewable RGB image, which is how you eyeball a six-level map in ComfyUI's preview. patched_foreground_mask is the updated topology - use it, not the old foreground, from here on. change_preview packs mask/changed-pixels/foreground into three channels so you can see exactly what the patch did. difference_report is JSON: action, target layer, the two outside-mask diffs (both zero), changed pixel count.

Install

cd ComfyUI/custom_nodes
git clone https://github.com/TeutonicMepheles/ComfyUI-DAELab-Custom-Nodes-Library

Restart ComfyUI. Manager by pack title also works. The badge module imports OpenCV, which the pack's requirements.txt doesn't declare - pip install opencv-python-headless if the node is absent from the menu.

Common issues

  • Nothing changed. apply_patch is false. Check difference_report - if action says pass_through_non_height_operation, that's your answer.
  • height, foreground, and edit mask must have identical dimensions and batch. A batch of 4 edits against a batch of 1 height map. Queue one edit at a time, or repeat the height map.
  • The badge got smaller. You cut out too much: with a 0.0 target, everything in the mask leaves the foreground. That's correct behaviour and a very easy way to delete your wordmark.
  • A filled tier looks like a floating sticker. You just promoted background into the silhouette with a nonzero target. The height is right; the shape is new. Check patched_foreground_mask before rendering.
CategoryDAELab/Badge

Inputs (5)

NameTypeDefaultDescription
current_heightMASK—
current_foreground_maskMASK—
edit_maskMASK—
apply_patchBOOLEANfalse—
target_layerBADGE_HEIGHT_LAYER—

Outputs (5)

NameTypeDescription
patched_heightMASK—
patched_height_imageIMAGE—
patched_foreground_maskMASK—
change_previewIMAGE—
difference_reportSTRING—