uniform sampler greyArea		: register(s0);
uniform sampler splat0			: register(s1);
uniform sampler diffusemap[4];

static const float LOS_THRESHOLD = 0.75f;
static const float LOS_DARKENING = 0.60f;

extern uniform float worldSize;
extern uniform float4 losTint; 

struct VS_INPUT 
{
	float2 uv0							: TEXCOORD0;
	float2 terrainUV					: TEXCOORD1;
	float4 color						: COLOR0;
};

float4 main_ps( VS_INPUT input ) : COLOR0
{
	float4 splatValues0 = tex2D(splat0, input.terrainUV);

	float fSum = splatValues0.a + splatValues0.r + splatValues0.g + splatValues0.b;

	float4 outColor = tex2D( diffusemap[0], input.uv0 ) * splatValues0.a/fSum ;
	outColor += tex2D( diffusemap[1], input.uv0 ) * splatValues0.b/fSum ;
	outColor += tex2D( diffusemap[2], input.uv0 ) * splatValues0.g/fSum ;
	outColor += tex2D( diffusemap[3], input.uv0 ) * splatValues0.r/fSum ;

	float offset = 1/worldSize;

	// Ashwin please review : rakehsj
	float fOneTileOffset = 4*offset;

	float2 tempGreyAreaUV = float2( input.terrainUV.x-fOneTileOffset, input.terrainUV.y );

	float4 tempGrey = tex2D( greyArea, float2(tempGreyAreaUV.x, tempGreyAreaUV.y) );

#ifndef FUZZY_LOS 
	if( tempGrey.r < LOS_THRESHOLD )
	{
		outColor.rgb *= losTint;
	}
#else
	// tempGrey:0.5->1.0
	outColor *= lerp( 2*losTint-1, 1, tempGrey.r);
#endif

	return outColor * input.color;
}
