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 5 of 5

Thread: Passing arrays per vertex to shader

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2012
    Posts
    19

    Passing arrays per vertex to shader

    Hi everyone!

    I have an application where I calculate an array of 16 floats per vertex and now I need to send these arrays to my shader program to do the further calculations. I have no idea how to pass the arrays per vertex, if anyone can explain the solution for me ,I would really appreciate it!

    Thanks!

  2. #2
    Member Regular Contributor
    Join Date
    Apr 2009
    Posts
    268
    Quote Originally Posted by saam_b View Post
    Hi everyone!

    I have an application where I calculate an array of 16 floats per vertex and now I need to send these arrays to my shader program to do the further calculations. I have no idea how to pass the arrays per vertex, if anyone can explain the solution for me ,I would really appreciate it!

    Thanks!
    You have 16 floats, each attribute can push 4 floats.
    You need to push this data as 4 separate attributes.

    If you are adventutous, you can declare this as an input matrix in vertex shader or array of 4 vec4 (doing array of 16 floats is also possible, but that would consume 16 attributes, so its not the best idea).

  3. #3
    Advanced Member Frequent Contributor
    Join Date
    Dec 2007
    Location
    Hungary
    Posts
    989
    Or you can also use a buffer texture and access it based on gl_VertexID. This way you can have as many floats per vertex as you wish.
    Disclaimer: This is my personal profile. Whatever I write here is my personal opinion and none of my statements or speculations are anyhow related to my employer and as such should not be treated as accurate or valid and in no case should those be considered to represent the opinions of my employer.
    Technical Blog: http://www.rastergrid.com/blog/

  4. #4
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    4,569
    Quote Originally Posted by kyle_ View Post
    You have 16 floats, each attribute can push 4 floats.
    You need to push this data as 4 separate attributes.
    Depending on how much precision you need, you could actually pack more than 4 floats per attribute.

    FOr instance, you can pass up to 8 floats per vertex attribute using FP16 format, and use the unpackHalf2x16() built-in function in GLSL to unpack them. Then you're down to 2 vtx attrib slots for all 16 floats.

    Of course if you need even less precision per attrib you could potentially sqeeze all 16 into 1 vtx attrib slot. But that's probably only true if they're all 0..1 values where you only need 1/255 accuracy.

  5. #5
    Junior Member Newbie
    Join Date
    Jan 2012
    Posts
    19
    Quote Originally Posted by kyle_ View Post
    You have 16 floats, each attribute can push 4 floats.
    You need to push this data as 4 separate attributes.

    If you are adventutous, you can declare this as an input matrix in vertex shader or array of 4 vec4 (doing array of 16 floats is also possible, but that would consume 16 attributes, so its not the best idea).
    Can you give my some example, I'm a bit confused... I know about attributes but can I use them with VBO and VAO?

Posting Permissions

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