30 lines
590 B
GLSL
30 lines
590 B
GLSL
//! type library
|
|
|
|
|
|
const float PI = 3.14159265;
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
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 );
|
|
}
|