Exercise 3: Transforms

DirectX8

 
Microsoft DirectX 8.1 (C++)

Exercise 3: Transforms

// 
// Effect File Workshop Solution for Exercise 3
// Copyright (c) 2001 Microsoft Corporation. All rights reserved.
//

vector lhtR;	// Light direction from app
vector matD; 	// Object diffuse material color

matrix mWld;	// World
matrix mTot;	// Total

// Load model
string XFile = "f40.x";

// Background Color
DWORD  BCLR = 0xff000000;

// No pixel shader
pixelshader pNIL; 

// Technique names for display in viewer window
string tec0 = "Solution 3: Transforms";

/////////////////////////////////////////////////////////////////////////////
///////        Exercise 3: Transforms                              //////////
///////     Transform the vertex normal into world space to take   //////////
///////     light source movement into consideration.              //////////
/////////////////////////////////////////////////////////////////////////////
technique tec0
{ 
    pass p0
    {
        // Load matrices
        VertexShaderConstant[0] = ;                   // World Matrix
        VertexShaderConstant[4] = ;                   // World*View*Proj Matrix
        
        // Material properties of object
        VertexShaderConstant[9]  = ;                  // Diffuse from object material diffuse
        VertexShaderConstant[10] = (0.0f,0.0f,0.0f,0.0f);   // Specular from constant color
        VertexShaderConstant[11] = (0.0f,0.0f,0.0f,0.0f);   // Ambient from constant color
        
        // Light Properties. lhtR is input from the shader app
        VertexShaderConstant[13] = (1.0f,0.9f,0.9f,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
        
        // Assign diffuse color to be used
        ColorOp[0]   = SelectArg1;
        ColorArg1[0] = Diffuse;
        AlphaOp[0]   = SelectArg1;
        AlphaArg1[0] = Diffuse;
        
        // Only one color being used
        ColorOp[1]   = Disable;
        AlphaOp[1]   = Disable;

        // Definition of the vertex shader, declarations then assembly
        VertexShader =
        decl
        {
            stream 0;
            float v0[3];        // Position
            float v3[3];        // Normal
            float v7[3];        // Texture coord1
            float v8[3];        // Texture coord2
        }   
        asm
        {
            vs.1.1              // Version number

            m4x4 oPos, v0, c4   // Transform point to projection space.
            
            mov  r0,v3          // Copy untransformed normal into r0.
            m3x3 r0,v3,c0       // Transform normal to world space, put result
                                //   into r0 so preceding mov not necessary.

    	    dp3  r0,r0,-c16     // Dot product against light, r0 now has lighting constant
                                // in x,y and z components (r,g,b).

            mul  r0,r0,c13      // Modulate against diffuse light color.
            mul  r0,r0,c9       // Modulate against diffuse material.
            
            mov oD0,r0          // Put into diffuse color output.
        };     
    }
}