Shader smoothstep使用

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010333737/article/details/82859246

  ret smoothstep(a, b, x)可以用来生成0到1的平滑过渡.

返回值 条件
0 x < a < b 或 x > a > b
1 x < b < a 或 x > b > a
某个值 根据x在域 [a, b] (或者[b, a])中的位置, 返回某个在 [0, 1] 内的值

  对于参数全是float的重载

float smoothstep(float a, float b, float x)
{
    float t = saturate((x - a)/(b - a));
    return t*t*(3.0 - (2.0*t));
}

  我们用图像来直观理解一下这个计算式, 可以看出smoothstep对于参数ab的大小并没有限制, 均能完成平滑的插值.

  smoothstep(0.2, 0.7, x)
  a=0.2, b=0.7

  smoothstep(0.5, 0, x)
  a=0.5, b=0

猜你喜欢

转载自blog.csdn.net/u010333737/article/details/82859246