Wednesday, 11 September 2013

Early stencil culling

Early stencil culling

I'm trying to get early fragment culling to work, based on the stencil
test. My scenario is the following: I have a fragment shader that does a
lot of work, but needs to be run only on very few fragments when I render
my scene. These fragments can be located pretty much anywhere on the
screen (I can't use a scissor to quickly filter out these fragments).
In rendering pass 1, I generate a stencil buffer with two possible values.
Values will have the following meaning for pass 2:
0: do not do anything
1: ok to proceed, (eg. enter the fragment shader, and render)
Pass 2 renders the scene properly speaking. The stencil buffer is
configured this way:
glStencilMask(1);
glStencilFunc(GL_EQUAL, 1, 1); // if the value is NOT 1, please early cull!
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // never write to stencil buffer
Now I run my app. The color of selected pixels is altered based on the
stencil value, which means the stencil test works fine.
However, I should see a huge, spectacular performance boost with early
stencil culling... but nothing happens. My guess is that the stencil test
either happens after the depth test, or even after the fragment shader has
been called. Why?
nVidia apparently has a patent on early stencil culling:
http://www.freepatentsonline.com/7184040.html Is this the right away for
having it enabled?
I'm using an nVidia GeForce GTS 450 graphics card. Is early stencil
culling supposed to work with this card? Running Windows 7 with latest
drivers.
Thanks, Fred

No comments:

Post a Comment