Shadertoy clone
Comes with a crippled glsl clone
vec3 main()
{
return vec3(1, 1, 1);
};
Produces a white screen.
The program is run for each pixel on the screen, the return value of main will be the color of the pixel on the screen.
vec3(0, 0, 0)
is black, vec3(1, 1, 1)
is white. x = red, y = green, z = blue.
Everything has to end with a semicolon - typically }
will always have a semicolon that follows it unless it's inside of an if else if else
chain.
vec3 main()
{
return vec3(uv.x, 0, 0);
};
Produces a red gradient that gets more intense as x increases. uv = (0, 0)
represents top left and uv = (1, 1)
represents bottom right.
uv
is automatically defined every time the program is run.
float function_name(float param, vec3 other_param)
{
return param;
};
Currently, a return statement won't exit the function, it will only set the return value that will be returned at the end of the function.
if (expr)
{
}
else if (other expr)
{
}
else
{
};
+
, -
, *
, /
work on floats and vectors.
<
and >
can compare floats.
Operators can only have the same type on both sides, so if you want to scale a vector for example by 2:
vec3 a = vec3(1, 2, 3);
a = a * vec3(2, 2, 2);
Unary -
doesn't exist, use 0-
instead.
print
: Print values. Debugging purposes typicallysqrt
: Square root of a floatdistance
: Distance between two vectors of variable sizedot
: Dot product between two vectors of variable sizenormalize
: Normalize vector of variable sizelength
: Length of vector of variable sizeabs
: Absolute valuepow
: pow(base, exp)sin
: sinecos
: cosinetan
: tangentasin
: arcsinacos
: arccosatan
: arctan