skip to content

What does smoothstep compute, and why does passing t through an easing curve make interpolated motion feel better than plain lerp?

level: juniorimportance: should knowfreq 45%

answer

  1. slow in, slow out
  2. reshape t, keep the lerp
  3. zero slope at both ends
  4. 3t^2 - 2t^3 after a clamp

basics

~20 s

Smoothstep clamps a value to [0, 1] between two edges and returns 3t^2 - 2t^3, a curve with zero slope at both ends. Feeding an eased t into lerp makes motion start and stop gently instead of jumping to full speed.

solid answer

~50 s

`smoothstep(e0, e1, x)` first computes `t = clamp((x - e0) / (e1 - e0), 0, 1)`, an inverse lerp, then returns `t * t * (3 - 2 * t)`. Its derivative `6t(1 - t)` is zero at `t = 0` and `t = 1` and peaks at 1.5 in the middle, so a value driven by it eases out of rest and into rest. Plain lerp with `t = elapsed / duration` moves at constant speed and stops dead, which reads as mechanical: the speed jumps from zero to full in one frame and back at the end. Easing is the general idea: keep `lerp(a, b, ease(t))` and swap the curve. `t * t` eases in, `1 - (1 - t)^2` eases out, smoothstep eases both ways, and smootherstep, `6t^5 - 15t^4 + 10t^3`, also zeroes the second derivative at the ends.

code

pseudocode · 10 lines
pseudocode
function smoothstep(e0, e1, x):
    t = clamp((x - e0) / (e1 - e0), 0, 1)
    return t * t * (3 - 2 * t)

function easeOutQuad(t):
    return 1 - (1 - t) * (1 - t)

// a UI panel sliding in over 0.3 s
t = clamp(elapsed / 0.3, 0, 1)
panelX = lerp(offscreenX, restX, easeOutQuad(t))

go deeper

for a junior

Recall the smoothstep steps: inverse lerp, clamp, then 3t^2 - 2t^3. Know that easing reshapes t and the lerp stays the same.

for a middle

Derive smoothstep's slope 6t(1 - t), show why zero end slopes remove the abrupt start, and match ease-in, ease-out and in-out to UI and camera moves.

for a senior

Explain where smoothstep's non-zero end acceleration shows, when smootherstep earns its cost, and why target-chasing needs time-based smoothing rather than an ease.

for a principal

Set a shared easing vocabulary and tuning data across UI, camera and gameplay so motion feels consistent and designers change curves without code.

