函数接口:
Tfd smoothstep(Tfd edge0, Tfd edge1, Tfd x)
Tf smoothstep(float edge0, float edge1, Tf x)
Td smoothstep(double edge0, double edge1, Td x)
函数说明:
smoothstep函数会先将x,在[edge0, edge1]的部分平滑的映射到[0,1],小于edge0部分映射到0, 大于edge1部分映射到1。smoothstep的内部实现可以参考如下,参考GLSL函数smoothstep讲解:
genType t;
t = clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0);
return (3.0 - 2.0 * t) * t * t
验证可参照function test smoothstep:
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
vec2 uv = fragCoord/iResolution.xy;
if (abs(uv.y-smoothstep(0.2,0.8,uv.x))<1e-2)
fragColor = vec4(1.,0.,0.,1.);
}
显示效果如下: