2D Linear Blend Skinning: Weights, Contraction and Seams
2D Linear Blend Skinning: Weights, Contraction and Seams
Search
Ask the AI

2D Linear Blend Skinning: Weights, Contraction and Seams

Independent arm layers can expose the background after rotation; the visible colour depends on the background and alpha edges. A continuous joint mesh lets each vertex respond to both bones through weights.

1. The linear blend skinning equation

Let a vertex be attached to n bones with weights w_j. Let M_j be the current bone matrix and B_j the bind-pose matrix. Linear blend skinning (LBS) is:

v' = sum_j w_j M_j B_j^-1 v
subject to: w_j >= 0,  sum_j w_j = 1

Here v is a bind-pose world-space vertex. The matrix B_j^-1 maps it into bone-local space, and M_j maps it to the current world pose. Omitting the inverse bind term generally breaks bind-pose identity; the displacement depends on the matrix convention.

2. A two-bone numerical example

Suppose an elbow vertex would be at p=(10,0) under the parent transform and c=(6,8) under the child transform. With w_parent=0.25 and w_child=0.75:

v' = 0.25 p + 0.75 c
   = 0.25(10,0) + 0.75(6,8)
   = (7,6)

If the weights accidentally sum to 0.25 + 0.60 = 0.85, the vertex shrinks toward the origin. Normalize by the weight sum before applying the blend.

3. How blend width changes the joint

An initial weight field can use each vertex’s horizontal distance from the elbow. A simple linear transition is:

w_child(x) = clamp((x - (pivot - r)) / (2r), 0, 1)
w_parent(x) = 1 - w_child(x)

If r is too small, the joint folds like hard paper. If it is too large, deformation spreads into rigid areas. In the demo, blue means parent weight and red means child weight. Change the joint angle and blend width to see the point grid bend continuously.

Weights · Deformation

Skinning Weights and Seams

Understand linear blend skinning, normalized weights, and why joints collapse or reveal gaps.

4. Where white seam dots come from

  • Geometry gaps: two parts do not share boundary vertices and expose a subpixel opening after rotation.
  • Transparent-edge contamination: transparent PNG pixels contain white RGB, which bilinear filtering mixes into visible edges.
  • SVG antialiasing: adjacent paths are rasterized separately, leaving two displaced translucent edges.
  • Discontinuous weights: neighboring vertices receive sharply different transforms and pull the boundary apart.

5. A production repair order

  1. Prefer one mesh or shared boundary vertices around the joint.
  2. Add a 1 to 2 pixel inward overlap for separate layers instead of making contours touch exactly.
  3. Run alpha dilation before exporting transparent PNGs so edge pixels inherit nearby real colors instead of white.
  4. Use a premultiplied-alpha texture pipeline and keep the export and runtime alpha modes consistent.
  5. Verify normalized weights and apply limited spatial smoothing without blurring the outer silhouette.

The browser Animation Asset Lab uses neighbouring-colour merging, closed contours and small overlaps for colour fragments and seams. Those operations differ from mesh skinning. Choose a repair after identifying geometry, sampling or alpha errors.

6. Limits of LBS

LBS linearly averages rigid transforms, so large bend angles lose volume, producing the familiar candy-wrapper or collapsing-joint artifact. 2D rigs often add corrective shapes, helper bones, or manually drawn corrective meshes at important poses instead of adding arbitrary weights.

Contraction under fixed rotation weights

The following calculation averages two rotations at fixed weights to show how LBS contracts geometry. Weight distribution, helper bones and corrective shapes can change the resulting deformation.

The root cause: LBS averages matrices linearly, and the set of rotation matrices is not closed under addition — the average of two rotation matrices is generally not a rotation matrix.

Take the extreme case: a vertex weighted equally to two bones whose relative rotation is 180 degrees. Let one be the identity rotation R(0) and the other R(π):

R(0)   = [ 1  0]      R(π)  = [-1   0]
         [ 0  1]              [ 0  -1]

0.5 R(0) + 0.5 R(π) = [0  0]
                      [0  0]

This 2D average is the zero matrix, so pure rotation with no translation maps every point to the origin. With translations, points map to the blended translation. In 3D, a 180° twist about a shared axis preserves the axial component while collapsing the cross-section. Distinguish that axis collapse from the 2D point collapse shown here.

For equal weights and relative rotation θ, the 2D length scale is |cos(θ/2)|: about 71% at 90° and 50% at 120°. For weights w and 1-w, it is sqrt(1-4w(1-w)sin²(θ/2)). Changing weights or adding helper transforms can therefore alter contraction while changing how deformation is distributed.

