PDA

View Full Version : converting float[9] to three vec3's

marmots
06-14-2011, 09:01 AM
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.

Ilian Dinev
06-14-2011, 11:18 AM
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

kyle_
06-14-2011, 11:19 AM
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.

marmots
06-14-2011, 12:17 PM
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).