!!ARBfp1.0

#simple phong lighting shader

#Declarations
TEMP tmp;
TEMP dif;
TEMP spec;
TEMP view;

ATTRIB tex = fragment.texcoord[0];
ATTRIB nrm = fragment.texcoord[1];
ATTRIB lVec = fragment.texcoord[2];
ATTRIB vDir = fragment.texcoord[3];

PARAM color = {0.2, 0.3, 1.0, 1.0};   
PARAM const = {0.2, 0.2, 0.2, 32.0};

OUTPUT out = result.color;

#Normalize the normal
DP3 tmp.a, nrm, nrm;
RSQ tmp.a, tmp.a;
MUL tmp.rgb, nrm, tmp.a;

#normalize the view direction
DP3 view.a, vDir, vDir;
RSQ view.a, view.a;
MUL view.rgb, vDir, view.a;

#compute half angle vector
ADD spec.rgb, view, lVec;
DP3 spec.a, spec, spec;
RSQ spec.a, spec.a;
MUL spec.rgb, spec, spec.a;

#compute specular intensisty
DP3_SAT spec.a, spec, tmp;
LG2 spec.a, spec.a;
MUL spec.a, spec.a, const.w;
EX2 spec.a, spec.a;

#compute diffuse illum
DP3_SAT dif, tmp, lVec;
ADD_SAT dif.rgb, dif, const;

#sum
MAD_SAT dif.rgb, color, dif, spec.a;
MOV dif.a, color.a;

MOV out, dif;


END
