Aulaulz
Aulaulz

Reputation: 469

Directx 11 skeletal animations

I'm lost with skeletal animation. I've read some things about this, but their is still one thing I don't understand. This is conclusions I have. I saw 3 ways to animate a mesh with bones :

So my questions are :

I hope you did understand me, because I'm not sure i explained well. And please excuse my english, I did as good as I could. Thanks in advance.

Upvotes: 4

Views: 5398

Answers (1)

Nico Schertler
Nico Schertler

Reputation: 32587

The first approach can work if there are only rigid parts in the model. As soon as there are deformable parts you get holes or other artifacts. E.g. if you have a model of an arm and you rotate the forearm, there will be a hole at the elbow and overlapping triangles at the crook.

For the second approach - well, I don't really know how you intend to do this. The pixel shader is definitely the wrong place to do it. Everything that needs to be done can be done in the vertex shader.

Which leads us to approach 3.

I admit that skeleton based animations are a bit tricky to understand. Let's consider the above example: a model of an arm, consisting of upper arm and forearm. For this model we need two bones: One from shoulder to elbow and one from elbow to the hand.

Each vertex should be linked to at least one bone. This is done with vertex weights. Let's assume that there are some shoulder vertices that are influenced by the shoulder only. The elbow vertices are influenced by both bones and the hand vertices are influenced by the forearm bone only. That yields the following weights:

bone:               | upper arm bone | forearm bone
--------------------+----------------+--------------
shoulder vertices:  |       1        |       0
elbow vertices:     |       0.5      |       0.5
hand vertices:      |       0        |       1

The first thing to do is to calculate the position and orientation of all bones. This is done with a matrix for each bone. Usually an animator is responsible for calculating these matrices. This matrix would place a bone from some reference position to its current position. The reference position is the same for all bones and can be chosen freely.

The next thing to do is to calculate the resulting vertex positions. We know that the vertices move together with their bones. Therefore, we need the vertex positions in a local coordinate system of the bone. However, usually the vertex positions are given in world coordinates in the bind pose. That's what the inverse matrix is for. It transforms vertices from world space (bind pose) to a bone's local space. There is one inverse matrix for each bone.

When we have the vertex in the bone's local system we have to transform them according to the bone's movement. For shoulder vertices and hand vertices this task is trivial. We can use the bone's matrices and multiply those to the inverse matrices.

For the elbow vertices this is not that easy. In fact there are a variety of methods to calculate the transformation. We need to blend the two bones' transformations with the given weights. The easiest way to do this is to multiply the matrices by their weights and add them together. This gives the final transformation that can be used to transform the vertex position.

The steps are (for one influencing bone only):

  1. Transform the vertex position from bind pose to local bone system.
  2. Calculate the bone transformation matrix with the animator.
  3. Transform the vertex position from local bone system to animated position with the bone matrix.

If there is more than one influencing bone, the matrices have to be blended. The link of bones and vertices is achieved with vertex weights. Usually, a vertex does not save weights for all bones. Instead the maximum number of influencing bones is restricted to e.g. 4. Then the vertex stores the indices of the first 4 most influencing bones and their weights.

Upvotes: 8

Related Questions