//
// Project:
//
//   D3D RightMark
//
// Description:
//   Effect file for "Geometry Processing Speed" test.
//
// Effect Version: 
//
//   DirectX 9.0 (Summer 2003 SDK Update)
//
// Shader Profile:
//
//   Fixed-Function Pixel Shader
//
//   Vertex Shaders 2.0 ( Vertex Shader Assembler )
//

vector vZero     = { 0.0f, 0.0f, 0.0f, 0.0f };
vector vOne      = { 1.0f, 1.0f, 1.0f, 1.0f };

vector vLight0Pos;
vector vLight1Pos;
vector vLight2Pos;

vector vLight0Diffuse = { 1.0f, 0.0f, 0.0f, 1.0f };
vector vLight1Diffuse = { 0.0f, 1.0f, 0.0f, 1.0f };
vector vLight2Diffuse = { 0.0f, 0.0f, 1.0f, 1.0f };

vector vLight0Specular = { 1.0f, 1.0f, 1.0f, 1.0f };
vector vLight1Specular = { 1.0f, 1.0f, 1.0f, 1.0f };
vector vLight2Specular = { 1.0f, 1.0f, 1.0f, 1.0f };

vector vLight0Attenuation = { 0.0f, 0.1f, 0.0f, 0.0f };
vector vLight1Attenuation = { 0.0f, 0.1f, 0.0f, 0.0f };
vector vLight2Attenuation = { 0.0f, 0.1f, 0.0f, 0.0f };

vector vLight0Range = { 500.0f, 500.0f, 500.0f, 500.0f };
vector vLight1Range = { 500.0f, 500.0f, 500.0f, 500.0f };
vector vLight2Range = { 500.0f, 500.0f, 500.0f, 500.0f };

vector vMaterialDiffuse  = { 40.0f,  40.0f,  40.0f, 255.0f };
vector vMaterialSpecular = { 40.0f,  40.0f,  40.0f, 255.0f };
vector vMaterialAmbient  = {  0.0f,   0.0f,   0.0f, 255.0f };
vector vMaterialEmissive = {  0.0f,   0.0f,   0.0f, 255.0f };

vector vMaterialPower = { 16.0f,  16.0f,  16.0f, 16.0f };
vector vAmbient = { 1.0f, 1.0f, 1.0f, 1.0f };

vector vCameraPos;	  // Camera Position

matrix mW;		  // World Matrix
matrix mWVP;		  // World * View * Projection Matrix

#define InPosition        v0
#define InNormal          v1

#define OutPosition       oPos
#define OutColor          oD0

#define MatWorld          8
#define MatWVP            16

#define LightPosition     40+aL
#define LightDiffuse      30+aL
#define LightSpecular     50+aL
#define LightAttenuation  70+aL
#define LightRange        80+aL

#define AmbientColor      0
#define CameraPosition    2

#define MaterialDiffuse   90
#define MaterialSpecular  91
#define MaterialPower     94

#define Temp              r0
#define TempLight         r1
#define TempLit           r2
#define TempColor         r4
#define TempIntensity     r5
#define TempEye           r6
#define TempNormal        r7
#define TempAttenuation   r8
#define TempDistance      r9
#define TempPosition      r10
#define TempHalfAngle     r11

#define LightPosition0    40
#define LightPosition1    41
#define LightPosition2    42

#define LightDiffuse0     30
#define LightDiffuse1     31
#define LightDiffuse2     32

#define LightSpecular0    50
#define LightSpecular1    51
#define LightSpecular2    52

#define LightAttenuation0 70
#define LightAttenuation1 71
#define LightAttenuation2 72

#define LightRange0       80
#define LightRange1       81
#define LightRange2       82

//
// Ambient Lighting
//

technique TAmbient
{   
	pass p0
	{
		// Common States

		CullMode		 = CCW;
		AlphaBlendEnable	 = False;
		ZWriteEnable		 = True;

		ColorOp[ 0 ]             = SelectArg1;
	        ColorArg1[ 0 ] 		 = Diffuse;

		AlphaOp[ 0 ]             = SelectArg1;
	        AlphaArg1[ 0 ] 		 = Diffuse;
        
	        ColorOp[ 1 ]   		 = Disable;
        	AlphaOp[ 1 ]   		 = Disable;

		// Shader Constants

		VertexShaderConstant[MatWVP]       = <mWVP>;	  // World * View * Projections matrix
		VertexShaderConstant[AmbientColor] = <vOne>;	  // Ambient color

		// Shaders

		VertexShader = 

		   asm {	
				vs_2_0

				dcl_position InPosition

				// Position Setup

				m4x4 OutPosition, InPosition, c[MatWVP]

				// Lighting 

				mov  OutColor, c[AmbientColor]
			};
	}
}

//
// 1 Diffuse Per-Vertex Point Light 
//

