Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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).

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading