// This is C3E3f_texture from "The Cg Tutorial" (Addison-Wesley, ISBN
// 0321194969) by Randima Fernando and Mark J. Kilgard.  See page 67.

float Ambient = 0.0;
float HighLight = 0.0;
float Thickness = 0.001;
float ColorBlend = 10.0;
float ShadeBlend = 10.0;
float HighLightBlend = 10.0;
float HighLightPower = 100;
float4 PenColor : Diffuse = { 0, 0, 0, 1 };
float4 ShadowColor : Diffuse = { 0, 0, 0, 1 };
float4 LightDir : Direction = { 0, 1, 0, 0 };
float4 LightDirForced : Direction = { 0, 0, -1, 0 };
float4 ColorRate = { 1, 1, 1, 1 };
float4 UVSCR = { 0, 0, 0, 0 };

struct C3E3f_Output {
  float4 color : COLOR;
};

C3E3f_Output C3E3f_texture(float4 position : POSITION,
                           float4 normal : TEXCOORD1,
                           float2 texCoord : TEXCOORD0,
                           uniform sampler2D shadeTex : TEX0,
                           uniform sampler2D colorTex : TEX1)
{
  C3E3f_Output OUT;
  float L = dot(normal, -LightDirForced);
  float lp = min(1.0, max(0.0, L*0.6 + Ambient*0.01));
  float hp0 = min(1.0, max(0.0, L*0.708 + HighLight*0.01));
  float hp = pow(hp0, HighLightPower);

  float4 shadecol = tex2D(shadeTex, float2(lp, 0.5));
  float4 texcol = tex2D(colorTex, texCoord);
  float4 hl = float4(hp, hp, hp, 1.0);

  float4 col;
  col = (texcol*(ColorBlend*0.1))*(shadecol*(ShadeBlend*0.1));
  col += hl*(HighLightBlend*0.0025);

  OUT.color = float4(col.rgb, texcol.a);
  return OUT;
}

