There's a built-in function for the modulo operation, called mod()
. It takes two arguments. The first one can be a vector as well as a float. For example, if x
, y
and r
are float variables, and v1
and v2
variables of type vec3
:
r = mod(x, y); // calculates x % y
v2 = mod(v1, y); // calculates component wise v2[i] = v1[i] % y
There is also a more specialized fract()
function that calculates the modulo with divisor 1.0.