Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: Early fragment culling using the stencil buffe

Hybrid View

  1. #1
    Junior Member Regular Contributor
    Join Date
    Jul 2010
    Posts
    130

    Early fragment culling using the stencil buffe

    Hi,

    I have a fragment shader that writes to the depth buffer (gl_FragDepth) and does some pretty expensive work. This shader only needs to run on a few screen pixels (maybe a thousand or more). They're scattered everywhere on screen.

    Is there a way I can early-cull fragments when rendering my scene, that is, before they even reach my fragment shader? Can I do this with the stencil buffer (I understand the stencil test is done before the depth test)? That way, I wouldn't have to programmatically discard fragments that I do not want to process.

    BTW, I'm exclusively working on nVidia hardware (GeForce 4xx) for the moment.

    Thanks,
    Fred

  2. #2
    Junior Member Regular Contributor
    Join Date
    Jul 2010
    Posts
    130
    Can't manage to get early stencil culling to work

    From what I can see, nVidia has a patent on stencil-based culling, but how I can enable it?
    http://www.freepatentsonline.com/7184040.html

    I have also found this page
    http://gameangst.com/?p=167
    where the following is written:

    "On most hardware early stencil cull is accomplished by storing a low resolution, low bit depth cache of the stencil buffer. Blocks of between 16 and 64 pixels are reduced to a single bit that represents a conservative average of the stencil function across all pixels in the block. This cache is then consulted prior to running the fragment shader to quickly discard pixels which are guaranteed to fail the stencil test"

    Would appreciate any insight.
    Last edited by fred_em; 09-11-2013 at 04:39 AM.

  3. #3
    Junior Member Regular Contributor
    Join Date
    Jul 2010
    Posts
    130
    It seems early stencil cull is completely disabled as soon as discard is being used in the shader.
    I don't understand why, as the stencil test should be done before the depth test and rasterization.
    Anyway, enough time spent on this...

  4. #4
    Advanced Member Frequent Contributor
    Join Date
    Dec 2007
    Location
    Hungary
    Posts
    985
    Both discard and depth writes can potentially disable early tests (usually both depth and stencil), so what you see sounds reasonable. But actual behavior might vary based on the GPU you are using.
    Disclaimer: This is my personal profile. Whatever I write here is my personal opinion and none of my statements or speculations are anyhow related to my employer and as such should not be treated as accurate or valid and in no case should those be considered to represent the opinions of my employer.
    Technical Blog: http://www.rastergrid.com/blog/

Posting Permissions

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