I use a computiationally expensive fragment shader in a multipass algorithm. I want to compute fragments which are not marked in eralier iterations. My question is:
When do such tests as Depth-Test, Stencil test and Alpha test happend - before or after the fragment processor?
Is it right, that early-z happens before the fragment processor if gl_FragDepth is not touched in the fragment shader?
All tests are done after the fragment shader in order scissor->alpha->stencil->depth
Yes, this is correct, but there may be additional conditions. On nvidia hardware, you cannot use early-z if rejection of a fragment would still lead to changes in depth/stencil/color. So basically, if you modify stencil on depth fail, you won’t get early-z.
The logical location of the depth/stencil test is after shading. In practice we do it early when we can.
Early z testing has lots of possible implementations, so it’s difficult to make claims that are universal. For example on GeForce 6 series and beyond, you can get early z rejection even when the depth buffer is being updated.
Hi,
Thanks for your answers. I still have problems with the early-Z. I have got a multipass algorithm, which just filters the input Texture (> 1024x1024) (ping-pong), so at the end I receive a set of numIterations textures, filtered.
I want to disable smoothing certain areas - I do this in an additional pass before the smoothing:
Afterwards the fbo is bound as texture and drawn to the screen. I can see that the rectangle in the middle is masked out (so depth test works), but no increase in performance.
everything works fine. The whole screen is blocked , and fps = 385.
When I now write the depth in the shader (from my post above), the framerate drops to 39. This is what I expected, beacause early-Z is disabled.
Now I want to “mark” the regions in the depth buffer. I replace the line
// I draw nothing into the depthbuffer
with the lines
glBegin( GL_QUADS ); {
glVertex3f( 0, 0, -1.0 );
glVertex3f( 1, 0, -1.0 );
glVertex3f( 1, 1, -1.0 );
glVertex3f( 0, 1, -1.0 );
} glEnd();
[/CODES]
which mimic the behavior of the 1st example. I don't change depth values afterwards, but fps stays at 39fps. Shouldn't they go up to 385?
thanks again