Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: converting float[9] to three vec3's

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2011
    Posts
    4

    converting float[9] to three vec3's

    Is the following a valid conversion(?):

    Code :
     
    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.

  2. #2
    Senior Member OpenGL Pro Ilian Dinev's Avatar
    Join Date
    Jan 2008
    Location
    Watford, UK
    Posts
    1,261

    Re: converting float[9] to three vec3's

    Code :
    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

    Code :
    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

  3. #3
    Member Regular Contributor
    Join Date
    Apr 2009
    Posts
    258

    Re: converting float[9] to three vec3's

    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.

  4. #4
    Junior Member Newbie
    Join Date
    Jun 2011
    Posts
    4

    Re: converting float[9] to three vec3's

    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).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •