sampler2D CarLight;
sampler2D CarLightFade;
sampler2D LightMap;

struct PS_INPUT{
	float Depth				: TEXCOORD0;
	float4 ShadowPos		: TEXCOORD1;
};

struct PS_OUTPUT{
    float4 Color			: COLOR;
};


PS_OUTPUT main(const PS_INPUT Input){
	float Depth = tex2Dproj(LightMap, Input.ShadowPos);
	
	float2 BaseCoords = Input.ShadowPos.xy / Input.ShadowPos.w;
	
	BaseCoords.x = clamp(BaseCoords.x, 0, 1);
	BaseCoords.y = clamp(BaseCoords.y, 0, 1);
	
	float4 BaseTexColor;
	if (BaseCoords.x >= 0.0f && BaseCoords.x <= 1.0f && 
		BaseCoords.y >= 0.0f && BaseCoords.y <= 1.0f && 
		Input.ShadowPos.w > 0){
		BaseTexColor = tex2D(CarLight, BaseCoords);
	}
	else BaseTexColor = 0;
	
	//float Dist = sqrt(dot(Input.ShadowPos.xyz, Input.ShadowPos.xyz));
	//float Dist = length(Input.ShadowPos.xyz);
	
	
	//BaseTexColor *= tex2D(CarLightFade, float2(Input.ShadowPos.z / 500, 0));
	//BaseTexColor *= 1.0f - (Input.ShadowPos.z / 1000);

	float ShadowColor;
	//if (Input.Depth - Depth > 0.001f){
	if (Input.Depth - Depth > 0.1f){
		ShadowColor = 0.0f;
	}
	else ShadowColor = 1;
	
	// Texturing
	//float4 BaseTexColor = tex2D(CarLight, BaseTex);

	float3 TexColor = ShadowColor;
	TexColor *= BaseTexColor;
		
	PS_OUTPUT Out;
	Out.Color.rgb = TexColor;
	Out.Color.a = 1.0f;
	return Out;
}
