2017-10-04 18:40:15 +02:00
|
|
|
//! type library
|
|
|
|
|
2017-10-04 19:06:50 +02:00
|
|
|
|
|
|
|
const float PI = 3.14159265;
|
|
|
|
|
|
|
|
|
2017-10-04 18:40:15 +02:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
2017-10-04 19:06:50 +02:00
|
|
|
float M_Hash(
|
|
|
|
in vec2 p )
|
2017-10-04 18:40:15 +02:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2017-10-04 19:06:50 +02:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
float M_Luminosity(
|
2017-10-05 17:03:31 +02:00
|
|
|
in vec3 color )
|
2017-10-04 19:06:50 +02:00
|
|
|
{
|
2017-10-05 11:47:33 +02:00
|
|
|
return dot( color , vec3( .299 , .587 , .114 ) );
|
2017-10-04 19:06:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
vec3 M_NormalizeColor(
|
2017-10-05 17:03:31 +02:00
|
|
|
in vec3 color )
|
2017-10-04 19:06:50 +02:00
|
|
|
{
|
|
|
|
const float l = M_Luminosity( color );
|
|
|
|
return l > 0 ? ( color / l ) : vec3( 1 );
|
|
|
|
}
|
2017-10-05 17:03:31 +02:00
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
float M_Saturate(
|
|
|
|
in float x )
|
|
|
|
{
|
|
|
|
return clamp( x , 0 , 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
float M_LengthSqr(
|
|
|
|
in vec3 x )
|
|
|
|
{
|
|
|
|
return dot( x , x );
|
|
|
|
}
|