AnsweredAssumed Answered

how to dynamically index to vector component

Question asked by viscocoa on Feb 20, 2012
Latest reply on Feb 27, 2012 by notzed

I have a piece of code as below:

 

...

int4 vec;

...

 

if (condition == 0)

    vec.x = 100;

else if (condition == 1)

    vec.y ++;

else if (condition == 2)

    vec.z ++;

else

    vec.w ++;

 

Is it possible to index to the component dynamically to avoid branching? Ideally, I can do this:

 

vec.condition ++;

 

But the above code does not work

Outcomes