Choose helper bones, another transform blend or corrective shapes according to the required poses:

  • Helper bones: add a half-angle transform and redistribute weights. A vertex blending only two equally weighted rotations separated by θ/2 has length scale |cos(θ/4)|. This bound does not apply if the original pair separated by θ still influences that vertex.
  • Dual quaternion skinning: blend sign-aligned, normalised dual quaternions for rigid transforms to avoid LBS rotation contraction. Check joint bulging, scale support and numerical degeneracies separately.
  • Corrective shapes: hand-author correct cross-sections at a few key angles and interpolate between them. Most controllable, most labour.

Measure contraction in the required poses, then compare weight changes, helper bones and alternative skinning. Extra bones alone do not guarantee improvement; their transforms and weights determine the blend.

Sort before truncating to four bones

If the format permits four influences per vertex, keep the four largest weights and then renormalise. The example below requires finite, nonnegative inputs and a positive retained sum. Reject zero-sum vertices or use an explicit bind-pose fallback.

An influence list’s in-memory order usually comes from the order things were written during binding, or from bone index order — neither correlates with weight magnitude. An implementation that takes the first four and renormalises can easily discard a dominant bone at 0.7 and keep four minor ones at 0.05 each. Renormalisation then inflates those four to 0.25 apiece, leaving the vertex entirely controlled by bones that barely mattered.

infl.sort(key=lambda i: i.weight, reverse=True)   # sort first
infl = infl[:4]                                    # then truncate
total = sum(i.weight for i in infl)
for i in infl: i.weight /= total                   # renormalise last

The symptom is deceptive: most vertices behave, and a scattered few fly somewhere strange once things move. Only vertices with more than four influences get truncated at all, and those cluster where several parts meet — armpits, hips, collars.

Use consistent truncation and normalisation at export and runtime. Discarding positive weights without renormalising lowers the effective sum. Renormalisation can preserve a sum of 1 while a different influence set still changes the deformation.

Distances and automatic weights across parts

The initial weights above came from lateral distance to the joint — a one-dimensional simplification for a single joint. Generalise it to a whole character by generating weights from “Euclidean distance from vertex to bone” and you hit a characteristic failure.

With the character’s arms hanging naturally at their sides, the upper-arm bone may sit only a dozen pixels from the torso. By Euclidean distance, the vertices on the side of the torso are very close to that bone and receive substantial weight. The result is that raising the arm drags a patch of torso up with it, as though the clothing were stuck to the hand.

A pose that separates the arm from the torso can expose cross-part weights. Also inspect bone indices, binding maps and mesh connectivity before assigning a cause.

Euclidean distance does not encode mesh topology. Surface distances or shape-aware weights can help, but must define how bones attach to the surface and how parts connect. A surface-to-interior-bone distance is not automatically a well-defined surface geodesic.

Automatic weights include heat-equilibrium methods and bounded biharmonic weights. The former solve a diffusion equilibrium with bone constraints; the latter minimise Laplacian energy subject to bounds. Both require mesh, boundary and normalisation choices. One diffusion step does not directly produce validated weights. See Baran and Popović and bounded biharmonic weights.

An explicit allowed-part set for each bone can prohibit assignments outside that set. Validate the labels and adjacency first, then check weights and deformation within the permitted region.

7. Turn seam quality into measurable checks

Save the bind pose and extreme poses, then inspect geometry, weights and pixel edges separately. The table’s 1e-6 and 1e-5 are example tolerances; choose them using coordinate scale, precision and import format.

CheckOperationPass conditionInspect first on failure
Bind-pose identityRun the full skinning path with bind matricesMaximum vertex displacement below 1e-6Inverse bind matrix and multiplication order
Weight normalizationCompute sum(w_j) per vertexError from 1 below 1e-5Uninitialized weights, import precision, missing influence
Neighborhood continuityCompare adjacent weights and deformed edge lengthsNo isolated discontinuity in the joint regionAutomatic-weight radius and hard-edge labels
Pixel edgeRender over black, white, and red at 1x, 2x, and 4xNo fixed-color bright or dark fringeTransparent RGB, premultiplied alpha, texture dilation
Extreme poseRender the maximum allowed bendNo intersection and acceptable volume lossCorrective shape, helper bone, blend width

8. The critical loop in a CPU reference

for vertex in mesh:
    out = (0, 0, 0)
    weight_sum = 0
    for influence in vertex.influences:
        w = max(influence.weight, 0)
        out += w * bone_world[influence.bone]
                 * inverse_bind[influence.bone]
                 * vertex.bind_position
        weight_sum += w
    vertex.position = out / max(weight_sum, epsilon)

The CPU loop below is pseudocode: matrix operations require actual vector types. Inputs must be finite and nonnegative. A zero weight sum needs an explicit fallback or error; dividing zero output by epsilon leaves it at the origin. GPU implementations may cap influences; four is a format-specific choice. Keep a CPU baseline for checking shader output.

9. Next: make the pose change naturally over time

Bones and skinning solve where geometry is in space. Keyframe curves solve when it arrives. Continue with Keyframes, Interpolation, and Easing. For the pose solver, review Two-Bone Inverse Kinematics.

Leave a Reply

Scroll down