struct vertex {
	float4 position  : POSITION;
	float4 color0    : COLOR0;
	float2 texcoord0 : TEXCOORD0;
	float4 normal    : NORMAL;
};

struct fragment {
	float4 position  : POSITION;
	float4 color0    : COLOR0;
	float2 texcoord0 : TEXCOORD0;
	float4 normal    : COLOR1;
};


fragment main(vertex IN,
			  uniform float4x4 modelViewProj,
			  uniform float2x2 textureMatrix,
			  uniform float4x4 modelViewIT)
{
	fragment OUT;

	OUT.position = mul(modelViewProj, IN.position);
	OUT.color0 = IN.color0;
	OUT.texcoord0 = mul(textureMatrix, IN.texcoord0);

	OUT.color0.a = OUT.position.z;
	if (OUT.color0.a < 0) OUT.color0.a = -OUT.color0.a;

	OUT.normal.xyz = normalize(mul(modelViewIT, IN.normal).xyz);

	float diffuse = 1-dot(OUT.normal.xyz, float3(0.0, -0.1, 0.9));
	OUT.color0.a = 1-(1-diffuse*diffuse*diffuse*diffuse);
	OUT.color0.a = OUT.color0.a + (1-diffuse)*(1-diffuse)*(1-diffuse);
	OUT.color0.a = (OUT.color0.a * OUT.color0.a)*2;


	return OUT;
}
