Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the logic for determining a min/max vector in GLSL?

Tags:

I'm a bit surprised I don't know this already, but it never hurts to admit you're still learning :)

In GLSL there are min and max functions that that, according to their documentation:

return the lesser/greater of two values

But how is that determined when the values are vectors? Obviously (1, 1) would be less than (2, 2), but what is the min or max of (1, 3) and (4, -2)? Where is that logic formally described?

like image 664
Toji Avatar asked Aug 23 '12 05:08

Toji


1 Answers

Quoting from the first source that I could find (PDF), at the top of §8.3 Common Functions, page 132:

These all operate component-wise. The description is per component.

Nearly all the functions that operator on vectors but really only make sense for a scalar operate component-wise. (This includes abs, sign, floor, trunc, round, roundEven, ceil, fract, mod, modf, min, max, clamp, mix, step, smoothstep, and a whole lot more.)

So, for example, the min of (1, 3) and (4, -2) is (1, -2).

like image 71
John Calsbeek Avatar answered Sep 18 '22 16:09

John Calsbeek