sampler2D Tex0;

sampler2D Tex9;		// Detail sterkte
sampler2D Tex10;	// Detail texture

float3 Half;
float3 FogColor;

struct PS_INPUT{
	float4 Diffuse			: COLOR0;
    float4 DirtIntensity	: COLOR1;
    
	float2 BaseTex			: TEXCOORD0;
	float2 DirtTex			: TEXCOORD1;
	
	float FogIntensity		: TEXCOORD2;
};

struct PS_OUTPUT{
    float4 Color			: COLOR;
};


PS_OUTPUT main(const PS_INPUT Input){
	// Texturing
	float4 DetailComponents = lerp(0.5f, tex2D(Tex10, Input.DirtTex), Input.DirtIntensity);
	float4 DetailStrength = tex2D(Tex9, Input.BaseTex);
	
	float3 Detail3 = DetailComponents * DetailStrength;
	float DetailColor = length(Detail3);//dot(Detail3, Detail3);
	
	float4 BaseTexColor = tex2D(Tex0, Input.BaseTex);

	float3 TexColor = Input.Diffuse;
	TexColor = clamp(TexColor, 0, 1);
	TexColor += DetailColor + Half;
	TexColor = clamp(TexColor, 0, 1);
	TexColor *= BaseTexColor;

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