
// Shader output, position and diffuse color
struct VS_OUTPUT
{
    float4 pos  : POSITION;
    float4 diff : COLOR0;
    float2 Txcoord0 : TEXCOORD0;
    float fog : FOG;
};

// The world view and projection matrices
float4x4 World: WORLD;
float4x4 ViewProj: VIEWPROJ;

float4 EyeLocation;

float4 LightDir0;
float4 LightDir1;

float4 DiffuseColor;
float4 AmbientColor;

float4 LightColor0;
float4 LightColor1;

bool IsForAnimtionTexture;
bool LightingEnabled;


VS_OUTPUT VS(float4 Pos  : POSITION, float3 Normal : NORMAL0, float2 Txcoord0 : TEXCOORD0)
{
    // Declare our return variable
    VS_OUTPUT Out = (VS_OUTPUT)0;

    // Transform our position
    float4 p = Pos;       
    
    float3 n = normalize(mul(Normal, World));
    n = normalize(n);	
    
	
    float4 wp = mul(p, World);
    
    float4 toEye = EyeLocation - wp;
    float3 toEyeTemp = toEye;
    if(dot(n, toEyeTemp) < 0)
		n = -1*n;
    
    //Set our color 
    if(LightingEnabled)
    {
		// 1st light
		float diffuse0 = saturate(dot(n, LightDir0));  
		float4 diffuseColor0 = LightColor0*diffuse0;
    
		 // 2nd light  
		 float diffuse1 = saturate(dot(n, LightDir1));
		float4 diffuseColor1 = LightColor1*diffuse1;
               
		float4 diffuseColorSum = diffuseColor0 + diffuseColor1;
		Out.diff = AmbientColor + DiffuseColor*diffuseColorSum;			
	}
	else
	{
		Out.diff.rgb = 0;
	}
	
	Out.diff.a = DiffuseColor.a;
	    
    p = mul(wp, ViewProj);
      
    Out.pos = p;
    Out.Txcoord0 = Txcoord0;
    	
	//fog
	Out.fog = 1.0f;  

    // Return
    return Out;
}


technique T
{
    pass P0
    {    
        FogEnable = True;
        // shaders
        VertexShader = compile vs_1_1 VS();
        PixelShader  = NULL;
    }
}

