Nodes/KJNodes for ComfyUI/Create Shape Mask On Path
ComfyUI Node Runs on cloud

Create Shape Mask On Path

Animated shape masks that move along a path

By kijai·Created 3 years ago·Updated about 9 hours ago· 2,930
Create Shape Mask On Path
    • mask
    • mask_inverted
    shapecircle
    coordinates
    frame_width512
    frame_height512
    shape_width128
    shape_height128
    size_multiplier1

    This one is for animation. CreateShapeMaskOnPath draws a shape - a circle, square, or triangle - and generates a whole batch of masks with that shape placed at a sequence of coordinates. Feed it a path (a list of positions, one per frame) and you get a mask that moves: the shape traveling across the frame over time. That's the raw material for masked video animation - think a spotlight tracking a subject, a region of motion guidance for AnimateDiff or Wan, or an animated matte you drive procedurally instead of painting frame by frame.

    How it works

    You give it a list of center coordinates. For each coordinate it renders the chosen shape at that spot on a blank frame of your specified size, and stacks all those frames into a batch of masks. Because the positions change from frame to frame, the shape appears to glide along the path when the batch is played back as video. The coordinates usually come from a spline or path-editor node upstream, so you draw the motion once and this node turns it into a frame-by-frame mask sequence.

    The inputs that matter

    • shape - circle, square, or triangle. The mask's form.
    • coordinates - a string of center positions, one per frame. This is the path. Each entry is where the shape's center sits on that frame. Pipe this from a coordinate/spline node rather than typing it by hand.
    • frame_width / frame_height - the size of each mask frame. Match this to the resolution of the video you're masking.
    • shape_width / shape_height - how big the shape is. These are the shape's dimensions, not the frame's.
    • size_multiplier (optional) - a float (or list of floats) that scales the shape, and because it can be a list, the shape can grow or shrink over the sequence - a circle that swells as it moves, say.

    Two outputs: mask and mask_inverted. The inverted one saves you a separate invert node when you need the outside of the shape rather than the inside.

    Where it fits

    Procedural animated masking. Anywhere you want a region that changes position over a video: guiding where motion happens, isolating a moving subject for a per-region effect, building animated transitions, or feeding a controllable matte into a video model. Kijai builds a lot of the community's video tooling, and nodes like this are the plumbing that makes masked, path-driven video effects possible without hand-animating every frame.

    Installing KJNodes

    In ComfyUI Manager, search "KJNodes for ComfyUI" in the Custom Nodes Manager, install, restart. Manual: cd ComfyUI/custom_nodes && git clone https://github.com/kijai/ComfyUI-KJNodes, then pip install -r ComfyUI-KJNodes/requirements.txt (portable: python_embeded\python.exe -m pip install -r ComfyUI\custom_nodes\ComfyUI-KJNodes\requirements.txt), then restart. No models needed.

    Gotchas

    The coordinates format is where people stumble. It expects a properly structured list of points, which is why it's meant to be driven by an upstream spline/coordinate node rather than typed in raw - get the format wrong and you'll get an empty or single-frame mask. If your "animation" isn't animating, check that you're actually supplying multiple coordinates, one per frame, and that the count lines up with your video's frame count.

    Also line up frame_width/frame_height with the resolution of whatever you're compositing against. A mask batch at the wrong size won't register against your video frames, and you'll spend ten minutes wondering why the effect isn't landing where the shape clearly is.

    CategoryKJNodes/masking/generate

    Inputs (7)

    NameTypeDefaultDescription
    shapeCOMBOcircle3 options: circle, square, triangle
    coordinatesSTRING
    frame_widthINT51216–4096
    frame_heightINT51216–4096
    shape_widthINT1288–4096
    shape_heightINT1288–4096
    size_multiplieroptFLOAT1

    Outputs (2)

    NameTypeDescription
    maskMASK
    mask_invertedMASK