GLSL 内置函数

greaterThan()

逐分量比较是否大于。

示例版本:GLSL ES 1.00 / WebGL 1示例阶段:片段

函数签名

bvec2 greaterThan(vec2 x, vec2 y)
bvec3 greaterThan(vec3 x, vec3 y)
bvec4 greaterThan(vec4 x, vec4 y)
bvec2 greaterThan(ivec2 x, ivec2 y)
bvec3 greaterThan(ivec3 x, ivec3 y)
bvec4 greaterThan(ivec4 x, ivec4 y)

参数

x
输入值或左侧向量
y
右侧向量或比较值

返回值

一个布尔向量,在 x 的对应分量严格大于 y 时,该分量为 true。

在线示例

修改右侧代码,左侧预览会实时更新。

greaterThan 做什么

逐分量比较是否大于。

看懂预览

预览只取 greaterThan(vec2(x,y),vec2(0.0)) 的 .x,所以右半边成立。把界限改成 vec2(0.5),分界就会移到 x = 0.5。

核心调用

float(greaterThan(vec2(x,y),vec2(0.0)).x);

结果的每个布尔分量对应同位置的输入分量。

修改实验

保留零界限,把取出的 .x 改为 .y。成立区域会从画面右半边换到上半边。

规范

GLSL ES 1.00 built-in functions, chapter 8

相关函数