!!ARBfp1.0

ATTRIB iColor = fragment.color.primary;
ATTRIB iPos = fragment.position;

ATTRIB iTex = fragment.texcoord[0];
ATTRIB iNormal = fragment.texcoord[1];
ATTRIB iLight0 = fragment.texcoord[2];
ATTRIB iLight1 = fragment.texcoord[3];
ATTRIB iLight2 = fragment.texcoord[4];

OUTPUT oColor = result.color;

PARAM lightColor0 = program.local[0];
PARAM lightColor1 = program.local[1];
PARAM lightColor2 = program.local[2];

PARAM matSpec = program.local[3];
PARAM fogColor = program.local[4];
PARAM fogParams = program.local[5];

PARAM e = {2.71828, 0, 0, 0};
#PARAM e = {20, 0, 0, 0};

TEMP N, L, C, NL, H, NH, texColor, ATT;

ALIAS diffuse = NL;
ALIAS specular = NH;
ALIAS fog = NH;

######### texture mapping ##############

TEX texColor, iTex, texture[0], 2D;

######### normalize the normal #########

DP3 N.w, iNormal, iNormal;
RSQ N.w, N.w;
MUL N, iNormal, N.w;

########## self illumination ###########

MOV C, {0, 0, 0, 1};
MUL C.rgb, iColor, texColor;

############## light 0 #################

# normalize the light vector
DP3 L.w, iLight0, iLight0;
RSQ L.w, L.w;
MUL L.xyz, iLight0, L.w;

# attenuation
MUL_SAT L.w, L, lightColor0;

# half vec
ADD H, L, {0, 0, 1};
DP3 H.w, H, H;
RSQ H.w, H.w;
MUL H, H, H.w;

#diffuse
DP3 NL, N, L;
MAX NL, NL, 0.0;
MUL diffuse, texColor, NL;
MUL diffuse, diffuse, L.w;
MAD C.rgb, diffuse, lightColor0, C;

#specular
DP3 NH, N, H;
MAX NH, NH, 0.0;
POW specular, NH.x, matSpec.w;
MUL specular, specular, matSpec;
MUL specular, specular, L.w;
MAD C.rgb, specular, lightColor0, C;

############## light 1 #################

# normalize the light vector
DP3 L.w, iLight1, iLight1;
RSQ L.w, L.w;
MUL L.xyz, iLight1, L.w;

# attenuation
MUL_SAT L.w, L, lightColor1;

# half vec
ADD H, L, {0, 0, 1};
DP3 H.w, H, H;
RSQ H.w, H.w;
MUL H, H, H.w;

#diffuse
DP3 NL, N, L;
MAX NL, NL, 0.0;
MUL diffuse, texColor, NL;
MUL diffuse, diffuse, L.w;
MAD C.rgb, diffuse, lightColor1, C;

#specular
DP3 NH, N, H;
MAX NH, NH, 0.0;
POW specular, NH.x, matSpec.w;
MUL specular, specular, matSpec;
MUL specular, specular, L.w;
MAD C.rgb, specular, lightColor1, C;

############## light 2 #################

# normalize the light vector
DP3 L.w, iLight2, iLight2;
RSQ L.w, L.w;
MUL L.xyz, iLight2, L.w;

# attenuation
MUL_SAT L.w, L, lightColor2;

# half vec
ADD H, L, {0, 0, 1};
DP3 H.w, H, H;
RSQ H.w, H.w;
MUL H, H, H.w;

#diffuse
DP3 NL, N, L;
MAX NL, NL, 0.0;
MUL diffuse, texColor, NL;
MUL diffuse, diffuse, L.w;
MAD C.rgb, diffuse, lightColor2, C;

#specular
DP3 NH, N, H;
MAX NH, NH, 0.0;
POW specular, NH.x, matSpec.w;
MUL specular, specular, matSpec;
MUL specular, specular, L.w;
MAD C.rgb, specular, lightColor2, C;

################ Fog ####################

#MUL fog.x, iPos.z, fogColor.w;
#MUL fog.x, fog.x, fog.x;
#POW fog.x, e.x, -fog.x;
#MAX fog.x, fog.x, 0.0;
#MIN fog.x, fog.x, 1.0;
#LRP oColor.rgb, fog.x, C, fogColor;

#SUB fog.x, iPos.z, fogParams.x;
#MUL fog.x, fog.x, fogParams.y;
#MAX fog.x, fog.x, 0.0;
#MIN fog.x, fog.x, 1.0;
#LRP oColor.rgb, fog.x, fogColor, C;

MOV oColor.rgb, C;
MOV oColor.a, texColor;

END