gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 22:36:36 30 4
gpt4 key购买 nike

我正在调查 smoothstep(edge0, edge1, x)功能。
docs如果 edge0 >= edge1,则表示结果未定义.

a shader有一行:

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

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

最佳答案

在我看来文档是错误的。

这是使用 smoothstep 进行的操作:
y = smoothstep(1.0,-1.0,x); enter image description here
y = smoothstep(-1.0,1.0,x); enter image description here

看起来当 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);
}

enter image description here

将 y 更改为从 0.9 到 0.1 的步长会将输出更改为:

enter image description here

关于math - 对于平滑步长函数 glsl,edge0 大于或等于 edge1 是什么情况,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57631669/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com