saturate
Constrains the input value to the standard `[0, 1]` range, acting as a common shorthand for `clamp(x, 0, 1)`. It's primarily used to ensure the validity of values like light intensity or mix factors.
Core Advantages
As a standard convention in shader programming, it more clearly expresses the intent to "normalize a value into a factor or intensity" than `clamp(x, 0, 1)`, significantly improving code readability.
Common Uses
Basic Lighting Calculations
Controlling Procedural Masks
Ensuring Valid Material Properties
How to adjust
saturate itself is not adjustable; its effect is to "clip" any value outside the `[0, 1]` range. For instance, passing an oscillating `sin(time)` value (from -1 to 1) through `saturate` will clip all negative values, turning a smooth wave animation into a "bouncing" effect that goes from 0 to 1 and then instantly drops back to 0.
Code Examples
1// Calculate dot product, which can be negative
2const lightIntensity = dot( normalWorld, lightDirection );
3
4// Use saturate to ensure light intensity is not negative
5const finalColor = saturate( lightIntensity );