HLSL Bump Mapping       

This program shows how to achieve a bump effect with HLSL shaders. There are three distincts objects : the three walls, the floor and the torus. Each one has a texture and a normal map stored in a texture. The diffuse lighting needs to calculate the dot product of the normal and the light vector. We need to assure that both vectors are in the same space before to calcultate the dot product. To achieve this, we must choose a common space, like object space. But this would require to transfer all the normals of the map in this space. Instead, we prefer to translate the light vector in the same space as the normal map. We call it the tangent space. This is the space which is localy tangent to the surface.

For each vertex, we need to calculate the matrix to transform a vector from object space to this tangent space. Therefore, we need a basis of this space. If we know the actual normal and the tangent vector, we can calculate their cross product and this leads to three vectors which form a basis for this new space (and also give us the transaltion matrix from object space to tangent space). For the walls and floor, normal and tangent in object space are part of our custom format vertex. For the torus, the analytical formula allows to easily calculate normal and tangent vectors from the derivatives (gradient in terms of s and t which are the two parameters of the torus).

Eventualy, we get the correct dot product for normal and light vector, thus we have a diffuse coefficient. For better realism, we add attenuation growing whith distance from light. Figures below illustrates the results.

Normal maps are generated with the NVidia plug-in filter for Photoshop.


Download

download  : exe+sources (C++,HLSL projet sous Visual C++ 6.0) (1380ko)

ps : you need to download my framework lib do compile the files.

Require a graphic card with support of vertex shader 2_0 et pixel shader 2_0.


Screenshots Gallery

 
 
 
 
 
 
 
 
 
 
 

 

 

 

 

Author :  Adrien Auclair  
adrien.auclair at club-internet.fr
Last update : 21/09/2004