It's free to join Gamasutra!|Have a question? Want to know who runs this site? Here you go.|Targeting the game development market with your product or service? Get info on advertising here.||For altering your contact information or changing email subscription preferences.
Registered members can log in here.Back to the home page.

Search articles, jobs, buyers guide, and more.

By Kim Pallister
Gamasutra
June 4, 1999

Letters to the Editor:
Write a letter
View all letters


Features

 

Contents

Introduction

Embossing, Part 1

Code Listing 1

DirectX 6 Environment-Map Bump Mapping

Code Listing 2

Using Bump Mapping Effects

Implementing the Techniques

DirectX 6 Environment-Map Bump Mapping

DirectX implements bump mapping using a technique best described as "environment-map bump mapping". This method can only be used on systems with hardware that specifically supports it. (See Table 2 for information regarding which DirectX caps bits indicate support under Direct3D). In the coming months, there will be a few 3D accelerator cards that support this method of bump mapping in hardware. Those announced include the Matrox G-400 and the 3D Labs Permedia3, and it is likely that many others will follow. The wide variety of effects it can achieve are impressive. We’ll get into it some of those later, but first, let’s see how the feature works and how it is used.

In DirectX 6, bump mapping is implemented using two textures (not including the object’s base texture). The first is a bump map which contains slope information (you can think of it as a height differential map), rather than height information, as is the case with the embossing method. (The bump map is generated by comparing adjacent texels in the height map). Hardware that supports DirectX 6 bump mapping uses these values to perturb the texel coordinates used in the lookup into a second texture (as opposed to using the data to alter the polygon’s normals). The second texture is an environment map, which is rendered onto the original polygon using these perturbed UV coordinates. Figure 2B shows what this looks like, where the environment map in this case is the scene above the water, render to a texture).

By making the environment map a radial gradient lightmap (something like you'd get holding the airbrush tool in a paint package in one place and holding down the mouse button for a second), we can achieve the same effect as the earlier embossing technique. Additionally, we are not limited to a single light source, nor to monochrome lighting.

The technique is as follows. First, set up D3Dtexture2 surfaces for the object’s base texture and the environment map, and fill them with bitmap data as usual. Next, set up a D3Dtexture2 for the bump map, but specify a couple additional caps bits during the DirectDraw surface creation. If necessary, create a height differential map from a height map. (I say "if necessary" because the bump map could be stored this way already, but if a height map is used, it needs to be modified.) Creating a height differential map from a height map simply involves stepping through the bitmap, and comparing neighboring pixels to get the slope, as shown in Listing 2. When you have the height differential map created, assign it to the surface you want to be bump mapped . Then you should set up the Direct3D texture cascade for the three textures and for the bump mapping-related D3DtextureStageState variables. These would be:

Stage 0 – Set texture to base texture (as usual)

Stage 1 - Set texture to bump map

Stage 2 – Set texture to environment map

For Stage 1, The additional render state values that can optionally be set up are:

  • D3DTSS_BUMPENVMATXX (where XX is 00, 01, 10 or 11). This is a 2x2 "bump mapping matrix".
  • D3DTSS_BUMPENVSCALE and D3DTSS_BUMPENVOFFSET. These two values alter the effect of the luminance component of the bump map, if a bump map with luminance is being used. (The luminance aspect is explained below).

The only thing left to do in each frame is render the triangles. Listing 2 is a code snippet demonstrating this technique.


Listing 2 - Code


join | contact us | advertise | write | my profile
news | features | companies | jobs | resumes | education | product guide | projects | store



Copyright © 2003 CMP Media LLC

privacy policy
| terms of service