Exercise 10: Anisotropic Bump Mapping
//
// Effect File Workshop Exercise 10
// Copyright (c) 2000 Microsoft Corporation. All rights reserved.
//
vector lhtR; // Light direction
matrix mWld; // World
matrix mTot; // Total
texture tDif; // Diffuse texture of object
texture tDf4; // Normal map for earth
texture tSt2; // Anisotropic lighting table
vector vCPS; // Camera position
// Background color
DWORD BCLR = 0xFF0000FF;
pixelshader pNIL;
string XFile = "bust.x";
// Technique names for display in viewer window
string tec0 = "Exercise 10: Anisotropic Bump Mapping";
technique tec0
{
pass p0
{
// Load matrices
VertexShaderConstant[0] = <mWld>; // World Matrix
VertexShaderConstant[4] = <mTot>; // World*View*Proj Matrix
// Material properties of object
VertexShaderConstant[9] = (1.0f,1.0f,1.0f,1.0f); // Diffuse
VertexShaderConstant[10] = (0.0f,0.0f,0.0f,0.0f); // Specular
VertexShaderConstant[11] = (0.0f,0.0f,0.0f,0.0f); // Ambient
// Properties of light
VertexShaderConstant[13] = (1.0f,1.0f,1.0f,1.0f); // Diffuse
VertexShaderConstant[14] = (0.0f,0.0f,0.0f,0.0f); // Specular
VertexShaderConstant[15] = (0.0f,0.0f,0.0f,0.0f); // Ambient
VertexShaderConstant[16] = ; // Light direction
vertexShaderConstant[20] = (.5f,.5f,.5f,.5f);
vertexShaderConstant[40] = (1.0f,1.0f,1.0f,1.0f);
// Camera information
VertexShaderConstant[24] = <vCPS>;
PixelShaderConstant[0] = (0.5f, 0.2f, 0.2f, 0.2f);
Texture[0] = <tDf4>;
Texture[3] = <tSt2>;
wrap0 = U | V;
wrap1 = 0;
wrap2 = 0;
wrap3 = 0;
AddressU[0] = wrap;
AddressV[0] = wrap;
AddressU[1] = wrap;
AddressV[1] = wrap;
AddressU[3] = wrap;
AddressV[3] = wrap;
MinFilter[0] = Linear;
MagFilter[0] = Linear;
MinFilter[1] = Linear;
MagFilter[1] = Linear;
VertexShader =
decl
{
stream 0;
float v0[3]; // Position
float v3[3]; // Normal
float v7[3]; // Texture Coord1
float v8[3]; // Tangent
}
asm
{
vs.1.1
// Transform position
m4x4 oPos,v0,c4
// Transform normal and tangent
m3x3 r7,v8,c0
m3x3 r8,v3,c0
// Cross product
mul r0,-r7.zxyw,r8.yzxw;
mad r5,-r7.yzxw,r8.zxyw,-r0;
// Transform position
m4x4 r2,v0,c0
// Get a vector toward the camera
add r2,-r2,c24
dp3 r11.x,r2.xyz,r2.xyz // Load the square into r11
rsq r11.xyz,r11.x // Get the inverse of the square
mul r2.xyz,r2.xyz,r11.xyz // Multiply, r0 = -(camera vector)
// Transform the view angle vector
dp3 r6.x,r7,r2
dp3 r6.y,r5,r2
dp3 r6.z,r8,r2
// Transform the light vector
dp3 r2.x,r7,-c16
dp3 r2.y,r5,-c16
dp3 r2.z,r8,-c16
mov oT0.xy,v7.xy // Coordinates to samp normal from
mov oT1.xyz,r2 // Light
mov oT2.xyz,r6 // View angle
mov oT3.xyz,c40 // Garbage in this register
};
PixelShader =
asm
{
ps.1.1
tex t0
texm3x3pad t1, t0_bx2 // 3x3 transform
texm3x3pad t2, t0_bx2 // These generate a texcoord which is
texm3x3tex t3, t0_bx2 // u = dot(light,normal)
// v = dot(view, normal)
// w = some positive number
mov r0,t3;
mad r0,c0,t3.a,r0; // Alpha has the diffuse, so add it
// to specular for final result
};
}
}