Smoothstep and Easing
Linear motion looks mechanical: it starts at full speed and stops dead. Real objects accelerate and decelerate. Easing functions reshape t before you lerp, so motion starts or ends gently, overshoots, or bounces. They are the backbone of UI animation and of "game feel".
eased = ease(t) t in 0..1, eased usually in 0..1
value = lerp(a, b, eased)Smoothstep
The most useful single easing is smoothstep, an S-curve that starts and ends with zero speed:
smoothstep(t) = t * t * (3 - 2t)GLSL and HLSL have it built in as smoothstep(edge0, edge1, x), which also does an inverse lerp and clamp first. Shader code uses it everywhere for soft edges.
#include <iostream>
#include <iomanip>
#include <algorithm>
double smoothstep(double edge0, double edge1, double x) { // like GLSL
double t = std::clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0);
return t * t * (3 - 2 * t);
}
double smootherstep(double t) { return t * t * t * (t * (t * 6 - 15) + 10); } // Ken Perlin's version
int main() {
std::cout << std::fixed << std::setprecision(3);
std::cout << " t linear smooth smoother\n";
for (int i = 0; i <= 8; i++) {
double t = i / 8.0;
std::cout << std::setw(6) << t << std::setw(8) << t << std::setw(8) << smoothstep(0, 1, t)
<< std::setw(9) << smootherstep(t) << "\n";
}
} t linear smooth smoother
0.000 0.000 0.000 0.000
0.125 0.125 0.043 0.016
0.250 0.250 0.156 0.104
0.375 0.375 0.316 0.275
0.500 0.500 0.500 0.500
0.625 0.625 0.684 0.725
0.750 0.750 0.844 0.896
0.875 0.875 0.957 0.984
1.000 1.000 1.000 1.000
All three agree at 0, 0.5 and 1. The difference is in the speed: smoothstep's changes most in the middle and least at the ends. Smootherstep also has zero acceleration at the ends, which avoids a visible "kick" when an animation starts.
A family of easing curves
Easing functions come in families named after their shape (quad, cubic, sine, expo, back, elastic, bounce), each in three flavors:
| Flavor | Meaning | Example (cubic) |
|---|---|---|
| in | starts slow, ends fast | t³ |
| out | starts fast, ends slow | 1 - (1-t)³ |
| in-out | slow, fast, slow | t < 0.5 ? 4t³ : 1 - (-2t+2)³/2 |
"Out" curves feel the most responsive for UI and camera moves: the reaction starts immediately and settles softly. "Back" curves overshoot a little before settling, which adds bounce to buttons and pickups.
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <numbers>
double easeInQuad(double t) { return t * t; }
double easeOutCubic(double t) { return 1 - std::pow(1 - t, 3); }
double easeInOutSine(double t) { return -(std::cos(std::numbers::pi * t) - 1) / 2; }
double easeOutBack(double t) {
const double c1 = 1.70158, c3 = c1 + 1;
return 1 + c3 * std::pow(t - 1, 3) + c1 * std::pow(t - 1, 2);
}
double easeOutBounce(double t) {
const double n = 7.5625, d = 2.75;
if (t < 1 / d) return n * t * t;
if (t < 2 / d) { t -= 1.5 / d; return n * t * t + 0.75; }
if (t < 2.5 / d) { t -= 2.25 / d; return n * t * t + 0.9375; }
t -= 2.625 / d; return n * t * t + 0.984375;
}
void plot(const char* name, double (*f)(double)) {
std::cout << name << "\n";
for (int i = 0; i <= 10; i++) {
double t = i / 10.0, v = f(t);
int col = static_cast<int>(std::lround(v * 30));
std::cout << " " << std::fixed << std::setprecision(1) << t << " " << std::setprecision(3) << std::setw(6) << v
<< " |" << std::string(std::max(col, 0), ' ') << "*\n";
}
}
int main() {
plot("easeOutCubic", easeOutCubic);
plot("easeOutBack (overshoots past 1)", easeOutBack);
plot("easeOutBounce", easeOutBounce);
std::cout << std::setprecision(3) << "easeInQuad(0.5) = " << easeInQuad(0.5)
<< ", easeInOutSine(0.25) = " << easeInOutSine(0.25) << "\n";
}easeOutCubic
0.0 0.000 |*
0.1 0.271 | *
0.2 0.488 | *
0.3 0.657 | *
0.4 0.784 | *
0.5 0.875 | *
0.6 0.936 | *
0.7 0.973 | *
0.8 0.992 | *
0.9 0.999 | *
1.0 1.000 | *
easeOutBack (overshoots past 1)
0.0 0.000 |*
0.1 0.409 | *
0.2 0.706 | *
0.3 0.907 | *
0.4 1.029 | *
0.5 1.088 | *
0.6 1.099 | *
0.7 1.080 | *
0.8 1.046 | *
0.9 1.014 | *
1.0 1.000 | *
easeOutBounce
0.0 0.000 |*
0.1 0.076 | *
0.2 0.303 | *
0.3 0.681 | *
0.4 0.910 | *
0.5 0.766 | *
0.6 0.772 | *
0.7 0.931 | *
0.8 0.940 | *
0.9 0.988 | *
1.0 1.000 | *
easeInQuad(0.5) = 0.250, easeInOutSine(0.25) = 0.146
The formulas above are the widely used "Robert Penner" set; easings.net shows all of them as curves. Tweening libraries (DOTween in Unity, Godot's Tween with set_trans/set_ease, GSAP and Tween.js on the web, Unreal's FMath::InterpEaseInOut and Timeline curves) all offer the same family by name.
Easing anything
Because easing only reshapes t, it works with any interpolation: positions, colors, scales, camera FOV, even quaternion slerp. A pickup that pops in with easeOutBack on its scale, then bobs with a sine wave, is two lines of math and feels far better than a linear fade.
Tip: Easing curves need a fixed start and end and a known duration. For following a moving target (a camera chasing a player), you want damping instead, covered in the next lesson.
Test yourself
What is smoothstep(0.5) for the curve t²(3 - 2t)?
- 0.25
- 0.5
- 0.75
- 1
Which easing flavor starts fast and ends slowly, the usual choice for responsive UI?
- ease-in
- ease-out
- linear
- ease-in-out
What is special about 'back' easing curves?
- They run backwards in time
- They briefly overshoot the target before settling
- They are linear
- They only work for rotations