GLSL Syntax
Further information for people interesting in writing GLSL
Additional shader example for understanding syntax
Functions to explore
Complete list of functions:
FUNCTIONS
Trigonometry
cos(x)
sin(x)
tan(x)
Power pow(x, 0.5) == sqrt(x)
pow(x, 1.)
pow(x, 2.)
pow(x, n) for any n:=number
sqrt(x): square root
inversesqrt(x) 1./sqrt(x)
Exponentials
exp(x) : base 10
exp2(x): base 2
Logarithms
log(x) : base 10
log2(x) : base 2
Geometry
length(x): length of a vector in the Euclidean norm.
distance(x,y): distance between x and y
dot(x,y): inner product between x and y (scalar product)
Other
abs(x) : absolute value of x. E.g. abs(1)=1, abs(-1)=1
sign(x) : sign of x. E.g. sign(1)=1 sign(-1)=0
floor(x) : the nearest whole number that is less than x. Ex: floor(3.14) = 3
ceiling(x):the nearest integer that is greater than x. Example: ceiling(3.14) = 4
fract(x): the fractional part of x. Example: fract(3.14)= .14;
min(a,b): minimum value between a and b
max(a,b): minimum value between a and b
clamp(x, a, b): if x
is less than a
returns a, if x
is greater than b
returns b
, otherwise returns x
.
mod(x, y): returns the remainder of the division of x divided by
y`
mix(x, y, a): x*(1.-a)+ya
step(x, a): returns 0 if x <= a, and returns 1 if x > a.
smoothstep(x,a,b): returns 0 if x<a, interpolates between 0 and 1 if a<x<=b, returns 1 if x > b.
Example for use in function explorer:
float y = cos(cos(cos(x
x+u_time*.1),1.5)*10.-u_time);
Last updated