Search code examples
openglglsl

Get component-wise maximum of vector in GLSL


I need to get the maximum of a vec3 in GLSL. Currently I am doing

max(max(col.r, col.g),col.b)

It works. But I am wondering if there a better way to do this with one built-in function call?


Solution

  • That is the best you are going to do in GLSL, unfortunately.

    I have gotten used to writing that sort of thing. However, if it bothers you, you can always write your own function that does that.

    For example:

    float max3 (vec3 v) {
      return max (max (v.x, v.y), v.z);
    }