varying vec3 eyeVec;
varying vec2 texCoord;
varying vec3 lightVec[]; 
varying vec3 spotDirVec[];

uniform float spotCount;
uniform vec3 spotDir[];
uniform vec3 spotPos[];

void main(void)
{
   gl_Position = ftransform();
   texCoord = gl_MultiTexCoord0.xy;
   
   vec3 n = normalize(gl_NormalMatrix * gl_Normal);
   vec3 b = normalize(gl_NormalMatrix * vec3(0.0, 1.0, 0.0));
   vec3 t = cross(b, n);
   
   vec3 vVertex = vec3(gl_ModelViewMatrix * gl_Vertex);
   
   vec3 tmpVec = -vVertex;
   eyeVec.x = dot(tmpVec, t);
   eyeVec.y = dot(tmpVec, b);
   eyeVec.z = dot(tmpVec, n);
   
   vec3 ltPos = vec3(gl_ModelViewMatrix * vec4(spotPos[0], 1.0));
   tmpVec = ltPos - vVertex;

   lightVec[0].x = dot(tmpVec, t);
   lightVec[0].y = dot(tmpVec, b);
   lightVec[0].z = dot(tmpVec, n);
   
   //tmpVec = spotDir;
   tmpVec = vec3(gl_ModelViewMatrix * vec4(spotDir[0], 0.0));
   //tmpVec = spotDir[0];
   //tmpVec = gl_NormalMatrix * spotDir;
   spotDirVec[0].x = dot(tmpVec, t);
   spotDirVec[0].y = dot(tmpVec, b);
   spotDirVec[0].z = dot(tmpVec, n);
   
   if(spotCount >= 2.0) {
	   ltPos = vec3(gl_ModelViewMatrix * vec4(spotPos[1], 1.0));
	   tmpVec = ltPos - vVertex;
	
	   lightVec[1].x = dot(tmpVec, t);
	   lightVec[1].y = dot(tmpVec, b);
	   lightVec[1].z = dot(tmpVec, n);
	   
	   //tmpVec = spotDir;
	   tmpVec = vec3(gl_ModelViewMatrix * vec4(spotDir[1], 0.0));
	   //tmpVec = gl_NormalMatrix * spotDir;
	   spotDirVec[1].x = dot(tmpVec, t);
	   spotDirVec[1].y = dot(tmpVec, b);
	   spotDirVec[1].z = dot(tmpVec, n);
   }
   
   if(spotCount >= 3.0) {
	   ltPos = vec3(gl_ModelViewMatrix * vec4(spotPos[2], 1.0));
	   tmpVec = ltPos - vVertex;
	
	   lightVec[2].x = dot(tmpVec, t);
	   lightVec[2].y = dot(tmpVec, b);
	   lightVec[2].z = dot(tmpVec, n);
	   
	   //tmpVec = spotDir;
	   tmpVec = vec3(gl_ModelViewMatrix * vec4(spotDir[2], 0.0));
	   //tmpVec = gl_NormalMatrix * spotDir;
	   spotDirVec[2].x = dot(tmpVec, t);
	   spotDirVec[2].y = dot(tmpVec, b);
	   spotDirVec[2].z = dot(tmpVec, n);
   }
}