Exercise 4: Texturing
//
// Effect File Workshop Solution for Exercise 4
// 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
texture tDif; // Diffuse texture of object
// Load model
string XFile = "bust.x";
// Background color
DWORD BCLR = 0xff000000;
// No pixel shader
pixelshader pNIL;
// Technique names for display in viewer window
string tec0 = "Exercise 4: Texturing";
/////////////////////////////////////////////////////////////////////////////
/////// Exercise 4: Texturing //////////
/////// Set up texture to pass onto FF PS //////////
/////// Modulate between the texture and diffuse color args. //////////
/////////////////////////////////////////////////////////////////////////////
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] = (0.8f,0.8f,0.8f,0.8f); // Diffuse
VertexShaderConstant[14] = (0.0f,0.0f,0.0f,0.0f); // Specular
VertexShaderConstant[15] = (0.3f,0.3f,0.3f,1.0f); // Ambient
VertexShaderConstant[16] = ; // Light Direction
// Useful constant(s)
VertexShaderConstant[20] = (-1.0f, -1.0f, 0.5f, 1.0f);
// Assign diffuse texture
Texture[0] = ;
// Set up texture wrapping mode
wrap0 = U | V;
AddressU[0] = Wrap;
AddressV[0] = Wrap;
// Assign texture color to be used
ColorArg1[0] = Texture;
ColorOp[0] = Modulate; // Modulate between args
ColorArg2[0] = Diffuse; // Add diffuse component as arg
AlphaOp[0] = SelectArg1;
AlphaArg1[0] = Diffuse;
// Ensure remaining stages are disabled
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
m3x3 r0,v3,c0 // Transform Normal to World Space, put result into r0
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 // Output diffuse color
//mov oT0,v7 // output texture coordinates
// OR
mov oT0.xy,v7.xy // output only the xand y channels for better efficiency
};
}
}