Skip to content

pymath.smooth_step

Daniel Flassig edited this page Jul 17, 2026 · 1 revision

Smoothly ramps from 0 to 1 as t crosses an interval — a smooth replacement for a hard step or a plain pymath.clamp.

s = pymath.smooth_step(t)                 -- ramp over [0, 1]
s = pymath.smooth_step(t, t_min, t_max)   -- ramp over [t_min, t_max]
Parameter Type Description
t number Input value.
t_min number (optional) Start of the ramp: the result is 0 for t <= t_min. Default 0.
t_max number (optional) End of the ramp: the result is 1 for t >= t_max. Default 1. Must differ from t_min.

Return value

Type Description
s A number in [0, 1] that increases smoothly (with zero slope at both ends) as t runs from t_min to t_max, and is constant outside the interval.

Notes:

  • The ramp is the cubic Hermite smoothstep s = 3u² - 2u³, where u is t rescaled to [0, 1] and clamped.
  • Unlike pymath.interpolate_linear, the result is clamped: 0 below t_min, 1 above t_max.
  • Swapping the bounds (t_min > t_max) yields a descending ramp from 1 down to 0.
  • smooth_step operates on numbers only.

Example:

pymath.smooth_step(0.0)          -- 0.0
pymath.smooth_step(0.25)         -- 0.15625
pymath.smooth_step(0.5)          -- 0.5
pymath.smooth_step(1.0)          -- 1.0

-- fade something in over the range [10, 20]
pymath.smooth_step(5, 10, 20)    -- 0.0
pymath.smooth_step(15, 10, 20)   -- 0.5
pymath.smooth_step(25, 10, 20)   -- 1.0

Version Support:

Minimum PYTHA Version: V27

See also:

pymath, pymath.clamp, pymath.interpolate_linear

Clone this wiki locally