i got some fx files if they'd be of any use.
this is the area lighting fx
//34567890123456789012345678901234567890123456789012345678901234567890123456789
// Effect file workshop Exercise 1
// Copyright (c) 2000 Microsoft Corporation. All rights reserved.
//
vector lhtR; //light Direction
vector matD; // material Diffuse
matrix mWld; // World
matrix mTot; // Total
texture tDif; // diffuse texture of object
//background color
DWORD BCLR = 0xFF000000;
pixelshader pNIL;
string XFile = "skullhiv.x";
//string XFile = "sphere.x";
// Technique names for display in viewer window:
string tec0 = "Area Lighting, 2-terms";
string tec1 = "Area Lighting + Darkening, 3-terms";
string tec2 = "Area and Diffuse Lighting, 4-terms";
technique tec0
{
pass p0
{
//load matrices
VertexShaderConstant[0] = <mWld>; //World Matrix
VertexShaderConstant[4] = <mTot>; //World*View*Proj Matrix
//Material properties of object
VertexShaderConstant[9] = <matD>; //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] = <lhtR>; //Light Direction
vertexShaderConstant[20] = (.5f,.5f,.5f,.5f);
vertexShaderConstant[40] = (1.0f,1.0f,1.0f,1.0f);
vertexShaderConstant[41] = (1.00f,0.86f,0.75f,1.0f); //sky color
vertexShaderConstant[42] = (0.25f,.25f,0.15f,1.0f); //ground color
vertexShaderConstant[43] = <matD>; //object color
VerteXShaderConstant[44] = (0.0f,-1.0f,0.0f,1.0f); //sky direction
Texture[0] = <tDif>;
wrap0 = U | V;
wrap1 = 0;
wrap2 = 0;
AddressU[0] = wrap;
AddressV[0] = wrap;
MinFilter[0] = Linear;
MagFilter[0] = Linear;
MinFilter[1] = Linear;
MagFilter[1] = Linear;
ColorOp[0] = Modulate;
ColorArg1[0] = Diffuse;
ColorArg2[0] = Texture;
AlphaOp[0] = SelectArg1;
AlphaArg1[0] = Diffuse;
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
m4x4 oPos,v0,c4 //tranform position
m3x3 r0,v3,c0 //tranform normal to world space
dp3 r0,r0,-c44 //dot product against sky vector
//the dot product was between -1 to 1. We want to re-range
//this to 0 to 1
mad r0,r0,c20,c20
//now lerp between the two sky colors
mov r1,c42
sub r1,c41,r1 //to save a clock, this delta should be saved
//in a register
mad r0,r1,r0,c42 //now lerp
// sub r1,c40,v7.zzz //this modulates against a darkening term
//or occlusion term, embedded in the z tex
//cordinate, we want 1-z though
// mul r0,r0,r1 //darken sky term
mul oD0,r0,c9 //now modulate against object's color
mov oT0.xy,v7.xy
};
}
}
technique tec1
{
pass p0
{
//load matrices
VertexShaderConstant[0] = <mWld>; //World Matrix
VertexShaderConstant[4] = <mTot>; //World*View*Proj Matrix
//Material properties of object
VertexShaderConstant[9] = <matD>; //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] = <lhtR>; //Light Direction
vertexShaderConstant[20] = (.5f,.5f,.5f,.5f);
vertexShaderConstant[40] = (1.0f,1.0f,1.0f,1.0f);
vertexShaderConstant[41] = (1.00f,0.86f,0.75f,1.0f); //sky color
vertexShaderConstant[42] = (0.25f,.25f,0.15f,1.0f); //ground color
vertexShaderConstant[43] = <matD>; //object color
VerteXShaderConstant[44] = (0.0f,-1.0f,0.0f,1.0f); //sky direction
Texture[0] = <tDif>;
wrap0 = U | V;
wrap1 = 0;
wrap2 = 0;
AddressU[0] = wrap;
AddressV[0] = wrap;
MinFilter[0] = Linear;
MagFilter[0] = Linear;
MinFilter[1] = Linear;
MagFilter[1] = Linear;
ColorOp[0] = Modulate;
ColorArg1[0] = Diffuse;
ColorArg2[0] = Texture;
AlphaOp[0] = SelectArg1;
AlphaArg1[0] = Diffuse;
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
m4x4 oPos,v0,c4 //tranform position
m3x3 r0,v3,c0 //tranform normal to world space
dp3 r0,r0,-c44 //dot product against sky vector
//the dot product was between -1 to 1. We want to re-range
//this to 0 to 1
mad r0,r0,c20,c20
//now lerp between the two sky colors
mov r1,c42
sub r1,c41,r1 //to save a clock, this delta should be saved
//in a register
mad r0,r1,r0,c42 //now lerp
sub r1,c40,v7.zzz //this modulates against a darkening term
//or occlusion term, embedded in the z tex
//cordinate, we want 1-z though
mul r0,r0,r1 //darken sky term
mul oD0,r0,c9 //now modulate against object's color
mov oT0.xy,v7.xy
};
}
}
technique tec2
{
pass p0
{
//load matrices
VertexShaderConstant[0] = <mWld>; //World Matrix
VertexShaderConstant[4] = <mTot>; //World*View*Proj Matrix
//Material properties of object
VertexShaderConstant[9] = <matD>; //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] = (.6f,.6f,.6f,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
vertexShaderConstant[20] = (.5f,.5f,.5f,.5f);
vertexShaderConstant[40] = (1.0f,1.0f,1.0f,1.0f);
vertexShaderConstant[41] = (.80f,0.76f,0.65f,1.0f); //sky color
vertexShaderConstant[42] = (0.25f,.25f,0.15f,1.0f); //ground color
vertexShaderConstant[43] = <matD>; //object color
VerteXShaderConstant[44] = (0.0f,-1.0f,0.0f,1.0f); //sky direction
// FillMode = Wireframe;
Texture[0] = <tDif>;
wrap0 = U | V;
wrap1 = 0;
wrap2 = 0;
AddressU[0] = wrap;
AddressV[0] = wrap;
MinFilter[0] = Linear;
MagFilter[0] = Linear;
MinFilter[1] = Linear;
MagFilter[1] = Linear;
ColorOp[0] = Modulate;
ColorArg1[0] = Diffuse;
ColorArg2[0] = Texture;
AlphaOp[0] = SelectArg1;
AlphaArg1[0] = Diffuse;
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
m4x4 oPos,v0,c4 //tranform position
m3x3 r9,v3,c0 //tranform normal to world space
dp3 r0,r9,-c44 //dot product against sky vector
//the dot product was between -1 to 1. We want to re-range
//this to 0 to 1
mad r0,r0,c20,c20
//now lerp between the two sky colors
mov r1,c42
sub r1,c41,r1 //to save a clock, this delta should be saved
//in a register
mad r0,r1,r0,c42 //now lerp
sub r1,c40,v7.zzz //this modulates against a darkening term
//or occlusion term, embedded in the z tex
//cordinate, we want 1-z though
mul r2,r0,r1 //darken sky term
dp3 r1,r9,-c16 // dot against light vector
max r1, c15, r1
// complement, square, complement
sub r1, c40, r1
mul r1, r1, r1
mul r1, r1, r1
sub r1, c40, r1
mad r0,r1,c13,r2 // combine with light diffuse
mul oD0,r0,c9 //now modulate against object's color
mov oT0.xy,v7.xy
};
}
}
this is the diffuse+specular fx:
//34567890123456789012345678901234567890123456789012345678901234567890123456789
// Effect file workshop Exercise 1
// 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 tDf3; // normal map for earth
texture tL10; // Light lookup texture for spec
texture tL80;
texture tL64;
texture tL32;
texture tL16;
vector vCPS; // Camera Position
//background color
DWORD BCLR = 0xFF0000FF;
pixelshader pNIL;
string XFile = "sphere.x";
// Technique names for display in viewer window:
string tec0 = "Diffuse";
string tec1 = "Multiply Specular";
string tec2 = "Table Specular";
technique tec0
{
pass p0
{
//load matrices
VertexShaderConstant[0] = <mWld>; //World Matrix
VertexShaderConstant[4] = <mTot>; //World*View*Proj Matrix
//Material properties of object
VertexShaderConstant[9] = (0.8f,0.8f,0.8f,0.8f); //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] = (0.7f,0.7f,0.7f,0.7f); //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
vertexShaderConstant[20] = (.5f,.5f,.5f,.5f);
//Camera Information
VertexShaderConstant[24] = <vCPS>;
Texture[0] = <tDif>;
Texture[1] = <tDf3>;
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]; //Tangent
}
asm
{
vs.1.1
//tranform position
m4x4 oPos,v0,c4
//tsb generation
m3x3 r3,v8,c0 //gen normal
m3x3 r5,v3,c0 //gen tangent
//gen binormal via Cross product
mul r0,-r3.zxyw,r5.yzxw;
mad r4,-r3.yzxw,r5.zxyw,-r0;
//diffuse, transform the light vector
dp3 r6.x,r3,-c16
dp3 r6.y,r4,-c16
dp3 r6.z,r5,-c16
//light in oD0
mad oD0.xyz,r6.xyz,c20,c20 //multiply by a half to bias, then add half
//tex coords
mov oT0.xy, v7.xy
mov oT1.xy, v7.xy
};
PixelShader =
asm
{
ps.1.1
tex t0 //sample texture
tex t1 //sample normal
//diffuse
dp3 r1,t1_bx2,v0_bx2 //dot(normal,light)
//assemble final color
mul r0,t0, r1 //modulate against base color
};
}
}
technique tec1
{
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] = <lhtR>; //Light Direction
vertexShaderConstant[20] = (.5f,.5f,.5f,.5f);
//Camera Information
VertexShaderConstant[24] = <vCPS>;
Texture[0] = <tDif>;
Texture[1] = <tDf3>;
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]; //Tangent
}
asm
{
vs.1.1
//tranform position
m4x4 oPos,v0,c4
//tsb generation
m3x3 r3,v8,c0 //gen normal
m3x3 r5,v3,c0 //gen tangent
//gen binormal via Cross product
mul r0,-r3.zxyw,r5.yzxw;
mad r4,-r3.yzxw,r5.zxyw,-r0;
//specular
m4x4 r2,v0,c0 //transform position
//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)
add r2.xyz,r2.xyz,-c16 //get half angle
//normalize
dp3 r11.x,r2.xyz,r2.xyz //load the square into r1
rsq r11.xyz,r11.x //get the inverse of the square
mul r2.xyz,r2.xyz,r11.xyz //multiply, r2 = HalfAngle
//transform the half angle vector
dp3 r8.x,r3,r2
dp3 r8.y,r4,r2
dp3 r8.z,r5,r2
//half-angle in oD1
mad oD1.xyz, r8.xyz,c20,c20 //mutiply by a half to bias, then add half
//tex coords
mov oT0.xy, v7.xy
mov oT1.xy, v7.xy
};
PixelShader =
asm
{
ps.1.1
tex t0 //sample base map
tex t1 //sample normal
dp3 r0,t1_bx2,v1_bx2; //dot(normal,half)
mul r1,r0,r0; //raise it to 32nd power
mul r0,r1,r1;
mul r1,r0,r0;
mul r0,r1,r1;
//assemble final color
mul r0,t0,r0
};
}
}
technique tec2
{
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] = <lhtR>; //Light Direction
vertexShaderConstant[20] = (.5f,.5f,.5f,.5f);
//Camera Information
VertexShaderConstant[24] = <vCPS>;
Texture[0] = <tDf3>;
Texture[2] = <tL16>;
Texture[3] = <tDif>;
wrap0 = U | V;
wrap1 = 0;
wrap2 = 0;
wrap3 = U | V;
AddressU[0] = wrap;
AddressV[0] = wrap;
AddressU[1] = clamp;
AddressV[1] = clamp;
AddressU[2] = clamp;
AddressV[2] = clamp;
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
//tranform position
m4x4 oPos,v0,c4
//tsb generation
m3x3 r3,v8,c0 //transform normal
m3x3 r5,v3,c0 //and tangent
//Cross product
mul r0,-r3.zxyw,r5.yzxw;
mad r4,-r3.yzxw,r5.zxyw,-r0;
//specular
m4x4 r2,v0,c0 //transform position
//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)
add r2.xyz,r2.xyz,-c16 //get half angle
//normalize
dp3 r11.x,r2.xyz,r2.xyz //load the square into r1
rsq r11.xyz,r11.x //get the inverse of the square
mul r2.xyz,r2.xyz,r11.xyz //multiply, r2 = HalfAngle
//transform the half angle vector
dp3 r8.x,r3,r2
dp3 r8.y,r4,r2
dp3 r8.z,r5,r2
//half-angle in oD1
// mad oD1.xyz, r8.xyz,c20,c20 //mutiply by a half to bias, then add half
//tex coords
mov oT0.xy, v7.xy //coord to samp normal from
mov oT1.xyz,r8 //Not a tex coord, but half
mov oT2.xyz,r8 //angle
mov oT3.xy, v7.xy
};
PixelShader =
asm
{
ps.1.1
tex t0 //sample normal
texm3x2pad t1, t0_bx2 //look it up in a table
texm3x2tex t2, t0_bx2
tex t3 //sample base color
//assemble final color
mov r0,t2
mul r0,r0,t3 //blend terms
};
}
}
and this another fx file:
vector lhtR; // Direction of Light
vector matD; // Object Diffuse Material Color
matrix mWld; // World
matrix mTot; // Total
// Load model
string XFile = "sphere.x";
// Background Color
DWORD BCLR = 0xff000000;
// No pixel shader
pixelshader pNIL;
// Technique names for display in viewer window:
string tec0 = "Solution 1a: Fixed Function Diffuse Lighting";
string tec1 = "Solution 1b: Vertex Shader Diffuse Lighting";
/////////////////////////////////////////////////////////////////////////////
/////// Exercise 1a: Fixed Function Diffuse Lighting //////////
/////// Change diffuse material color to color from model, //////////
/////// rather than the current white material constant //////////
/////////////////////////////////////////////////////////////////////////////
// Given: The App has already set the matrices before calling this technique
technique tec0
{
pass P0
{
// Diffuse, Specular and Ambient Material colors of object
MaterialDiffuse = <matD>; // Diffuse from object material diffuse
// MaterialDiffuse = (0.0f,0.0f,1.0f,1.0f); // Diffuse from constant color
MaterialSpecular = (0.0f,0.0f,0.0f,0.0f);
MaterialAmbient = (0.0f,0.0f,0.0f,0.0f);
// Light Properties. lhtR, the light direction, is input from the shader app
LightType[0] = DIRECTIONAL;
LightDiffuse[0] = (1.0f,1.0f,1.0f,1.0f);
LightSpecular[0] = (0.0f,0.0f,0.0f,0.0f);
LightAmbient[0] = (0.0f,0.0f,0.0f,0.0f);
LightDirection[0] = <lhtR>;
LightRange[0] = 100000.0f;
//turn lighting on and use light zero
LightEnable[0] = TRUE;
Lighting = TRUE;
// Assign diffuse color to be used
ColorOp[0] = SelectArg1;
ColorArg1[0] = Diffuse;
AlphaOp[0] = SelectArg1;
AlphaArg1[0] = Diffuse;
// Only one colour being used
ColorOp[1] = Disable;
AlphaOp[1] = Disable;
// Z-Buffering to be used
ZEnable = true;
ZWriteEnable = true;
}
}
/////////////////////////////////////////////////////////////////////////////
/////// Exercise 1b: Vertex Shader Diffuse Lighting //////////
/////// Change diffuse material color to color from model, //////////
/////// rather than the current white material constant //////////
/////////////////////////////////////////////////////////////////////////////
technique tec1
{
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 from constant color
VertexShaderConstant[9] = <matD>; // 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, the light direction, is input from the shader app
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] = <lhtR>; // Light Direction
// Assign diffuse color to be used
ColorOp[0] = SelectArg1;
ColorArg1[0] = Diffuse;
AlphaOp[0] = SelectArg1;
AlphaArg1[0] = Diffuse;
// Only one colour 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
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
mov oD0,r0 // put into Diffuse Color output
};
}
}
cheers
Once you start down the Dark Path, forever will it dominate your destiny...