Nodes/ComfyUI-My-Nodes/映射范围
ComfyUI Node

映射范围

Rescale any number from one range to another, clamp included

By Tagbliton·Created 2 years ago·Updated about a year ago· 11
映射范围
  • input
  • output
from_min0.000
from_max1.000
to_min0.000
to_max1.000
clamptrue

Here's a node that quietly solves a problem every workflow eventually hits: you have a number in one range and you need it in a different range. Your step counter runs 0 to 100 but the sampler wants a strength between 0 and 1. Your slider outputs 0 to 10 but the CFG field expects 1 to 7. Manual math nodes for this are ugly and error-prone. This node does the linear remap in one shot: input in, rescaled output out, with an optional clamp so nothing escapes the target range.

The inputs are self-explanatory once you see them together: from_min and from_max describe the range your input currently lives in; to_min and to_max describe the range you want it in; clamp (a boolean, default on) pins the output to the target range. The math is the standard linear mapping - normalized = (input - from_min) / (from_max - from_min), then output = normalized * (to_max - to_min) + to_min. The source even handles the degenerate case where from_max == from_min (it outputs to_min instead of dividing by zero), so you won't crash a workflow with a zero-width source range.

Two details are worth knowing. First, input is * (any type) - the node works on plain numbers and on tensors, so you can map a whole tensor's values with the same settings. Second, clamp is on by default. If you want values to overshoot the target range (say, you're using the mapping as an extrapolation), switch it off - but for 90% of uses, "stay inside the target range" is exactly the behavior you wanted.

Where does this fit in a graph? The classic ComfyUI use is turning a loop iteration into a smooth parameter sweep: map an index from 0..N onto a denoise range or a strength range so each pass through the loop moves the knob. It also pairs nicely with the pack's "比较分流器" and "重置/重复索引" for building animated or batched variations where a scalar has to become a usable parameter.

Install: it ships in ComfyUI-My-Nodes - ComfyUI Manager → search "ComfyUI-My-Nodes", or git clone https://github.com/Tagbliton/ComfyUI-My-Nodes into custom_nodes and restart. No API key, no network - pure local utility.

Gotchas. Check your from_min/from_max direction: the mapping is directional, so if from_max < from_min you get an inverted remap, which is a classic "why is my output backwards" moment. And remember the default clamp is on - if you map 0..1 to 0..100, a 1.2 input becomes 100, not 120. If you see outputs stuck at the ceiling, that's the clamp doing its job, not a bug.

Category我的节点/Tools

Inputs (6)

NameTypeDefaultDescription
input*
from_minoptFLOAT0.000-9999–9999
from_maxoptFLOAT1.000-9999–9999
to_minoptFLOAT0.000-9999–9999
to_maxoptFLOAT1.000-9999–9999
clampoptBOOLEANtrue钳制:将输出限制在to_min和to_max之间

Outputs (1)

NameTypeDescription
output*