Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: Alpha test and early z test

  1. #1
    Intern Newbie
    Join Date
    Feb 2004
    Location
    Milan, Italy
    Posts
    48

    Alpha test and early z test

    I was wondering if I enable alpha-testing does it disable early z-testing on modern boards? Looking at the OpenGL spec it appears that the alpha test should happen before the depth test so theorically the GL should calculate the alpha value of the pixel and do the alpha test before the depth test. Does this really happen in practice or is the alpha test just delayed until the alpha value is known after the stencil/depth tests?

  2. #2
    Junior Member Regular Contributor
    Join Date
    Jun 2001
    Location
    Princeton, NJ
    Posts
    120

    Re: Alpha test and early z test

    Alpha-test disables early-Z on ATI and NVIDIA boards. It is reenabled on the Radeon after you switch off alpha-test, but remains disabled on the FX.

    There is no early alpha-test, thus, as alpha-test is performed before the z-test according to the spec, early-z must be switched off.

    BTW: ATI boards also perform an early-stencil test.

    - Klaus

  3. #3
    Super Moderator OpenGL Guru dorbie's Avatar
    Join Date
    Jul 2000
    Location
    Bay Area, CA, USA
    Posts
    4,388

    Re: Alpha test and early z test

    Without overdoing the whole semantic thing again between early z vs coarse z vs a marketing catchall "hyperz"...

    It doesn't matter what the spec says w.r.t. the order of OpenGL fragment processing stages in this context. The point of early z is to do z testing first to save on the earlier pipelined operations should you fail z, similarly with coarse z. So there's really no sensible excuse I've heard other than the intricacies of efficient hardware design for early z not working with alpha test. OK that's a BIG and reasonable excuse.

    Alpha test cannot turn a fragment back on so there is no risk to an early z test, the only issue is the accompanying early z write.

    Additionally, if you consider something like coarse zbuffer region reject it shouldn't be a problem but it is very hardware design dependent.

    So the real issue as far as I can tell with early z & other operations that might reject fragments is early z writes on a depth pass either to the classic zbuffer or whatever else is there.

    Once again, when software developers talk about early z they mean the whole thing. It's a black box with performance being the only thing that can be measured, so early z hyperz coarse z effectively look like one operation. When hidden fragments render at normal speed developers can only say that all hidden fragment optimizations are defeated. When performance is improved they cannot tell why, only that something worked.

    [This message has been edited by dorbie (edited 02-20-2004).]

  4. #4

    Re: Alpha test and early z test

    Originally posted by dorbie:
    Once again, when software developers talk about early z they mean the whole thing. It's a black box with performance being the only thing that can be measured, so early z hyperz coarse z effectively look like one operation. When hidden fragments render at normal speed developers can only say that all hidden fragment optimizations are defeated. When performance is improved they cannot tell why, only that something worked.
    There has to be some magic here, dorbie, else IHVs would go out of business

    Anyway, I'd just read the IHV SDK docs and follow the guidelines there as those should help find the path with the best performance.
    I speak only for myself.

  5. #5
    Super Moderator OpenGL Guru dorbie's Avatar
    Join Date
    Jul 2000
    Location
    Bay Area, CA, USA
    Posts
    4,388

    Re: Alpha test and early z test

    Well I'm thinking in many cases it would make more sense to perform a double z buffer operation than simply disabling early "top of shader" z, in this scenario you do an early z reject if possible without writing and repeat the test later if the shader hasn't killed or alpha test failed the fragment. Ideally you'd actually keep the depth write around in a register before writing it but if that is difficult or too close to memory fine, just do two tests. The success will depend on the shader complexity and the ratio of occluded fragments but I'm thinking it would be a win a lot of the time, especially if the initial read is cached.

    [This message has been edited by dorbie (edited 02-20-2004).]

  6. #6
    Junior Member Newbie
    Join Date
    Nov 2003
    Posts
    29

    Re: Alpha test and early z test

    On GeForce 4 and GeForceFX, alpha test prevents the fragments from being used as occluders.
    These fragments can still be z-culled, they
    just can't z-cull subsequent fragments.
    After alpha test is disabled, everything is
    peachy keen and the z-cull works normally.
    The use of alpha test does not invalidate
    z-cull for the duration of the frame.

  7. #7
    Junior Member Regular Contributor
    Join Date
    Jun 2001
    Location
    Princeton, NJ
    Posts
    120

    Re: Alpha test and early z test

    The use of alpha test does not invalidate z-cull for the duration of the frame.
    This is definately not true, at least on the FX.

    Klaus

  8. #8
    Senior Member OpenGL Pro cass's Avatar
    Join Date
    Feb 2000
    Location
    Austin, TX, USA
    Posts
    1,058

    Re: Alpha test and early z test

    Originally posted by Klaus:
    This is definately not true, at least on the FX.

    Klaus
    Klaus,

    Jeremy's statement is true, however, I wouldn't go so far as to call it peachy keen. Depth buffer updates with alpha test enabled reduce early z reject effectiveness. Some of that effectiveness can be regained, some cannot.

    As you might expect, it's very scene and render-order dependent.

    Thanks -
    Cass
    Cass Everitt -- cass@xyzw.us

  9. #9
    Junior Member Regular Contributor
    Join Date
    Jun 2001
    Location
    Princeton, NJ
    Posts
    120

    Re: Alpha test and early z test

    Cass,

    i have a simple test program - it is rendering one single opaque quad in front and then a large number of semi-transparent quads behind it. As soon as alpha-test is enabled(only for the opaque quad), early-z does not work anymore.

    No extensions used, frustum set conservatively, strict front-to-back rendering, works fine on the Radeon.

    - Klaus

  10. #10
    Intern Newbie
    Join Date
    Feb 2004
    Location
    Milan, Italy
    Posts
    48

    Re: Alpha test and early z test

    Ok, thanks for your replys. That was what I feared... So it is not wise to couple alpha-test with big shaders because all fragments have to be shaded in order to do the alpha test even if most of them would be rejected by the depth-test. I'll be careful with alpha-test from now on

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •