TExcelTAD

Skinning

Skeletons and Poses ended with one skin matrix per bone. Skinning uses them to move the mesh: each vertex follows one or more bones, mixed by weights. The standard method, used by virtually every game, is linear blend skinning (LBS, also called smooth skinning or matrix palette skinning).

Linear blend skinning

Each vertex stores up to N bone indices and N weights (N = 4 in most engines). The weights are non-negative and sum to 1. The skinned position is a weighted average of where each bone would put the vertex:

text
v' = w0 * (skin[b0] * v) + w1 * (skin[b1] * v) + w2 * (skin[b2] * v) + w3 * (skin[b3] * v)

Because the skin matrices are linear, you can also blend the matrices first and transform once, which is what vertex shaders do: v' = (Σ wi * skin[bi]) * v. Normals are skinned the same way (with the rotation part only) and renormalized.

A vertex with a single weight of 1 is rigid: it moves exactly with one bone, like a robot's armour plate. Organic characters need blended weights around joints, otherwise the mesh cracks at the elbow. The example bends a 2D arm by 90° at the elbow and compares rigid binding (each vertex follows the bone with the larger weight) with LBS:

cpp · try it yourself
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>

double z0(double v) { return std::fabs(v) < 5e-4 ? 0.0 : v; }
const double DEG = 3.141592653589793 / 180;

struct P { double x, y; };
struct Xform { double angle, x, y; };            // rotate, then translate
P apply(const Xform& t, P p) {
    double c = std::cos(t.angle), s = std::sin(t.angle);
    return {t.x + c * p.x - s * p.y, t.y + s * p.x + c * p.y};
}

int main() {
    std::cout << std::fixed << std::setprecision(3);
    // Two bones in the bind pose: upper arm from (0,0), forearm from the elbow at (2,0).
    // Skin transforms for an elbow bent 90 degrees (upper arm does not move):
    Xform skinUpper{0, 0, 0};
    // forearm: rotate 90 degrees about the elbow (2, 0) = rotate about the origin, then fix the pivot
    Xform skinFore{90 * DEG, 2, -2};
    // Vertices on the top and bottom of the arm near the elbow, with their forearm weight.
    struct Vert { P pos; double wFore; };
    std::vector<Vert> verts = {
        {{1.4, 0.3}, 0.0}, {{1.8, 0.3}, 0.25}, {{2.0, 0.3}, 0.5}, {{2.2, 0.3}, 0.75}, {{2.6, 0.3}, 1.0},
        {{1.8, -0.3}, 0.25}, {{2.0, -0.3}, 0.5}, {{2.2, -0.3}, 0.75},
    };
    std::cout << "bind pos        w(fore)  rigid (one bone)    blended (LBS)\n";
    for (const Vert& v : verts) {
        const Xform& rigidBone = v.wFore >= 0.5 ? skinFore : skinUpper;
        P rigid = apply(rigidBone, v.pos);
        P a = apply(skinUpper, v.pos), b = apply(skinFore, v.pos);      // skin with each bone...
        double w = v.wFore;
        P lbs{(1 - w) * a.x + w * b.x, (1 - w) * a.y + w * b.y};        // ...then blend the results
        std::cout << "(" << v.pos.x << ", " << std::setw(6) << v.pos.y << ")  " << w << "   ("
                  << z0(rigid.x) << ", " << std::setw(6) << z0(rigid.y) << ")   (" << z0(lbs.x) << ", " << std::setw(6) << z0(lbs.y) << ")\n";
    }
}
bind pos        w(fore)  rigid (one bone)    blended (LBS)
(1.400,  0.300)  0.000   (1.400,  0.300)   (1.400,  0.300)
(1.800,  0.300)  0.250   (1.800,  0.300)   (1.775,  0.175)
(2.000,  0.300)  0.500   (1.700,  0.000)   (1.850,  0.150)
(2.200,  0.300)  0.750   (1.700,  0.200)   (1.825,  0.225)
(2.600,  0.300)  1.000   (1.700,  0.600)   (1.700,  0.600)
(1.800, -0.300)  0.250   (1.800, -0.300)   (1.925, -0.275)
(2.000, -0.300)  0.500   (2.300,  0.000)   (2.150, -0.150)
(2.200, -0.300)  0.750   (2.300,  0.200)   (2.275,  0.075)

The forearm now points up (+y), so the top row (y = 0.3) is the inside of the elbow and the bottom row is the outside.

  • Rigid: the outside jumps from (1.8, -0.3) straight to (2.3, 0.0), a crack in the surface. On the inside, the forearm vertex at (1.7, 0.0) lands behind the upper arm's vertices: the two parts intersect.
  • LBS: each vertex lands between the two bones' answers, so the joint becomes a smooth curve. The vertices with weight 0 and 1 are the same as rigid.

Artists paint these weights in Blender, Maya or 3ds Max ("weight painting"), and the exporter normalizes them and keeps the four largest influences per vertex. A weight that does not sum to 1 makes the vertex drift toward the origin as the character walks away from it, a classic import bug.

The candy-wrapper problem

LBS averages positions, and the average of two points on a circle lies inside the circle. For bending that only shrinks the elbow a little. For twisting it is dramatic: rotate the wrist bone around the forearm's axis, and a vertex weighted half to the elbow and half to the wrist moves toward the axis. At 180° it collapses onto the bone, and the forearm looks like the twisted end of a candy wrapper.

cpp · try it yourself
#include <iostream>
#include <iomanip>
#include <cmath>

const double DEG = 3.141592653589793 / 180;
struct V3 { double x, y, z; };
struct Quat { double w, x, y, z; };

Quat twistX(double angle) { return {std::cos(angle / 2), std::sin(angle / 2), 0, 0}; }   // about the bone axis
V3 rotate(Quat q, V3 v) {                                    // v' = q v q*, expanded
    V3 u{q.x, q.y, q.z};
    auto cross = [](V3 a, V3 b) { return V3{a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x}; };
    V3 t = cross(u, v); t = {2 * t.x, 2 * t.y, 2 * t.z};
    V3 c = cross(u, t);
    return {v.x + q.w * t.x + c.x, v.y + q.w * t.y + c.y, v.z + q.w * t.z + c.z};
}
double radius(V3 v) { return std::sqrt(v.y * v.y + v.z * v.z); }   // distance from the bone axis (x)

int main() {
    std::cout << std::fixed << std::setprecision(3);
    // A forearm vertex on the skin surface, 1 unit from the bone axis, halfway between
    // the elbow bone (no twist) and the wrist bone (twisted by `angle`): weights 0.5 / 0.5.
    V3 v{2, 1, 0};
    std::cout << "twist   LBS radius   quaternion-blend radius\n";
    for (int deg : {0, 45, 90, 135, 170, 180}) {
        Quat a = twistX(0), b = twistX(deg * DEG);
        // Linear blend skinning: transform with each bone, then average the positions.
        V3 pa = rotate(a, v), pb = rotate(b, v);
        V3 lbs{(pa.x + pb.x) / 2, (pa.y + pb.y) / 2, (pa.z + pb.z) / 2};
        // Dual quaternion skinning (pure rotations here, so the dual part is zero):
        // blend the rotations first, normalize, then transform once.
        Quat q{(a.w + b.w) / 2, (a.x + b.x) / 2, (a.y + b.y) / 2, (a.z + b.z) / 2};
        double n = std::sqrt(q.w * q.w + q.x * q.x + q.y * q.y + q.z * q.z);
        q = {q.w / n, q.x / n, q.y / n, q.z / n};
        V3 dq = rotate(q, v);
        std::cout << std::setw(5) << deg << std::setw(12) << radius(lbs) << std::setw(16) << radius(dq) << "\n";
    }
}
twist   LBS radius   quaternion-blend radius
    0       1.000           1.000
   45       0.924           1.000
   90       0.707           1.000
  135       0.383           1.000
  170       0.087           1.000
  180       0.000           1.000

The LBS radius is |cos(twist / 2)|: 71% of the arm's thickness at 90° of twist, zero at 180°. Blending the rotations instead of the positions keeps the vertex on the surface, because the blended rotation is simply "half the twist".

That is the idea behind dual quaternion skinning (DQS): each skin transform is converted to a unit dual quaternion (a rotation quaternion plus a "dual" part encoding the translation), the dual quaternions are blended with the weights, normalized, and applied once. For pure rotations about a common axis, as in this example, it reduces to the quaternion blend shown. (Like any quaternion blend, it must flip quaternions into the same hemisphere first: see Blending Poses and Quaternions.)

Linear blend skinning Dual quaternion skinning
Cost lowest: a matrix blend per vertex a little more: blend, normalize, transform
Twists collapses (candy wrapper) keeps volume
Bends slight volume loss at elbows and knees can bulge outward on bends
Non-uniform scale supported needs extra handling
Availability every engine and DCC tool Blender ("Preserve Volume" on the Armature modifier), Maya; in game engines usually through plugins or custom skinning shaders

Note: Built-in DQS support differs by engine and version; check what yours offers before planning around it. Most game studios stay with LBS and fix twists in the rig instead.

The rigging fix: twist bones

The usual production fix is not a different skinning algorithm but twist bones: one or two extra bones along the forearm (and upper arm, thigh) that take a fraction of the wrist's twist each (for example 25%, 50%, 75%). Each vertex then sits between two bones that differ by a small twist, where LBS is accurate. Engines drive twist bones with constraints: Unity's Animation Rigging has a Twist Correction constraint, Unreal rigs usually drive them in Control Rig, and in Godot a SkeletonModifier3D (or a short script) can copy a fraction of the wrist rotation.

Practical limits

  • 4 influences per vertex is the common default (Unity's quality setting "Skin Weights" offers 1, 2, 4 or unlimited; Unreal supports more with "unlimited bone influences" settings). Fewer influences are cheaper but harsher at joints.
  • Bone count per draw call used to be limited by shader constants; modern engines use buffers, but mobile platforms may still split meshes.
  • GPU vs CPU skinning: almost every engine skins on the GPU (in a vertex or compute shader). CPU skinning is still useful for physics proxies and hit detection.
  • Blend shapes (morph targets) for faces and muscle bulges are applied before skinning, in bind space.

Test yourself

In linear blend skinning, what must a vertex's bone weights add up to?

  1. 0
  2. 1
  3. The number of bones
  4. Any value; they are normalized by the GPU

Why does LBS collapse a forearm twisted 180° (the candy-wrapper effect)?

  1. The GPU runs out of precision
  2. It averages positions, and the average of two points rotated apart around the axis lies closer to the axis
  3. Twisting is not allowed in skeletons
  4. The weights are too large

What is the most common production fix for twist collapse?

  1. More influences per vertex
  2. Twist bones that each take a fraction of the twist
  3. Disabling skinning on arms
  4. Using Euler angles