This demo come from book <Direct3D Graphic Programming introduction>. It show mirror effect and shadow effect, both of them using stencil buffer. In the mirror effect, the stencil buffer used to figure out the mirror area on the screen, so that these objects that should be displayed on this mirror will not beyond it’s boundary. For the shadow effect, actually we could it blob shadow. This technology working like that projecting a 3D object into a 2D plane. The stencil buffer used here to avoid overlap some pixels that already marked as shadow. The first time shadow shadered with stencil marked, and the second time will do stencil checking. If it already, this time will be skipped.
Although the stencil buffer is just a single value, or single channel mark buffer, it is very useful. For example, stencil volume shadow that use stencil buffer. Pre-calculate the light’s volume into the stencil buffer, we could skip a lot of pixel lighting calculation.
D3DX library provide some useful function: 1) D3DXMatrixShadow() build a projection matrix that project a object along a direction to a 2D plane. 2) D3DXMatrixReflect() build a matrix that reflect against a plane.
The full source code could be download from here.
本文介绍Direct3D图形编程中使用模板缓冲实现的镜像与阴影效果。通过投影3D对象到2D平面创建阴影,并利用模板缓冲避免像素重复标记。镜像效果则确保屏幕上的镜面区域正确显示对象。文章还提供了D3DX库的实用函数,如D3DXMatrixShadow和D3DXMatrixReflect。

1982

被折叠的 条评论
为什么被折叠?



