Planar Shadows

I have shadow working in my little world, but i’m kind of worried that for each shadow i map on a surface, i have to clear the stencil buffer with glClear(GL_STENCIL_BUFFER_BIT), and this is too expensive in a big world…, if i need to project the model in 10 polygons it would be extremely expensive to clear the stencil buffer 10 times, wouldn’t it ?



You can setup three extra clippingplanes do deal with it. Set each clippingplane, so they touch the edge of each side of the triangle. Draw the whole shadow as usual, but instead of “cutting the shadow” in the stencil buffer, you do it with the planes.

And yes, shadows ARE complex. And they get even more complex if the shadowed surface is complex aswell. But as we all know, we usually gain visual quality by offering speed. Speed in this case becasue of extra clipping, or stencil operations, or whatever.

Good ideia…,

Another trick is to keep using up stencil
bits, and only clear when you run out of
bits (i e it’ll cut your clearing in 8 if
you have 8 bits stencil buffer).

In some circumstances, you can just keep
inverting the sense of each bit, so you
don’t have to keep clearing.

You might also be able to use a counter
value instead of bits, for a total of 255
different values (again, at 8 bits stencil).