本文介绍了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):

好像您想要 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上的运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 02:12