ComfyUI Node Runs on cloud

Layer Mask

The only way to cut a layer to shape once it's in the stack

By WASasquatch·Created 3 years ago·Updated 4 days ago· 1,844
Layer Mask
  • layers
  • mask
  • layers
  • mask
index-1
layer_name
operation
feather0.0
expand0

Here's the thing most people learn the hard way: once a picture is inside a LAYERS stack, Layer Edit moves it, scales it and blends it but never touches its mask. Layer Mask is the node that actually cuts a layer to shape - give it a mask, combine one with the mask it already has, soften the edge, or strip the mask off entirely.

Everything in the pack's compositor reads a mask as white where the layer paints, so a cut-out arrives in the stack already carrying its coverage. What this node does is edit that coverage on a single layer without disturbing its placement, angle or name.

The operations

The operation dropdown is where the power is:

  • replace - the wired mask is the layer's coverage now. This is how you drop a BiRefNet or SAM mask onto a layer and recut it.
  • add - widens what the layer covers (union).
  • subtract - cuts the wired mask out of the layer.
  • intersect - keeps only what both cover.
  • invert / remove - need no mask wired at all. Invert flips the coverage; remove takes the mask away entirely so the layer paints its whole rectangle again.

On top of the operation sit two cleanup knobs. feather blurs the edge afterwards in pixels - 0 is a hard edge, 8 a soft one, 64 a gradient a composite fades across. expand grows the covered area by pixels before feathering; negative values pull the edge in, which is exactly how you strip a bright halo off a cut-out that was matted a pixel too wide.

Inputs and outputs

You point it at the layer with index (0 from the bottom, -1 is the front) or layer_name - the name wins when both are set. The optional mask input is stretched to the layer's own pixels, so you don't need to match sizes by hand. You get two outputs: the updated layers stack for Create Layered Image or the next edit, and the layer's mask on its own, which is handy when you want that exact shape somewhere else in the graph (as an inpaint mask, say) without flattening anything.

Note the "white where it paints" convention cuts against muscle memory if you've been feeding masks to a sampler. When this pack hands you a mask from mask here or from Layers to Image Batch, white is the part that draws. Wire it where a layer mask is expected and it just lines up.

Installing it

Layer Mask is part of WAS Node Suite, so it comes with the whole pack. ComfyUI Manager → search "WAS Node Suite v3", or:

cd ComfyUI/custom_nodes
git clone https://github.com/WASasquatch/was-node-suite-comfyui.git

Then restart ComfyUI. The v3 rewrite needs ComfyUI 0.14.0+ and Python 3.10+; it installs no pip packages of its own. If nodes don't appear after install, that's the ComfyUI version, not the pack - update and restart.

Where people trip

The classic mistake is using replace with a soft mask and wondering why the layer shrank - a fuzzy mask replaces clean coverage with a gradient, so run expand up a few pixels or feather a touch to recover a solid core. And if you subtract a mask whose orientation or size doesn't match the layer, remember the mask is stretched to the layer's pixels automatically, so a misalignment is usually a flipped or offset source rather than a size problem. Get the operation right first, feather last: feathering is the thing you tune by eye at the very end of the workflow.

CategoryWAS Suite/Image/Layers

Inputs (7)

NameTypeDefaultDescription
layersLAYERSThe stack holding the layer to mask. Wire in Add Layer, Layer Edit or anything else answering a LAYERS document.
indexINT-1-16384–16384Which layer is masked, counting 0 from the back of the stack. -1 is the front layer. Ignored while layer_name names one.
layer_nameSTRINGName of the layer to mask instead of index. Blank uses index. 'sky' finds a layer called Sky, and finds Sky Backdrop where nothing is called exactly Sky.
operationCOMBOWhat happens to the layer's mask. `replace` takes the wired mask as it is; `add` widens what the layer covers; `subtract` cuts the wired mask out of it; `intersect` keeps only what both cover; `invert` and `remove` need no mask wired.
featherFLOAT0.00–512Pixels the edge is blurred over afterwards. 0 = a hard edge, 8 = a soft one, 64 = a wide gradient a composite fades across.
expandINT0-512–512Pixels the covered area grows by before feathering. 0 = as it is, 8 = 8px wider all round, -8 = 8px tighter, which pulls a halo off a cut-out edge.
maskoptMASKWhat the layer covers, white where it paints. Stretched to the layer's own pixels. Not read on `invert` or `remove`.

Outputs (2)

NameTypeDescription
layersLAYERSThe stack with the layer's mask changed, for Create Layered Image or another edit.
maskMASKWhat the layer covers afterwards, white where it paints, at the layer's own size.