|Microsoft DirectX 9.0|
The ClipVolume sample demonstrates a technique for using shaders to "subtract" a sphere from an arbitrary model when rendering. This technique could be useful in visualization applications to see inside complex objects. The sample also shows how to perform two-sided lighting.
Source: (SDK root)\Samples\C++\Direct3D\ClipVolume
Executable: (SDK root)\Samples\C++\Direct3D\Bin
The following table lists the keys that are implemented. You can use menu commands for the same controls.
|ENTER||Starts and stops the scene.|
|SPACEBAR||Advances the scene by a small increment.|
|F1||Shows help or available commands.|
|F2||Prompts the user to select a new rendering device or a new display mode.|
|ALT+ENTER||Toggles between full-screen and windowed modes.|
|ESC||Exits the application.|
The mouse is also used in this sample to control the viewing position.
The sample creates two ID3DXMesh objects, one for the teapot and one for the sphere. A vertex shader and pixel shader are used when rendering the teapot, and a different vertex shader is used to render the sphere.
The sphere's vertex shader doesn't do anything unusual; it just performs the standard world-view projection transformation on the vertex position and sets the diffuse color to be dark blue with 50 percent alpha. Note that the sphere is drawn for illustration purposes only. The rendering of the sphere is not necessary to get the clipping effect shown in the sample.
The teapot's vertex shader does three tasks as follows:
The teapot's pixel shader uses the texkill instruction to not render any pixel if any texture coordinate is less than zero. The x-texture coordinate will be negative for all vertices and pixels inside the sphere, so this prevents any pixels inside the sphere from being rendered.
This sample uses the sample framework code that is shared with other samples in the Microsoft?DirectX® software development kit (SDK). You can find the sample framework headers and source code in (SDK root)\DXSDK\Samples\C++\Common\Include and (SDK root)\DXSDK\Samples\C++\Common\Src.