IT lexicon › Programming › Lerp (linear interpolation)

Lerp (linear interpolation)

Programming På svenska → Updated: 2026-10-26

The function a + (b − a) · t, which picks a point on the straight line between two values and is plausibly the most-called line of code in game development.

At t = 0 you get a, at t = 1 you get b, and in between a straight slide. Positions, colours, volume, camera zoom — anything that has to move smoothly from one state to another goes through a lerp, often with an easing curve applied to t. HLSL calls it lerp, GLSL calls it mix, and C++ only got std::lerp in 2020. Rotations need something else: slerp.

The classic trap is x = lerp(x, target, 0.1) once per frame. It looks like smoothing but is tied to frame rate: at 144 Hz the camera catches up more than twice as fast as at 60. The correct form is t = 1 − exp(−k · dt) using delta time. The variant a·(1−t) + b·t is also worth knowing, since it lands exactly on b at t = 1 despite floating-point rounding.

← Back to the lexicon