You are currently viewing the GMLscripts.com static mirror. Forum access and script submissions are not available through this mirror.

Invert GMLscripts.com

smoothstep

This function makes a smooth transition from 0 to 1 beginning at threshold a and ending at threshold b. In order to do this, smoothstep contains a cubic function whose slope is 0 at a and b and whose value is 0 at a and 1 at b. There is only one cubic function that has these properties for a = 0 and b = 1, namely the function \(3x^2 - 2x^3\). This function can be used to provide smooth transitions between values or to "ease" animation in and out.

smoothstep

smoothstep(a, b, x)
Returns 0 when (x <= a), 1 when (x >= b), a smooth transition from 0 to 1 otherwise.
COPY/// @func   smoothstep(a, b, x)
///
/// @desc   Returns 0 when (x <= a), 1 when (x >= b), a smooth transition
///         from 0 to 1 otherwise. If a >= b the result is not defined.
///
/// @param  {real}      a           lower bound
/// @param  {real}      b           upper bound
/// @param  {real}      x           value
///
/// @return {real}      adjusted value
///
/// GMLscripts.com/license

function smoothstep(a, b, x)
{
    var t = clamp((x - a) / (b - a), 0, 1);
    return t * t * (3 - 2 * t);
}

Contributors: xot

GitHub: View · Commits · Blame · Raw