CLAMP
The CLAMP node constrains an input integer value to a specified range defined by a minimum and maximum value. If the input value falls within the range, it is passed through unchanged. If the input value is less than the minimum or greater than the maximum, it is “clamped” to the nearest boundary value.Inputs
value(integer): The input value to be clamped. Default is 0.min(integer): The minimum allowed value. Default is 0.max(integer): The maximum allowed value. Default is 0.
Outputs
result(integer): The clamped output value.
Configuration
This node has no configuration options.Usage
- Connect an integer value to the
valueinput. This is the value you want to constrain to the specified range. - Set the
mininput to the minimum allowed value for the output. - Set the
maxinput to the maximum allowed value for the output. - The
resultoutput will emit the input value if it’s within the [min, max] range. If the input is less thanmin,resultwill bemin. If the input is greater thanmax,resultwill bemax.
Example
Let’s say you have a spell that generates a random integer between -100 and 100, but you need to ensure the value is always between 0 and 50 before using it. You can use the CLAMP node like this:- Connect the random integer generator to the
valueinput of CLAMP. - Set the CLAMP
mininput to 0. - Set the CLAMP
maxinput to 50. - Connect the
resultoutput to the rest of your spell.
Tips
- CLAMP is useful any time you need to constrain a value to a known range. This is common when working with parameters that have legal bounds, like percentages (0-100), RGB color values (0-255), etc.
- Remember that CLAMP is inclusive of the
minandmaxvalues. If you need an exclusive range, adjust your bounds accordingly. - If
minis greater thanmax, CLAMP will swap their values internally so thatminis always less than or equal tomax.
Cautions
- Both the input value and the
min/maxbounds must be integers. For floating-point clamping, use the CLAMP (Float) node instead. - Be aware that clamping discards out-of-bounds values rather than scaling or normalizing them. If you need to fit a range of values proportionally into a different range, consider using a map or lerp node instead.
