Game Development Reference
In-Depth Information
D3DMATERIAL9 mtrl = d3d::InitMtrl(d3d::BLACK, d3d::BLACK,
d3d::BLACK, d3d::BLACK, 0.0f);
mtrl.Diffuse.a = 0.5f; // 50% transparency.
// Disable depth buffer so that z-fighting doesn't occur when we
// render the shadow on top of the floor.
Device->SetRenderState(D3DRS_ZENABLE, false);
Device->SetMaterial(&mtrl);
Device->SetTexture(0, 0);
Teapot->DrawSubset(0);
Device->SetRenderState(D3DRS_ZENABLE, true);
Device->SetRenderState(D3DRS_ALPHABLENDENABLE, false);
Device->SetRenderState(D3DRS_STENCILENABLE,
false);
}//end RenderShadow()
8.4 Summary
The stencil buffer and depth buffer share the same surface and are
therefore created at the same time. We specify the format of the
depth/stencil surface using the D3DFORMAT types.
Stenciling is used to block certain pixels from being rasterized. As
we have seen in this chapter, this ability is useful for implementing
mirrors and shadows among other applications.
We can control stenciling operations and how the stencil buffer is
updated through the D3DRS_STENCIL* render states.
Some other applications that can be implemented with the stencil
buffer:
Shadow volumes
Dissolves and fades
Visualizing depth complexity
Outlines and silhouettes
Constructive solid geometry
Fixing z-fighting caused by coplanar geometry
Search WWH ::




Custom Search