Search code examples
syntax-errorglslfragment-shader

Why am I getting a syntax error when using modulo on floats in my fragment shader?


I'm new to using the fragment shader. Why does my code raise a syntax error? I can't understand why it doesn't work. This is the piece of code that raises the error:

if ((int) pos.y % 9 == 1) shade = 1;

Both pos.y and shade are floats. I've put (int) before pos.y so that I could use modulo on it. The error message says this:

ERROR: 0:17: ')' : syntax error syntax error

I'm taking the error to mean I have too many or to few brackets, but I checked that and my code seems fine. Why is there an error, and what can I do to solve it?


Solution

  • GLSL is not C. As stated in the GLSL specification:

    There is no typecast operator; constructors are used instead.

    As such, (int) is not a thing in GLSL. If you want to convert some float to an int, you use constructor syntax: int(pos.y).