math - 对于 smoothstep 函数 glsl,edge0 大于或等于 edge1 是什么情况
问题描述
我正在研究smoothstep(edge0, edge1, x)
功能。
文档说结果未定义 if edge0 >= edge1
。
在着色器中有一行:
smoothstep(radius + SIZE, radius + SIZE / 1.2, dist);
这意味着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);
}
将 y 更改为从 0.9 到 0.1 的步长会将输出更改为:
推荐阅读
- dji-sdk - DJI 无人机定位 - 移动 SDK
- android - Android - 如何在聚焦时以编程方式获取 TextInputLayout 的提示大小?
- ios - 第一个 leftBarButtonItem 隐藏
- angular - 如何将数据(Json 对象)从 Angular 2 发布到 Web api?
- typescript - 打字稿类对象存储到firebase db
- android - Android - LocationManager requestLocationUpdates 回调在 Lollipop 上不起作用
- excel - Excel VBA从具有文件路径的单元格中附加多个文件
- ruby-on-rails - 如何让我的数据库查询更高效?
- javascript - 如何在 javascript 中将相同的键值对(以不同的顺序)表示为 Map 的相同键?
- java - 带底栏的浮动操作按钮