Exercise 7: Multi-Texturing with Shaders
//
// Effect File Workshop Exercise 7
// 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 tNSE; // Noise texture
// Background color
DWORD BCLR = 0xFF0000FF;
pixelshader pNIL;
string XFile = "sphere.x";
// Technique names for display in viewer window
string tec0 = "Exercise 7: Multi-Texturing with shaders";
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,0.0f,0.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] = <lhtR>; // Light direction
// Useful constant(s)
VertexShaderConstant[20] = (-1.0f,-1.0f,-1.0f,-1.0f);
Texture[0] = <tDif>;
Texture[1] = <tNSE>;
wrap0 = U | V;
wrap1 = U | V;
AddressU[0] = wrap;
AddressV[0] = wrap;
AddressU[1] = wrap;
AddressV[1] = 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]; // 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)
mov r0.xy,v7.xy // Copy texture coordinates to r0
//mul r0.y,r0.y,c20 // Invert texture coordinates
mov oT0.xy,r0.xy // Copy texture coordinates to oT0
mov oT1.xy,r0.xy // Copy texture coordinates to oT1
mov oD0,r0 // Copy diffuse to output
};
PixelShader =
asm
{
ps.1.1
tex t0 // Get texture sample from stage 0
tex t1 // Get texture sample from stage 1
mul_x2 r0,t1,t0; // Blend them together in an interesting way
};
}
}