technique T1Diffuse
{   
	pass p0
	{
		//
		// Common States
		//

		CullMode		 = CCW;
		AlphaBlendEnable	 = False;
		ZWriteEnable		 = True;

		ColorOp[ 0 ]             = SelectArg1;
	        ColorArg1[ 0 ] 		 = Diffuse;

		AlphaOp[ 0 ]             = SelectArg1;
	        AlphaArg1[ 0 ] 		 = Diffuse;
        
	        ColorOp[ 1 ]   		 = Disable;
        	AlphaOp[ 1 ]   		 = Disable;

		//
		// Shader Constants
		//

		VertexShaderConstant[AmbientColor] = <vZero>;	                 // Ambient color

		VertexShaderConstant[MatWorld] = <mW>;	                         // World matrix
		VertexShaderConstant[MatWVP]   = <mWVP>;	                 // World * View * Projections matrix

		VertexShaderConstant[LightPosition0] = <vLight0Pos>;             // Light 0 Position
		VertexShaderConstant[LightPosition1] = <vLight1Pos>;             // Light 1 Position
		VertexShaderConstant[LightPosition2] = <vLight2Pos>;             // Light 2 Position

		VertexShaderConstant[LightDiffuse0] = <vLight0Diffuse>;          // Light 0 Diffuse Color
		VertexShaderConstant[LightDiffuse1] = <vLight1Diffuse>;          // Light 1 Diffuse Color
		VertexShaderConstant[LightDiffuse2] = <vLight2Diffuse>;          // Light 2 Diffuse Color

		VertexShaderConstant[LightAttenuation0] = <vLight0Attenuation>;  // Light 0 Attenuation
		VertexShaderConstant[LightAttenuation1] = <vLight1Attenuation>;  // Light 1 Attenuation
		VertexShaderConstant[LightAttenuation2] = <vLight2Attenuation>;  // Light 2 Attenuation

		VertexShaderConstant[LightRange0] = <vLight0Range>;              // Light 0 Range
		VertexShaderConstant[LightRange1] = <vLight1Range>;              // Light 1 Range
		VertexShaderConstant[LightRange2] = <vLight2Range>;              // Light 2 Range

		VertexShaderConstant[MaterialDiffuse]  = <vMaterialDiffuse>;     // Material Diffuse Color
		VertexShaderConstant[MaterialSpecular] = <vMaterialSpecular>;    // Material Specular Color

		VertexShaderConstant[MaterialPower] = <vMaterialPower>;          // Material Specular Power

		//
		// Shaders
		//

		VertexShader = 

		   asm {	
				vs_2_0

				dcl_position InPosition
				dcl_normal   InNormal

				// Position Setup

				m4x4 OutPosition, InPosition, c[MatWVP]

				// Lighting Setup
				
				m4x4 TempPosition, InPosition, c[MatWorld] // transform position to world space

				m3x3 Temp.xyz, InNormal.xyz, c[MatWorld]   // transform normal to world space
				nrm  TempNormal, Temp    	           // normalize normal

				mov  TempColor, c[AmbientColor]		   // add ambient

				mov  TempLit, c[AmbientColor]              // setup diffuse,specular factors
				mov  TempLit.w, c[MaterialPower]           // setup specular power

				// Lighting

				add TempLight, c[LightPosition0], -TempPosition    // the light vector
				dp3 Temp.w, TempLight, TempLight
				rsq TempLight.w, Temp.w

				dst TempDistance, Temp.w, TempLight.w              // (1, d, d*d, 1/d)
				dp3 Temp.w, TempDistance, c[LightAttenuation0]     // (a0 + a1*d + a2*d2)
				rcp TempAttenuation.w, Temp.w		           // 1 / (a0 + a1*d + a2*d)	

				mul TempLight, TempLight, TempLight.w              // normalize the light vector

				dp3 TempLit.x, TempNormal, TempLight               // N*L

				sge Temp.x, c[LightRange0].y, TempDistance.y       // (range > d) ? 1:0
				mul TempLit.x, TempLit.x, Temp.x

				lit Temp, TempLit		                   // calculate the diffuse & specular factors
				mul Temp, Temp, TempAttenuation.w	           // scale by attenuation

				mul Temp, Temp.y, c[LightDiffuse0]	           // calculate diffuse color
				mad TempColor, Temp, c[MaterialDiffuse], TempColor // add (diffuse color * material diffuse)

				mov  OutColor, TempColor		           // final color
			};
	}
}

//
// 2 Diffuse Per-Vertex Point Light 
//

