shader func
1、step
float step(float edge, float x) vec2 step(vec2 edge, vec2 x) vec3 step(vec3 edge, vec3 x) vec4 step(vec4 edge, vec4 x)
GLSL 的 step 函数用于比较两个参数的大小,当第一个参数小于第二个参数时返回 0,大于等于时返回 1。
应用场景:
// 画圆(有锯齿) void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 uv = fragCoord/iResolution.xy; // 标准化坐标 [0,1] uv.x *= iResolution.x / iResolution.y; // 修正宽高比 vec2 center = vec2(0.5,0.5); float dist = length(uv - center); float radius = 0.3; float circle = 1.0 - step(radius, dist); fragColor = vec4(vec3(circle),1.0); }
2、clamp
float clamp(float x, float minVal, float maxVal); vec2 clamp(vec2 x, vec2 minVal, vec2 maxVal); vec3 clamp(vec3 x, vec3 minVal, vec3 maxVal); vec4 clamp(vec4 x, vec4 minVal, vec4 maxVal);
GLSL的clamp函数用于将数值或向量限制在指定范围内,确保其值介于最小值和最大值之间
3、smoothstep
smoothstep(edge0, edge1, x) 接受三个参数:
edge0:范围下限阈值
edge1:范围上限阈值
x:当前计算值
- 当 x < edge0 时,返回 0.0
- 当 x > edge1 时,返回 1.0
- 当 edge0 ≤ x ≤ edge1 时,返回一个平滑过渡的值(0~1之间)
4、

浙公网安备 33010602011771号