 #define SPEC_POWER 10.0
 
#define DIFFUSE_LIGHTING_SCALE 1.5
 
 #define FRESNEL_SCALE 1.0
 #define FRESNEL_BIAS 0.00
 #define FRESENEL_POWER 10
  
  float4 ambientColor  : register (c0);
  float4 diffuseColor  : register (c1);
  float4 worldLight    : register (c2);
  float4 specularColor : register (c3); //power in c3.w
  float4 blendPct      : register (c4); //bump map blend in c4.z, cube map blend in c4.w
  
  struct PS_INPUT
  {
    float4 Color   : COLOR0;
    float4 Omni    : COLOR1;
    float  Fog     : FOG;

    float2 Tex0    : TEXCOORD0; // base0=xy, spec=zw - textures swapped
    float  Distance    : TEXCOORD1; // bump=xy, base1=zw - textures swapped
    float3 EyeVec  : TEXCOORD2;	
    float3 Normal  : TEXCOORD3; // 
  };
  
  struct PS_OUTPUT
  {
    float4 Color : COLOR0;
  };
      
  sampler2D sBase:  register (s0);
    
  PS_OUTPUT ps20_RZFoilageSprites (PS_INPUT Input)
  {
    PS_OUTPUT Out;
	
    float3 distances = float3(LOD_START,LOD_DISTANCE,LOD_START+LOD_DISTANCE) * specularColor.a;
    if(Input.Distance > distances.z)
		discard;
	
	Input.Distance = saturate((Input.Distance - distances.x)/distances.y);
		
    float4 basePixel  = tex2D (sBase, Input.Tex0.xy);  // sample base tex
	
	if(basePixel.a == 0.0f)
		discard;
		        
	float3 normal = normalize(Input.Normal);
	float3 normEyeVec = normalize(Input.EyeVec);
	float3 halfway =  normalize (worldLight -  normEyeVec); 
    float NdotL = saturate(dot(normal,worldLight));
    float NdotH = saturate(dot(normal,halfway));

	ambientColor += diffuseColor * 0.5;
	diffuseColor *= 0.6;
		
	Out.Color = saturate(NdotL * DIFFUSE_LIGHTING_SCALE) * diffuseColor;
	Out.Color += (pow(NdotH, SPEC_POWER)) * specularColor * saturate(NdotL * 3) * basePixel.b;
	Out.Color += ambientColor + Input.Omni;
	Out.Color *= basePixel * Input.Color;
	Out.Color.a = lerp(basePixel.a,0.0f,Input.Distance);
	
    return (Out);
  }
  
  
  