!!ARBvp1.0

ATTRIB iPos     = vertex.position;
ATTRIB iNormal  = vertex.normal;
ATTRIB iColour  = vertex.color;
#PARAM  mvinv[4] = { state.matrix.modelview.invtrans };
PARAM  mvp[4]   = { state.matrix.mvp };
PARAM  lightDir0 = state.light[0].position;
PARAM  halfDir0  = state.light[0].half;
PARAM  lightPos1 = state.light[1].position;
PARAM  specExp   = state.material.shininess;
PARAM  ambientCol   = state.lightmodel.ambient;
PARAM  diffuseCol0  = state.light[0].diffuse;
PARAM  specularCol0 = state.lightprod[0].specular;
PARAM  diffuseCol1  = state.light[1].diffuse;
PARAM  specularCol1 = state.lightprod[1].specular;

TEMP   eyeNormal, temp, dots0, dots1, lightcoefs0, lightcoefs1, diffuse0, diffuse1, ambient, lightDir1, half1, eyePos;
OUTPUT oPos     = result.position;
OUTPUT oColor   = result.color;

# Transform the vertex to clip coordinates.
DP4	 oPos.x, mvp[0], iPos;
DP4	 oPos.y, mvp[1], iPos;
DP4	 oPos.z, mvp[2], iPos;
DP4	 oPos.w, mvp[3], iPos;

# Transform the normal into eye space.
# NB no rotation assumed!
MOV  eyeNormal, iNormal;
#DP3	 eyeNormal.x, mvinv[0], iNormal;
#DP3	 eyeNormal.y, mvinv[1], iNormal;
#DP3	 eyeNormal.z, mvinv[2], iNormal;

# Compute diffuse and specular dot products
# and use LIT to compute lighting coefficients.
DP3	 dots0.x, eyeNormal, lightDir0;
DP3	 dots0.y, eyeNormal, halfDir0;
MOV	 dots0.w, specExp.x;
LIT	 lightcoefs0, dots0;

# light 1 is a point light
# NB no rotation assumed!
MOV  eyePos, iPos;
SUB  lightDir1, lightPos1, eyePos;
DP3  temp, lightDir1, lightDir1;
RSQ  temp, temp.x;
MUL  lightDir1, temp, lightDir1;
ADD  half1, lightDir1, {0,0,1};
DP3  temp, half1, half1;
RSQ  temp, temp.x;
MUL  half1, temp, half1;
DP3	 dots1.x, eyeNormal, lightDir1;
DP3	 dots1.y, eyeNormal, half1;
MOV	 dots1.w, specExp.x;
LIT	 lightcoefs1, dots1;

# combine vertex and light colours
MUL  diffuse0, diffuseCol0, iColour;
MUL  diffuse1, diffuseCol1, iColour;
MUL  ambient, ambientCol, iColour;

# Accumulate color contributions.
MAD	 temp, lightcoefs0.y, diffuse0, ambient;
MAD	 temp, lightcoefs1.y, diffuse1, temp;
MAD	 temp, lightcoefs0.z, specularCol0, temp;
MAD	 oColor.xyz, lightcoefs1.z, specularCol1, temp;
MOV	 oColor.w, iColour.w;

MOV  result.texcoord[0], vertex.texcoord;

END
