1
\$\begingroup\$

I got this piece of code in a fragment shader:

if (color.a < 0.01f)
    discard;

It runs fine on an older graphic card but can't even compile on my newer (maybe not new, but..) GTX 770. I got the most recent drivers and everything. The versions is correct. OpenGL 4.4. The shader compiles like normal if I remove the discard statement.

I've been searching around and I'm finding nothing about this. Does the discard just not work on certain graphic cards or what?

\$\endgroup\$

closed as off-topic by Nicol Bolas, Maximus Minimus, Trevor Powell, Gnemlock, DMGregory May 21 '17 at 13:47

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about debugging a problem must provide a minimal, complete, verifiable example of the issue so that readers can diagnose it without needing to guess, read all of your code, or engage in extensive back-and-forth dialog. For more information, see this meta thread." – Nicol Bolas, Trevor Powell, Gnemlock, DMGregory
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 4
    \$\begingroup\$ Can you obtain any information about the specific compilation error that's occurring? \$\endgroup\$ – DMGregory May 20 '17 at 17:50
  • 1
    \$\begingroup\$ Possible duplicate of glsl Expected token ')', found 'identifier' with function mix \$\endgroup\$ – Maximus Minimus May 20 '17 at 20:51
  • \$\begingroup\$ This might be better suited for Computer Graphics StackExchange \$\endgroup\$ – Archmede May 21 '17 at 1:02
  • 1
    \$\begingroup\$ Really needs the whole shader and the glGetShaderInfoLog() messages to diagnose what's going wrong. \$\endgroup\$ – Trevor Powell May 21 '17 at 1:33
3
\$\begingroup\$

Remove the 'f' on your float constants. It's not part of the GLSL language.

Source: GLSL Specification

If you do not put a #version NNN pragma at the top of your shader it will compile according to GLSL 1.10 which does not supports the f suffix.

Source: khronos wiki

\$\endgroup\$
  • \$\begingroup\$ Support for the 'f' suffix on float constants was added to GLSL in version 1.2, more than a decade ago. \$\endgroup\$ – Trevor Powell May 21 '17 at 1:28
  • 2
    \$\begingroup\$ If you don't use the directive #version the shader will be compiled as version 1.1 which does not support the f suffix. And newer drivers tend to enforce this. \$\endgroup\$ – Stephane Hockenhull May 21 '17 at 1:51

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