View Full Version : Coloring gl_lines using vertex shader

12-04-2006, 10:19 PM
Hi, I already know I should be able to solve my problem easily with a geometry shader. But that is not in my possession, and probably will not for a while.

During rendering I am sending lines to the GPU in that line order. I want to color all the lines(that do have the same length) in the same way.

for example: the first vertex of the line should be yellow, the last (for example vertex 100 of the line, if the line length is 100) should be red.

I was wondering if I could use the vertex shader in any way to color them correctly.

At the moment it is working if I use an extra color array of the same size as all the vertices I need. But since I use 16k vertices over 5400 time steps, the color array will be as big, and that is not preferable.

I am using this to draw these lines(path lines, curves)
glMultiDrawArraysEXT(GL_LINE_STRIP, indices[t], count[length], particles);

I think this is not easily solved, maybe impossible...

12-04-2006, 11:59 PM
What about using texture coordinates ?
So within your pixel shader, you can sample a large 1D texture, instead of a limited color array.

And you can get free linear interpolation if you want.

12-05-2006, 06:17 AM
I solved this by adding the time for each particle in the "w" attribute of the Vertex.

When comparing to the overall time i can color the vertices accordingly and the result is the same as with color arrays. But this way I save ~40% of data!