Smoothstep function

Smoothstep function

本文关键字:function Smoothstep      更新时间:2023-10-16

我正试图通过使用AMD提供的Smoothstep函数来获得一些结果,该函数出现在维基百科页面Smoothstep上。使用;

下面是AMD[4]提供的C/C++示例实现。

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

问题是,由于static method clamp不可用,我无法使用此方法。

我已导入以下内容;

#include <math.h> 
#include <cmath> 
#include <algorithm>  

然而,还没有定义clamp方法。

我的数学能力不是最好的,但有没有办法像有办法实现LERP function一样实现Smoothstep function

float linearIntepolate(float currentLocation, float Goal, float time){
    return (1 - time) * currentLocation + time * Goal;
}

也许只是缺少了命名空间"std":这是我编译的代码:

#include <algorithm>
float smoothstep(float edge0, float edge1, float x) {
    // Scale, bias and saturate x to 0..1 range
    x = std::clamp((x - edge0) / (edge1 - edge0), 0.0f, 1.0f);
    // Evaluate polynomial
    return x * x * (3 - 2 * x);
}