Dead Blending Node in Unreal Engine

13/08/2023

Unreal Engine 5.3 comes with a new experimental "Dead Blending" node that acts as a drop-in replacement to the Inertialization node.

In general I've found it creates better looking blends than the standard Inertialization node, in particular when you have transitions between poses that are very different:

Or when you are triggering transitions very frequently:

However you may find that sometimes it tends to damp out the motion a bit more than the normal Inertialization node.

The way it works is a similar to the basic exponential decay method I described in my previous article on Dead Blending, with a few small differences.

First, instead of updating the extrapolated pose each frame we just store the pose at the point of transition and use an implicit extrapolation function to get the extrapolated transform of the joint at an arbitrary time in the future past the point of transition (given some half-life used to control the rate of decay of the velocity).

Here is some similar extrapolation code adapted for quaternions and allowing an individual half-life per rotation axis:

void extrapolate_decay_rotation(
    quat& x,
    vec3& v,
    vec3 halflife,
    float dt,
    float eps = 1e-8f)
{
    vec3 y = LN2f / (halflife + eps);
    x = quat_mul(quat_from_scaled_angle_axis(
        (v / (y + eps)) * (1.0f - fast_negexp(y * dt))), x);
    v = v * fast_negexp(y * dt);
}

Although it doesn't make much difference to the final result, this feels like a more elegant solution to me since it reduces the amount of state being mutated each frame and more closely resembles the setup for normal Inertialization.

The big difference in this implementation comes from having individual half-lives per degree of freedom for each joint of the character. This allows us to safely extrapolate joints on axes that we are sure can move far, while limiting the extrapolation for joints on axes that we are not certain can move.

These half-lives aren't set by hand. Instead we use a simple heuristic to compute them. At the point of transition we look at the source and destination animation and determine which joint axes are moving toward the destination animation and at what rate. Axes which are moving toward the destination animation with a low velocity can be extrapolated for a long time, while axes that are moving with a fast velocity, or away from the destination animation we want to give a short half-life.

In code it looks something like this:

float max_mag(float x, float eps)
{
    return
        x >= 0.0f && x <  eps ?  eps :
        x <  0.0f && x > -eps ? -eps : x;
}

vec3 max_mag(vec3 x, float eps)
{
    return vec3(
        max_mag(x.x, eps),
        max_mag(x.y, eps),
        max_mag(x.z, eps));
}

vec3 estimate_halflife(
    vec3 src_dst_diff,
    vec3 src_vel,
    float halflife_scale = 0.3f,
    float halflife_min = 0.1f,
    float halflife_max = 1.0f,
    float eps = 1e-8f)
{
    return clamp(
        halflife_scale * (src_dst_diff / max_mag(src_vel, eps)), 
        halflife_min, 
        halflife_max);
}

Here src_dst_diff is the difference between source and destination animations (rotations are encoded as scaled-angle-axis), src_vel is the velocity (or angular velocity) of the source animation, halflife_scale controls the overall expected scale of the half-lives, and halflife_min and halflife_max control the overall min and max half-life to allow.

If we visualize the extrapolations we can see how this heuristic affects them - some joints are allowed to extrapolate for a long time while others are brought to a halt almost instantly. In this way we almost always avoid violating joint limits while maintaining long extrapolations where we can.

This is still an experimental node, so the implementation and interface are subject to change, but I hope it will provide useful to developers who are having a bit of trouble getting good results out of the normal Inertialization node.

And if you'd like to try it out yourself I've added the same heuristic as an option in my previous article's demo code.