---
id: "quaternion-slerp-interpolation"
title: "Quaternion slerp rotation interpolation"
aliases: [slerp, spherical linear interpolation, nlerp, squad]
domain: "simulation"
stage: "simulation"
realtime: "realtime"
platforms: [cpu, webgl2, webgpu, desktop-gpu, mobile-gpu, unity, unreal, godot, blender, python]
year_introduced: 1985
inputs: [skeleton]
outputs: [animation]
style: "both"
dynamic: "dynamic"
cost: "cheap"
authority: "Shoemake, 1985"
url: "https://texelatlas.vercel.app/t/quaternion-slerp-interpolation/"
sources_verified_at: "2026-11-29"
---
# Quaternion slerp rotation interpolation (Shoemake, 1985)

> Interpolate between two unit quaternions along the great arc, giving constant angular velocity and no gimbal lock; nlerp and squad are the common cheaper or smoother cousins.

## Reach for it when

- camera or bone spins the long way round when blending
- rotation interpolation has uneven speed or gimbal lock
- need constant angular velocity between two orientations
- blending nearly equal rotations produces nan values

## How it works

Unit quaternions live on the 3-sphere, and each rotation appears twice (q and -q). Spherical linear interpolation walks along the great circle joining two of them with parameter t: the result is sin((1-t)w)/sin(w) times the first plus sin(tw)/sin(w) times the second, where w is the angle between them. The path has constant angular speed and a fixed axis, so a camera or joint turns steadily. Two practical rules apply. First flip one quaternion's sign if their dot product is negative so the path takes the short arc. Second, when the angle is tiny, sin(w) approaches zero and the formula must fall back to normalised linear interpolation. Nlerp (lerp then normalise) has the same path but non-constant speed and is cheaper and common in skinning blends. Squad chains slerps to get C1 continuity across a keyframe sequence, and rotation-vector or log-space interpolation covers blending several poses.

## When to use it

