Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get component-wise maximum of vector in GLSL

Tags:

opengl

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?

like image 891
hanno Avatar asked Jan 18 '15 01:01

hanno


People also ask

What is vec3 in GLSL?

vec3 is a floating point vector with three components. It can be initialized by: Providing a scalar value for each component. Providing one scalar value. This value is used for all components.

How many bytes is a vec4?

So, the alignment of a mat4 is like that of a vec4, which is 16 bytes. And the size of a mat4 is 4*sizeof(vec4) = 4*16 bytes.


1 Answers

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);
}
like image 162
Andon M. Coleman Avatar answered Sep 20 '22 21:09

Andon M. Coleman