LayerMask: Mask Grain
Add noise to a mask edge for natural blends
- mask
- mask
Perfectly clean masks can look too clean. A razor-smooth alpha edge composited onto a grainy, textured background reads as fake - the human eye catches that the cutout is suspiciously crisp. This node roughens a mask's transition with noise/grain so the blend looks like it belongs, the way a little film grain hides the seams in real compositing.
It's a small, specialized tool, but it's the kind of thing that separates a composite that "looks AI" from one that doesn't. Sprinkle grain into the mask edge and the boundary dithers instead of slicing, which sells the integration.
How it works
It adds random noise to the mask, concentrated in the semi-transparent transition zone, breaking up the smooth gradient into a stippled edge. When that mask then drives a composite, the seam between layers gets a natural, textured falloff instead of a clean line. The grain value controls how much noise goes in.
The inputs and outputs that matter
mask(MASK) - the mask to roughen.grain(INT, 0–127, default 6) - the amount of noise. This is the whole node, really. 6 is subtle; push higher for a coarser, more visible dither. Too high and you get a speckled mess, so nudge it up gradually.invert_mask(BOOLEAN, default false) - flip if needed. Note this one defaults to false, unlike several of its sibling nodes.
Output is a single grained mask (MASK).
How to install it
ComfyUI Manager: search ComfyUI Layer Style, install, restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/chflame163/ComfyUI_LayerStyle
Restart to install requirements. Nothing to download.
Common issues & troubleshooting
If the node isn't there, it's the pack-wide IMPORT FAILED issue rather than this node - check startup logs for ComfyUI_LayerStyle. The usual causes across this pack: a stale install from before it split into ComfyUI_LayerStyle and ComfyUI_LayerStyle_Advanced (delete and reinstall), or a broken dependency crashing the import. Reinstall clean via Manager.
Practically: grain in a mask is subtle by design, so if you can't see any effect on the final composite, either your grain is too low or the mask edge is already so hard there's no transition zone for the noise to live in - feather the mask a touch first (a small blur or a MaskEdgeShrink soft value) so there's a gradient to grain up. And go easy; this is seasoning, not the meal. A grain of 6–15 usually does the job.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| mask | MASK | — | |
| grain | INT | 60–127 | — |
| invert_mask | BOOLEAN | false | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| mask | MASK | — |