//*
// All the joints
uniform mat4 joints[60];

uniform vec4 lightPos;

varying vec3 normal;
varying vec3 toLight;

void main(void)
{
   vec4 weight = gl_MultiTexCoord1;
   vec4 index = gl_MultiTexCoord2;

   gl_TexCoord[0] = gl_MultiTexCoord0;

   mat4 trans = weight.x * joints[int(index.x)] +
			weight.y * joints[int(index.y)] +
			weight.z * joints[int(index.z)] +
			weight.w * joints[int(index.w)];

   vec4 pos = trans * gl_Vertex;
   pos.w = 1.0;

   vec4 norm = trans * vec4(gl_Normal, 0.0);
   normal = normalize(gl_NormalMatrix * vec3(norm));
   
   vec4 transVert = gl_ModelViewMatrix * pos;
   toLight = normalize(vec3(lightPos - transVert));
   
   gl_Position = gl_ModelViewProjectionMatrix * pos;
}
//*/
/*
// All the joints (up to 81 joints)
uniform vec4 joints[243];

uniform vec4 lightPos;

varying vec3 normal;
varying vec3 toLight;

void main(void)
{
   vec4 weight = gl_MultiTexCoord1;
   vec4 index = gl_MultiTexCoord2;

   gl_TexCoord[0] = gl_MultiTexCoord0;

   // Make the matrices from vectors
   mat4 mats[4];
   vec4 jnts[4];
   jnts[0] = vec4(joints[int(index.x)].xyz, 0.0);
   jnts[1] = vec4(joints[int(index.x) + 1].xyz, 0.0);
   jnts[2] = vec4(joints[int(index.x) + 2].xyz, 0.0);
   jnts[3] = vec4(joints[int(index.x)].w, joints[int(index.x) + 1].w, joints[int(index.x) + 2].w, 1.0);
   mats[0] = mat4(jnts);
   
   jnts[0] = vec4(joints[int(index.y)].xyz, 0.0);
   jnts[1] = vec4(joints[int(index.y) + 1].xyz, 0.0);
   jnts[2] = vec4(joints[int(index.y) + 2].xyz, 0.0);
   jnts[3] = vec4(joints[int(index.y)].w, joints[int(index.y) + 1].w, joints[int(index.y) + 2].w, 1.0);
   mats[1] = mat4(jnts);
   
   jnts[0] = vec4(joints[int(index.z)].xyz, 0.0);
   jnts[1] = vec4(joints[int(index.z) + 1].xyz, 0.0);
   jnts[2] = vec4(joints[int(index.z) + 2].xyz, 0.0);
   jnts[3] = vec4(joints[int(index.z)].w, joints[int(index.z) + 1].w, joints[int(index.z) + 2].w, 1.0);
   mats[2] = mat4(jnts);
   
   jnts[0] = vec4(joints[int(index.w)].xyz, 0.0);
   jnts[1] = vec4(joints[int(index.w) + 1].xyz, 0.0);
   jnts[2] = vec4(joints[int(index.w) + 2].xyz, 0.0);
   jnts[3] = vec4(joints[int(index.w)].w, joints[int(index.w) + 1].w, joints[int(index.w) + 2].w, 1.0);
   mats[3] = mat4(jnts);
   
   
   //mats[0] = mat4(joints[int(index.x)], joints[int(index.x) + 1],
   //               joints[int(index.x) + 2], vec4(0.0, 0.0, 0.0, 1.0));
                  
   //mats[1] = mat4(joints[int(index.y)], joints[int(index.y) + 1],
   //               joints[int(index.y) + 2], vec4(0.0, 0.0, 0.0, 1.0));
                  
   //mats[2] = mat4(joints[int(index.z)], joints[int(index.z) + 1],
   //               joints[int(index.z) + 2], vec4(0.0, 0.0, 0.0, 1.0));
                  
   //mats[3] = mat4(joints[int(index.w)], joints[int(index.w) + 1],
   //               joints[int(index.w) + 2], vec4(0.0, 0.0, 0.0, 1.0));
                  
   mat4 trans = weight.x * mats[0] +
                weight.y * mats[1] + 
                weight.z * mats[2] + 
                weight.w * mats[3];
                
   vec4 pos = trans * gl_Vertex;
   pos.w = 1.0;

   vec4 norm = trans * vec4(gl_Normal, 0.0);
   normal = normalize(gl_NormalMatrix * vec3(norm));
   
   vec4 transVert = gl_ModelViewMatrix * pos;
   toLight = normalize(vec3(lightPos - transVert));
   
   gl_Position = gl_ModelViewProjectionMatrix * pos;
}
//*/