Smoothstep and Smootherstep
Smoothstep bends a straight-line into an S-curve, , that leaves and arrives at with zero slope, so a motion starts gently and settles gently instead of lurching. Smootherstep, , also flattens the curvature at both ends, so even the acceleration starts and stops at zero.
What the symbols mean
- Progress
The plain fraction of the move, 0 to 1: usually elapsed time over duration.
- Smoothed progress
What you feed to lerp instead of t: lerp(a, b, s(t)).
What the symbols mean
- Smoother progress
Zero slope and zero curvature at both ends.
What the symbols mean
- Speed of smoothstep
Zero at both ends and 1.5 in the middle, in units of the average speed.
What the symbols mean
- Lower edge
Where the output starts rising from 0.
- Upper edge
Where it reaches 1.
Explanation
Smoothstep is simply a way to bend progress so that a motion eases in and eases out. You still go from to , but instead of moving at one constant speed (lerp's straight line), you start slow, speed up through the middle and slow down again before you arrive. The formula is a cubic with two terms: (which gets things going gently, since a square starts out flat) and (which bends the curve back over so it lands exactly on ). You use it by feeding it to lerp, instead of . It's a change to one line of code, and it makes motion look far less mechanical.
const smoothstep01 = (t: number) => t * t * (3 - 2 * t);
const x = lerp(start, end, smoothstep01(elapsed / duration));
Why plain lerp feels robotic. With (time over duration), the position moves at from the very first instant until the last, and then not at all. The speed jumps from to full and back to with no time in between, which would take an infinite acceleration. On screen, the object lurches into motion and stops dead. Real things don't move like that; they have mass and take time to speed up. So we want a progress curve whose slope is at both ends.
Deriving smoothstep. Ask for exactly that: and (start and end in the right places), and and (at rest at both ends). Four conditions, so try a polynomial with four unknown coefficients, a cubic . The two conditions at kill and , and the two at give and , so and . (The first worked example goes through it one step at a time.) There's nothing magic about smoothstep: it's the simplest polynomial that starts and ends at rest.
Its slope is , a hump that's at both ends and biggest at , where it's . Since the slope of progress is speed measured in units of the average speed, a smoothstepped move peaks at times the speed a plain lerp would use the whole way. That makes sense: if you spend the beginning and end going slowly, you have to make up the time in the middle. The curve is also symmetric, : the second half is the first half turned upside down, and .
Smootherstep: no jolt in the acceleration, either. Look one derivative further. , so at the acceleration is , not . Smoothstep's speed starts at and climbs smoothly, but its acceleration switches on all at once. The rate at which acceleration changes is called jerk (a real physics term, and you can feel it: it's the lurch when an elevator starts or a car's brakes grab), and an acceleration that switches on instantly is a spike of jerk. Ken Perlin's smootherstep, which he introduced for his improved noise function in 2002, adds two more conditions, . Six conditions call for six coefficients, a degree- polynomial, and they give . Its speed starts flat, and its acceleration starts at . The price is a steeper middle: its peak speed is times the average. There are animations further down showing all three curves, their speeds and their accelerations.
Smoothstep in shaders. The built-in smoothstep(edge0, edge1, x) in GLSL and HLSL does the previous lesson's clamped inverse lerp first, then bends the result. Shaders use it to soften edges: a circle whose alpha is 1.0 - smoothstep(0.48, 0.5, r) fades out over a thin ring instead of ending in jagged pixels.
function smoothstep(edge0: number, edge1: number, x: number): number {
const t = Math.min(Math.max((x - edge0) / (edge1 - edge0), 0), 1);
return t * t * (3 - 2 * t);
}
A common mistake. Skipping the clamp. The cubic is only well behaved between and ; outside, it turns around. and , so a timer that runs a little past its duration makes the object slide back toward where it started. Clamp to first, as the shader version does.
Another one. Thinking smoothstep makes a move take longer. The duration is the same and the start and end are the same, so the average speed is the same; only the way the time is spent changes. A related trap is GLSL's argument order: the value goes last, smoothstep(edge0, edge1, x), and the specification leaves the result undefined when edge0 >= edge1, so use 1.0 - smoothstep(...) rather than swapping the edges.
Smoothstep is the first easing curve; Timing: Why Motion Needs Easing builds a whole family of them. It's also a special Hermite curve, one with both end tangents set to zero (see Hermite and Catmull-Rom), and the slopes here are ordinary derivatives, with the chain rule turning progress per unit into speed per second.
See it
Worked examples
Find the cubic with , , and .
- 1
Four conditions and four unknown coefficients, so we expect exactly one answer. Use the easy conditions, the ones at , first.
A door swings open in seconds with its angle following smoothstep: for s, where . Find the angle at s and the door's fastest turning speed.
- 1
Convert time to progress: .
Practice
Type your answer and check it. Solve them all to complete the lesson.
Evaluate smoothstep at .
Evaluate smootherstep at .
A shader softens an edge with , which clamps to and returns . Find its value at .
A camera dolly travels m along a track in s, its position following with smoothstep . What's its top speed, in m/s?
A timer bug lets reach before any clamp is applied. What does smoothstep return at ?
An elevator car must rise m in s, its height following with smoothstep . What is its acceleration just after it starts, at , in m/s²?
Find the polynomial of degree with , , and with and both zero at and at .
The hardest one here. Get it, and you've got this lesson.
A crane lifts a load m in s along the profile , with smootherstep , so the load starts and stops with zero speed and zero acceleration. What is the largest acceleration the load feels, in m/s²?
Where it's used
Smoothstep and smootherstep show up wherever a value has to change without a visible kink. Interfaces slide panels open and fade dialogs in with S-curves like these; game cameras turn hard cuts into short glides; shaders use to soften the edges of circles, vignettes and text outlines, to blend terrain textures by height and to fade fog with distance; and value noise (used for clouds, terrain and screen shake) blends between random lattice values with smoothstep or smootherstep so the result has no creases. Quintic profiles like smootherstep are also a standard way to plan moves for robot arms and motion-control camera rigs, where a sudden jump in acceleration would shake the payload.