Early fragment culling using the stencil buffe
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.