⚡| VAE Encode (for Soft Inpainting)
The soft VAE encode, explained
- pixels
- vae
- mask
- LATENT
This is the node that makes mask-based inpainting on Z-Image not suck. You feed it an image, a mask, and your VAE, and it returns a single LATENT with the mask baked in as a noise_mask - the standard ComfyUI inpainting signal. The "soft" part is the whole trick: instead of a hard-edged mask that leaves a visible seam, it blurs the mask edges so the regenerated area melts into the original image. Same author, same tuning philosophy as the Z-Sampler Turbo, so it's the encoder the pack's own sampler was designed to work with.
Why this over the stock VAE Encode
Stock ComfyUI inpainting means VAE Encode, then a separate "Set Latent Noise Mask" node, and usually some manual resizing so the image sits in Z-Image's happy zone. Z-Image is a Turbo model - it wants CFG 1, few steps, and resolutions around 1–2 megapixels, and it degrades past ~2MP. This node bakes all of that into the encode step. It also came from the pack's v1.0 release specifically because the author wanted inpainting to be a first-class citizen in his workflows, not an afterthought bolted onto a txt2img graph.
How it works
Under the hood it does four things, in order:
- Blurs your mask. A Gaussian blur whose kernel grows with
mask_blur_pixels(kernel width2 * px + 1, sigmapx / 2), clamped to 0–1. Higher values = softer edges, but also a larger effective masked area, since the blur pushes feathered values outward. - Resizes. It scales both image and mask to the
output_sizeyou pick. - Crops to VAE-compatible resolution. Z-Image's VAE needs dimensions that divide cleanly; the node snaps to the nearest compatible size (centered, so you lose a few edge pixels rather than getting an encode error).
- Encodes with the mask embedded.
vae.encode(pixels)plus the processed mask asnoise_maskin the latent dict.
The inputs that matter
- pixels - the image to encode (IMAGE).
- vae - the Z-Image VAE. The pack's README links two:
ae.safetensors(335 MB) orZ-Image_half_natural_vae.safetensors, both dropped intoComfyUI/models/vae/. - mask - white where you want regeneration (standard ComfyUI semantics).
- output_size -
same_as_input,small(~1024×1024 area),medium(~1300×1300, marked "recommended"), orlarge(~1600×1600). Medium is the sweet spot for Z-Image quality; golargeonly if the inpainted area is big and your GPU has headroom. - mask_blur_pixels - 0–256. Start around 10–20 for soft blends; crank it up if you see a visible boundary, but remember bigger blurs eat into the surrounding image.
Output is a single LATENT. Feed it into a Z-Sampler Turbo node with denoise between 0.8 and 0.9 - that's the range the pack docs recommend for inpainting (intensity-style controls only kick in at denoise 1.0 anyway), then VAE-decode and you're done.
Installing it and what it needs
It's part of ComfyUI-ZImagePowerNodes: Manager → search "Z-Image Power Nodes" → Install → restart, or:
cd ComfyUI/custom_nodes
git clone https://github.com/martin-rizzo/ComfyUI-ZImagePowerNodes.git
No Python dependencies beyond what ComfyUI already has; the only "download" is the VAE itself, which the pack doesn't fetch for you.
Gotchas
If the masked area comes back with a flat gray or obviously wrong patch, check your mask orientation - white = change, black = keep. If the untouched parts of the image shift slightly, it's usually the resize: medium/large rescale the whole frame, so for pixel-exact edits use same_as_input and let the mask blur do the blending. And don't combine this with turbo_creativity on the sampler - that feature is documented as not recommended for inpainting, because latent scrambling and a fixed mask are a bad date.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| pixels | IMAGE | The input image to encode | |
| vae | VAE | The VAE model to use for encoding | |
| mask | MASK | Mask indicating the area of the image to apply inpainting. | |
| output_size | COMBO | Determines the size of the output latent space. | |
| mask_blur_pixels | FLOAT | 0–256 | Width in pixels for softening the mask edges. Higher values create a smoother transition with larger masked area. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| LATENT | LATENT | Latent space representation of the encoded image and mask. |