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){
	
	float2 BaseCoords = Input.ShadowPos.xy / Input.ShadowPos.w;
	BaseCoords = clamp(BaseCoords, 0, 1);
	
	float4 BaseTexColor;
	if (Input.ShadowPos.z > 1.0f){
		BaseTexColor = tex2D(CarLight, BaseCoords);
	}
	else BaseTexColor = 0;
		
	BaseTexColor *= tex2D(CarLightFade, float2(Input.ShadowPos.z / 500, 0));

	float Depth = tex2Dproj(LightMap, Input.ShadowPos);

	float Diff = clamp(Input.Depth - Depth, 0, 1);
	float ShadowColor = 1.0f - (Diff * 3);
	
	// Texturing
	float3 TexColor = ShadowColor;
	TexColor *= BaseTexColor;
		
	PS_OUTPUT Out;
	Out.Color.rgb = TexColor;
	Out.Color.a = 1.0f;
	return Out;
}
