In one of my projects, I use the following smoothstep()
function :
float smoothstep(float a, float b, float m, int n)
{
for(int i = 0 ; i < n ; i++)
{
m = m * m * (3 - 2 * m);
}
return a + (b - a) * m;
}
It works great, however, it has two disadvantages :
- It's slow (especially for big values of
n
) - It doesn't work for non integer values (eg :
n = 1.5
)
Is there an alternative (excluding precalculating points and then interpolating) providing better performance (and same behavior), or another function giving a great approximation ?