sampler2D Tex0;
sampler2D DirtTex;

float3 Half;

float3 FogColor;

#include "dcShadowMap_P.HLSL"

struct PS_INPUT{
	float4 Diff				: COLOR0;
	float4 DirtIntensity	: COLOR1;

	float2 BaseTex			: TEXCOORD0;
	float2 DirtTex			: TEXCOORD1;
	float Depth				: TEXCOORD2;
	float4 ShadowPos		: TEXCOORD3;
};

struct PS_OUTPUT{
    float4 Color			: COLOR;
};


PS_OUTPUT main(const PS_INPUT Input){
	float ShadowColor = ComputeShadow(Input.ShadowPos, Input.Depth);
		
	// Texturing
	float3 DirtTexColor = lerp(0.5f, tex2D(DirtTex, Input.DirtTex), Input.DirtIntensity);
	float4 BaseTexColor = tex2D(Tex0, Input.BaseTex);

	float3 TexColor = Input.Diff * ShadowColor;
	TexColor = clamp(TexColor, 0, 1);
	TexColor += DirtTexColor + Half;
	TexColor = clamp(TexColor, 0, 1);
	TexColor *= BaseTexColor;

	TexColor = lerp(BaseTexColor, TexColor, BaseTexColor.a);
	TexColor += FogColor * Input.DirtIntensity.a;
		
	PS_OUTPUT Out;
	Out.Color.rgb = TexColor;
	Out.Color.a = Input.Diff.a;
	return Out;
}
