54 lines
1.2 KiB
Plaintext
54 lines
1.2 KiB
Plaintext
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 ) );
|
|
}
|
|
|
|
vec2 map_v2( vec2 value, vec2 inMin, vec2 inMax, vec2 outMin, vec2 outMax )
|
|
{
|
|
float x = map( value.x, inMin.x, inMax.x, outMin.x, outMax.x );
|
|
float y = map( value.y, inMin.y, inMax.y, outMin.y, outMax.y );
|
|
|
|
return vec2( x, y );
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
vec2 onCircle( float angle )
|
|
{
|
|
return vec2( cos( angle ), sin( angle ) );
|
|
} |