PDA

View Full Version : Reusing small color array for large vertex arrays

Dylan
12-03-2006, 03:45 AM
Hi,

I am rendering a large number of curves(partcile paths), about 16k. the curves are 300 points long.
Now i want to use a color array of 300 rgba values to color code these curves(all in the same way).
Is there a possibility to use an array of 300 values (well, 300 times 4 float values), for each curve?

I can only get it to work to hava a color array the same size as the vertex array - 300 * 16k(number of curves). The curves already take a lot of data in the vertex buffer, so I want to keep the color array as small as possible.

REYES
12-03-2006, 05:11 AM
Is it possible to formulate a linear or nonlinear relation between the curve positions or something else and the color values?

Dylan
12-03-2006, 05:24 AM
the is a simple linear relation between the curve positions in the array.
The vertex array consists of all the curves, in curve order: so first all the 300 positions of the first curve, then the next etc, so 16k times 300 positions. I hope it is possible to use one color coding for the one curve and reuse it for the other curves.

REYES
12-03-2006, 06:11 AM
Good then, hope it works..

zeoverlord
12-03-2006, 06:13 AM
Unless you can programatically map the color using the position of the curve coordinates, you either need to have that 300*16K color array, or a texcoord array(of the same size) and then map the color using a 1D texture.

If you could use a geometry shader then it would be a lot easier, just put the curve coordinates in one or more textures (you could even generate them with a custom fragment shader) and then just generate the curve in the geo program along with colors or texture coordinates.

Dylan
12-03-2006, 07:56 AM
I'll keep that in Mind when I get a GeForce 8 :)

In the mean time is tehre any solution without geometry shader?

Zengar
12-03-2006, 08:48 AM
I would do what zeoverlord suggested: using an 1D texture and add a texture coordinate per-vertex.

This is actually a nice example for instancing :-)

zeoverlord
12-03-2006, 08:50 AM
Maybe, to save in on space a little you can use a 1D texcoord for each vertex and then use a texture lookup.

There is also the possibility to use textures to store coordinate information on, if so you would only need a slightly more manageable number of vertics in the VBO, though you will still need to store and send all that data.
something like 3 2048*2048 textures (it would be smoother if you could use 256 points instead of 300) should work.

k_szczech
12-04-2006, 06:47 AM
Another idea is to have limited number of colors allowed, and sort particles by color (bucketsort).
You can then use one draw call for every set of curves - simply use glColor before such draw call.
Using glColor for every curve would work slow since you would have to make separate draw call for every of 16k curves, but it should work fine with 30-50 groups.
Of course it won't work if you have to do z-sorting for some reason.
If you need something really dynamic then using additional coordinate to lookup in 1D texture would probably be the best solution. Still, you would have to split your geometry to 4-8 parts due to maximum texture size limit.

Dylan
12-04-2006, 11:52 AM
I'm using this now:

glMultiDrawArraysEXT(GL_LINE_STRIP, indices[t], count[length], particles);

so for every timestep t I render "particle" times gl_lines.

And I want every gl_line to have the same color coding every timestep. It is working right now with another VBO filled with color info as I told before.

I am not sure if it will work with your methods?

k_szczech
12-06-2006, 03:36 AM
I am not sure if it will work with your methods?Yes, you can use that additional texcoord freely with glMultiDrawArrays - this will work fastest, but will limit number of different colors you can use to the maximum texture size. It will also cost you one float per vertex.
What I described in my previous post does not require any extra memory, but will certainly cost some performance if there are many different colors. So use this approach if you want to save memory at cost of some performance.

Dylan
12-06-2006, 03:42 AM
Originally posted by k_szczech:

I am not sure if it will work with your methods?Yes, you can use that additional texcoord freely with glMultiDrawArrays - this will work fastest, but will limit number of different colors you can use to the maximum texture size. It will also cost you one float per vertex.
What I described in my previous post does not require any extra memory, but will certainly cost some performance if there are many different colors. So use this approach if you want to save memory at cost of some performance. I solved this by putting the time for each particle in each w-component. I color according to the difference between particle time and global time.