uniform float4 fvSpecular;
uniform float4 fvDiffuse;
uniform float fSpecularPower;

uniform sampler2D baseMap1:register(s0);
uniform sampler2D AlphaMap1:register(s1);
uniform sampler2D baseMap2:register(s2);
uniform sampler2D AlphaMap2:register(s3);
uniform sampler2D bumpMap:register(s4);
uniform sampler2D specMap:register(s5);

struct PS_INPUT 
{
   float2 Texcoord :        TEXCOORD0;
   float3 ViewDirection :   TEXCOORD1;
   float3 LightDirection:   TEXCOORD2;
   
};

float4 main_ps( PS_INPUT Input ) : COLOR0
{
	float3 fvNormal         = normalize( ( tex2D( bumpMap, Input.Texcoord).xyz * 2.0f ) - 1.0f );
	float  fNDotL           = dot( fvNormal, Input.LightDirection ); 
   
	float3 fvReflection     = normalize( ( ( 2.0f * fvNormal ) * ( fNDotL ) ) - Input.LightDirection ); 
	float  fRDotV           = max( 0.0f, dot( fvReflection, Input.ViewDirection ) );

	float4 fvBaseColor		= tex2D( baseMap1, Input.Texcoord);
	float fAlpha			= tex2D( AlphaMap1, Input.Texcoord).a;
	fvBaseColor.a = fAlpha;

	if(fAlpha)
	{
		float fAlpha2			= tex2D(AlphaMap2, Input.Texcoord).a;
		
		if(fAlpha2)
		{
			float4 fvBaseColor2		= tex2D( baseMap2, Input.Texcoord);	
			fvBaseColor.rgb = fvBaseColor2.rgb;
		}
	}

	float fSpecColor		= tex2D( specMap, Input.Texcoord ).r;
 			
	float4 fvTotalAmbient   = fRDotV * fvBaseColor; 
	fvTotalAmbient			= fvTotalAmbient + fvDiffuse * fNDotL * fvBaseColor; 
	fvTotalAmbient			= fvTotalAmbient + (fvSpecular * fSpecColor) * pow( fRDotV , fSpecularPower);
	
	fvTotalAmbient			= saturate(fvTotalAmbient + fvBaseColor * 0.5 );
	fvBaseColor.rgb = fvTotalAmbient.rgb;

	return fvBaseColor;
}
