
// 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 LightDir0;
float4 LightDir1;

float4 LightColor0;
float4 LightColor1;

float4 DiffuseColor;
float4 AmbientColor;


bool IsForAnimtionTexture;
bool LightingEnabled;


float GlowSize;


VS_OUTPUT VSNormal(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);	
    
    //Set our color 
    if(LightingEnabled)
    {
		// 1st light
		float diffuse0 = max(dot(n, -LightDir0), 0);  
		float4 diffuseColor0 = LightColor0*diffuse0;
    
		// 2nd light  
		float diffuse1 = max(dot(n, -LightDir1), 0);
		float4 diffuseColor1 = LightColor1*diffuse1;
               
		float4 diffuseColorSum = diffuseColor0 + diffuseColor1;
		Out.diff = AmbientColor + DiffuseColor*diffuseColorSum;	
		Out.diff.a = DiffuseColor.a;
	}
	else
	{
		Out.diff = DiffuseColor;
	}
	
	
    float4 wp = mul(p, World);
    
    p = mul(wp, ViewProj);
      
    Out.pos = p;
    Out.Txcoord0 = Txcoord0;
    	
	//fog
	Out.fog = 1.0f;  

    // Return
    return Out;
}


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

    // Transform our position
    float3 n = normalize(mul(Normal, World));

 
    float3 wp = mul(Pos, World);
    wp += n*GlowSize;
     
    Out.pos = mul(float4(wp.xyz, 1.0f), ViewProj);
    		
	Out.diff = DiffuseColor;
	
	//fog
	Out.fog = 1.0f;  

    // Return
    return Out;
}


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


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

