discard or glAlphaFunc

I want to kill fragments based on their alpha value being 0.0

Is “discard” in the shader better than using glAlphaFunc(GL_GREATER, 0.0)?

I suspect they’re mostly identical…with the exception that if you’re doing this as part of a depth-only pass to set up early-z, then it’s probably good to glDisable(GL_ALPHA_TEST) first, so go with discard.

from meoery when this question was last asked ~1 year ago, (so not to sure about the latest hardware) but alphatest is faster/or as fast + supported on all hardware (this may change in ogl3.0 when alphatest maybe dropped)
on a related note

whats quicker
glAlphaFunc(GL_GREATER, 0.0)
glAlphaFunc(GL_NOTEQUAL, 0.0)

I’d say that, if all these apply:

  • you have a lenghty fragment shader
  • can discard early in it
  • close fragments discard similarly (i.e. not every other pixel, but 4x4 blocks of pixels) … (might not apply to the very latest unified shader cards)

then you might want to try discard. Otherwise alpha test is ok because it allows increased pipelining, but your fragment shader will always run completely.

But of course, you should benchmark to see if it is makes any difference.

Originally posted by zed:

whats quicker
glAlphaFunc(GL_GREATER, 0.0)
glAlphaFunc(GL_NOTEQUAL, 0.0)

they should be somewhat the same speed, but if you have a signed alpha buffer they will not produce the same result.

Isn’t the FF alpha test goings away in Mount Evans?

Isn’t the FF alpha test goings away in Mount Evans?
I seriously doubt it. Particularly with alpha-to-coverage stuff that shaders can’t really do.

Originally posted by MarcusL:
[b] I’d say that, if all these apply:

  • you have a lenghty fragment shader
  • can discard early in it
  • close fragments discard similarly (i.e. not every other pixel, but 4x4 blocks of pixels) … (might not apply to the very latest unified shader cards)
    [/b]
    Thanks, I think it’s possible to benefit from early discard specially on SM 3 and SM 4 so I will take this route.
    From what I remember, with SM 2, the hw can’t stop executing a fs

Originally posted by zed:
whats quicker
glAlphaFunc(GL_GREATER, 0.0)
glAlphaFunc(GL_NOTEQUAL, 0.0)

Should be no difference.

Originally posted by Korval:
[quote]Isn’t the FF alpha test goings away in Mount Evans?
I seriously doubt it. Particularly with alpha-to-coverage stuff that shaders can’t really do.
[/QUOTE]DX10 has done away with alpha test, so I don’t see why Mount Evans can’t. Alpha-to-coverage should stay though, but one might consider modifying it so that you don’t write alpha but instead a separate coverage output. Would make more sense IMO.