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!

[QUOTE=saam_b;1238790]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![/QUOTE]

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

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.

[QUOTE=kyle_;1238791]You have 16 floats, each attribute can push 4 floats.
You need to push this data as 4 separate attributes.[/QUOTE]
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.

[QUOTE=kyle_;1238791]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).[/QUOTE]

Can you give my some example, I’m a bit confused… I know about attributes but can I use them with VBO and VAO?

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