//! type library const float PI = 3.1415926535; const float TAU = 2 * PI; const float PHI = sqrt( 5 ) * .5 + .5; // ----------------------------------------------------------------------------- float M_Hash( in vec2 p ) { p = fract(p * vec2(5.3987, 5.4421)); p += dot(p.yx, p.xy + vec2(21.5351, 14.3137)); return fract(p.x * p.y * 95.4307); } // ----------------------------------------------------------------------------- float M_Luminosity( in vec3 color ) { return dot( color , vec3( .299 , .587 , .114 ) ); } vec3 M_NormalizeColor( in vec3 color ) { const float l = M_Luminosity( color ); return l > 0 ? ( color / l ) : vec3( 1 ); } // ----------------------------------------------------------------------------- float M_Saturate( in float x ) { return clamp( x , 0 , 1 ); } float M_LengthSqr( in vec3 x ) { return dot( x , x ); } float M_Sqr( in float x ) { return x * x; } vec2 M_Sqr( in vec2 x ) { return x * x; } vec3 M_Sqr( in vec3 x ) { return x * x; } float M_Sign( in float x ) { return ( x < 0 ) ? -1 : 1; } vec2 M_Sign( in vec2 v ) { return vec2( M_Sign( v.x ) , M_Sign( v.y ) ); } float M_VecMax( in vec2 v ) { return max( v.x , v.y ); } float M_VecMax( in vec3 v ) { return max( M_VecMax( v.xy ) , v.z ); } float M_VecMax( in vec4 v ) { return max( M_VecMax( v.xy ) , M_VecMax( v.zw ) ); } float M_VecMin( in vec2 v ) { return min( v.x , v.y ); } float M_VecMin( in vec3 v ) { return min( M_VecMin( v.xy ) , v.z ); } float M_VecMin( in vec4 v ) { return min( M_VecMin( v.xy ) , M_VecMin( v.zw ) ); }