  //--------------------------------
  // Per Pixel Lighting
  //--------------------------------
  // By Evolved
  // http://www.vector3r.com/
  //--------------------------------

  //-----------------
  // un-tweaks
  //-----------------
   matrix WorldVP:WorldViewProjection; 
   matrix World:World;    

  //-----------------
  // tweaks
  //-----------------
   float4 Ambient   = {0.3f, 0.3f, 0.3f, 1.0f};    
   float4 LightPosition_1 = {0.0f, 50.0f, 0.0f, 1.0f};    
   float4 LightColor_1 = {1.0f, 0.0f, 0.0f, 1.0f};    
   float  LightRange_1 = 55.0f;    
   float4 LightPosition_2 = {50.0f, 50.0f, 0.0f, 1.0f}; 
   float4 LightColor_2 = {1.0f, 0.0f, 0.0f, 1.0f};    
   float  LightRange_2 = 55.0f; 
   float4 LightPosition_3 = {100.0f, 50.0f, 0.0f, 1.0f};     
   float4 LightColor_3 = {0.0f, 1.0f, 0.0f, 1.0f};    
   float  LightRange_3 = 55.0f; 
   float4 LightPosition_4 = {150.0f, 50.0f, 0.0f, 1.0f};       
   float4 LightColor_4 = {0.0f, 0.0f, 1.0f, 1.0f};    
   float  LightRange_4 = 55.0f;    
   float4 LightPosition_5 = {0.0f, 50.0f, 50.0f, 1.0f};    
   float4 LightColor_5 = {1.0f, 1.0f, 1.0f, 1.0f};    
   float  LightRange_5 = 55.0f;    
   float4 LightPosition_6 = {50.0f, 50.0f, 50.0f, 1.0f}; 
   float4 LightColor_6 = {1.0f, 0.0f, 0.0f, 1.0f};    
   float  LightRange_6 = 55.0f; 
   float U = 1.0f; 
   float V = 1.0f; 

  //-----------------
  // Textures
  //-----------------
   texture BaseTX
    <
	string Name="";
    >;	
   sampler2D Base = sampler_state 
    {
 	texture = <BaseTX>;
    };

  //-----------------
  // structs 
  //-----------------
   struct input
     {
 	float4 Pos:POSITION; 
 	float2 UV:TEXCOORD; 
	float3 Normal : NORMAL;
     };
   struct output
     {
	float4 OPos:POSITION; 
 	float2 Tex:TEXCOORD0;  
	float3 Attenuation:TEXCOORD1;
	float Diffuse:TEXCOORD2;
     };
   struct output0
     {
	float4 OPos:POSITION; 
 	float2 Tex:TEXCOORD0;  
	float3 Attenuation:TEXCOORD1;
	float Diffuse:TEXCOORD2;
	float3 Attenuation0:TEXCOORD3;
	float Diffuse0:TEXCOORD4;
     };

  //-----------------
  // vertex shader
  //-----------------
    output VS(input IN) 
     {
 	output OUT;
	OUT.OPos=mul(IN.Pos,WorldVP); 
 	OUT.Tex=IN.UV*float2(U,V);
	OUT.Attenuation=0;
 	OUT.Diffuse=0; 
	return OUT;
     }
   output VS_L1(input IN) 
     {
 	output OUT;
	OUT.OPos=mul(IN.Pos,WorldVP); 
 	OUT.Tex=IN.UV*float2(U,V);
	float3 Wnor=mul(IN.Normal,World); Wnor=normalize(Wnor);
	float3 WPos=mul(IN.Pos,World);  
	float3 LightPos=LightPosition_1-WPos; 
	OUT.Attenuation=-LightPos/LightRange_1;
 	OUT.Diffuse=saturate(0.02f+mul(Wnor,LightPos)*0.02f); 
	return OUT;
     }
   output0 VS_L2(input IN) 
     {
 	output0 OUT;
	OUT.OPos=mul(IN.Pos,WorldVP); 
 	OUT.Tex=IN.UV*float2(U,V);
	float3 Wnor=mul(IN.Normal,World); Wnor=normalize(Wnor);
	float3 WPos=mul(IN.Pos,World);  
	float3 LightPos=LightPosition_1-WPos; 
	OUT.Attenuation=-LightPos/LightRange_1;
 	OUT.Diffuse=saturate(0.02f+mul(Wnor,LightPos)*0.02f); 
	LightPos=LightPosition_2-WPos; 
	OUT.Attenuation0=-LightPos/LightRange_2;
 	OUT.Diffuse0=saturate(0.02f+mul(Wnor,LightPos)*0.02f); 
	return OUT;
     }
   output VS_L3(input IN) 
     {
 	output OUT;
	OUT.OPos=mul(IN.Pos,WorldVP); 
 	OUT.Tex=IN.UV*float2(U,V);
	float3 Wnor=mul(IN.Normal,World); Wnor=normalize(Wnor);
	float3 WPos=mul(IN.Pos,World);  
	float3 LightPos=LightPosition_3-WPos; 
	OUT.Attenuation=-LightPos/LightRange_3;
 	OUT.Diffuse=saturate(0.02f+mul(Wnor,LightPos)*0.02f); 
	return OUT;
     }
   output0 VS_L4(input IN) 
     {
 	output0 OUT;
	OUT.OPos=mul(IN.Pos,WorldVP); 
 	OUT.Tex=IN.UV*float2(U,V);
	float3 Wnor=mul(IN.Normal,World); Wnor=normalize(Wnor);
	float3 WPos=mul(IN.Pos,World);  
	float3 LightPos=LightPosition_3-WPos; 
	OUT.Attenuation=-LightPos/LightRange_3;
 	OUT.Diffuse=saturate(0.02f+mul(Wnor,LightPos)*0.02f); 
	LightPos=LightPosition_4-WPos; 
	OUT.Attenuation0=-LightPos/LightRange_4;
 	OUT.Diffuse0=saturate(0.02f+mul(Wnor,LightPos)*0.02f); 
	return OUT;
     }
   output VS_L5(input IN) 
     {
 	output OUT;
	OUT.OPos=mul(IN.Pos,WorldVP); 
 	OUT.Tex=IN.UV*float2(U,V);
	float3 Wnor=mul(IN.Normal,World); Wnor=normalize(Wnor);
	float3 WPos=mul(IN.Pos,World);  
	float3 LightPos=LightPosition_5-WPos; 
	OUT.Attenuation=-LightPos/LightRange_5;
 	OUT.Diffuse=saturate(0.02f+mul(Wnor,LightPos)*0.02f); 
	return OUT;
     }
   output0 VS_L6(input IN) 
     {
 	output0 OUT;
	OUT.OPos=mul(IN.Pos,WorldVP); 
 	OUT.Tex=IN.UV*float2(U,V);
	float3 Wnor=mul(IN.Normal,World); Wnor=normalize(Wnor);
	float3 WPos=mul(IN.Pos,World);  
	float3 LightPos=LightPosition_5-WPos; 
	OUT.Attenuation=-LightPos/LightRange_5;
 	OUT.Diffuse=saturate(0.02f+mul(Wnor,LightPos)*0.02f); 
	LightPos=LightPosition_6-WPos; 
	OUT.Attenuation0=-LightPos/LightRange_6;
 	OUT.Diffuse0=saturate(0.02f+mul(Wnor,LightPos)*0.02f); 
	return OUT;
     }

  //-----------------
  // pixel shader
  //-----------------
    float4 PS(output IN)  : COLOR
     {
	float4 Texture=tex2D(Base,IN.Tex); 
	return Texture*Ambient;
     }
    float4 PS_L1(output IN)  : COLOR
     {
	float4 Texture=tex2D(Base,IN.Tex); 
	float4 DiffuseLight=1-saturate(dot(IN.Attenuation,IN.Attenuation));
	float4 Light=DiffuseLight*LightColor_1*IN.Diffuse;
	return Texture*(Light+Ambient);
     }
    float4 PS_L2(output0 IN)  : COLOR
     {
	float4 Texture=tex2D(Base,IN.Tex); 
	float4 DiffuseLight=1-saturate(dot(IN.Attenuation,IN.Attenuation));
	float4 Light=DiffuseLight*LightColor_1*IN.Diffuse;
	DiffuseLight=1-saturate(dot(IN.Attenuation0,IN.Attenuation0));
	Light=Light+DiffuseLight*LightColor_2*IN.Diffuse0;
	return Texture*(Light+Ambient);
     }
    float4 PS_L3(output IN)  : COLOR
     {
	float4 Texture=tex2D(Base,IN.Tex); 
	float4 DiffuseLight=1-saturate(dot(IN.Attenuation,IN.Attenuation));
	float4 Light=DiffuseLight*LightColor_3*IN.Diffuse;
	return Texture*Light;
     }
    float4 PS_L4(output0 IN)  : COLOR
     {
	float4 Texture=tex2D(Base,IN.Tex); 
	float4 DiffuseLight=1-saturate(dot(IN.Attenuation,IN.Attenuation));
	float4 Light=DiffuseLight*LightColor_3*IN.Diffuse;
	DiffuseLight=1-saturate(dot(IN.Attenuation0,IN.Attenuation0));
	Light=Light+DiffuseLight*LightColor_4*IN.Diffuse0;
	return Texture*Light;
     }
    float4 PS_L5(output IN)  : COLOR
     {
	float4 Texture=tex2D(Base,IN.Tex); 
	float4 DiffuseLight=1-saturate(dot(IN.Attenuation,IN.Attenuation));
	float4 Light=DiffuseLight*LightColor_5*IN.Diffuse;
	return Texture*Light;
     }
    float4 PS_L6(output0 IN)  : COLOR
     {
	float4 Texture=tex2D(Base,IN.Tex); 
	float4 DiffuseLight=1-saturate(dot(IN.Attenuation,IN.Attenuation));
	float4 Light=DiffuseLight*LightColor_5*IN.Diffuse;
	DiffuseLight=1-saturate(dot(IN.Attenuation0,IN.Attenuation0));
	Light=Light+DiffuseLight*LightColor_6*IN.Diffuse0;
	return Texture*Light;
     }


  //-----------------
  // techniques   
  //-----------------
   technique Ambient
      {
 	pass p1
      {		
 	vertexShader = compile vs_1_1 VS(); 
 	pixelShader  = compile ps_1_4 PS(); 	
      }
      }
   technique Light1
      {
 	pass p1
      {		
 	vertexShader = compile vs_1_1 VS_L1(); 
 	pixelShader  = compile ps_1_4 PS_L1(); 	
      }
      }
   technique Light2
      {
 	pass p1
      {		
 	vertexShader = compile vs_1_1 VS_L2(); 
 	pixelShader  = compile ps_1_4 PS_L2(); 	
      }
      }
   technique Light3
      {
 	pass p1
      {		
 	vertexShader = compile vs_1_1 VS_L2(); 
 	pixelShader  = compile ps_1_4 PS_L2(); 	
      }
 	pass p2
      {		
 	vertexShader = compile vs_1_1 VS_L3(); 
 	pixelShader  = compile ps_1_4 PS_L3();
	AlphaBlendEnable = True;
 	SrcBlend = One;
 	DestBlend = One;
      }
      }
   technique Light4
      {
 	pass p1
      {		
 	vertexShader = compile vs_1_1 VS_L2(); 
 	pixelShader  = compile ps_1_4 PS_L2(); 	
      }
 	pass p2
      {		
 	vertexShader = compile vs_1_1 VS_L4(); 
 	pixelShader  = compile ps_1_4 PS_L4();
	AlphaBlendEnable = True;
 	SrcBlend = One;
 	DestBlend = One;
      }
      }
  technique Light5
      {
 	pass p1
      {		
 	vertexShader = compile vs_1_1 VS_L2(); 
 	pixelShader  = compile ps_1_4 PS_L2(); 	
      }
 	pass p2
      {		
 	vertexShader = compile vs_1_1 VS_L4(); 
 	pixelShader  = compile ps_1_4 PS_L4();
	AlphaBlendEnable = True;
 	SrcBlend = One;
 	DestBlend = One;
      }
 	pass p3
      {		
 	vertexShader = compile vs_1_1 VS_L5(); 
 	pixelShader  = compile ps_1_4 PS_L5();
	AlphaBlendEnable = True;
 	SrcBlend = One;
 	DestBlend = One;
      }
      }
   technique Light6
      {
 	pass p1
      {		
 	vertexShader = compile vs_1_1 VS_L2(); 
 	pixelShader  = compile ps_1_4 PS_L2(); 	
      }
 	pass p2
      {		
 	vertexShader = compile vs_1_1 VS_L4(); 
 	pixelShader  = compile ps_1_4 PS_L4();
	AlphaBlendEnable = True;
 	SrcBlend = One;
 	DestBlend = One;
      }
 	pass p3
      {		
 	vertexShader = compile vs_1_1 VS_L6(); 
 	pixelShader  = compile ps_1_4 PS_L6();
	AlphaBlendEnable = True;
 	SrcBlend = One;
 	DestBlend = One;
      }
      }