Nodes/KJNodes for ComfyUI/Create Gradient Mask
ComfyUI Node Runs on cloud

Create Gradient Mask

A smooth gradient mask, still or animated

By kijai·Created 3 years ago·Updated a day ago· 3,011
Create Gradient Mask
    • MASK
    invertfalse
    frames0
    width256
    height256

    Generates a smooth gradient mask from scratch - a ramp from black to white across the frame. It's a small utility, but a gradient mask is one of those primitives you end up wanting constantly once you do any compositing: soft blends between two images, feathered transitions, region weighting that fades instead of cutting hard. And because it can output a batch of frames, it doubles as a way to drive animated transitions in video work.

    What you'd do with it

    A mask is just a grayscale coverage map - white means "fully here," black means "not here," and the greys in between are partial. A gradient mask is therefore a fade. Composite image A over image B through a left-to-right gradient and you get a smooth wipe from one to the other instead of a hard edge. Use it as a weight on a conditioning or an effect and the strength ramps across the frame. In inpainting-style blends it's the soft falloff that makes a paste look seamless rather than stamped.

    The frames input is the clever bit: set it above 0 and instead of a single mask you get a batch, which in a video pipeline becomes a mask that changes over time - an animated reveal or transition you can drive a compositing wipe with. At 0 you get one static gradient.

    The inputs and output

    There are only four, so here's all of them:

    • width (default 256) / height (default 256) - the dimensions of the mask. Match these to whatever you're masking.
    • invert (default false) - flips the ramp direction, so the light and dark ends swap. This is how you point the fade the other way.
    • frames (default 0) - 0 for a single mask; any positive number produces a batch of that many masks, for animated/temporal use.

    The single output is a MASK (or a batch of them). Feed it into an image-blend, a SetLatentNoiseMask, a ConditioningSetMask, or anywhere a mask is accepted.

    How to install it

    It's part of kijai's KJNodes pack.

    • ComfyUI Manager - search KJNodes for ComfyUI, install, restart.
    • Manual - cd ComfyUI/custom_nodes && git clone https://github.com/kijai/ComfyUI-KJNodes, then pip install -r ComfyUI-KJNodes/requirements.txt, restart.

    No models or dependencies - it's generated procedurally.

    Common issues & troubleshooting

    The gradient runs the wrong way. Toggle invert to swap the light and dark ends. That's the control for flipping the ramp's direction.

    Size mismatch when compositing. The mask has to match the images you're blending. If your composite errors or misaligns, set width and height to the exact dimensions of the target images rather than leaving the 256 defaults.

    The transition looks too abrupt or too gradual. The ramp spans the full dimension, so a wider mask gives a longer, gentler fade and a narrow one a quicker transition. If you need the fade concentrated in part of the frame rather than edge-to-edge, that's a job for cropping/positioning the mask afterward - this node makes a full-frame ramp.

    frames didn't animate anything. The batch of masks only becomes a moving transition if the downstream nodes actually consume a mask batch over the video's frames. Make sure the frame count lines up with your clip length and that the compositing path is batch-aware; otherwise you've just made a stack of masks nothing is stepping through.

    CategoryKJNodes/masking/generate

    Inputs (4)

    NameTypeDefaultDescription
    invertBOOLEANfalse
    framesINT00–255
    widthINT25616–4096
    heightINT25616–4096

    Outputs (1)

    NameTypeDescription
    MASKMASK