float4x4    mViewProj : VIEWPROJECTION;

struct VS_INPUT_terrain { 
	float3 Pos			: POSITION0; 
	float3 Normal		: NORMAL0;
	float4 Color		: COLOR0;
	float2 UV0			: TEXCOORD0; 
	float2 UV1			: TEXCOORD1; 
}; 

struct VS_OUTPUT_terrain { 
	float4 Pos	    	: POSITION; 
	float3 Normal		: NORMAL;
	float4 Color		: COLOR;
	float2 UV0			: TEXCOORD0;
	float2 UV1			: TEXCOORD1; 
}; 

VS_OUTPUT_terrain VSTerrain(VS_INPUT_terrain i)
{
	VS_OUTPUT_terrain Out = (VS_OUTPUT_terrain)0;

	Out.Pos = mul(float4(i.Pos,1), mViewProj);
	Out.Normal = i.Normal;
	Out.Color = i.Color;
	Out.UV0 = i.UV0;
	Out.UV1 = i.UV1;

	return Out;
}

texture TexTerrainColor;
texture TexTerrainNormal;
float3	terrainDirLightDir;
float3	terrainDirLightVal;
float3	terrainAmbLight;
sampler2D SamplerTerrainColor = sampler_state { Texture = TexTerrainColor; MAGFILTER = LINEAR; MINFILTER = POINT; MIPFILTER = LINEAR; };
sampler2D SamplerTerrainNormal = sampler_state { Texture = TexTerrainNormal; MAGFILTER = LINEAR; MINFILTER = POINT; MIPFILTER = LINEAR; };

float4 PSTerrain(VS_OUTPUT_terrain i) : COLOR 
{
	float4	tex1	=	tex2D(SamplerTerrainColor, i.UV0);
	float4	tex2	=	tex2D(SamplerTerrainColor, i.UV1);
	float4	pixnorm =	tex2D(SamplerTerrainNormal, i.UV0);

	float4	ltexcolor = lerp(tex1, tex2, i.Color.a) * i.Color.r;

	float	lnormval = dot(i.Normal, terrainDirLightDir);
	//float	lnormval = dot(pixnorm.rgb, terrainDirLightDir);

	float4	lcolor = lnormval * ltexcolor * float4(terrainDirLightVal, 0) + float4(terrainAmbLight, 0) * ltexcolor;

	lcolor.a = 1.0;

	return ltexcolor;
}

technique terrain {
	pass p0 {
		AlphaBlendEnable = true;
		AlphaTestEnable = false;
		VertexShader = compile vs_3_0 VSTerrain();
		PixelShader = compile ps_3_0 PSTerrain();
	}
}


