The mod() function is a built-in function in the GLSL shading language that computes the remainder of the division \a / \b. It returns the value a - b * trunc(a / b).
The mod() function takes two arguments, both of which must be the same data type. The function returns a value with the same data type as the input arguments.
The syntax for the mod() function is as follows:
T mod(T a, T b)
Where:
T is any valid GLSL data type, such as float, vec2, vec3, vec4, int, ivec2, ivec3, ivec4, bool, bvec2, bvec3, bvec4, mat2, mat3, mat4, and so on.a is the dividend, the numerator of the division.b is the divisor, the denominator of the division.The mod() function can also be called with a single argument, in which case it returns the same value as the input argument, but with a positive sign. This is equivalent to calling mod(a, a).
float a = 16.0;
float b = 3.0;
float result = mod(a, b); // result = 1.0
In this example, the mod() function is used to compute the remainder of the division 16 / 3, which gives a remainder of 1.
The mod() function has some restrictions in GLSL:
mod() is undefined if the divisor or dividend is NaN.