Nodes/ComfyUI/Latent Composite Masked
ComfyUI Node Runs on cloud

Latent Composite Masked

Paste one latent onto another, before sampling

By Comfy-Org·Created 4 years ago·Updated about an hour ago· 129,962
Latent Composite Masked
  • destination
  • source
  • mask
  • LATENT
x0
y0
resize_sourcefalse

There are two ways to combine two images in ComfyUI: in pixel space with Image Composite Masked, or in latent space with this node. Latent Composite Masked pastes a source latent onto a destination latent at a position you choose, optionally through a mask, and hands the merged result to the sampler. It's the latent-space version of Photoshop layers - and because the merge happens before diffusion, the seam gets treated by the model instead of just being pasted.

Inputs:

  • destination - the LATENT being pasted onto (the background).
  • source - the LATENT being pasted in (the subject).
  • x / y - where to place the source, in pixels of the final image (step 8, matching the 8× latent downscale).
  • resize_source - default false; if the source and destination are different sizes, this rescales the source to fit the destination.
  • mask - optional. A MASK that controls where the source actually lands (white = paste, black = leave the destination). Without it, the whole source rectangle replaces the destination at x/y.

Output: a merged LATENT you feed to the sampler, which denoises the composite and (this is the magic) resolves the boundary - the model invents transition detail that a naive pixel paste can't.

What it's actually for

  • Composing subjects before generation. Generate a subject latent and a background latent separately (different prompts), composite them, then one sampling pass blends them. This is how you get "person in a scene" without the model mangling either half - each got its own generation budget.
  • Outpainting. Take a latent of your image, make a bigger destination latent, and paste the original at an offset - then sample the empty area into an extended scene.
  • Region-based inpainting without a mask-regeneration graph. Use the mask to say "only replace this region of the destination with the source."

The trade-offs nobody says out loud

  • Latent compositing is cheap and lossy. You skip a decode-encode cycle (each of which costs a little quality), but you're gluing together compressed representations that were never meant to touch. Seams in latent space can come out as halos or color mismatches in the final image - the model helps, but it doesn't always save you.
  • The mask does not become a noise mask. This is the big confusion: pasting with a mask here affects which pixels come from the source, but it doesn't tell the sampler "denoise only here." If you composite two latents and then sample the result, the whole composite gets denoised. For true masked regeneration you want Set Latent Noise Mask or VAE Encode for Inpainting instead.
  • Size mismatches. If destination and source differ, you must either resize_source or composite over only part of the destination. Forgetting it errors out.

The practical recipe

The pattern that actually gets used in the wild: generate a subject (often at high res for detail), generate a background, then composite the subject latent onto the background latent at a scale where the subject occupies the right fraction of the frame, then sample at moderate denoise. Compared to pasting pixels, the result has a chance of looking lit rather than cut-out. It's fiddly - getting x/y and scale right is trial and error - but it's the closest ComfyUI comes to layer-based generation, and once it clicks it's hard to go back.

Categorymodel/latent

Inputs (6)

NameTypeDefaultDescription
destinationLATENT
sourceLATENT
xINT00–16384
yINT00–16384
resize_sourceBOOLEANfalse
maskoptMASK

Outputs (1)

NameTypeDescription
LATENTLATENT