I have written a function in GLSL that returns the min index (index 0 is the x component, 1 is the y component, and 2 is the z component) of a vec3 variable.
uint getMinIndex(vec3 vector)
{
float minValue = min(min(vector.x, vector.y), vector.z);
if(vector.x == minValue)
return 0;
if(vector.y == minValue)
return 1;
return 2;
}
As you can see, this function causes branching and slows down the whole shader.... Is there already such a function in GLSL? Or is there a better way to do this without branching?