/*
// All the joints
uniform float4 joints[223];

//uniform vec4 lightPos;

//varying vec3 normal;
//varying vec3 toLight;

struct vert
{
	float4 pos : POSITION;
	float2 tex : TEXCOORD0;
	float4 weight : TEXCOORD1;
	float4 index : TEXCOORD1;
};

struct toFrag
{
	float4 pos : POSITION;
	float2 tex : TEXCOORD0;
};

uniform float4x4 ModelViewProjection : state.matrix.mvp;

toFrag main(vert IN)
{
   float4 weight = IN.weight;
   float4 index = IN.index;

//   float4x4 trans = weight.x * float4x4(joints[index.x + 0], joints[index.x + 1], joints[index.x + 2], float4(0,0,0,1));
//		    weight.y * joints[index.y] +
//		    weight.z * joints[index.z] +
//		    weight.w * joints[index.w];

   float4x4 trans;
   trans = weight.x * float4x4(float4(joints[index.x + 0].xyz,0),
			float4(joints[index.x + 1].xyz,0), float4(joints[index.x + 2].xyz, 0),
			float4(joints[index.x + 0].w,joints[index.x + 1].w,joints[index.x + 2].w,1)) +

	   weight.y * float4x4(float4(joints[index.y + 0].xyz,0),
			float4(joints[index.y + 1].xyz,0), float4(joints[index.y + 2].xyz, 0),
			float4(joints[index.y + 0].w,joints[index.x + 1].w,joints[index.y + 2].w,1)) +

	   weight.z * float4x4(float4(joints[index.z + 0].xyz,0),
			float4(joints[index.z + 1].xyz,0), float4(joints[index.z + 2].xyz, 0),
			float4(joints[index.z + 0].w,joints[index.z + 1].w,joints[index.z + 2].w,1)) +

	   weight.w * float4x4(float4(joints[index.w + 0].xyz,0),
			float4(joints[index.w + 1].xyz,0), float4(joints[index.w + 2].xyz, 0),
			float4(joints[index.w + 0].w,joints[index.w + 1].w,joints[index.w + 2].w,1));

   float4 pos = mul(trans, IN.pos);
   pos.w = 1.0;

   toFrag OUT;
   OUT.tex = IN.tex;
   
   OUT.pos = mul(ModelViewProjection, pos);

   return OUT;
}
*/

void main(float3 position : POSITION,
                  float3 normal : NORMAL,
                  float2 texCoord : TEXCOORD0,
                  float4 weight : TEXCOORD1,
                  float4 matrixIndex : TEXCOORD2,

        out float4 oPosition : POSITION,
        out float2 oTexCoord : TEXCOORD0,

    uniform float4 boneMatrix[220], // 24 matrices
    uniform float4x4 modelViewProj : state.matrix.mvp)
{
  float3 netPosition = 0, netNormal = 0;

  for (int i = 0; i < 4; i++)
  {
    float index = matrixIndex[i];
    float3x4 model = float3x4(boneMatrix[index + 0],
                              boneMatrix[index + 1],
                              boneMatrix[index + 2]);
    float3 bonePosition = mul(model, float4(position, 1));
    // Assume no scaling in matrix, just rotate & translate
    float3x3 rotate = float3x3(model[0].xyz,
                             model[1].xyz,
                             model[2].xyz);
    float3 boneNormal = mul(rotate, normal);
    netPosition += weight[i] * bonePosition;
    netNormal += weight[i] * boneNormal;
  }

  netNormal = normalize(netNormal);

  oPosition = mul(modelViewProj, float4(netPosition, 1));
  oTexCoord = texCoord;
}