Stencil Early Selection

I am trying to get an early selection of fragments to work based on a stencil test. My scenario is this: I have a fragment shader that does a lot of work, but only needs to be executed on very few fragments when I make my scene. These fragments can be located almost everywhere on the screen (I cannot use scissors to quickly filter these fragments).

In rendering 1, I create a stencil buffer with two possible values. The values ​​will have the following meaning for pass 2:

  • 0: do nothing
  • 1: ok to continue (for example, enter a fragment shader and render)

Pass 2 correctly displays the scene. The stencil buffer is configured as follows:

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 application. The color of the selected pixels changes based on the stencil value, which means that the stencil test works fine.

However, I should see a huge, impressive increase in productivity with an early selection of stencil ... but nothing happens. I assume that the stencil test happens either after the depth test, or even after the fragment shader has been called. Why?

nVidia obviously has a patent for the early selection of stencil: http://www.freepatentsonline.com/7184040.html Is this right away because it's on?

I am using an nVidia GeForce GTS 450 graphics card. Do you plan to use stencil early selection to work with this card? Starting Windows 7 with the latest drivers.

+4
source share
1 answer

Like early Z, early stencil is often performed using hierarchical stencil buffering.

There are a number of factors that can prevent the hierarchical tile from working properly, including rendering in FBO on older hardware. However, the biggest obstacle to early testing of the stencil that works in your example is that you left the template entries for 1 / (8) bits in the second pass.

I would suggest using glStencilMask (0x00) at the beginning of the second pass, so that the GPU knows that you are not going to write anything to the stencil buffer.

It is interesting to read the early testing of fragments, as it is implemented in the current generation hardware here . This entire blog is worth reading if you have the time.

+1
source

Source: https://habr.com/ru/post/1501644/


All Articles