Depth fail Shadows.

Could someone tell me how to implement the whole “render the shadow volume back faces if depth fail then inc, else do nothing. Then render front faces, if depth fail decr else do nothing”.
To be more precise, how do you check if the depth test fails? In the depth pass approach its obvious, if it renders, it must have passed the depth test.
For depth fail, i can so far only think of a really inefficient way, render the back face with no depth testing into the stencil buffer and increment, then you render the back faces again with depth testing on this time, and you set the stencil to 0 where it renders. Then you repeat the same for the front faces.

However, this is really inefficient as you basically render teh shadow volume twice.

Did you read the description of StencilOp()? Do you understand when each of the three operations will be used? It should be fairly obvious how to apply those to what you describe. Like, almost word for word.

In general, I suggest downloading the OpenGL 1.4 specification PDF file from the front page of this web site, and reading through it.

However, this is really inefficient as you basically render teh shadow volume twice.

If you have a card that supports it, you can use the ‘two sided stencil’ extension so you don’t have to render the volume more than once. I think it’s only on the Radeon 9000 and higher series and the GeForce FX series though.

-SirKnight

To be more precise, how do you check if the depth test fails? In the depth pass approach its obvious, if it renders, it must have passed the depth test.

Read any OpenGL book/tutoral series/documentation on the stencil buffer. After that it will be obvious how to do this. Check the infinite shadow volume whitepaper on nvidia’s developer site for code example snippets. The full demo is on their dev site too.

-SirKnight

Originally posted by SirKnight:
[b] If you have a card that supports it, you can use the ‘two sided stencil’ extension so you don’t have to render the volume more than once. I think it’s only on the Radeon 9000 and higher series and the GeForce FX series though.

-SirKnight[/b]

Yes, you can use the multi-vendor EXT_stencil_two_side extension. NVIDIA supports the extension on GeForce FX and Quadro FX GPUs. Mesa supports the extension too even if for software rasterization.

The specification is here:
http://oss.sgi.com/projects/ogl-sample/registry/EXT/stencil_two_side.txt

There’s an example in the extension specification describing how to use it for single-pass rendering of stenciled shadow volumes.

While two-sided stencil testing definitely improves stenciled shadow volume rendering performance, the inefficiency of rendering stenciled shadow volumes in two passes with face culling may not be as great as you might first think (ie, it is NOT twice as slow as a single pass). While the vertices have to be transformed twice, the number of fragments rasterized is the same with two passes as it is with one two-sided stencil pass because each of the two pass only renders front-facing or back-facing polygons so in total, you rasterize the same number of triangles.

There’s still a CPU advantage and a vertex transformation advantage so you should use EXT_stencil_two_side if available.

  • Mark