## Why linear motion feels mechanical A tween written as `lerp(start, end, t)` with `t = elapsed / duration` moves at a constant speed from its first frame to its last. That sounds ideal, but the eye reads it as robotic: the object goes from rest to full speed in one frame and stops dead at the end. Physical objects accelerate and decelerate, and animators have long called the fix **slow in and slow out**. In code the fix is an **easing curve**: a function `ease(t)` that maps [0, 1] onto [0, 1], keeps `ease(0) = 0` and `ease(1) = 1`, and changes how fast the value moves in between. You keep the same lerp and only reshape its parameter: `value = lerp(start, end, ease(elapsed / duration))` ## Smoothstep, step by step **Smoothstep** is one of the most widely used easing curves and doubles as a soft threshold. `smoothstep(e0, e1, x)` takes two **edges** and an input: 1. normalise: `t = (x - e0) / (e1 - e0)`, an inverse lerp of `x` between the edges; 2. clamp `t` to [0, 1], so inputs before `e0` give 0 and inputs after `e1` give 1; 3. return `t * t * (3 - 2 * t)`, the cubic `3t^2 - 2t^3`. The cubic is chosen for its derivative, `6t - 6t^2 = 6t(1 - t)`. It is zero at both ends, so the value leaves 0 and arrives at 1 with zero slope, and it peaks at 1.5 at `t = 0.5`, so the middle moves half again as fast as a linear tween of the same duration to make up the time. Sample values make the shape concrete: `smoothstep(0, 1, 0.25) = 0.15625`, `smoothstep(0, 1, 0.5) = 0.5`, `smoothstep(0, 1, 0.75) = 0.84375`. The output always lies in [0, 1]: the edges set *where* on the input axis the transition happens, not the output range. To move between two arbitrary values, feed the result into a lerp. Because smoothstep contains the inverse lerp and the clamp, it also works as a **soft threshold**: `smoothstep(4, 6, distance)` fades an effect in across a 2-metre band instead of popping it on at 5 metres. A falling edge is `1 - smoothstep(e0, e1, x)`; some implementations leave reversed or equal edges undefined, so writing the falling edge this way is the portable habit. ## A family of easing curves | Curve | Formula | Slope at start | Slope at end | Feel | |---|---|---|---|---| | linear | `t` | 1 | 1 | constant speed, abrupt start and stop | | ease-in (quadratic) | `t * t` | 0 | 2 | starts gently, arrives fast | | ease-out (quadratic) | `1 - (1 - t)^2` | 2 | 0 | leaves fast, settles gently | | smoothstep | `3t^2 - 2t^3` | 0 | 0 | gentle at both ends | | smootherstep | `6t^5 - 15t^4 + 10t^3` | 0 | 0 | gentle at both ends, zero acceleration there too | Choosing among them is a feel decision, but the conventions are stable: - **UI that enters** the screen usually eases out, so it arrives quickly and settles; - **UI that leaves** usually eases in, so it gathers speed as it goes; - **a camera moving between two framings** usually eases both ways, with smoothstep or smootherstep; - **overshoot curves** deliberately go past 1 before settling, for a springy, playful arrival; they break the "output stays in [0, 1]" property, so anything clamped downstream will flatten them. ## Smootherstep and higher continuity Smoothstep has zero velocity at its ends but not zero acceleration: its second derivative, `6 - 12t`, is 6 at the start and -6 at the end. When motions are chained (one tween hands over to another) or the eased value drives something sensitive to acceleration, such as a procedural head bob, that sudden change in acceleration can show. **Smootherstep** zeroes both the first and second derivatives at the ends, at the price of a few more multiplies and a steeper middle: its peak slope is 1.875 at `t = 0.5`. It is not smoothstep applied twice; composing smoothstep with itself gives a different, ninth-degree curve. ## Practical rules - **Ease the parameter, not the output**: `lerp(a, b, ease(t))` works for scalars, vectors and colours alike, with one curve definition. - **Clamp `t` before easing**: outside [0, 1] a polynomial curve leaves its intended range or turns back (an unclamped ease-in gives 1.21 at `t = 1.1`, the bare smoothstep cubic about 0.97), so a late frame would overshoot or reverse. - **Fixed-duration tweens and target-chasing are different problems**: a value that follows a moving target every frame needs time-based exponential smoothing or a damped follow, not an easing curve over a duration. - **Keep curves tunable**: designers usually pick curves from data, but a candidate should be able to write the closed forms on a whiteboard and say why each end slope matters.

  • When would you choose smootherstep over smoothstep?
    When acceleration at the ends matters. Smoothstep starts and stops with zero velocity but a non-zero second derivative (6 and -6), so chained tweens or acceleration-sensitive effects can show a small kink. Smootherstep, `6t^5 - 15t^4 + 10t^3`, has zero first and second derivatives at both ends. It costs a few more multiplies and has a steeper middle, peaking at slope 1.875 instead of 1.5.
  • What goes wrong if the end value of an eased tween changes while the tween is running?
    The tween was planned between a fixed start and end. Restarting it from the current value resets the speed to zero, so the object visibly hesitates as the ease-in begins again. Lerping toward the live end value keeps the timing and still lands on it at `t = 1`, but the path bends. For targets that move continuously, frame-rate-independent exponential smoothing or a critically damped follow suits better than a fixed-duration ease.

  • Smoothstep returns a value between its two edge arguments.
  • Easing changes where a tween ends, not only how it gets there.
  • Smoothstep has zero slope only at the start, like an ease-in.
  • Each easing curve needs its own interpolation formula instead of lerp.
  • Smootherstep is just smoothstep applied twice.