clamp
clamp
Clamps the input value between a specified minimum and maximum. It's commonly used to ensure values like color or mix factors stay within a valid range, such as 0 to 1.
Core Advantages
Provides a clear and efficient node to enforce a numerical range, avoiding the cumbersome and less readable manual combination of `max` and `min` nodes. It's a key tool for ensuring valid color values and controlling effect ranges.
Common Uses
Color Value Protection
Controlling Animation/Effect Ranges
Generating and Sharpening Masks
How to adjust
Define the effect's boundaries by adjusting the `min` and `max` parameters. For example, `clamp(sin(time), 0, 1)` clips a wave oscillating between [-1, 1], keeping only its positive half to create a 'heartbeat' effect that pulses from 0 to 1 and back.
Code Examples
1// Ensure the final color value is within the valid [0, 1] range
2const finalColor = clamp( someColorCalculation, 0.0, 1.0 );