Mask Gradient
A soft gradient mask without opening Photoshop
- MASK
What it is
MaskGradient does the obvious thing: it takes the same light-direction gradient as its sibling ImageGradient and outputs it as a MASK instead of an image. White (1.0) on the light side, black (0.0) on the far side, with a smooth falloff in between. A soft feather on demand.
And soft feathers matter more than they get credit for. Hard mask edges are the root of most visible compositing seams, and a gradient falloff is the standard cure. You reach for this when you need a feathered alpha to blend two images, a gradual boundary so an inpainting pass doesn't carve a hard line, or a directional soft mask in a lighting workflow. If you're feeding an IC-Light-style relight setup a gradient background to fake a light direction, this node hands you the matching mask for free - same geometry by construction, so the image and the mask always agree.
How it works
Identical machinery to ImageGradient: a numpy ramp for the four cardinal directions, sqrt(x² + y²) / sqrt(2) radial falloff for the diagonals, then the red channel is pulled out as a single-channel mask. The one real difference from its sibling is that there are no color inputs - the mask is always white → black, with white meaning "keep/show" (the light side) and black meaning "hide."
multiplier is the exponent on the ramp, same as in the image node. At 1.0 the mask is a clean linear white-to-black. Lower it and the mask gets pushed toward black: at 0.5 most of the mask is near-black with only a thin white band at the light source, and at 0.0 it's a flat black mask - which usually means "remove everything." So if you want the longest, most gradual feather, keep multiplier at 1.0; lowering it makes the falloff shorter and steeper, not softer.
The inputs that matter
Four inputs, all simple:
light_position- the eight... Lightoptions; decides which side stays white.multiplier- feather steepness, 0–1, default 1.0 (linear).width/height- default 512, step 8.
The output is a single MASK, so it wires into anything that takes a mask - compositing, masking, inpainting, attention masks - and since it's generated on the fly, you can drive its size off the canvas you're working on.
Installing it
Same pack as ImageGradient, so one install covers both. ComfyUI Manager → search "Light Gradient" → install → restart, or by hand:
cd ComfyUI/custom_nodes
git clone https://github.com/huagetai/ComfyUI_LightGradient
# then restart ComfyUI
No dependencies beyond numpy and torch (which ComfyUI already has), no model downloads. About as safe an install as custom nodes get.
Gotchas
- If both nodes sit in one workflow you're computing the gradient math twice - ImageGradient actually builds a mask internally and then discards it. Harmless, just slightly wasteful.
- The pack is a one-commit 2024 project by huagetai, with no community footprint. Fine for static math, just don't expect updates.
- The tempting knob is the trap: lowering
multipliertoward 0 to "soften" the mask instead collapses it to solid black. Keep it near 1.0 for a gentle feather and change colors or canvas size when you want a different falloff distance.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| light_position | COMBO | 8 options: Left Light, Right Light, Top Light, Bottom Light, Top Left Light, Top Right Light, +2 | |
| multiplier | FLOAT | 1.0000–1 | — |
| width | INT | 5120–16384 | — |
| height | INT | 5120–16384 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| MASK | MASK | — |