sampler2D CarLight;
sampler2D CarLightFade;
sampler2D LightMap;
sampler2D Tex0;

struct PS_INPUT{
	float4 ShadowPos		: TEXCOORD0;
	float2 BaseTex			: TEXCOORD1;
};

struct PS_OUTPUT{
    float4 Color			: COLOR;
};

PS_OUTPUT main(const PS_INPUT Input){
	// Base texture
	float4 BaseTex = tex2D(Tex0, Input.BaseTex);
	
	// Shadow + Light coords
	float2 BaseCoords = Input.ShadowPos.xy / Input.ShadowPos.w;
	BaseCoords = clamp(BaseCoords, 0, 1);
	
	float4 LightColor;
	if (Input.ShadowPos.z > 1.0f){
		LightColor = tex2D(CarLight, BaseCoords);
	}
	else LightColor = 0;
	
	// Distance fading
	LightColor *= tex2D(CarLightFade, float2(Input.ShadowPos.z / 500, 0));
	
	// Final contribution
	float3 TexColor = 1;
	TexColor *= LightColor;
	TexColor *= BaseTex.a;
		
	PS_OUTPUT Out;
	Out.Color.rgb = TexColor;
	Out.Color.a = 1.0f;
	return Out;
}
