Stencil support

· by Steve · Read in about 2 min · (332 Words)

Sorry for the lack of updates, my working week has been awful and I had to put some hours in over the weekend too, so OGRE has suffered. I haven’t stood still though, I had a bit of a problem with D3D9 in that I wanted to use the approach covered in a recent nVidia paper where you use an xyzw position buffer to do shadow extrusion and rendering of the original mesh, however D3D9 would not render the original mesh from the 4d position buffer. Turns out this is a limitation in fixed-function D3D (GL handles it fine), which is extremely annoying, because I need to use the same buffers for both fixed-function and vertex program rendering. Rather than duplicate entire buffers because of this shortcoming, I’ve separated off the ‘w’ component into a 1D texture coord buffer which I ony use when extruding the shadow. It’s a hack though, and I’ve made my opinion clear on the directx newsgroups about poor design choices, for all the good it will do 😉 Why is it that D3D changes interface every version, but GL stays stable, just with a gradual addition of extensions? Because it’s designed better, that’s why.

Tonight I revamped the stencil operations in the render systems and added support for 2-sided stencil operations. These let you perform different operations for front and back faces without having to render the geometry twice, which is a good saving. D3D9 and GL both support this, although not every card does so I’m having to code for both circumstances.

I’m also adding support for 2 stencil shadow types - the ‘proper’ sort where you perform a complete rendering cycle per light, adding the results together, and a cheaper version where you render as normal, but perform a post-render modulation instead, with the stencil comparison operation inverted so you render where there is shadow instead of where there isn’t. You also only have to render a quad over the whole screen to achieve this.