technique T2Diffuse
{   
	pass p0
	{
		//
		// Common States
		//

		CullMode		 = CCW;
		AlphaBlendEnable	 = False;
		ZWriteEnable		 = True;

		ColorOp[ 0 ]             = SelectArg1;
	        ColorArg1[ 0 ] 		 = Diffuse;

		AlphaOp[ 0 ]             = SelectArg1;
	        AlphaArg1[ 0 ] 		 = Diffuse;
        
	        ColorOp[ 1 ]   		 = Disable;
        	AlphaOp[ 1 ]   		 = Disable;

		//
		// Shader Constants
		//

		VertexShaderConstant[AmbientColor] = <vZero>;	                 // Ambient color

		VertexShaderConstant[MatWorld] = <mW>;	                         // World matrix
		VertexShaderConstant[MatWVP]   = <mWVP>;	                 // World * View * Projections matrix

		VertexShaderConstant[LightPosition0] = <vLight0Pos>;             // Light 0 Position
		VertexShaderConstant[LightPosition1] = <vLight1Pos>;             // Light 1 Position
		VertexShaderConstant[LightPosition2] = <vLight2Pos>;             // Light 2 Position

		VertexShaderConstant[LightDiffuse0] = <vLight0Diffuse>;          // Light 0 Diffuse Color
		VertexShaderConstant[LightDiffuse1] = <vLight1Diffuse>;          // Light 1 Diffuse Color
		VertexShaderConstant[LightDiffuse2] = <vLight2Diffuse>;          // Light 2 Diffuse Color

		VertexShaderConstant[LightAttenuation0] = <vLight0Attenuation>;  // Light 0 Attenuation
		VertexShaderConstant[LightAttenuation1] = <vLight1Attenuation>;  // Light 1 Attenuation
		VertexShaderConstant[LightAttenuation2] = <vLight2Attenuation>;  // Light 2 Attenuation

		VertexShaderConstant[LightRange0] = <vLight0Range>;              // Light 0 Range
		VertexShaderConstant[LightRange1] = <vLight1Range>;              // Light 1 Range
		VertexShaderConstant[LightRange2] = <vLight2Range>;              // Light 2 Range

		VertexShaderConstant[MaterialDiffuse]  = <vMaterialDiffuse>;     // Material Diffuse Color
		VertexShaderConstant[MaterialSpecular] = <vMaterialSpecular>;    // Material Specular Color

		VertexShaderConstant[MaterialPower] = <vMaterialPower>;          // Material Specular Power

		//
		// Shaders
		//

		VertexShader = 

		   asm {	
				vs_2_0

				dcl_position InPosition
				dcl_normal   InNormal

				// Position Setup

				m4x4 OutPosition, InPosition, c[MatWVP]

				// Lighting Setup
				
				m4x4 TempPosition, InPosition, c[MatWorld] // transform position to world space

				m3x3 Temp.xyz, InNormal.xyz, c[MatWorld]   // transform normal to world space
				nrm  TempNormal, Temp    	           // normalize normal

				mov  TempColor, c[AmbientColor]		   // add ambient

				mov  TempLit, c[AmbientColor]              // setup diffuse,specular factors
				mov  TempLit.w, c[MaterialPower]           // setup specular power

				// Lighting
				
				// 1

				add TempLight, c[LightPosition0], -TempPosition    // the light vector
				dp3 Temp.w, TempLight, TempLight
				rsq TempLight.w, Temp.w

				dst TempDistance, Temp.w, TempLight.w              // (1, d, d*d, 1/d)
				dp3 Temp.w, TempDistance, c[LightAttenuation0]     // (a0 + a1*d + a2*d2)
				rcp TempAttenuation.w, Temp.w		           // 1 / (a0 + a1*d + a2*d)	

				mul TempLight, TempLight, TempLight.w              // normalize the light vector

				dp3 TempLit.x, TempNormal, TempLight               // N*L

				sge Temp.x, c[LightRange0].y, TempDistance.y       // (range > d) ? 1:0
				mul TempLit.x, TempLit.x, Temp.x

				lit Temp, TempLit		                   // calculate the diffuse & specular factors
				mul Temp, Temp, TempAttenuation.w	           // scale by attenuation

				mul Temp, Temp.y, c[LightDiffuse0]	           // calculate diffuse color
				mad TempColor, Temp, c[MaterialDiffuse], TempColor // add (diffuse color * material diffuse)

				// 2

				add TempLight, c[LightPosition1], -TempPosition    // the light vector
				dp3 Temp.w, TempLight, TempLight
				rsq TempLight.w, Temp.w

				dst TempDistance, Temp.w, TempLight.w              // (1, d, d*d, 1/d)
				dp3 Temp.w, TempDistance, c[LightAttenuation1]     // (a0 + a1*d + a2*d2)
				rcp TempAttenuation.w, Temp.w		           // 1 / (a0 + a1*d + a2*d)	

				mul TempLight, TempLight, TempLight.w              // normalize the light vector

				dp3 TempLit.x, TempNormal, TempLight               // N*L

				sge Temp.x, c[LightRange1].y, TempDistance.y       // (range > d) ? 1:0
				mul TempLit.x, TempLit.x, Temp.x

				lit Temp, TempLit		                   // calculate the diffuse & specular factors
				mul Temp, Temp, TempAttenuation.w	           // scale by attenuation

				mul Temp, Temp.y, c[LightDiffuse1]	           // calculate diffuse color
				mad TempColor, Temp, c[MaterialDiffuse], TempColor // add (diffuse color * material diffuse)

				mov  OutColor, TempColor		           // final color
			};
	}
}

//
// 3 Diffuse Per-Vertex Point Light 
//

