Stencil Shadow Volume demo

Blitz3D Forums/Blitz3D Programming/Stencil Shadow Volume demo

I think the ATI problems are something to do with theway Blitz clears the Zbuffer, it needs to be False,False else every RenderWorld will clear them, and we don't want that.

The DeviceClear() should be clearing everything as needed at the beginning of each loop.

Here's a rough rundown of how all this works b.t.w (let's see if I got it right :)


Clear all buffers & render target

Show scene items

Enable Z writes, Disable Stencils

Renderworld (Color & Zbuffer is written)

Disable Zbuffer writes, hide scene, show shadow volume

Set stencil OPs, now the next RenderWorld affects Stencils only

RenderWorld (check each pixel Z value against old Zbuffer, write to Stencil on result)

Flip shadow volumes to now test back faces

Renderworld (check each pixels Z value against old Zbuffer, write to Stencil on result)

At this point, the Stencil Mask would only show pixels in the Scene, that are inside the shadow volume!

Now Disable Stencils & Zbuffer Writes, put a Shadow Plane in front of the camera, and set Stencil OPs to only render parts of the Shadow Plane where the Stencil = 1 (draws shadow color!)

Simple when you think about it, but the code looks messy :)