Platform SDK: DirectX |
User-defined clip planes enable applications to clip geometry in a scene by applying arbitrary clip planes. These clipping planes are described by the general plane equation, which the system assumes to be in world-space.
The following image is taken from a version of the Spheremap sample, slightly modified to emphasize the effects of clipping. (The sample was modified to render in wire-frame, with back-face culling disabled.) In this image, no clip planes are applied.
When user-defined clipping planes are applied, you can easily clip the geometry in a scene. A point with world-coordinates coordinates (x, y, z) are clipped from the half space of the plane if the following inequality is satisfied.
In the preceding formula, A, B, C, and D are coefficients supplied by an application to the system to define a plane. Points that exist on or behind the clipping plane are clipped from the scene. The following image shows two teapots, clipped by two different planes.
The teapot on the left has been clipped by a plane that has the coefficients [A = -1.0, B = 0.0, C = 0.0, D = 0.0], which causes the system to clip all vertices with at x >=0. The teapot on the right was clipped by a plane defined by the coefficients [A = 1.0, B = 0.0, C = 1.0, D = 0.0], which clips all vertices at z >= 0.0.
You can clip geometry by clipping with multiple planes. When you use multiple clip planes, the rendered area is the union of the half-spaces defined by each plane. The following image shows the teapot clipped by two planes.
The teapot in the preceding image was clipped by two planes: one with the coefficients [A = 1.0, B = 0.0, C = 0.0, D = 0.0], and another plane defined by the [A = 0.0, B = -1.0, C = 0.0, D = 0.0] coefficients.
Direct3D supports clipping with up to 32 (D3DMAXUSERCLIPPLANES) clipping planes, although device support can vary. To be sure, always check device capabilities for the current device (the wMaxUserClipPlanes member of the D3DDEVICEDESC7 structure).
Direct3D supports clipping with up to 32 clipping planes, although device support can vary. To be sure, always check device capabilities for the current device (the nMaxUserClipPlanes member of the D3DDEVICEDESC7 type).
User-defined clip planes can be used for much more than the simple geometry clipping shown here, although this can be useful in many cases. You might combine user-defined clip planes and stencil buffers to perform advanced tasks like capping, or interference testing.