
float4x4 worldViewProj;
float4x4 world;

struct VS_Input
{
	float4 Position : POSITION;
	float3 Normal : NORMAL;
	float2 TexCoord : TEXCOORD0;
};

struct VS_Output
{
	float4 Position : POSITION;
	float3 Normal : NORMAL;
	float2 TexCoord : TEXCOORD0;
};


VS_Output VtxStd(VS_Input inp)
{
	VS_Output o;
	o.Position = mul(inp.Position, worldViewProj);
	o.Normal = mul(float4(inp.Normal, 0), world).xyz;
	o.TexCoord = inp.TexCoord;
	return o;
}

float4 k_a;
float4 k_d;
float4 k_s;
float k_pow;
float4 k_e;

float3 lightDir;
texture2D diffuse;
sampler2D samDif = sampler_state
{
    Texture = diffuse;
    MinFilter = LINEAR;
    MagFilter = LINEAR;    
    MipFilter = LINEAR;
	
	AddressU = WRAP;
	AddressV = WRAP;
};

struct PS_Input
{
	float3 Normal : NORMAL;
	float2 TexCoord : TEXCOORD0;
	float face : VFACE;
};

float4 PixStd(PS_Input inp) : COLOR
{

	float ndl = dot(inp.Normal, lightDir);
	
	if (inp.face<0)
	{
		ndl = max(0, -ndl);
	}
	else
	{
		ndl = max(0, ndl);
	}

	float4 res = tex2D(samDif, inp.TexCoord);

	res.rgb *= (k_a + k_d*ndl + k_e).rgb*1.1;
	res.a *= k_a.a;

	return res;
}

technique Standard
{
	pass p0
	{
		VertexShader = compile vs_3_0 VtxStd();
		PixelShader = compile ps_3_0 PixStd();
	}
}