vec4上的GLSL <>运算符

ans*_*art 10 opengl glsl

我正在寻找一些新的GLSL代码,它不能编译到我当前的OpenGL版本,我想知道以下简短形式是什么意思:

vec4 base;

if (base < 0.5) {
    result = (2.0 * base * blend);
}
Run Code Online (Sandbox Code Playgroud)

这相当于:

if (base.r < 0.5 && base.g < 0.5 && base.b < 0.5 && base.a < 0.5) {
    result.r = 2.0 * base.r * blend.r;
    result.g = 2.0 * base.g * blend.g;
    result.b = 2.0 * base.b * blend.b;
    result.a = 2.0 * base.a * blend.a;
}
Run Code Online (Sandbox Code Playgroud)

编辑:

Error:
Fragment shader failed to compile with the following errors:
Wrong operand types no operation '<' exists that takes a left-hand operand of type 'highp 3-component vector of float' and a right operand of type 'const float' (or there is no acceptable conversion)
Run Code Online (Sandbox Code Playgroud)

我也尝试过:

(base.rgb < vec3(0.5))
... Wrong operand types no operation '<' exists that takes a left-hand operand of type 'highp 3-component vector of float' and a right operand of type 'const highp 3-component vector of float'
Run Code Online (Sandbox Code Playgroud)

我假设这是因为我使用的是GLSL 1.2.ATI Radeon 3450

gen*_*ult 10

规范,第5.9节(第38页的顶部):

大于(>),小于(<),大于或等于(> =)且小于或等于(<=)的关系运算符仅对标量整数和标量浮点表达式起作用.结果是标量布尔值.操作数的类型必须匹配,或者第4.1.10节"隐式转换"中的转换将应用于整数操作数,之后类型必须匹配.要对向量进行分量关系比较,请使用内置函数lessThan,lessThanEqual,greaterThan和greaterThanEqual.

看起来你想要lessThan函数.检查第8.6节(第62页).

  • @Bart:OP表示他/她正在使用GLSL 1.2,所以我想我会从该版本的规范中提取.加上梅萨仍然在2.1,所以4.1还不存在:) (2认同)