Exercise 6: Standard Texture Effect
//
// Standard Texture Effect
// Copyright (c) 2000 Microsoft Corporation. All rights reserved.
//
vector matD; // Material diffuse
vector matS; // Material specular
vector matA; // Material ambient
DWORD lhtT; // Light type
vector lhtD; // Light diffuse
vector lhtS; // Light specular
vector lhtA; // Light ambient
vector lhtR; // Light direction
vector lhtP; // Light position
vector vOff; // Emboss offset
vector vVwD; // View direction
vector vCPS; // Camera position
matrix mEnv; // Environment map transform
matrix mWld; // World
matrix mTot; // Total
matrix mWl0; // Blending matrices
matrix mWl1;
matrix mWl2;
matrix mWl3;
matrix mWl4;
matrix mWl5;
matrix mWl6;
matrix mWl7;
matrix mIdt =
[
1.0,0.0,0.0,0.0,
0.0,1.0,0.0,0.0,
0.0,0.0,1.0,0.0,
0.0,0.0,0.0,1.0
];
DWORD BCLR = 0x0000000;
texture tDif; // Diffuse texture
texture tEnv; // Environment texture
texture tEvC; // Circulary integratex cube texture
texture tEvL;
texture tDf2; // Second texture
texture tDf3;
texture tDf4;
texture tSt1; // Procedural satin texture
texture tSt2; // Procedural stain texture2
texture tMt1; // Brushed metal texture
texture tFrn; // Fresnel Shader
texture tGlw; // Glow Shader
texture tL10; // Light lookup texture for spec
texture tL80;
texture tL64;
texture tL32;
texture tL16;
texture tfg1;
texture tfg2;
texture tNSE;
texture tNSN;
pixelshader pNIL;
string XFile = "tiny.x";
string Skinned = "true";
// Skinned version, lots of transforms have to happen here
vertexshader sDif =
decl
{
stream 0;
float v0[3]; // Blend weights
float v1[3]; // Indices
ubyte v2[4];
// OR
// d3dcolor v2[1]; // if hardware doesn't support ubyte, use d3dcolor instead
float v3[3];
float v7[3];
float v8[3];
}
asm
{
vs.1.1
// The indices are put into an color
// If ubyte is supported, this the right way to do it
mul r1,v2.xyzw,c41.zzzz
// OR
// If ubyte is not supported, decode from a 32 bit d3dcolor value
//mul r1,v2.zyxw,c41.wwww
// First compute the last blending weight
mov r0.xyz,v1.xyz;
dp3 r0.w,v1.xyz,c40.xxx;
add r0.w,-r0.w,c40.x
// Now do a bunch of matrix multiples,
// r5 = Position
// r6 = Normal
mov a0.x,r1.x
mov r5,v0
m4x3 r5,v0,c[a0.x]; //World matrices start at 0
m3x3 r6,v3,c[a0.x];
// Blend them
mul r5,r5,r0.xxxx
mul r6,r6,r0.xxxx
// Set 2
mov a0.x,r1.y
m4x3 r2,v0,c[a0.x];
m3x3 r3,v3,c[a0.x];
// Add them in
mad r5,r2,r0.yyyy,r5;
mad r6,r3,r0.yyyy,r6;
// Set 3
mov a0.x,r1.z
m4x3 r2,v0,c[a0.x];
m3x3 r3,v3,c[a0.x];
// Add them in
mad r5,r2,r0.zzzz,r5;
mad r6,r3,r0.zzzz,r6;
// Set 4
mov a0.x,r1.w
m4x3 r2,v0,c[a0.x];
m3x3 r3,v3,c[a0.x];
// Add them in
mad r5,r2,r0.wwww,r5;
mad r6,r3,r0.wwww,r6;
// Compute position
mov r5.w,c40.x
m4x4 oPos,r5,c50;
dp3 r11.x,r6.xyz,r6.xyz // Load the square into r1
rsq r11.xyz,r11.x // Get the inverse of the square
mul r6.xyz,r6.xyz,r11.xyz // Multiply
dp3 r4.xyz,r6,-c48
mov oD0.xyz,r4.xyz
mov oT0.xy,v7.xy
};
//Skinned Diffuse 1
string tec0 = "Exercise 6: Skinned Diffuse";
technique tec0
{
pass P0
{
ColorOp[0] = Modulate;
ColorArg1[0] = Texture;
ColorArg2[0] = Diffuse;
AlphaOp[0] = SelectArg1;
AlphaArg1[0] = Current;
ColorOp[1] = Disable;
AlphaOp[1] = Disable;
MinFilter[0] = Linear;
MagFilter[0] = Linear;
MipFilter[0] = Linear;
VertexShaderConstant[0] = <mWl0>;
VertexShaderConstant[4] = <mWl1>;
VertexShaderConstant[8] = <mWl2>;
VertexShaderConstant[12] = <mWl3>;
VertexShaderConstant[16] = <mWl4>;
VertexShaderConstant[20] = <mWl5>;
VertexShaderConstant[24] = <mWl6>;
VertexShaderConstant[28] = <mWl7>;
VertexShaderConstant[32] = <mIdt>;
VertexShaderConstant[50] = <mTot>; // mTot is just view*proj
VertexShaderConstant[48] = <lhtR>;
VertexShaderConstant[40] = (1.0f,-1.0f,0.0f,.0f);
VertexShaderConstant[41] = (0.00390625f, 256.0f, 4.0f,1020.01f);
VertexShaderConstant[43] = (0.0,0.0,1.0,0.0f);
VertexShaderConstant[44] = (0.0,0.0,0.0,0.0);
VertexShaderConstant[60] = (0.5,0.5,0.5,0.5);
VertexShaderConstant[60] = (1.0f,1.0f,1.0f,1.0f);
VertexShaderConstant[61] = (.50f,0.43f,0.38f,1.0f); // Sky color
VertexShaderConstant[62] = (0.18f,.10f,0.15f,1.0f); // Ground color
VertexShaderConstant[63] = <matD>; // Object color
VerteXShaderConstant[64] = (0.0f,1.0f,0.0f,1.0f); // Sky direction
Texture[0] = <tDif>;
vertexshader = <sDif>;
wrap0 = U | V;
wrap1 = U | V;
AddressU[0] = Wrap;
AddressV[0] = Wrap;
AlphaBlendEnable = False;
}
}