I got this piece of code in a fragment shader:

if (color.a < 0.01f)

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?

  • 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

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

  • \$\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.