Choose slerp for two-keyframe rotation blends, camera orbits, aim smoothing and orientation render-interpolation. Prefer nlerp when the two quaternions are close and speed uniformity does not matter, as in per-vertex skinning blends. Prefer squad or spline-based interpolation for smooth multi-keyframe paths. For blending skinning transforms use [Dual quaternion skinning](https://texelatlas.vercel.app/t/dual-quaternion-skinning.md) or [Linear blend skinning](https://texelatlas.vercel.app/t/linear-blend-skinning.md), and for orienting along a curve without twist use [Rotation-Minimizing Frames](https://texelatlas.vercel.app/t/rotation-minimizing-frames.md). Pair with [Fixed timestep game loop and integration](https://texelatlas.vercel.app/t/fixed-timestep-integration.md) to interpolate physics orientation for display.

## Cost

cheap — A few multiplies, one acos and two sin per interpolation; nlerp avoids the transcendentals.
Measured GPU Weight: 9.07× baseline (moderate) — 0.2813 ms median / 0.2876 ms p95 on Tesla T4/PCIe/SSE2 @ 1920x1080 (opengl-timer-query).
Ada L4 scaling: 6.86× baseline (moderate) — 0.109 ms median (2.58× faster on L4).
Ampere A100 scaling: 6.1× baseline (moderate) — 0.1756 ms median (1.6× faster on A100).

## Failure modes

- Long-way-round spins when the sign flip for a negative dot product is skipped
- Division by near-zero sin(w) producing NaNs for almost identical orientations
- Not renormalising after repeated interpolation lets quaternions drift off the unit sphere
- Slerp between consecutive keyframes has a velocity discontinuity at each key unless squad or a spline is used
- Per-bone interpolation ignores the hierarchy, so end effectors can slip even though each joint turns smoothly

## Engine support

- babylonjs: builtin — `Quaternion.Slerp(a, b, t)` (evidence: https://github.com/BabylonJS/Babylon.js/blob/9.38.0/packages/dev/core/src/Maths/math.vector.pure.ts, checked 2026-12-01)
- blender: builtin — `Object/Pose Quaternion rotation interpolation and BLI_math_quaternion.hh shortest-arc spherical linear interpolation` (evidence: https://github.com/blender/blender/blob/main/source/blender/blenlib/BLI_math_quaternion.hh, checked 2026-12-01)
- godot: builtin — `Quaternion.slerp(to, weight); Basis.slerp` (evidence: https://github.com/godotengine/godot/blob/4.7.2-stable/doc/classes/Quaternion.xml, checked 2026-12-01)
- threejs: builtin — `quaternion.slerp(qb, t)` (evidence: https://github.com/mrdoob/three.js/blob/r187/src/math/Quaternion.js, checked 2026-12-01)
- unity: builtin — `Quaternion.Slerp(a, b, t)` (evidence: https://docs.unity3d.com/6000.0/Documentation/ScriptReference/Quaternion.Slerp.html, checked 2026-12-01)
- unreal: builtin — `FQuat::Slerp / unreal.Quat.slerp and Sequencer / Constraint Quaternion Slerp blending` (evidence: https://dev.epicgames.com/documentation/en-us/unreal-engine/python-api/class/Quat, checked 2026-12-01)

## Dataflow

- Inputs: skeleton
- Outputs: animation
- Platforms: cpu, webgl2, webgpu, desktop-gpu, mobile-gpu, unity, unreal, godot, blender, python

## Presets

### Quaternion SLERP — constant-speed geodesic arc on S^3 (cyan) vs uneven NLERP/Euler path (amber) (glsl-fragment; rendered 2026-11-30)

```json
{
  "P_ROT_ANGLE": 2.35,
  "P_SPEED": 0.85,
  "P_TICKS": 12,
  "P_TRAIL_GLOW": 1
}
```

```glsl
const float P_ROT_ANGLE = 2.35; // P Sweep Angle Rad [0.8, 3.05, 0.05]
const float P_SPEED = 0.85; // P Cycle Speed [0.0, 2.5, 0.05]
const float P_TICKS = 12.0; // P Arc Sample Ticks [6.0, 20.0, 1.0]
const float P_TRAIL_GLOW = 1.0; // P Arc Brightness [0.3, 1.8, 0.05]

// Unit quaternion helpers: q = (x, y, z, w)
vec4 qFromAxisAngle(vec3 axis, float ang) {
  float h = ang * 0.5;
  return vec4(normalize(axis) * sin(h), cos(h));
}

vec4 qSlerp(vec4 q0, vec4 q1, float t) {
  float d = dot(q0, q1);
  if (d < 0.0) { q1 = -q1; d = -d; }
  d = clamp(d, -1.0, 1.0);
  if (d > 0.9995) return normalize(mix(q0, q1, t));
  float theta = acos(d);
  float s = max(sin(theta), 1e-5);
  return (sin((1.0 - t) * theta) * q0 + sin(t * theta) * q1) / s;
}

vec4 qNlerp(vec4 q0, vec4 q1, float t) {
  if (dot(q0, q1) < 0.0) q1 = -q1;
  return normalize(mix(q0, q1, t));
}

vec3 qRotate(vec4 q, vec3 v) {
  vec3 t = 2.0 * cross(q.xyz, v);
  return v + q.w * t + cross(q.xyz, t);
}

// Distance from 3D point p to segment a-b
float sdSeg3(vec3 p, vec3 a, vec3 b) {
  vec3 pa = p - a;
  vec3 ba = b - a;
  float h = clamp(dot(pa, ba) / max(dot(ba, ba), 1e-5), 0.0, 1.0);
  return length(pa - ba * h);
}

vec3 aces(vec3 x) {
  x = max(x, 0.0);
  return (x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14);
}

void mainImage(out vec4 fragColor, in vec2 fragCoord) {
  vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
  float ang = clamp(P_ROT_ANGLE, 0.6, 3.08);
  float tCyc = 0.5 - 0.5 * cos(iTime * max(P_SPEED, 0.0) * 1.4);
  float nTicks = clamp(floor(P_TICKS + 0.5), 6.0, 20.0);
  float glow = clamp(P_TRAIL_GLOW, 0.2, 2.0);

  // Start and end unit quaternions spanning a large rotation angle
  vec4 q0 = qFromAxisAngle(vec3(-0.35, 0.85, 0.25), -ang * 0.5);
  vec4 q1 = qFromAxisAngle(vec3(0.45, 0.72, -0.42), ang * 0.5);

  vec4 qCurSlerp = qSlerp(q0, q1, tCyc);
  vec4 qCurNlerp = qNlerp(q0, q1, tCyc);

  vec3 ro = vec3(0.0, 0.28, 2.85);
  vec3 rd = normalize(vec3(uv - vec2(0.0, 0.04), -1.65));

  vec3 col = mix(vec3(0.022, 0.030, 0.052), vec3(0.058, 0.075, 0.122), smoothstep(-0.55, 0.55, uv.y));

  // Analytical unit reference sphere (radius R = 0.88)
  float R = 0.88;
  float b = dot(ro, rd);
  float c = dot(ro, ro) - R * R;
  float disc = b * b - c;
  float tSphere = 1e5;

  if (disc > 0.0) {
    tSphere = -b - sqrt(disc);
    vec3 p = ro + rd * tSphere;
    vec3 n = normalize(p);

    // Lat/lon spherical coordinate grid on S^2
    float lat = abs(fract(asin(clamp(n.y, -1.0, 1.0)) * 6.0 / 3.1415926) - 0.5);
    float lon = abs(fract(atan(n.x, n.z) * 12.0 / 6.2831853) - 0.5);
    float wire = smoothstep(0.035, 0.008, min(lat, lon));

    vec3 lDir = normalize(vec3(0.5, 0.78, 0.62));
    float diff = max(dot(n, lDir), 0.0);
    float fres = pow(1.0 - max(dot(n, -rd), 0.0), 3.0);

    vec3 sphCol = vec3(0.06, 0.10, 0.17) * (0.45 + 0.75 * diff) + vec3(0.14, 0.24, 0.40) * wire * 0.55;
    sphCol += vec3(0.24, 0.54, 0.88) * fres * 0.42;

    // Project SLERP (constant angular velocity) vs distorted Euler/NLERP curves onto the sphere surface
    vec3 baseAxis = normalize(vec3(0.0, 0.12, 1.0));
    float dSlerpMin = 1e5;
    float dNlerpMin = 1e5;
    float tickSlerp = 0.0;
    float tickNlerp = 0.0;

    vec3 prevS = qRotate(q0, baseAxis) * R;
    vec3 prevN = prevS;
    for (int i = 1; i <= 20; i++) {
      if (float(i) > nTicks) break;
      float u = float(i) / nTicks;
      vec3 curS = qRotate(qSlerp(q0, q1, u), baseAxis) * R;
      // Emphasize non-uniform NLERP speed + Euler cross-axis detour for clear comparison
      float uWarp = u + 0.14 * sin(u * 6.2831853);
      vec3 curN = qRotate(qNlerp(q0, q1, clamp(uWarp, 0.0, 1.0)), baseAxis) * R;
      curN = normalize(curN + vec3(0.0, 0.24 * sin(u * 3.1415926), 0.0)) * R;

      dSlerpMin = min(dSlerpMin, sdSeg3(p, prevS, curS));
      dNlerpMin = min(dNlerpMin, sdSeg3(p, prevN, curN));

      tickSlerp = max(tickSlerp, smoothstep(0.036, 0.015, length(p - curS)));
      tickNlerp = max(tickNlerp, smoothstep(0.036, 0.015, length(p - curN)));

      prevS = curS;
      prevN = curN;
    }

    // Cyan SLERP geodesic arc with perfectly uniform tick marks
    sphCol += vec3(0.12, 0.92, 1.0) * smoothstep(0.022, 0.006, dSlerpMin) * 0.88 * glow;
    sphCol = mix(sphCol, vec3(0.75, 0.98, 1.0), tickSlerp * 0.92);

    // Amber Euler/NLERP detour arc with visibly bunched tick marks
    sphCol += vec3(1.0, 0.62, 0.16) * smoothstep(0.022, 0.006, dNlerpMin) * 0.78 * glow;
    sphCol = mix(sphCol, vec3(1.0, 0.84, 0.42), tickNlerp * 0.90);

    // Moving live triad heads on the sphere
    vec3 headS = qRotate(qCurSlerp, baseAxis) * R;
    float uW = clamp(tCyc + 0.14 * sin(tCyc * 6.2831853), 0.0, 1.0);
    vec3 headN = normalize(qRotate(qNlerp(q0, q1, uW), baseAxis) + vec3(0.0, 0.24 * sin(tCyc * 3.1415926), 0.0)) * R;
    sphCol += vec3(0.35, 1.0, 1.0) * smoothstep(0.085, 0.022, length(p - headS)) * 1.1;
    sphCol += vec3(1.0, 0.72, 0.24) * smoothstep(0.085, 0.022, length(p - headN)) * 1.1;

    col = sphCol;
  }

  // Bottom angular-velocity strip plot comparing SLERP (flat constant omega) vs NLERP (spiky omega)
  vec2 plotUV = vec2((uv.x + 0.68) / 1.36, (uv.y + 0.45) / 0.16);
  if (plotUV.x > 0.0 && plotUV.x < 1.0 && plotUV.y > 0.0 && plotUV.y < 1.0) {
    col = mix(col, vec3(0.03, 0.045, 0.075), 0.85);
    float omegaS = 0.55;
    float omegaN = 0.55 + 0.36 * cos(plotUV.x * 6.2831853);
    col = mix(col, vec3(0.16, 0.92, 1.0), smoothstep(0.06, 0.015, abs(plotUV.y - omegaS)));
    col = mix(col, vec3(1.0, 0.62, 0.16), smoothstep(0.06, 0.015, abs(plotUV.y - omegaN)));
    col = mix(col, vec3(0.95, 0.97, 1.0), smoothstep(0.012, 0.003, abs(plotUV.x - tCyc)) * 0.75);
  }

  fragColor = vec4(pow(clamp(aces(col), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);
}
```

Attribution: MIT — written for this index.

## Combines with

- [Motion matching](https://texelatlas.vercel.app/t/motion-matching.md): Blending between matched animation clips interpolates each bone rotation with slerp or nlerp to avoid pops.
- [FABRIK inverse kinematics](https://texelatlas.vercel.app/t/fabrik-ik.md): IK solves produce target orientations that are slerped from the animated pose for smooth blending in and out.

## Sources

1. [primary] Ken Shoemake (1985) Animating rotation with quaternion curves. Proceedings of the 12th annual conference on Computer graphics and interactive techniques  - SIGGRAPH '85. https://doi.org/10.1145/325334.325242 (verified via crossref on 2026-11-29)
2. [implementation] mrdoob (2010) mrdoob/three.js. https://github.com/mrdoob/three.js License: MIT. (verified via github on 2026-11-29)

## Cite this entry

Texel. "Quaternion slerp rotation interpolation." https://texelatlas.vercel.app/t/quaternion-slerp-interpolation/ (accessed 2026-12-01).
