6. Other Functions

6.1. fract

The fract operation returns the fractional part of a floating point number.

<<static_funcdefs>>=
static float fract(float x);
<<funcs>>=
static float fract(float x)
{
    return x - floor(x);
}

6.2. random

The random function is a random number generator implemented in the original shader code. It takes in a 2d vector coordinate, and returns a corresponding unit-magnitude random number.

<<static_funcdefs>>=
static float random(vec2 st);
<<funcs>>=
static float random(vec2 st)
{
    return fract(sin(dot(st,
                         mkvec2(12.9898,78.233))) *
                 43758.5453123);
}

6.3. mix

mix will blend two values using linear interpolation given an alpha value.

<<static_funcdefs>>=
static float mix(float x, float y, float a);
<<funcs>>=
static float mix(float x, float y, float a)
{
    return x * (1 -a) + y * a;
}



prev | home | next