Nodes/As_ComfyUI_CustomNodes/LatentMixMasked_As
ComfyUI Node

LatentMixMasked_As

Masked latent blending — stitch two latents by region

By flyingshutter·Created 3 years ago·Updated about a year ago· 8
LatentMixMasked_As
  • samples_to
  • samples_from
  • mask
  • LATENT

LatentMixMasked_As blends two latents together using a mask, instead of a single global weight. Where the mask is bright you get latent A, where it's dark you get latent B, and the boundary is as soft as your mask. It's the latent-space twin of ImageMixMasked_As from the same pack, and it's the tool you want when you need a region-based stitch before decoding - not after.

Part of flyingshutter's As_ComfyUI_CustomNodes, a deliberately dependency-free pack (author's disclaimer: it's a playground, nothing guaranteed). No models, no installs beyond the clone.

How it works

The blend is the masked linear interpolation you'd expect:

out = samples_to * mask + samples_from * (1 - mask)

Applied per channel across the latent tensor. The mask is used exactly as given - no resizing, no smoothing, no autoscaling. Whatever resolution your mask is, that's the resolution it blends at.

The inputs

  • samples_to - the LATENT that shows through where the mask is bright.
  • samples_from - the LATENT that shows where the mask is dark.
  • mask - a MASK, same spatial size as the latents.

Output: a single LATENT.

Where you'd use it

Masked latent blending is the backbone of a lot of region-editing workflows that want to avoid decode/re-encode cycles. The killer use case: generate a full image, create a second latent that's been regenerated or altered for just one region (say, an inpainted object or a face), then blend it in with a mask in latent space and decode once at the end. Because the VAE decode/encode round trip is lossy, stitching latents instead of images preserves detail - the same reason the KB's shared-latent-space notes recommend skipping decode/encode cycles where you can.

It's also great for tiling workflows, where you stitch independently-generated latent tiles together with feathered masks to hide the seams.

Installing it

cd ComfyUI/custom_nodes
git clone https://github.com/flyingshutter/As_ComfyUI_CustomNodes

Restart ComfyUI and it's under ASNodes (or ComfyUI Manager → "As_ComfyUI_CustomNodes").

Common issues

  • Mask resolution is critical. This is the big one. Latents are typically 8× smaller than the corresponding image (SD/SDXL/Flux latents are downsampled), and this node applies the mask at latent resolution with no resizing. If you feed a full-res mask, shapes won't line up - you'll get a blend that's wrong regionally or a broadcast error. Downscale your mask to the latent size (or better, generate it at latent resolution) before wiring it in. ComfyUI's core mask-resize nodes handle this; use one.
  • Batch assumptions. It clones samples_to's structure and applies the mask against it; mismatched batch shapes between the latents and mask cause tensor errors. Keep everything single-image and shape-matched.
  • Soft edges are your friend. A hard-edged mask at latent resolution produces visible seam artifacts when decoded. Feather the mask a bit.

Used right, this is one of the more genuinely useful nodes in the pack - latent-space region stitching is a real technique, and this is a clean, no-dependency implementation of it.

CategoryASNodes

Inputs (3)

NameTypeDefaultDescription
samples_toLATENT
samples_fromLATENT
maskMASK

Outputs (1)

NameTypeDescription
LATENTLATENT