[英]what is the case for edge0 greater than or equal to edge1 for smoothstep function glsl
I am looking into smoothstep(edge0, edge1, x)
function.我正在研究
smoothstep(edge0, edge1, x)
函数。 docs say results are undefined if edge0 >= edge1
. 文档说如果
edge0 >= edge1
结果未定义。
In a shader there is a line:在着色器中有一行:
smoothstep(radius + SIZE, radius + SIZE / 1.2, dist);
this means edge0 >= edge1
it still works fine, how is that possible?这意味着
edge0 >= edge1
它仍然可以正常工作,这怎么可能?
Looks to me like the docs are wrong.在我看来文档是错误的。
Here's from playing around with smoothstep:这是使用 smoothstep 进行的操作:
It looks like when edge0 > edge1, it flips the side at 1 to be at negative infinity, and the side at 0 to be at positive infinity.看起来当 edge0 > edge1 时,它将 1 处的边翻转为负无穷大,将 0 处的边翻转为正无穷大。
Another example:另一个例子:
#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);
}
Changing y to a step from 0.9 to 0.1 changes the output to this:将 y 更改为从 0.9 到 0.1 的步长会将输出更改为:
Adding to @Asthamatic's answer above, from Nvidia developer docs:添加到@Asthamatic 上面的答案,来自 Nvidia 开发人员文档:
https://developer.download.nvidia.com/cg/smoothstep.html https://developer.download.nvidia.com/cg/smoothstep.html
Interpolates smoothly from 0 to 1 based on x compared to a and b.与 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].
The slope of smoothstep(a,b,a) and smoothstep(a,b,b) is zero. smoothstep(a,b,a) 和 smoothstep(a,b,b) 的斜率为零。
For vectors, the returned vector contains the smooth interpolation of each element of the vector x对于向量,返回的向量包含向量 x 的每个元素的平滑插值
This explains any kind of behavior represented by smoothstep functions.这解释了由平滑步函数表示的任何类型的行为。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.