uniform sampler falloff : register(s0);

static const int NUM_LIGHTS = 2;

uniform float3 lightAmbient[NUM_LIGHTS];
uniform float3 lightDiffuse[NUM_LIGHTS];

uniform float4 wsPosCamera;
static float fDistMax = 1000;

struct VS_INPUT 
{
	float2 uv0							: TEXCOORD0;
	float4 shadowUV						: TEXCOORD1;
	float2 terrainUV					: TEXCOORD2;
	float3 tsLightDir					: TEXCOORD3;	//tangent space light direction
	float3 wsNormal						: TEXCOORD6;
	float3 wsPos						: TEXCOORD7;
};

float4 main_ps( VS_INPUT input ) : COLOR0
{
	float4 outColor = float4(1, 1, 1, 1);

	float3 normal = normalize( input.wsNormal );
	float3 lightDir = normalize( input.tsLightDir );
	float nDotL = dot(normal, lightDir);
	float3 l = lightAmbient[0] + lightDiffuse[0] * max( 0, nDotL );
	outColor.rgb = saturate( l + l );
	
	float fDist = distance( input.wsPos, wsPosCamera );
	float3 fBrightness = tex1D( falloff, fDist/fDistMax ); 
	outColor.rgb *= fBrightness;
	
	return outColor;
}
