0
\$\begingroup\$

I have a Fragment shader that contains:

[...]
float c = texture2D(tex, tc).a;
float alpha = mix(0.0f, 1.0f, c);
gl_FragColor = vec4(1, 1, 1, alpha) * color;

This works fine on my desktop and Nexus 5. However I get an exception while running on a Wiko mobile:

0:22: L0001: Expected token ')', found 'identifier'

Line 22 is the line containing the mix function.

What I'm doing wrong?

\$\endgroup\$
  • 2
    \$\begingroup\$ You seem to be missing a semicolon at the end of the line float c = texture2D... — is that present in the original? It could be that some platforms' shader compilers fix this common error automatically, but the one that's throwing the exception doesn't. \$\endgroup\$ – DMGregory Mar 29 '17 at 13:32
  • \$\begingroup\$ Thanks DMGregory, it was just a mistake when I pasted the code \$\endgroup\$ – FloFu Mar 29 '17 at 13:59
  • \$\begingroup\$ Just by the way, do you have #version directive in the shader? \$\endgroup\$ – HolyBlackCat Mar 29 '17 at 14:37
  • \$\begingroup\$ HolyBlackCat, I have a #version 100 directive \$\endgroup\$ – FloFu Mar 29 '17 at 15:02
1
\$\begingroup\$

Depending on your driver and GLSL version, the "f" suffix on floats may be illegal. Change to:

float alpha = mix(0.0, 1.0, c);

As always, OS is irrelevant; you really need to say what hardware (in particular what GPU) you have.

\$\endgroup\$
  • \$\begingroup\$ Thanks, this was the issue. Next time I'll remember about the hardware and GPU :) \$\endgroup\$ – FloFu Mar 29 '17 at 14:00
  • \$\begingroup\$ Sometimes OS matters, even within a single vendor's drivers. I've had Catalyst shader bugs that only manifested on one OS or another. \$\endgroup\$ – Lars Viklund Mar 30 '17 at 1:05
  • \$\begingroup\$ @LarsViklund - that's not the OS, it's the driver. The driver is OS-specific for sure, but it's still the driver. \$\endgroup\$ – Maximus Minimus Mar 30 '17 at 6:58
  • \$\begingroup\$ @LeComteduMerde-fou I did deploy what was claimed to be identical drivers on Windows and Linux, upstream couldn't repro on Windows. Sometimes variations happen. \$\endgroup\$ – Lars Viklund Apr 1 '17 at 17:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.