PDA

View Full Version : vertex buffer object with dynamic color array



saam_b
08-01-2012, 03:40 AM
Hi all,

I have a static scene where the only thing that changes on each frame is the color of each vertex. I'm using VBO and GLSL for drawing my scene. The color array is calculated on each frame, which is dependent on the rotation of the environment map and some other stuff. So It will be changed for each frame, and I have to recalculate it again and again. I have two questions:

1- How I can transfer this color array to the shader at each frame
2- How can I move the calculation to the shader because it drops the frame rate, and is highly dependent on the number of vertices of the object.

the calculation of the color for each vertex is the sum of multiplication of two arrays of coefficients related to that vertex, one of them is light coefficients and the other is transfer function coefficients. (spherical harmonic lighting) light coefficients will change with the rotation of the environment map, but it is the same for all vertices. but transfer function coefficients varies for each vertex.


thanks if advance for any help :)

V-man
08-01-2012, 04:43 PM
1. Store the color values in a separate array. Set the usage field to GL_STREAM. Update it with glBufferSubData.
2. Perhaps you can do it in the vertex shader. It depends on if the arrays aren't too large and you can declare them as a uniform in the vertex shader. If it is large, then make a 1D texture out of it and read the texture and add up the values in your vertex shader. If you are on a SM 4 GPU, you can make the texture any format you want and sample it. If it is just float values, then it will work on SM 3 GPUs as well.