Reputation: 1
I have been trying for several days to create 3D skeletal animations in my game. I am using Java with LWJGL.
Before even trying to do animations, I am trying to achieve a bind pose in my program. I load up informations from a collada file that I export from Blender. I currently have all this loaded up in my game: For each Joint in my skeleton:
The skeleton is a hierarchical structure containing a list of all joints, aswell as the root joint. It also has the bind shape matrix and another matrix that I am unsure of what it is used for.
I load up all the skinning informations into VBOs for each models (boneIDs, and their corresponding weights).
I have read alot on the internet about skinning things but I am completly lost. I have no idea what to do with all these matrices and stuff.
Here is what I have in my current vertex shader, I am pretty sure it is alright:
const int MAX_BONES = 32;
in ivec4 boneIDs;
in vec4 boneWeights;
uniform mat4 boneTransforms[MAX_BONES];
void main(void) {
mat4 boneTransform = boneTransforms[boneIDs[0]] * boneWeights[0];
boneTransform += boneTransforms[boneIDs[1]] * boneWeights[1];
boneTransform += boneTransforms[boneIDs[2]] * boneWeights[2];
boneTransform += boneTransforms[boneIDs[3]] * boneWeights[3];
vec4 worldPosition = transformationMatrix * boneTransform * vec4(position, 1.0);
…
My problem here is that I don't know what the array of matrices should be. I have a ton of matrices loaded up from the skinning information that I got from the collada file but I have no idea what their relation is together.
I have tried a couple of things without any success. Here is a picture with what my model should look like, and what it currently looks like on the right.
The matrices contained in the boneTransforms array in the shader are the following (I'll call it skinning matrix):
skinningMatrix = parentJoint.localMatrix * localMatrix * inverseBindShapeMatrix of the joint
I found this little formula on the internet so I have no idea if it is ok but it doesn't work really well.
Upvotes: 0
Views: 2660
Reputation: 338
In order to know what matrices you should send, you must first understand why. The inverse bind pose matrices get your vertices into bone space so that their parent joint is the origin. Then once in bone space, multiplying the vertices with the global matrices (that store the current pose you want) gets them back to their correct space after rotating and offsetting them correctly. But instead of sending two matrix arrays to your vertex shader, you can combine the inverse and current pose matrices to make one matrix to multiply your vertex by. So, make a matrix array that, for each matrix, multiplies the inverse times the current pose matrix (in that order). Then send that to your vertex shader.
Upvotes: 4