|XNA 4.0 Normal Mapping Demo.
This Windows XNA application demonstrates tangent space normal mapping. An effect (.fx) file is provided that implements tangent space normal mapping using a series of HLSL shaders. The lighting models implemented are: directional lighting, point lighting, and spotlight lighting.
Tangent space normal mapping involves evaluating the lighting equations per pixel in the surface local coordinate space of the normal map texture. Rather than using the mesh's interpolated vertex normals tangent space normal mapping uses the normals from the normal map texture instead. Doing this allows additional surface detail to be applied to each triangle of the mesh without requiring extra geometry to be added to the mesh.
1. This demo requires shader model 2.0 or higher support.
2. This demo is provided in source form only. No pre built binaries are supplied.
Download source, assets, and XNA Game Studio 4.0 solution files.
15 January 2011.
Initial release of demo for XNA Game Studio 4.0. The previous XNA Game Studio 3.0 version of the demo is no longer supported and is now only available upon request.
16 November 2008.
Initial release of demo for XNA Game Studio 3.0. The previous XNA Game Studio 2.0 version of the demo is no longer supported and is now only available upon request.
27 January 2008.
Initial release of demo for XNA Game Studio 2.0. The original XNA Game Studio Express 1.0 Refresh version of the demo is no longer supported and is now only available upon request.
4 January 2008.
Demo.cs: Removed attenuation field from the Light structure. Added light radius field to the Light structure. Added camera setting constants: CAMERA_FOVY, CAMERA_ZNEAR, CAMERA_ZFAR. Added constants for the cube: CUBE_DOLLY_MIN, CUBE_DOLLY_MAX, CUBE_SIZE, CUBE_SPEED_DOLLYING, CUBE_SPEED_ROTATING, CUBE_SPEED_TRACKING. Added constant for the light radius. Added a field for the cube position. Added a field to store cube x and y axis rotations. Added fields to support a simple frame rate counter. Changed ProcessMouse() method to manipulate the cube instead of the camera. Added ToggleFullScreen() method. The UpdateEffect() method now includes a translation transformation for the world matrix. Added a simple frame rate counter. Implementation is in the UpdateFrameRate() method. This method is called once per frame in the Draw() method.
normal_mapping.fx: Switched to a new light attenuation method based on a light radius. Changed all vector outputs from the vertex shaders to float3. Added diffuse and specular outputs for the vertex shaders. Fixed bug in the vertex shaders where the worldInverseTransposeMatrix was not being cast to a float3x3. Updated pixel shaders to use the float3 vector outputs from the vertex shaders. Updated pixel shaders to use the diffuse and specular outputs from the vertex shaders.
7 November 2007.
Program.cs: Removed file. Contents have been merged into the Demo.cs file.
Demo.cs: Added Light and Material structures. Refactored existing light and material fields into these structures. These structures match the ones in the effect file (normal_mapping.fx). Rewrote the keyboard and mouse processing methods.
NormalMappingUtils.cs: Replaced the NormalMappedVertex.CalcTangentSpaceVectors() method with the NormalMappedVertex.CalcTangent() method. Removed the bitangent field from the NormalMappedVertex structure. Removed the debugging methods in the NormalMappedCube class that draws the tangent space basis vectors.
normal_mapping.fx: Fixed a bug in the vertex shaders where the tbnMatrix was being incorrectly calculated. The vertex shaders now calculate the bitangent vectors. The vertex shaders now use the handedness stored in the tangent vectors when calculating the bitangent vectors. Removed the no texturing techniques.
28 April 2007.
Demo.cs: Now uses the XNA default clockwise triangle winding order.
NormalMappingUtils.cs: Updated the NormalMappedCube class to use XNA's default clockwise triangle winding order. Changed the namespace to Dhpoware.
24 January 2007.
Updated solution so that Content is no longer copied to the output directory.
NormalMappingUtils.cs: Moved NormalMappedCube.CalcTangentSpaceVectors() method to NormalMappedVertex structure. Updated CalcTangentSpaceVectors() method to check if the texture has been mapped backwards onto the triangle.