PDA

View Full Version : discard or glAlphaFunc



V-man
08-07-2007, 09:56 PM
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)?

Lindley
08-07-2007, 10:14 PM
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.

zed
08-08-2007, 12:39 AM
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)

MarcusL
08-08-2007, 01:13 AM
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.

zeoverlord
08-08-2007, 07:45 AM
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.

Brolingstanz
08-08-2007, 09:25 AM
Isn't the FF alpha test goings away in Mount Evans?

Korval
08-08-2007, 10:27 AM
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.

V-man
08-08-2007, 10:24 PM
Originally posted by MarcusL:
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)
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

Humus
08-08-2007, 11:44 PM
Originally posted by zed:
whats quicker
glAlphaFunc(GL_GREATER, 0.0)
glAlphaFunc(GL_NOTEQUAL, 0.0) Should be no difference.

Humus
08-08-2007, 11:52 PM
Originally posted by Korval:

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