Latent Mask π (TensorVizion)
Draw a Mask Straight on the Latent and Skip the Round Trip
- latent
- mask
- latent
- mask_out
Most masking in ComfyUI happens in pixel space: you draw on the image, then VAE-encode both together for inpainting. Latent Mask cuts out the round trip. It generates a rectangle, ellipse, or gradient mask in latent space and applies it directly to the latent tensor - zeroing a region, filling it with noise, clamping it, whatever you ask for. The coordinates are all fractions of the latent's size, so you get a mask that would look right on the decoded image without ever touching pixel space.
How it works
Pick a mask_shape - rectangle, ellipse, horizontal or vertical gradient, or external to supply your own MASK. Then pick what happens inside the masked region with blend_mode:
- zero - wipe it to 0. Full erase, the "make this region blank" move.
- noise - fill with Gaussian noise. This is the one that sets up an inpaint-style regeneration.
- clamp - clamp values to Β±
clamp_value. Softens extreme values in a region. - invert - multiply by β1. Bizarre and usually a mistake, but it's there.
Position and size are normalized fractions: x, y, width, height in 0β1 space, so a rectangle at x=0.25, y=0.25, width=0.5, height=0.5 is a centered box covering the middle half. feather softens the mask edge (0β0.5, default 0.05) - small values are usually enough; heavy feathering bleeds the effect into surrounding areas. invert_mask flips inside/outside, and seed makes the noise mode deterministic.
Inputs and outputs
- latent - in.
- mask_shape, blend_mode, x/y/width/height, feather, clamp_value, invert_mask, seed - the controls.
- mask (optional) - supply your own when shape is
external. - latent - the masked result. mask_out - the mask it used, in case you want to reuse it downstream.
Where it fits
The flagship use is latent-space inpainting prep: mask a region, fill with noise, then sample with a prompt focused on that area - the noise gives the sampler something to build from, and because you never left latent space, nothing got lost to an encode/decode round trip. Pair it with the pack's KSampler Masked Inpaint if you'd rather hand over an image + mask and let that node do the whole encode-and-sample dance.
It's also a handy tool for structure experiments: mask out a chunk, zero it, and see what the model does with the hole. And it's cheap - no VAE work, just tensor math.
Install and troubleshooting
Same as the rest of the pack - pure PyTorch, no extra deps:
cd ComfyUI/custom_nodes
git clone https://github.com/TensorVizion/OmniNodes
Restart, find it under TensorVizion/Latent (ComfyUI Manager, search "OmniNodes", works too).
One genuinely pack-specific gotcha: latent_mask_node.py had a real syntax error in earlier releases - four lines of unseparated statements - that made the entire file fail to import. It's fixed as of the pack's 2026-07-30 update, but if you installed an old copy and this node is missing from your menu, git pull and restart. Check the terminal for [OmniNodes] β Syntax Error lines to diagnose.
- The mask doesn't line up with your image. Fractions are relative to the latent, and the latent is 8x smaller per side than the image - but the same fraction maps to the same proportional location, so a 0.5 box is the middle half of both. If things look offset, check
invert_maskandfeather. - Noise mode looks chaotic. It's latent-space Gaussian noise, not visible pixel noise. At high strength the decoded result will look more like static than grain - lower the noise's role by sampling at lower denoise, or use
zeroif you wanted a clean hole.
Latent Mask is the kind of node that feels niche until you need it, and then it's the difference between a two-node detour and a one-node straight line. Worth having in the toolbox for any latent-space work.
Inputs (12)
| Name | Type | Default | Description |
|---|---|---|---|
| latent | LATENT | β | |
| mask_shape | COMBO | 5 options: rectangle, ellipse, gradient_h, gradient_v, external | |
| blend_mode | COMBO | 4 options: zero, noise, clamp, invert | |
| x | FLOAT | 0.250β1 | β |
| y | FLOAT | 0.250β1 | β |
| width | FLOAT | 0.500β1 | β |
| height | FLOAT | 0.500β1 | β |
| feather | FLOAT | 0.050β0.5 | β |
| clamp_value | FLOAT | 1.00β10 | β |
| invert_mask | BOOLEAN | false | β |
| seed | INT | 00β4294967295 | β |
| maskopt | MASK | β |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| latent | LATENT | β |
| mask_out | MASK | β |