float clamp01( float value ) { return clamp( value, 0.0, 1.0 ); } vec4 clamp01_v4( vec4 value ) { value.r = clamp01( value.r ); value.g = clamp01( value.g ); value.b = clamp01( value.b ); value.a = clamp01( value.a ); return value; } float normalizeToRange( float value, float min, float max ) { return ( value - min ) / ( max - min ); } float normalizeToRange01( float value, float min, float max ) { return clamp01( normalizeToRange( value, min, max ) ); } float map( float value, float inMin, float inMax, float outMin, float outMax ) { return mix( outMin, outMax, normalizeToRange( value, inMin, inMax ) ); } float mapClamped( float value, float inMin, float inMax, float outMin, float outMax ) { return mix( outMin, outMax, normalizeToRange01( value, inMin, inMax ) ); } float triangle( float value ) { float inverted = 1.0 - value; return min( value, inverted ) * 2.0; }