technique T3Diffuse
{   
	pass p0
	{
		//
		// Common States
		//

		CullMode		 = CCW;
		AlphaBlendEnable	 = False;
		ZWriteEnable		 = True;

		ColorOp[ 0 ]             = SelectArg1;
	        ColorArg1[ 0 ] 		 = Diffuse;

		AlphaOp[ 0 ]             = SelectArg1;
	        AlphaArg1[ 0 ] 		 = Diffuse;
        
	        ColorOp[ 1 ]   		 = Disable;
        	AlphaOp[ 1 ]   		 = Disable;

		//
		// Shader Constants
		//

		VertexShaderConstant[AmbientColor] = <vZero>;	                 // Ambient color

		VertexShaderConstant[MatWorld] = <mW>;	                         // World matrix
		VertexShaderConstant[MatWVP]   = <mWVP>;	                 // World * View * Projections matrix

		VertexShaderConstant[LightPosition0] = <vLight0Pos>;             // Light 0 Position
		VertexShaderConstant[LightPosition1] = <vLight1Pos>;             // Light 1 Position
		VertexShaderConstant[LightPosition2] = <vLight2Pos>;             // Light 2 Position

		VertexShaderConstant[LightDiffuse0] = <vLight0Diffuse>;          // Light 0 Diffuse Color
		VertexShaderConstant[LightDiffuse1] = <vLight1Diffuse>;          // Light 1 Diffuse Color
		VertexShaderConstant[LightDiffuse2] = <vLight2Diffuse>;          // Light 2 Diffuse Color

		VertexShaderConstant[LightAttenuation0] = <vLight0Attenuation>;  // Light 0 Attenuation
		VertexShaderConstant[LightAttenuation1] = <vLight1Attenuation>;  // Light 1 Attenuation
		VertexShaderConstant[LightAttenuation2] = <vLight2Attenuation>;  // Light 2 Attenuation

		VertexShaderConstant[LightRange0] = <vLight0Range>;              // Light 0 Range
		VertexShaderConstant[LightRange1] = <vLight1Range>;              // Light 1 Range
		VertexShaderConstant[LightRange2] = <vLight2Range>;              // Light 2 Range

		VertexShaderConstant[MaterialDiffuse]  = <vMaterialDiffuse>;     // Material Diffuse Color
		VertexShaderConstant[MaterialSpecular] = <vMaterialSpecular>;    // Material Specular Color

		VertexShaderConstant[MaterialPower] = <vMaterialPower>;          // Material Specular Power

		//
		// Shaders
		//

		VertexShader = 

		   asm {	
				vs_2_0

				dcl_position InPosition
				dcl_normal   InNormal

				// Position Setup

				m4x4 OutPosition, InPosition, c[MatWVP]

				// Lighting Setup
				
				m4x4 TempPosition, InPosition, c[MatWorld] // transform position to world space

				m3x3 Temp.xyz, InNormal.xyz, c[MatWorld]   // transform normal to world space
				nrm  TempNormal, Temp    	           // normalize normal

				mov  TempColor, c[AmbientColor]		   // add ambient

				mov  TempLit, c[AmbientColor]              // setup diffuse,specular factors
				mov  TempLit.w, c[MaterialPower]           // setup specular power

				// Lighting

				// 1

				add TempLight, c[LightPosition0], -TempPosition    // the light vector
				dp3 Temp.w, TempLight, TempLight
				rsq TempLight.w, Temp.w

				dst TempDistance, Temp.w, TempLight.w              // (1, d, d*d, 1/d)
				dp3 Temp.w, TempDistance, c[LightAttenuation0]     // (a0 + a1*d + a2*d2)
				rcp TempAttenuation.w, Temp.w		           // 1 / (a0 + a1*d + a2*d)	

				mul TempLight, TempLight, TempLight.w              // normalize the light vector

				dp3 TempLit.x, TempNormal, TempLight               // N*L

				sge Temp.x, c[LightRange0].y, TempDistance.y       // (range > d) ? 1:0
				mul TempLit.x, TempLit.x, Temp.x

				lit Temp, TempLit		                   // calculate the diffuse & specular factors
				mul Temp, Temp, TempAttenuation.w	           // scale by attenuation

				mul Temp, Temp.y, c[LightDiffuse0]	           // calculate diffuse color
				mad TempColor, Temp, c[MaterialDiffuse], TempColor // add (diffuse color * material diffuse)

				// 2

				add TempLight, c[LightPosition1], -TempPosition    // the light vector
				dp3 Temp.w, TempLight, TempLight
				rsq TempLight.w, Temp.w

				dst TempDistance, Temp.w, TempLight.w              // (1, d, d*d, 1/d)
				dp3 Temp.w, TempDistance, c[LightAttenuation1]     // (a0 + a1*d + a2*d2)
				rcp TempAttenuation.w, Temp.w		           // 1 / (a0 + a1*d + a2*d)	

				mul TempLight, TempLight, TempLight.w              // normalize the light vector

				dp3 TempLit.x, TempNormal, TempLight               // N*L

				sge Temp.x, c[LightRange1].y, TempDistance.y       // (range > d) ? 1:0
				mul TempLit.x, TempLit.x, Temp.x

				lit Temp, TempLit		                   // calculate the diffuse & specular factors
				mul Temp, Temp, TempAttenuation.w	           // scale by attenuation

				mul Temp, Temp.y, c[LightDiffuse1]	           // calculate diffuse color
				mad TempColor, Temp, c[MaterialDiffuse], TempColor // add (diffuse color * material diffuse)

				// 3

				add TempLight, c[LightPosition2], -TempPosition    // the light vector
				dp3 Temp.w, TempLight, TempLight
				rsq TempLight.w, Temp.w

				dst TempDistance, Temp.w, TempLight.w              // (1, d, d*d, 1/d)
				dp3 Temp.w, TempDistance, c[LightAttenuation2]     // (a0 + a1*d + a2*d2)
				rcp TempAttenuation.w, Temp.w		           // 1 / (a0 + a1*d + a2*d)	

				mul TempLight, TempLight, TempLight.w              // normalize the light vector

				dp3 TempLit.x, TempNormal, TempLight               // N*L

				sge Temp.x, c[LightRange2].y, TempDistance.y       // (range > d) ? 1:0
				mul TempLit.x, TempLit.x, Temp.x

				lit Temp, TempLit		                   // calculate the diffuse & specular factors
				mul Temp, Temp, TempAttenuation.w	           // scale by attenuation

				mul Temp, Temp.y, c[LightDiffuse2]	           // calculate diffuse color
				mad TempColor, Temp, c[MaterialDiffuse], TempColor // add (diffuse color * material diffuse)

				mov  OutColor, TempColor		           // final color
			};
	}
}

