Nodes/ComfyUI-PBRFusion4/Clamp Resolution
ComfyUI Node

Clamp Resolution

A cap for your texture size, and a flag that tells you when it fired

By Night1099·Created 7 months ago·Updated 4 months ago· 19
Clamp Resolution
    • width
    • height
    • was_clamped
    width1024
    height1024
    max_size2048

    Clamp Resolution (AIXPOLY_ClampResolution) is the safety valve in this pack's resolution chain. Give it a width, a height, and a max_size, and if either dimension exceeds the cap it scales both down to fit - aspect ratio preserved. If nothing needs clamping, it passes the numbers through untouched and tells you so.

    It doesn't touch pixels. Like the Smart Upscale Calculator, it's pure integer math on dimensions. But that's precisely what makes it useful: it's the node you put after the calculator to guarantee your texture never comes out bigger than your GPU or your target format can handle. Compute a 4K upscale, clamp it to 2048 for a low-VRAM pass, and the workflow adapts instead of OOM-ing.

    How it works

    The logic is simple: if both dimensions are within max_size, pass through unchanged. Otherwise it finds the larger dimension, scales by max_size / larger, and rounds down - so a 4096×2048 input clamped to 2048 becomes 2048×1024. was_clamped is the flag that says whether anything actually changed, and that flag is half the value of the node: it lets downstream logic know the source needed reigning in.

    Inputs and outputs

    • width, height (defaults 1024 each, range 1–16384) - the dimensions you're clamping. Wire these from the Smart Upscale Calculator's width/height outputs.
    • max_size (default 2048, range 64–8192) - the cap.

    Outputs are width, height, and was_clamped (boolean). You can chain the whole resolution stage like this:

    1. Smart Upscale Calculator picks a 2K target → width/height.
    2. Clamp Resolution caps the result at a safe maximum → clamped width/height.
    3. Those dimensions feed your actual scale/resize node, and was_clamped tells you (or a conditional branch) that the cap engaged.

    Install

    Part of the ComfyUI-PBRFusion4 pack - same install as its siblings. In ComfyUI Manager, search "ComfyUI-PBRFusion4" and install, or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/Night1099/COMFYUI-PBRFusion4
    

    Restart ComfyUI. No model involved, runs instantly.

    Gotchas

    • It only works on numbers, not on images. If you drop this node into a graph expecting it to resize an actual IMAGE, nothing will happen - feed it the integer dimensions and let a scale node do the resizing.
    • It rounds down. Clamping 4096 to 2048 gives you 2048×1024, not 2048×1024.5 - slightly conservative sizes, which is what you want from a safety cap anyway.
    • The pack-level note applies: if this node (and the rest of the pack) doesn't appear, the missing dependency is almost certainly opencv-python-headless - the pack imports it at load time, so install the requirements and restart.
    CategoryPBRFUSION4/Utils

    Inputs (3)

    NameTypeDefaultDescription
    widthINT10241–16384
    heightINT10241–16384
    max_sizeINT204864–8192

    Outputs (3)

    NameTypeDescription
    widthINT
    heightINT
    was_clampedBOOLEAN