Question

0:13(22): error: operator '%' is reserved in GLSL 1.10 (GLSL 1.30 or GLSL ES 3.00 required)

somewhat nonplussed to hit this error!

I'm initially wanting to wrap texture coordinates to keep them in the range 0-1 - but modulo is such a useful function I could do with a general purpose replacement!

Was it helpful?

Solution

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.

OTHER TIPS

Well, first of all in implementations that do support %, it is an integer operation just like most sensible languages (Java is the oddball). What you want here appears to be floating-point.

All versions of OpenGL ES support mod (...), this should do what you need.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top