+4 bones vertex skinning

Started by
13 comments, last by keym 11 years, 2 months ago




I'm confused. Is was under the impression that in fact this is the "bind pose approach" - these weight positions are provided only in bind pose (scratch that, they are pose independant, they only inform about mesh "volume", combined with bones, bind pose or not, they give the final result) and I also have bind pose skeleton provided. So how do I get rid of these weight positions? What's the usual approach here? Right now I have bind pose skeleton but in fact I don't use it while animating. It's only helpful when "unpacking" animation (skeleton) frames but it looks like there's a reason it's there. I have no idea if Doom3 uses these weight positions in shaders. I just followed mentioned tutorial and ended up here.

I animate MD5 meshes in a way C0lumbo implied. Post multiply your animation pose matrices with the inverse bind pose. Then you can just send the bind posed vertices to the GPU.

I'm not sure how animating is done in Doom 3, but maybe it is possible that they did not use GPU skinning, because they needed the transformed vertices for constructing shadow volumes. Then it should be faster to have the vertices in weight space so that post multiplication by inverse bind pose is avoided.
Thank you all for great tips. I'll try to do that but it'll take me some time cause I'm using quaternions so far. So, to sum this up, what I need to do is:

1. Build vertex positions in object space (using bind pose joints) and store them
2. Build bind pose matrices and then inverse bind pose matrices for my bind pose joints (from joint positions and orientations)
3. Build animation pose matrices from joints (like above)
4. Multiply animation pose matrices with inverse bind pose matrices and send them to shader
5. Send bind pose vertices, weight factors and bone indices to shader
7. Compute final matrix from "component" matrices that are weighted
8. Multiply bind pose vertex by final matrix.

Is that correct?
Advertisement

Yep, it works. Just finished implementing my quat to matrix + few helpers. Thank you all!

So it turns out that the other day I was bit too optimistic - tested it with bindpose only and I presumed it's allright. What I did - I got the bind pose matrices and then inverted ones, then multiplied bind pose by inverted and then sent it to the shader (silly me, I forgot that multiplying matrix by its inverse gives identity matrix, so no wonder the bind pose object space vertices were ok). Happy to see that it works I assumed that I only need to build animated matrices and replace bind pose matrices by animated ones in multiplication. But sadly this doesn't work. The result is totally messed up. It helps a little if I invert the final matrix but it's still not right.

What I already double checked:

1. quat to matrix conversion

2. matrix by matrix multiplication

3. matrix inverse routine

Bump, I'm still stuck.

My quaternion to matrix code:


matrix4x4::matrix4x4(quaternion quat)
{
    quat.normalize();
    this->row[0].x = 1 - 2 * quat.y * quat.y - 2 * quat.z * quat.z;
    this->row[0].y = 2 * quat.x * quat.y - 2 * quat.z * quat.w;
    this->row[0].z = 2 * quat.x * quat.z + 2 * quat.y * quat.w;
    this->row[0].w = 0;

    this->row[1].x = 2 * quat.x * quat.y + 2 * quat.z * quat.w;
    this->row[1].y = 1 - 2 * quat.x * quat.x - 2 * quat.z * quat.z;
    this->row[1].z = 2 * quat.y * quat.z - 2 * quat.x * quat.w;
    this->row[1].w = 0;

    this->row[2].x = 2 * quat.x * quat.z - 2 * quat.y * quat.w;
    this->row[2].y = 2 * quat.y * quat.z + 2 * quat.x * quat.w;
    this->row[2].z = 1 - 2 * quat.x * quat.x - 2 * quat.y * quat.y;
    this->row[2].w = 0;

    this->row[3] = vector4d(0,0,0,1);
} 

How I build bind pose and inverse bind pose matrices:


    for(int i = 0; i < this->numJoints; i++)
    {
        matrix4x4 matr(this->joints[i].orient);
        matr.row[3] = vector4d(this->joints[i].pos);

        this->bindPoseMatrices[i] = matr;
        this->invBindPoseMatrices[i] = this->bindPoseMatrices[i].getInverse();;
    } 

How I build animated matrices:


void md5OBJ::updateSkeleton(int animNum, int frameNum)
{
    for(int i = 0; i < this->numJoints; i++)
    {
        matrix4x4 animMatr(this->animations[animNum].frames[frameNum].joints[i].orient);
        animMatr.row[3] = vector4d(this->animations[animNum].frames[frameNum].joints[i].pos);
        this->animatedMatrices[i] = animMatr * this->invBindPoseMatrices[i];
    }
}
 

Matrices are row major.

This topic is closed to new replies.

Advertisement