Modelintro
Blendshape model
Also called blend shapes, morph targets.
A face or body as the neutral mesh plus a weighted sum of sculpted target offsets, animated by the weights.
A blendshape model describes a face, or another deformable part of a character, as one neutral mesh and sculpted target meshes with the same vertices in the same order. An animator, a solver or a performance capture system sets one weight per target, and the model gives the mesh
This is the delta form: each target acts through its offset from the neutral. In most face rigs each weight is bounded to , so that gives the full sculpted shape and removes it. The bound is a convention of the rig and of the solvers that fit weights, not a part of the model, and the formula is defined for any real weights. The model is linear, cheap and fully under the control of the artist, and it is the main face model in film and games.
The machine
Quantities. The mesh has vertices, so a shape is a vector in . The neutral and the delta matrix are the parameters of the model. They are sculpted by hand, scanned from an actor, or computed by deformation transfer or example-based facial rigging. The weight vector is the state, and it changes at each frame. The output is
Targets. A target is usually local and has a meaning: one side of a smile, a raised inner brow, an open jaw. Many rigs name the targets after the action units of the facial action coding system, so that a target set covers the visible movements of a face. The deltas are not orthogonal. Two targets can move the same vertex, and then their offsets add.
Evaluation. The deltas are computed once and stored sparsely, because most targets move only a small part of the mesh.
BLEND(b₀, b₁ … b_K, w)- 1
for each target k: dₖ ← bₖ - b₀, kept only at the vertices it moves ▷ once per rig - 2
v ← b₀ - 3
for each target k with wₖ ≠ 0 do - 4
for each vertex i in dₖ: vᵢ ← vᵢ + wₖ dₖ,ᵢ - 5
return v
The whole-face form. An older form writes the shape as a weighted sum of whole meshes, with . With it is the same mesh as the delta form. The two forms differ in what a weight means to the artist. In the whole-face form a target is a full expression, and raising one weight must lower the others. In the delta form the targets are independent offsets, and a weight of zero always means "this target is off".
Corrective shapes. When two targets look wrong together, a rig adds a combination shape with the weight . Such a term makes the model a polynomial in and no longer linear. The plain model of this page has no such terms.
What it counts
The model has a cost per frame and a cost in memory.
- Time per frame. Line L4 runs once per nonzero entry of the active deltas. With stored vertex offsets over all targets the cost is , and for dense deltas. This is the cost in the real RAM model.
- Memory. The deltas take vectors, and dense.
- GPU. A vertex shader or a compute pass adds the active deltas. Engines often limit the number of active targets per draw call, because each one costs bandwidth for its offsets. That limit is a choice of the engine.
The model does not count physical quantities. It is a geometric model: no mass, no muscle force and no volume is part of it. A blendshape face looks right only for the shapes that the artist sculpted and for the weight combinations that the artist checked.
Relation to other models
- Linear blend skinning. Linear blend skinning is linear in the joint transforms and moves vertices by rotations, so it suits limbs. A blendshape model is linear in the weights and moves vertices by fixed offsets, so a target cannot rotate a region. Rigs often use both: the jaw and the eyes by skinning, the soft tissue by blendshapes.
- Pose space deformation. Pose space deformation drives corrective offsets by the pose of the skeleton through radial basis functions. Its offsets are blendshape deltas whose weights are computed, not keyed.
- PCA models. A principal component analysis of scanned faces also gives a model , with orthonormal columns in . The basis is optimal in the least squares sense for the data, but its directions have no meaning for an animator. Blendshape deltas have a meaning and are not orthogonal.
- FACS. The facial action coding system is a description of facial movements, not a model of a mesh. It is a common guide for which targets to sculpt.
Known results in the model
All of these are proved properties of the formula, in exact arithmetic, unless marked as a measurement.
- Affine in the weights. is an affine map of . The reachable shapes are the affine subspace . With the bound they are the zonotope , the image of the unit cube by a linear map.
- The two forms agree. The delta form with weights equals the whole-face form with weights . The test file checks this identity with exact rational arithmetic.
- Endpoints. gives , and gives .
- Interference. The offsets of two targets that move the same vertex add. In the example below, a smile and an open jaw both move the corner of the mouth, and the combination is not the shape of either target. This is the reason for corrective shapes, and it is also the reason why solving for weights is harder than it looks: because the deltas are not orthogonal, the best value of one weight depends on the others.
- Fitting weights. For a given mesh , the best weights in the least squares sense solve , a least squares problem. The solution is unique if and only if the deltas are linearly independent. With the bound the problem is a convex quadratic program. Direct manipulation of blendshapes adds a term that keeps the weights near their current values, which also makes the solution unique.
- Practice. Film face rigs often have many targets, from tens up to hundreds, as the 2014 survey of Lewis and others reports. This is a report on practice, not a result of the model.
Example. Take one vertex, the corner of the mouth, at . The smile target moves it to , and the open jaw target moves it to . So and .
| weights | vertex |
|---|---|
With both weights at 1 the corner moves out and down, which neither target shows.
An artist who wants a different corner for "smile with open jaw" sculpts a corrective shape for that pair.
The tests in impl/python check these values exactly.
The history of the model starts with Parke (1972), who animated a face by interpolation between key shapes of a polygon mesh. The delta form with independent targets became the standard in production, and Lewis and others (2014) survey its practice and theory.
Code
Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/blendshape-model/. The authors are listed in prov/ENWK12.jsonl.
"""The blendshape model in the delta form.
A mesh is a list of vertex tuples. The neutral mesh is b_0 and the targets
are b_1, ..., b_K, all with the same vertex count and order. The model is
v = b_0 + sum_k w_k (b_k - b_0).
The deltas d_k = b_k - b_0 are computed once. Most rigs keep each w_k in
[0, 1]; that bound is a convention of the rig, not part of the model, so
the clamp is an option here.
"""
def deltas(b0, targets):
"""Return the delta meshes d_k = b_k - b_0, stored sparsely.
Each delta is a dict {vertex index: offset tuple}, without the vertices
that the target does not move.
"""
out = []
for bk in targets: # @line L1
d = {}
for i, (p, q) in enumerate(zip(b0, bk)):
off = tuple(y - x for x, y in zip(p, q))
if any(c != 0 for c in off):
d[i] = off
out.append(d)
return out
def evaluate(b0, ds, w, clamp=False):
"""Return the mesh b_0 + sum_k w_k d_k for sparse deltas ds."""
if len(ds) != len(w):
raise ValueError("one weight per target is needed")
v = [list(p) for p in b0] # @line L2
for d, wk in zip(ds, w): # @line L3
if clamp:
wk = min(1.0, max(0.0, wk))
if wk == 0:
continue
for i, off in d.items(): # @line L4
vi = v[i]
for c in range(len(vi)):
vi[c] += wk * off[c]
return [tuple(p) for p in v] # @line L5
def evaluate_whole(b0, targets, w):
"""Return the whole-face form w_0 b_0 + sum_k w_k b_k with w_0 = 1 - sum_k w_k.
This is the same mesh as the delta form; it is here for the tests.
"""
w0 = 1 - sum(w)
out = []
for i, p in enumerate(b0):
q = [w0 * x for x in p]
for bk, wk in zip(targets, w):
for c in range(len(q)):
q[c] += wk * bk[i][c]
out.append(tuple(q))
return out
test_blendshape_model.py 88 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/blendshape-model/. The authors are listed in prov/ENWK12.jsonl.
"""Tests of the blendshape model in the delta form.
They check that zero weights give the neutral mesh, that a unit weight gives
its target, that the delta form equals the whole-face form, that the model
is affine in the weights, the interference check value of the page, and the
optional clamp.
"""
import random
from fractions import Fraction as F
from blendshape_model import deltas, evaluate, evaluate_whole
def rand_mesh(rng, n):
return [tuple(F(rng.randint(-20, 20), 8) for _ in range(3)) for _ in range(n)]
def rig(seed=1, n=12, k=4):
rng = random.Random(seed)
b0 = rand_mesh(rng, n)
targets = []
for _ in range(k):
bk = list(b0)
for i in rng.sample(range(n), 5):
bk[i] = tuple(x + F(rng.randint(-8, 8), 16) for x in b0[i])
targets.append(bk)
return rng, b0, targets
def test_zero_weights_give_the_neutral():
_, b0, targets = rig()
assert evaluate(b0, deltas(b0, targets), [0] * len(targets)) == b0
def test_unit_weight_gives_the_target():
_, b0, targets = rig()
ds = deltas(b0, targets)
for k, bk in enumerate(targets):
w = [0] * len(targets)
w[k] = 1
assert evaluate(b0, ds, w) == [tuple(p) for p in bk]
def test_delta_form_equals_whole_face_form():
rng, b0, targets = rig(seed=2)
ds = deltas(b0, targets)
for _ in range(20):
w = [F(rng.randint(-4, 12), 8) for _ in targets]
assert evaluate(b0, ds, w) == evaluate_whole(b0, targets, w)
def test_affine_in_the_weights():
rng, b0, targets = rig(seed=3)
ds = deltas(b0, targets)
w1 = [F(rng.randint(0, 8), 8) for _ in targets]
w2 = [F(rng.randint(0, 8), 8) for _ in targets]
t = F(3, 7)
wt = [(1 - t) * a + t * b for a, b in zip(w1, w2)]
v1, v2, vt = evaluate(b0, ds, w1), evaluate(b0, ds, w2), evaluate(b0, ds, wt)
for p, q, r in zip(v1, v2, vt):
assert tuple((1 - t) * x + t * y for x, y in zip(p, q)) == r
def test_sparse_deltas_skip_still_vertices():
_, b0, targets = rig()
for d in deltas(b0, targets):
assert len(d) <= 5
def test_interference_check_value():
b0 = [(F(1), F(0), F(0))]
smile = [(F(6, 5), F(3, 10), F(0))]
jaw = [(F(1), F(-1, 2), F(0))]
ds = deltas(b0, [smile, jaw])
assert evaluate(b0, ds, [1, 1]) == [(F(6, 5), F(-1, 5), F(0))]
assert evaluate(b0, ds, [F(1, 2), F(1, 2)]) == [(F(11, 10), F(-1, 10), F(0))]
def test_clamp_option():
b0 = [(0.0, 0.0, 0.0)]
t1 = [(1.0, 0.0, 0.0)]
ds = deltas(b0, [t1])
assert evaluate(b0, ds, [1.5])[0][0] == 1.5
assert evaluate(b0, ds, [1.5], clamp=True)[0][0] == 1.0
assert evaluate(b0, ds, [-0.5], clamp=True)[0][0] == 0.0
References
- J. P. Lewis, Ken Anjyo, Taehyun Rhee, Mengjie Zhang, Fred Pighin and Zhigang Deng, Practice and theory of blendshape facial models, Eurographics 2014 State of the Art Reports, 199-218, the sections on the whole-face and delta formulations, on the interference between targets and on corrective combination shapes (general locator)
- J. P. Lewis and Ken Anjyo, Direct manipulation blendshapes, IEEE Computer Graphics and Applications 30(4), 2010, 42-50, the sidebar on the blendshape model (the delta form f = B w + f0)
- Frederic I. Parke, Computer generated animation of faces, Proceedings of the ACM Annual Conference, 1972, volume 1, starting at page 451, the interpolation between key face shapes (general locator)
Where this leads
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W4 complete |
|
Tag ENWK12 Edit this page History Report an error Markdown