
#ifdef BASE_TEXTURE
	uniform	sampler2D Base:register(s0);
	uniform sampler2D Alpha:register(s1);
	
   #ifdef ALPHA_MODULATION
      sampler2D Alpha_Modulation:register(s1);
   #endif
#endif
float4 vAmbient;
uniform float FadeTransparency;

float4 main_ps(
#ifdef BASE_TEXTURE
   float2 texcoord: TEXCOORD0
   #ifdef TILING
      ,float2 texcoord_tiled : TEXCOORD1
   #endif
#endif
   ) : COLOR0
{
   float4 result;
#ifdef BASE_TEXTURE
      float4 base;
   #ifdef TILING
      base = tex2D(Base, texcoord_tiled);
   #else
      base = tex2D(Base, texcoord);
   #endif
   #ifdef ONE_BIT_ALPHA
      if(base.a < 0.8)
      {
         clip(-1);
      }
   #endif
      result = base * vAmbient * 0.5;
   #ifdef AVERAGE_ALPHA_CORRECTION_OUTPUT
      result.w *= (result.x + result.y + result.z) * 0.33;
   #endif
   #ifdef ADD_ALPHA_CORRECTION_OUTPUT
      result.xyz *= base.w;
   #endif
   #ifdef ALPHA_MODULATION
      result *= tex2D( Alpha_Modulation, texcoord ).r;
   #endif
 //  result *= FadeTransparency;
#else
   result = float4(vAmbient.xyz, vAmbient.w * FadeTransparency);
#endif

	float4 alpha = tex2D(Alpha, texcoord);
	result.a = alpha.a;
	return result;
}
