Smoothstep
Encyclopedia
Smoothstep is a scalar interpolation
Interpolation
In the mathematical field of numerical analysis, interpolation is a method of constructing new data points within the range of a discrete set of known data points....

 function commonly used in computer graphics
Computer graphics
Computer graphics are graphics created using computers and, more generally, the representation and manipulation of image data by a computer with help from specialized software and hardware....

  and video game engines
Game engine
A game engine is a system designed for the creation and development of video games. There are many game engines that are designed to work on video game consoles and personal computers...

. The function interpolates smoothly
Smooth function
In mathematical analysis, a differentiability class is a classification of functions according to the properties of their derivatives. Higher order differentiability classes correspond to the existence of more derivatives. Functions that have derivatives of all orders are called smooth.Most of...

 between two input values based on a third one that should be between the first two. The returned value is clamped between 0 and 1.

The slope (i.e. derivative) of the smoothstep function starts at 0 and ends at 0. This makes it easy to create a sequence of transitions using smoothstep to interpolate each segment rather than using a more sophisticated or expensive interpolation technique.

As pointed out in MSDN
Microsoft Developer Network
The Microsoft Developer Network is the portion of Microsoft responsible for managing the firm's relationship with developers and testers: hardware developers interested in the operating system , developers standing on the various OS platforms, developers using the API and scripting languages of...

 and OpenGL
OpenGL
OpenGL is a standard specification defining a cross-language, cross-platform API for writing applications that produce 2D and 3D computer graphics. The interface consists of over 250 different function calls which can be used to draw complex three-dimensional scenes from simple primitives. OpenGL...

 documentation, smoothstep implements cubic Hermite interpolation
Hermite interpolation
In numerical analysis, Hermite interpolation, named after Charles Hermite, is a method of interpolating data points as a polynomial function. The generated Hermite polynomial is closely related to the Newton polynomial, in that both are derived from the calculation of divided differences.Unlike...

 after doing a clamp:


An example implementation provided by AMD follows.


float smoothstep(float edge0, float edge1, float x)
{
// Scale, bias and saturate x to 0..1 range
x = saturate((x - edge0)/(edge1 - edge0));
// Evaluate polynomial
return x*x*(3 - 2*x);
}

Variations

In Ken Perlin
Ken Perlin
Ken Perlin is a professor in the Department of Computer Science at New York University, founding director of the Media Research Lab at NYU, and the Director of the Games for Learning Institute. His research interests include graphics, animation, multimedia, and science education...

 suggests an improved version of the smoothstep function which has zero 1st and 2nd order derivatives at t=0 and t=1:


Reference implementation:

float smootherstep(float edge0, float edge1, float x)
{
// Scale, and clamp x to 0..1 range
x = clamp((x - edge0)/(edge1 - edge0), 0, 1);
// Evaluate polynomial
return x*x*x*(x*(x*6 - 15) + 10);
}

External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK