Skip to content

Skinning tutorial does not detail joint matrix calculation #98

@kevinmoran

Description

@kevinmoran

The Skins Tutorial focuses mainly on the vertex shader calculations involved in skinning, and gives almost no useful information on producing the joint matrices to pass to the shader:

So the pseudocode for computing the joint matrix of joint j may look as follows:

jointMatrix(j) =
globalTransformOfJointNode(j) *
inverseBindMatrixForJoint(j);

There is no other mention of globalTransformOfJointNode, and this transform is not immediately obvious - most animation file formats produce animation in local space, whereas GLTF animation data also converts a joint into its parent's local space. I had a lot of trouble deducing this (see here) and so did the writer of this very useful blog post, without which I would have been even more lost.

The actual way you compute joint matrices is:

mat4 animMatrix[i] = /*calculate interpolated pose from animation keyframe data*/ 
int parentIndex = joints[i].parentIndex;
jointMatrix[i] =  animMatrix[parentIndex] * animMatrix[i] * invBindPoses[i];

Assuming right-to-left matrix multiplication order. Additionally there are plenty of gotchas due to the (in my opinion) mistake of specifying animation data in this coordinate space, for example if an animation does not specify any keyframe data for a joint you must transform that joint into its parent space manually using:

mat4 animMatrix[i] = invBindPose[parentIndex] * bindPose[i]

I think the tutorial should be expanded to explain how to calculate joint matrices, as it stands that blog post is far more useful than what's there currently. Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions