PDA

View Full Version : Passing arrays per vertex to shader



saam_b
06-14-2012, 09:50 AM
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!

kyle_
06-14-2012, 10:02 AM
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).

aqnuep
06-14-2012, 10:59 AM
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.

Dark Photon
06-14-2012, 05:14 PM
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.

saam_b
06-16-2012, 03:01 AM
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?