Converting float[9] to three vec3's

Is the following a valid conversion(?):



uniform float aNiceFloat[9];

void main()
{
vec3 vA=vec3(aNiceFloat[0]);
vec3 vB=vec3(aNiceFloat[3]);
vec3 vC=vec3(aNiceFloat[6]);
// Do some relevant operations stuff
}

I have not tried using this yet, but I was afraid it might work, but is not allowed somewhere in the spec. I tried searching for an example that shows that this is valid but I did not come across one.


uniform float aNiceFloat[9];

void main()
{
vec3 vA=vec3(aNiceFloat[0],aNiceFloat[1],aNiceFloat[2]);
vec3 vB=vec3(aNiceFloat[3],aNiceFloat[4],aNiceFloat[5]);
vec3 vC=vec3(aNiceFloat[6],aNiceFloat[7],aNiceFloat[8]);
// Do some relevant operations stuff

What you’re currently doing is


uniform float aNiceFloat[9];

void main()
{
vec3 vA=vec3(aNiceFloat[0],aNiceFloat[0],aNiceFloat[0]);
vec3 vB=vec3(aNiceFloat[3],aNiceFloat[3],aNiceFloat[3]);
vec3 vC=vec3(aNiceFloat[6],aNiceFloat[6],aNiceFloat[6]);
// Do some relevant operations stuff

It is valid code. It should compile and do what its specified to do.

Note however, that vec3(aNiceFloat[0]) creates a vec3 with all three components set to aNiceFloat[0]. This probably isnt what you want.

Thanks for the answer - that makes perfect sense I don’t know why I didn’t see the error of what I was doing (and the solution of setting the vec3 as vec3(f[0],f[1],f[2]) is pretty obvious).

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.