GLSL<> vec4上的运算符 [英] GLSL <> operators on a vec4

查看:726
本文介绍了GLSL<> vec4上的运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查看一些无法编译到当前版本OpenGL的更新GLSL代码,我想知道以下简短形式的含义是什么:

I'm looking at some newer GLSL code that doesn't compile to my current version of OpenGL and I'm wondering what the short form of the following means:

vec4 base;

if (base < 0.5) {
    result = (2.0 * base * blend);
}

这等同于:

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;
}

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)

我也尝试过:

(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'

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

I'm assuming this is because I'm using GLSL 1.2. ATI Radeon 3450

推荐答案

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

From the spec, section 5.9 (top of page 38):

关系运算符大于 (>),小于(<),大于或 等于(> =),且小于或等于 (< =)仅对标量整数运算 和标量浮点表达式. 结果是标量布尔值.任何一个 操作数的类型必须匹配,否则 来自第4.1.10节的转换 将应用隐式转换" 到整数操作数,之后 类型必须匹配.去做 逐组件关系比较 在向量上,使用内置函数 小于,小于等于,大于, 并大于Equal.

The relational operators greater than (>), less than (<), greater than or equal (>=), and less than or equal (<=) operate only on scalar integer and scalar floating-point expressions. The result is scalar Boolean. Either the operands’ types must match, or the conversions from Section 4.1.10 "Implicit Conversions" will be applied to the integer operand, after which the types must match. To do component-wise relational comparisons on vectors, use the built-in functions lessThan, lessThanEqual, greaterThan, and greaterThanEqual.

好像您想要 lessThan 功能.检查第8.6节(第62页).

Looks like you want the lessThan function. Check section 8.6 (page 62).

  • lessThan() - http://www.opengl.org/ (see also: all())

这篇关于GLSL&lt;&gt; vec4上的运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