technique T1DiffuseSpecular
{   
	pass p0
	{
		//
		// Common States
		//

		CullMode		 = CCW;
		AlphaBlendEnable	 = False;
		ZWriteEnable		 = True;

		ColorOp[ 0 ]             = SelectArg1;
	        ColorArg1[ 0 ] 		 = Diffuse;

		AlphaOp[ 0 ]             = SelectArg1;
	        AlphaArg1[ 0 ] 		 = Diffuse;
        
	        ColorOp[ 1 ]   		 = Disable;
        	AlphaOp[ 1 ]   		 = Disable;

		// Shader Constants

		VertexShaderConstant[AmbientColor] = <vZero>;	                // Ambient color

		VertexShaderConstant[CameraPosition] = <vCameraPos>;            // Camera position

		VertexShaderConstant[MatWorld] = <mW>;	                        // World matrix
		VertexShaderConstant[MatWVP]   = <mWVP>;	                // World * View * Projections matrix

		VertexShaderConstant[LightPosition0] = <vLight0Pos>;            // Light 0 position
		VertexShaderConstant[LightPosition1] = <vLight1Pos>;            // Light 1 position
		VertexShaderConstant[LightPosition2] = <vLight2Pos>;            // Light 2 position

		VertexShaderConstant[LightDiffuse0] = <vLight0Diffuse>;         // Light 0 diffuse color
		VertexShaderConstant[LightDiffuse1] = <vLight1Diffuse>;         // Light 1 diffuse color
		VertexShaderConstant[LightDiffuse2] = <vLight2Diffuse>;         // Light 2 diffuse color

		VertexShaderConstant[LightSpecular0] = <vLight0Specular>;       // Light 0 specular color
		VertexShaderConstant[LightSpecular1] = <vLight1Specular>;       // Light 1 specular color
		VertexShaderConstant[LightSpecular2] = <vLight2Specular>;       // Light 2 specular color

		VertexShaderConstant[LightAttenuation0] = <vLight0Attenuation>; // Light 0 attenuation
		VertexShaderConstant[LightAttenuation1] = <vLight1Attenuation>; // Light 1 attenuation
		VertexShaderConstant[LightAttenuation2] = <vLight2Attenuation>; // Light 2 attenuation

		VertexShaderConstant[LightRange0] = <vLight0Range>;             // Light 0 range
		VertexShaderConstant[LightRange1] = <vLight1Range>;             // Light 1 range
		VertexShaderConstant[LightRange2] = <vLight2Range>;             // Light 2 range

		VertexShaderConstant[MaterialDiffuse]  = <vMaterialDiffuse>;    // Material diffuse color
		VertexShaderConstant[MaterialSpecular] = <vMaterialSpecular>;   // Material dpecular color

		VertexShaderConstant[MaterialPower] = <vMaterialPower>;         // Material specular cower

		//
		// Shaders
		//

		VertexShader = 

		   asm {	
				vs_2_0

				dcl_position InPosition
				dcl_normal   InNormal

				// Position Setup

				m4x4 OutPosition, InPosition, c[MatWVP]

				// Lighting Setup
				
				m4x4 TempPosition, InPosition, c[MatWorld] // transform position to world space

				m3x3 Temp.xyz, InNormal.xyz, c[MatWorld]   // transform normal to world space
				nrm  TempNormal, Temp    	           // normalize normal

				add Temp, -TempPosition, c[CameraPosition] // get a vector toward the camera position
				nrm TempEye, Temp		           // normalize eye vector

				mov  TempColor, c[AmbientColor]		   // add ambient

				mov  TempLit, c[AmbientColor]              // setup diffuse,specular factors
				mov  TempLit.w, c[MaterialPower]           // setup specular power

				// Lighting

				add TempLight, c[LightPosition0], -TempPosition     // the light vector
				dp3 Temp.w, TempLight, TempLight
				rsq TempLight.w, Temp.w

				dst TempDistance, Temp.w, TempLight.w               // (1, d, d*d, 1/d)
				dp3 Temp.w, TempDistance, c[LightAttenuation0]      // (a0 + a1*d + a2*d2)
				rcp TempAttenuation.w, Temp.w		            // 1 / (a0 + a1*d + a2*d)	

				mul TempLight, TempLight, TempLight.w               // normalize the light vector

				add Temp, TempEye, TempLight		            // calculate half-vector (light vector + eye vector)
				nrm TempHalfAngle, Temp		                    // normalize half-vector

				dp3 TempLit.x, TempNormal, TempLight                // N*L
				dp3 TempLit.yz, TempNormal, TempHalfAngle           // N*H

				sge Temp.x, c[LightRange0].y, TempDistance.y        // (range > d) ? 1:0
				mul TempLit.x, TempLit.x, Temp.x
				mul TempLit.y, TempLit.y, Temp.x

				lit Temp, TempLit		                    // calculate the diffuse & specular factors
				mul TempIntensity, Temp, TempAttenuation.w          // scale by attenuation

				mul Temp, TempIntensity.y, c[LightDiffuse0]	    // calculate diffuse color
				mad TempColor, Temp, c[MaterialDiffuse], TempColor  // add (diffuse color * material diffuse)

				mul Temp, TempIntensity.z, c[LightSpecular0]	    // calculate specular color
				mad TempColor, Temp, c[MaterialSpecular], TempColor // add (specular color * material specular)

				mov  OutColor, TempColor		            // final color
			};
	}
}

