ComfyUI Node

Image Gradient

A gradient image in ten seconds — and the fake-lighting trick it unlocks

By huagetai·Created 2 years ago·Updated 2 years ago· 9
Image Gradient
    • IMAGE
    light_position
    multiplier1.000
    start_color#FFFFFF
    end_color#000000
    width512
    height512

    What it is

    ImageGradient makes a plain two-color gradient image at whatever width and height you ask for, with the fade coming from any of eight directions. That's the entire job - no models, no weights, no API key. It's the kind of node that looks pointless until you need a gradient inside the graph, at a specific resolution, in the middle of an automated workflow, and you realize opening Photoshop for it is the annoying option.

    The genuinely interesting use is fake lighting. Gradient backgrounds are how a lot of relight workflows - IC-Light and its successors - communicate light direction to the model. Feed a model a background that's white on the left and black on the right and it reads "key light from the left." It's a known, slightly absurd technique: in one relight thread someone tested with nothing but a gradient background, and a commenter noted that no human could tell you the lighting situation from that image - which is exactly why it works as a neutral probe. Being able to synthesize that gradient at the exact size your sampler wants, without leaving ComfyUI, is what this node is for.

    How it works

    It's a few lines of numpy. The node builds a 0→1 ramp, tiles it across the canvas, and interpolates between start_color and end_color along it. The four cardinal directions are linear ramps; the four diagonals use sqrt(x² + y²) / sqrt(2), which gives a smooth radial falloff out of the corner.

    multiplier is the exponent on that ramp, and it behaves the way exponents do in the 0–1 range. At 1.0 you get a straight linear fade. Drop it and the ramp gets pushed toward the end color, so the falloff steepens right at the light source and most of the canvas sits at the end color. I checked the math: at multiplier 0.5 the midpoint of the fade lands a quarter of the way across the image instead of halfway, and at 0.0 the whole thing is a flat block of end color. So read it as "how far the light reaches," not "how bright it is."

    The inputs that matter

    Six inputs; three you'll actually touch:

    • light_position - the eight ... Light options. This is the whole point; pick the direction the light comes from.
    • multiplier - falloff steepness, 0–1, default 1.0.
    • start_color / end_color - either hex (#FFFFFF) or comma-RGB (255,255,255), defaulting to white → black.

    width and height default to 512 and step by 8. One real trap: colors are parsed strictly. white or #FFF will crash the node with a ValueError - it wants #FFFFFF or 255,255,255.

    The output is a single IMAGE, ready to wire into anything that takes one - most usefully as the background input of an IC-Light-style relight setup, or as a quick vignette or test pattern. Fun fact: the code also computes a matching mask internally and then throws it away; the node only declares and returns the image.

    Installing it

    Same drill as its sibling MaskGradient, because they ship in one pack. ComfyUI Manager → search "Light Gradient" (the pack title is "Light Gradient for ComfyUI") → install → restart. Or by hand:

    cd ComfyUI/custom_nodes
    git clone https://github.com/huagetai/ComfyUI_LightGradient
    # then restart ComfyUI
    

    That's the whole install. No requirements.txt, no model files, no CUDA extras - just numpy and torch, which ComfyUI already ships. This is the rare custom node that cannot break your Python environment.

    Gotchas

    • It's a ghost town. One commit from May 2024 by "huagetai" (ray), and zero discussion anywhere I could find. For something this small that's fine - the math isn't going to rot - but don't expect maintenance.
    • The pack ships some "crease" functions (parabolic, cross) that no node calls. Leftover experiments; ignore them.
    • If you need the matching mask to go with the image, note that ImageGradient doesn't expose it - that's literally the sibling node's job.
    CategoryLightGradient

    Inputs (6)

    NameTypeDefaultDescription
    light_positionCOMBO8 options: Left Light, Right Light, Top Light, Bottom Light, Top Left Light, Top Right Light, +2
    multiplierFLOAT1.0000–1
    start_colorSTRING#FFFFFF
    end_colorSTRING#000000
    widthINT5120–16384
    heightINT5120–16384

    Outputs (1)

    NameTypeDescription
    IMAGEIMAGE