egu*_*eys 6 math glsl smoothstep
我正在研究smoothstep(edge0, edge1, x)功能。
docs说结果是 undefined if edge0 >= edge1。
在着色器中有一行:
smoothstep(radius + SIZE, radius + SIZE / 1.2, dist);
Run Code Online (Sandbox Code Playgroud)
这意味着edge0 >= edge1它仍然可以正常工作,这怎么可能?
在我看来,文档是错误的。
以下是使用 smoothstep 的结果:
看起来当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);
}
Run Code Online (Sandbox Code Playgroud)
将 y 的步长从 0.9 更改为 0.1 会将输出更改为: