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(a,b,x)
- Returns 0 when (x < a), 1 when (x >= b), a smooth transition from 0 to 1 otherwise, or (-1) on error (a == b).
COPY/// smoothstep(a,b,x)
//
// Returns 0 when (x < a), 1 when (x >= b), a smooth transition
// from 0 to 1 otherwise, or (-1) on error (a == b).
//
// a upper bound, real
// b lower bound, real
// x value, real
//
/// gmlscripts.pro/license
{
var p;
if (argument2 < argument0) return 0;
if (argument2 >= argument1) return 1;
if (argument0 == argument1) return -1;
p = (argument2 - argument0) / (argument1 - argument0);
return (p * p * (3 - 2 * p));
}
Contributors: xot
GitHub: View · Commits · Blame · Raw