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);
}
Is this equivalent to:
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;
}
Edit:
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)
I've also tried:
(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'
I'm assuming this is because I'm using GLSL 1.2. ATI Radeon 3450
vec4 is a floating point vector with four components. It can be initialized by: Providing a scalar value for each component. Providing one scalar value. This value is used for all components.
GLM's vec2 is a utility class representing 2D vector, there are also vec3 , vec4 classes available for 3D and 4D respectively. GLM is also offering matrix classes following same naming conditions mat2 , mat3 , mat4 . You can multiply a matrix with a matrix or a matrix with a vector using overloaded * operator.
Fragment shaders can be difficult to debug. Debugging a normal computer program is typically done in one of two ways: 1) print intermediate values to a console window, or 2) use an interactive debugger to set breakpoints and step through the code one statement at a time.
One way to speed up GLSL code, is by marking some variables constant at compile-time. This way the compiler may optimize code (e.g. unroll loops) and remove unused code (e.g. if hard shadows are disabled). The drawback is that changing these constant variables requires that the GLSL code is compiled again.
From the spec, section 5.9 (top of page 38):
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.
Looks like you want the lessThan function. Check section 8.6 (page 62).
lessThan()
- http://www.opengl.org/ (see also: all()
)If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With