Nodes/WAS Node Suite v3/Inpainting VAE Encode
ComfyUI Node Runs on cloud

Inpainting VAE Encode

The core inpaint encode, plus a mask-offset knob

By WASasquatch·Created 3 years ago·Updated 4 days ago· 1,844
Inpainting VAE Encode
  • pixels
  • vae
  • mask
  • LATENT
mask_offset6

ComfyUI already ships a "VAE Encode (for Inpainting)" node, so the first question is why this one exists. The answer is one extra dial: mask_offset. This WAS version does the same job - encode an image plus a mask into a latent with a noise_mask attached - but lets you grow or shrink the mask before it ever touches the encoder, which is the difference between a clean inpaint and one with a visible seam.

How it works

The mechanic is standard masked-latent inpainting: the mask gets resized to match your image, applied to the pixels, and the whole thing gets VAE-encoded into a latent that carries a noise_mask alongside it. Whatever's under the white part of the mask is what your sampler is allowed to touch; the black part is locked. Where this node earns its keep is mask_offset - a positive value dilates (expands) the mask, a negative value erodes (shrinks) it, before encoding. Painting a mask that hugs the object too tightly tends to leave a visible ring where old and new content meet; nudging the offset a few pixels positive gives the model some buffer around the edge to blend into, which is exactly the boundary-artifact problem this node was built to reduce.

Worth knowing going in: encoding the masked region to latent noise like this generally wants a denoise of 1.0 downstream - you're regenerating the masked area from scratch, not lightly touching it up. If you want to inpaint at a lower denoise while keeping some of the original content as a hint, that's a job for InpaintModelConditioning instead, which core ComfyUI added specifically to handle the "keep original content, partial denoise" case that plain VAE-encode-for-inpaint can't do cleanly.

The inputs and outputs that matter

  • pixels (IMAGE) - the image you're inpainting.
  • vae (VAE) - the VAE to encode with; match it to whatever checkpoint you're sampling with.
  • mask (MASK) - white = paint here, black = leave alone.
  • mask_offset (default 6, range -128 to 128) - the one setting you'll actually tune. Positive dilates the mask (bigger buffer, softer blend, safer against leftover halos); negative erodes it (tighter to your painted region, less risk of eating into detail you wanted to keep). The default of 6 is a mild dilate, which is a reasonable starting point for most masks.

Single output: LATENT, ready to feed straight into a KSampler alongside your usual positive/negative conditioning.

How to install it

Via ComfyUI Manager: search "WAS_Extras", install, restart. Manually:

cd ComfyUI/custom_nodes
git clone https://github.com/WASasquatch/WAS_Extras

Restart ComfyUI. No extra Python dependencies for this particular node - the pack's requirements.txt is only needed for the ksampler_sequence.py nodes (the CLIP Text Encode Sequence / KSampler Sequence family), not this one.

Common issues & troubleshooting

Results look muddy or washed out at the seam. That's the classic sign of too little mask buffer. Bump mask_offset up a few units before touching anything else - it's cheaper than fighting it with denoise or CFG.

The inpaint isn't taking at all, or looks like a no-op. Check your downstream KSampler's denoise. This node's noise_mask is built for a full 1.0 denoise on the masked region; a low denoise here will barely touch the mask and you'll wonder why nothing changed.

Fine detail you wanted to keep got erased. You probably over-dilated. Pull mask_offset toward zero, or negative, to tighten the mask back down to what you actually painted.

Need partial-denoise inpainting that respects the original pixels underneath. This node isn't the tool for that - reach for core ComfyUI's InpaintModelConditioning node instead, which was built precisely so you can inpaint at less than full denoise without the masked region collapsing to pure noise first.

CategoryWAS Suite/Latent

Inputs (4)

NameTypeDefaultDescription
pixelsIMAGEThe image to inpaint. Its width and height are cropped to the nearest multiple of 8, taking the trim evenly from both sides. A latent addresses the image 8 pixels at a time.
vaeVAEThe VAE that turns the prepared image into a latent. Use the one that belongs to the checkpoint the sampler runs, or the colours shift.
maskMASKWhich part is repainted. White is repainted, black is kept, and grey is rounded to one or the other. It is stretched to the image's size first, so a mask drawn at another resolution still lines up.
mask_offsetINT6-128–128How far the painted area grows or shrinks before encoding, in pixels of the input image. 0 uses the mask exactly as drawn.

Outputs (1)

NameTypeDescription
LATENTLATENTThe encoded latent with the adjusted mask attached as its noise mask. Feed it to a KSampler, which will only replace the masked part.