I've been writing a model viewer for a popular game and began tackling animations. The skeleton/animation is stored in a Havok binary file which I load and animate using the Havok engine. The animated bone matrices are then sent to a GLSL shader to be skinned.
This is what the shader looks like:
#version 150
precision highp float;
uniform mat4 uModelMatrix;
uniform mat4 uViewMatrix;
uniform mat4 uProjMatrix;
uniform int uNumBones;
uniform mat4 uBones[252];
attribute vec4 aPosition;
attribute vec4 aNormal;
attribute vec4 aTexCoord;
attribute vec4 aColor;
attribute vec4 aBiTangent;
attribute ivec4 aBlendWeight;
attribute ivec4 aBlendIndex;
varying vec4 vPosition;
varying vec4 vNormal;
varying vec4 vTexCoord;
varying vec4 vColor;
varying mat4 vTBNMatrix;
varying vec3 vLightDir;
varying vec3 vEyeVec;
void main(void) {
vec4 transformedPosition = vec4(0.0);
vec3 transformedNormal = vec3(0.0);
ivec4 curIndex = aBlendIndex;
ivec4 curWeight = aBlendWeight;
vec4 pos = aPosition;
for (int i = 0; i < 4; i++)
{
mat4 m44 = uBones[curIndex.x];
// transform the offset by bone i
transformedPosition += m44 * pos * (curWeight.x/255.0);
// shift over the index/weight variables, this moves the index and
// weight for the current bone into the .x component of the index
// and weight variables
curIndex = curIndex.yzwx;
curWeight = curWeight.yzwx;
}
gl_Position = uProjMatrix * uViewMatrix * uModelMatrix * transformedPosition ;
}
The weights are stored in the UBYTE4N DirectX format, so I send them to the shader as integers and divide by 255.0 to get the true result.
Strangely, this is what the reference pose should look like (no skinning operation applied to the mesh, the red dots are the individual bone translations only):
Instead I get:
The model is a mimic and looks like
http://ffxiv.consolegameswiki.com/images/thumb/e/e6/Treasure_box2.jpg/400px-Treasure_box2.jpg
Does this shader look correct? What could cause this issue?