technique T2DiffuseSpecular
{   
	pass p0
	{
		//
		// Common States
		//

		CullMode		 = CCW;
		AlphaBlendEnable	 = False;
		ZWriteEnable		 = True;

		ColorOp[ 0 ]             = SelectArg1;
	        ColorArg1[ 0 ] 		 = Diffuse;

		AlphaOp[ 0 ]             = SelectArg1;
	        AlphaArg1[ 0 ] 		 = Diffuse;
        
	        ColorOp[ 1 ]   		 = Disable;
        	AlphaOp[ 1 ]   		 = Disable;

		// Shader Constants

		VertexShaderConstant[AmbientColor] = <vZero>;	                // Ambient color

		VertexShaderConstant[CameraPosition] = <vCameraPos>;            // Camera position

		VertexShaderConstant[MatWorld] = <mW>;	                        // World matrix
		VertexShaderConstant[MatWVP]   = <mWVP>;	                // World * View * Projections matrix

		VertexShaderConstant[LightPosition0] = <vLight0Pos>;            // Light 0 position
		VertexShaderConstant[LightPosition1] = <vLight1Pos>;            // Light 1 position
		VertexShaderConstant[LightPosition2] = <vLight2Pos>;            // Light 2 position

		VertexShaderConstant[LightDiffuse0] = <vLight0Diffuse>;         // Light 0 diffuse color
		VertexShaderConstant[LightDiffuse1] = <vLight1Diffuse>;         // Light 1 diffuse color
		VertexShaderConstant[LightDiffuse2] = <vLight2Diffuse>;         // Light 2 diffuse color

		VertexShaderConstant[LightSpecular0] = <vLight0Specular>;       // Light 0 specular color
		VertexShaderConstant[LightSpecular1] = <vLight1Specular>;       // Light 1 specular color
		VertexShaderConstant[LightSpecular2] = <vLight2Specular>;       // Light 2 specular color

		VertexShaderConstant[LightAttenuation0] = <vLight0Attenuation>; // Light 0 attenuation
		VertexShaderConstant[LightAttenuation1] = <vLight1Attenuation>; // Light 1 attenuation
		VertexShaderConstant[LightAttenuation2] = <vLight2Attenuation>; // Light 2 attenuation

		VertexShaderConstant[LightRange0] = <vLight0Range>;             // Light 0 range
		VertexShaderConstant[LightRange1] = <vLight1Range>;             // Light 1 range
		VertexShaderConstant[LightRange2] = <vLight2Range>;             // Light 2 range

		VertexShaderConstant[MaterialDiffuse]  = <vMaterialDiffuse>;    // Material diffuse color
		VertexShaderConstant[MaterialSpecular] = <vMaterialSpecular>;   // Material dpecular color

		VertexShaderConstant[MaterialPower] = <vMaterialPower>;         // Material specular cower

		//
		// Shaders
		//

		VertexShader = 

		   asm {	
				vs_2_0

				dcl_position InPosition
				dcl_normal   InNormal

				// Position Setup

				m4x4 OutPosition, InPosition, c[MatWVP]

				// Lighting Setup
				
				m4x4 TempPosition, InPosition, c[MatWorld] // transform position to world space

				m3x3 Temp.xyz, InNormal.xyz, c[MatWorld]   // transform normal to world space
				nrm  TempNormal, Temp    	           // normalize normal

				add Temp, -TempPosition, c[CameraPosition] // get a vector toward the camera position
				nrm TempEye, Temp		           // normalize eye vector

				mov  TempColor, c[AmbientColor]		   // add ambient

				mov  TempLit, c[AmbientColor]              // setup diffuse,specular factors
				mov  TempLit.w, c[MaterialPower]           // setup specular power

				// Lighting

				// 1

				add TempLight, c[LightPosition0], -TempPosition     // the light vector
				dp3 Temp.w, TempLight, TempLight
				rsq TempLight.w, Temp.w

				dst TempDistance, Temp.w, TempLight.w               // (1, d, d*d, 1/d)
				dp3 Temp.w, TempDistance, c[LightAttenuation0]      // (a0 + a1*d + a2*d2)
				rcp TempAttenuation.w, Temp.w		            // 1 / (a0 + a1*d + a2*d)	

				mul TempLight, TempLight, TempLight.w               // normalize the light vector

				add Temp, TempEye, TempLight		            // calculate half-vector (light vector + eye vector)
				nrm TempHalfAngle, Temp		                    // normalize half-vector

				dp3 TempLit.x, TempNormal, TempLight                // N*L
				dp3 TempLit.yz, TempNormal, TempHalfAngle           // N*H

				sge Temp.x, c[LightRange0].y, TempDistance.y        // (range > d) ? 1:0
				mul TempLit.x, TempLit.x, Temp.x
				mul TempLit.y, TempLit.y, Temp.x

				lit Temp, TempLit		                    // calculate the diffuse & specular factors
				mul TempIntensity, Temp, TempAttenuation.w          // scale by attenuation

				mul Temp, TempIntensity.y, c[LightDiffuse0]	    // calculate diffuse color
				mad TempColor, Temp, c[MaterialDiffuse], TempColor  // add (diffuse color * material diffuse)

				mul Temp, TempIntensity.z, c[LightSpecular0]	    // calculate specular color
				mad TempColor, Temp, c[MaterialSpecular], TempColor // add (specular color * material specular)

				// 2

				add TempLight, c[LightPosition1], -TempPosition     // the light vector
				dp3 Temp.w, TempLight, TempLight
				rsq TempLight.w, Temp.w

				dst TempDistance, Temp.w, TempLight.w               // (1, d, d*d, 1/d)
				dp3 Temp.w, TempDistance, c[LightAttenuation1]      // (a0 + a1*d + a2*d2)
				rcp TempAttenuation.w, Temp.w		            // 1 / (a0 + a1*d + a2*d)	

				mul TempLight, TempLight, TempLight.w               // normalize the light vector

				add Temp, TempEye, TempLight		            // calculate half-vector (light vector + eye vector)
				nrm TempHalfAngle, Temp		                    // normalize half-vector

				dp3 TempLit.x, TempNormal, TempLight                // N*L
				dp3 TempLit.yz, TempNormal, TempHalfAngle           // N*H

				sge Temp.x, c[LightRange1].y, TempDistance.y        // (range > d) ? 1:0
				mul TempLit.x, TempLit.x, Temp.x
				mul TempLit.y, TempLit.y, Temp.x

				lit Temp, TempLit		                    // calculate the diffuse & specular factors
				mul TempIntensity, Temp, TempAttenuation.w          // scale by attenuation

				mul Temp, TempIntensity.y, c[LightDiffuse1]	    // calculate diffuse color
				mad TempColor, Temp, c[MaterialDiffuse], TempColor  // add (diffuse color * material diffuse)

				mul Temp, TempIntensity.z, c[LightSpecular1]	    // calculate specular color
				mad TempColor, Temp, c[MaterialSpecular], TempColor // add (specular color * material specular)

				mov  OutColor, TempColor		            // final color
			};
	}
}

