Math 对于平滑步长函数glsl,edge0大于或等于edge1的情况是什么

Math 对于平滑步长函数glsl,edge0大于或等于edge1的情况是什么,math,glsl,smoothstep,Math,Glsl,Smoothstep,我正在研究smoothstep(edge0,edge1,x)函数。 如果edge0>=edge1,则表示结果未定义 其中有一行: smoothstep(radius + SIZE, radius + SIZE / 1.2, dist); 这意味着edge0>=edge1它仍然可以正常工作,这怎么可能呢?在我看来,文档是错的 以下是使用smoothstep的一些经验: y=smoothstep(1.0,-1.0,x) y=smoothstep(-1.0,1.0,x) 看起来,当edge0>e

我正在研究
smoothstep(edge0,edge1,x)
函数。 如果
edge0>=edge1
,则表示结果未定义

其中有一行:

smoothstep(radius + SIZE, radius + SIZE / 1.2, dist);

这意味着
edge0>=edge1
它仍然可以正常工作,这怎么可能呢?

在我看来,文档是错的

以下是使用smoothstep的一些经验:

y=smoothstep(1.0,-1.0,x)

y=smoothstep(-1.0,1.0,x)

看起来,当edge0>edge1时,它翻转1处的边为负无穷大,翻转0处的边为正无穷大

另一个例子:

#ifdef GL_ES
precision mediump float;
#endif

#define PI 3.14159265359

uniform vec2 u_resolution;

float plot(vec2 st, float pct){
  return  smoothstep( pct+0.02, pct, st.y) -
          smoothstep( pct, pct-0.02, st.y);
}

void main() {
    vec2 st = gl_FragCoord.xy/u_resolution;

    // Smooth interpolation between 0.1 and 0.9
    float y = smoothstep(0.1,0.9,st.x);

    vec3 color = vec3(y);

    float pct = plot(st,y);
    color = (1.0-pct)*color+pct*vec3(0.0,1.0,0.0);

    gl_FragColor = vec4(color,1.0);
}

将y从0.9更改为0.1将输出更改为:


从Nvidia开发者文档添加到@astamatic的上述答案:

与a和b相比,基于x从0平滑插值到1

1) Returns 0 if x < a < b or x > a > b 
1) Returns 1 if x < b < a or x > b > a 
3) Returns a value in the range [0,1] for the domain [a,b]. 
1)如果xa>b,则返回0
1) 如果xb>a,则返回1
3) 返回域[a,b]的范围[0,1]内的值。
smoothstep(a,b,a)和smoothstep(a,b,b)的斜率为零

对于向量,返回的向量包含向量x的每个元素的平滑插值


这解释了smoothstep函数表示的任何类型的行为。

这与
javascript
html
无关,请删除这些标记。此外,如果您进一步阅读文档,您会发现
smoothstep
相当于
t=clamp((x-edge0)/(edge1-edge0),0.0,1.0);返回t*t*(3.0-2.0*t)因此,如果
edge0=>edge1
它可以工作,但结果没有定义。我不认为文档是错误的,它们和规范只是没有指定如果
edge0=>edge1
应该发生什么,所以结果可能是任何东西。但在其他方面答案很好。未定义在某种意义上与未指定同义是准确的,所以更好的说法是文档不清楚。谢谢