uniform mat4 BoneStack[20];

varying vec4 ViewPos;
varying vec3 normal;
varying vec3 up;

void main()
{
  // skinnning!
  mat4 boneMatrix;
  vec4 vertPosition = vec4( 0.0f, 0.0f, 0.0f, 0.0f );
  mat3 boneNormalMatrix;
  vec3 rotNormal;

  vec4 BoneWeights = gl_MultiTexCoord2;
  vec4 BoneIndices = gl_MultiTexCoord3;

  vertPosition = gl_Vertex;
  // matrix 0
  boneMatrix = BoneStack[ 0 ];//int( BoneIndices.x ) ];
  vertPosition += (boneMatrix * gl_Vertex);// * BoneWeights.x;
  boneNormalMatrix = mat3( boneMatrix[0].xyz, boneMatrix[1].xyz, boneMatrix[2].xyz );
  rotNormal = boneNormalMatrix * gl_Normal;

  // matrix 1
  boneMatrix = BoneStack[ int( BoneIndices.y ) ];
  vertPosition += (boneMatrix * gl_Vertex) * BoneWeights.y;

  // matrix 2
  boneMatrix = BoneStack[ int( BoneIndices.z ) ];
  vertPosition += (boneMatrix * gl_Vertex) * BoneWeights.z;

  // matrix 3 
  boneMatrix = BoneStack[ int( BoneIndices.w ) ];
  vertPosition += (boneMatrix * gl_Vertex) * BoneWeights.w;

  // position
  ViewPos = gl_ModelViewMatrix * vertPosition;

  // normal
  normal = normalize(gl_NormalMatrix * rotNormal);
  up = normalize( gl_NormalMatrix * vec3( 0.0, 1.0, 0.0 ) );
    
  // set texture coords
  gl_TexCoord[0] = gl_MultiTexCoord0; // Color Map and normal map share coords
  
  // transform position
  gl_Position = gl_ModelViewProjectionMatrix * vertPosition;
  
  // save pos
  //ViewPos = gl_Position;
}