technique T3DiffuseSpecular
{   
	pass p0
	{
		//
		// Common States
		//

		CullMode		 = CCW;
		AlphaBlendEnable	 = False;
		ZWriteEnable		 = True;

		ColorOp[ 0 ]             = SelectArg1;
	        ColorArg1[ 0 ] 		 = Diffuse;

		AlphaOp[ 0 ]             = SelectArg1;
	        AlphaArg1[ 0 ] 		 = Diffuse;
        
	        ColorOp[ 1 ]   		 = Disable;
        	AlphaOp[ 1 ]   		 = Disable;

		// Shader Constants

		VertexShaderConstant[AmbientColor] = <vZero>;	                // Ambient color

		VertexShaderConstant[CameraPosition] = <vCameraPos>;            // Camera position

		VertexShaderConstant[MatWorld] = <mW>;	                        // World matrix
		VertexShaderConstant[MatWVP]   = <mWVP>;	                // World * View * Projections matrix

		VertexShaderConstant[LightPosition0] = <vLight0Pos>;            // Light 0 position
		VertexShaderConstant[LightPosition1] = <vLight1Pos>;            // Light 1 position
		VertexShaderConstant[LightPosition2] = <vLight2Pos>;            // Light 2 position

		VertexShaderConstant[LightDiffuse0] = <vLight0Diffuse>;         // Light 0 diffuse color
		VertexShaderConstant[LightDiffuse1] = <vLight1Diffuse>;         // Light 1 diffuse color
		VertexShaderConstant[LightDiffuse2] = <vLight2Diffuse>;         // Light 2 diffuse color

		VertexShaderConstant[LightSpecular0] = <vLight0Specular>;       // Light 0 specular color
		VertexShaderConstant[LightSpecular1] = <vLight1Specular>;       // Light 1 specular color
		VertexShaderConstant[LightSpecular2] = <vLight2Specular>;       // Light 2 specular color

		VertexShaderConstant[LightAttenuation0] = <vLight0Attenuation>; // Light 0 attenuation
		VertexShaderConstant[LightAttenuation1] = <vLight1Attenuation>; // Light 1 attenuation
		VertexShaderConstant[LightAttenuation2] = <vLight2Attenuation>; // Light 2 attenuation

		VertexShaderConstant[LightRange0] = <vLight0Range>;             // Light 0 range
		VertexShaderConstant[LightRange1] = <vLight1Range>;             // Light 1 range
		VertexShaderConstant[LightRange2] = <vLight2Range>;             // Light 2 range

		VertexShaderConstant[MaterialDiffuse]  = <vMaterialDiffuse>;    // Material diffuse color
		VertexShaderConstant[MaterialSpecular] = <vMaterialSpecular>;   // Material dpecular color

		VertexShaderConstant[MaterialPower] = <vMaterialPower>;         // Material specular cower

		//
		// Shaders
		//

		VertexShader = 

		   asm {	
				vs_2_0

				dcl_position InPosition
				dcl_normal   InNormal

				// Position Setup

				m4x4 OutPosition, InPosition, c[MatWVP]

				// Lighting Setup
				
				m4x4 TempPosition, InPosition, c[MatWorld] // transform position to world space

				m3x3 Temp.xyz, InNormal.xyz, c[MatWorld]   // transform normal to world space
				nrm  TempNormal, Temp    	           // normalize normal

				add Temp, -TempPosition, c[CameraPosition] // get a vector toward the camera position
				nrm TempEye, Temp		           // normalize eye vector

				mov  TempColor, c[AmbientColor]		   // add ambient

				mov  TempLit, c[AmbientColor]              // setup diffuse,specular factors
				mov  TempLit.w, c[MaterialPower]           // setup specular power

				// Lighting

				// 1

				add TempLight, c[LightPosition0], -TempPosition     // the light vector
				dp3 Temp.w, TempLight, TempLight
				rsq TempLight.w, Temp.w

				dst TempDistance, Temp.w, TempLight.w               // (1, d, d*d, 1/d)
				dp3 Temp.w, TempDistance, c[LightAttenuation0]      // (a0 + a1*d + a2*d2)
				rcp TempAttenuation.w, Temp.w		            // 1 / (a0 + a1*d + a2*d)	

				mul TempLight, TempLight, TempLight.w               // normalize the light vector

				add Temp, TempEye, TempLight		            // calculate half-vector (light vector + eye vector)
				nrm TempHalfAngle, Temp		                    // normalize half-vector

				dp3 TempLit.x, TempNormal, TempLight                // N*L
				dp3 TempLit.yz, TempNormal, TempHalfAngle           // N*H

				sge Temp.x, c[LightRange0].y, TempDistance.y        // (range > d) ? 1:0
				mul TempLit.x, TempLit.x, Temp.x
				mul TempLit.y, TempLit.y, Temp.x

				lit Temp, TempLit		                    // calculate the diffuse & specular factors
				mul TempIntensity, Temp, TempAttenuation.w          // scale by attenuation

				mul Temp, TempIntensity.y, c[LightDiffuse0]	    // calculate diffuse color
				mad TempColor, Temp, c[MaterialDiffuse], TempColor  // add (diffuse color * material diffuse)

				mul Temp, TempIntensity.z, c[LightSpecular0]	    // calculate specular color
				mad TempColor, Temp, c[MaterialSpecular], TempColor // add (specular color * material specular)

				// 2

				add TempLight, c[LightPosition1], -TempPosition     // the light vector
				dp3 Temp.w, TempLight, TempLight
				rsq TempLight.w, Temp.w

				dst TempDistance, Temp.w, TempLight.w               // (1, d, d*d, 1/d)
				dp3 Temp.w, TempDistance, c[LightAttenuation1]      // (a0 + a1*d + a2*d2)
				rcp TempAttenuation.w, Temp.w		            // 1 / (a0 + a1*d + a2*d)	

				mul TempLight, TempLight, TempLight.w               // normalize the light vector

				add Temp, TempEye, TempLight		            // calculate half-vector (light vector + eye vector)
				nrm TempHalfAngle, Temp		                    // normalize half-vector

				dp3 TempLit.x, TempNormal, TempLight                // N*L
				dp3 TempLit.yz, TempNormal, TempHalfAngle           // N*H

				sge Temp.x, c[LightRange1].y, TempDistance.y        // (range > d) ? 1:0
				mul TempLit.x, TempLit.x, Temp.x
				mul TempLit.y, TempLit.y, Temp.x

				lit Temp, TempLit		                    // calculate the diffuse & specular factors
				mul TempIntensity, Temp, TempAttenuation.w          // scale by attenuation

				mul Temp, TempIntensity.y, c[LightDiffuse1]	    // calculate diffuse color
				mad TempColor, Temp, c[MaterialDiffuse], TempColor  // add (diffuse color * material diffuse)

				mul Temp, TempIntensity.z, c[LightSpecular1]	    // calculate specular color
				mad TempColor, Temp, c[MaterialSpecular], TempColor // add (specular color * material specular)

				// 3

				add TempLight, c[LightPosition2], -TempPosition     // the light vector
				dp3 Temp.w, TempLight, TempLight
				rsq TempLight.w, Temp.w

				dst TempDistance, Temp.w, TempLight.w               // (1, d, d*d, 1/d)
				dp3 Temp.w, TempDistance, c[LightAttenuation2]      // (a0 + a1*d + a2*d2)
				rcp TempAttenuation.w, Temp.w		            // 1 / (a0 + a1*d + a2*d)	

				mul TempLight, TempLight, TempLight.w               // normalize the light vector

				add Temp, TempEye, TempLight		            // calculate half-vector (light vector + eye vector)
				nrm TempHalfAngle, Temp		                    // normalize half-vector

				dp3 TempLit.x, TempNormal, TempLight                // N*L
				dp3 TempLit.yz, TempNormal, TempHalfAngle           // N*H

				sge Temp.x, c[LightRange2].y, TempDistance.y        // (range > d) ? 1:0
				mul TempLit.x, TempLit.x, Temp.x
				mul TempLit.y, TempLit.y, Temp.x

				lit Temp, TempLit		                    // calculate the diffuse & specular factors
				mul TempIntensity, Temp, TempAttenuation.w          // scale by attenuation

				mul Temp, TempIntensity.y, c[LightDiffuse2]	    // calculate diffuse color
				mad TempColor, Temp, c[MaterialDiffuse], TempColor  // add (diffuse color * material diffuse)

				mul Temp, TempIntensity.z, c[LightSpecular2]	    // calculate specular color
				mad TempColor, Temp, c[MaterialSpecular], TempColor // add (specular color * material specular)

				mov  OutColor, TempColor		            // final color
			};
	}
}