Microsoft DirectX 8.1 (C++)

DotProduct3 Sample

Description

The DotProduct3 sample demonstrates an alternative approach to Microsoft® Direct3D® bump mapping. This technique is named after the mathematical operation that combines a light vector with a surface normal. The normals for a surface are traditional (x,y,z) vectors stored in RGBA format in a texture map—called a normal map for this technique.

Not all cards support DotProduct3 blending texture stages, and not all cards support Direct3D bump mapping.

Path

Source: (SDK root)\Samples\Multimedia\Direct3D\BumpMapping\DotProduct3

Executable: (SDK root)\Samples\Multimedia\Direct3D\Bin

User's Guide

The following table lists the keys that are implemented. You can use menu commands for the same controls.

Key Action
ENTER Starts and stops the scene.
SPACEBAR Advances the scene by a small increment.
F2 Prompts the user to select a new rendering device or display mode.
ALT+ENTER Toggles between full-screen and windowed modes.
ESC Exits the application.

Programming Notes

The lighting equation for simulating bump mapping involves using the dot product of the surface normal and the lighting vector. The lighting vector is passed into the texture factor, and the normals are encoded in a texture map. The blend stages look like this:

SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_DOTPRODUCT3 );
SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_TFACTOR );

The next step is to store the normals in the texture. To do this, the components of a vector (XYZW) are each turned from a 32-bit floating value into a signed 8-bit integer and packed into a texture color (RGBA). The code shows how to do this using a custom-generated normal map, as well as one built from a bump mapping texture image.

Not all cards support all features for bump mapping techniques. Some hardware has no, or limited, bump mapping support. For more information on bump mapping, refer to the Microsoft® DirectX® SDK documentation.

This sample uses common DirectX code that consists programming elements such as helper functions. This code is shared with other samples in the DirectX SDK. You can find the common headers and source code in (SDK root)\Samples\Multimedia\Common.