2
votes

I have some data that I do not have control of (provided by the client) which specifies:

vertices

indices

a "colorPalette" (8 different colours of vec4, 32 values in total)

a "vertexColors" array that defines which vertices should have which colour from the colorPalette applied to them. e.g. 0,0,1280 in this array means, "colour '0' from colorPalette should be applied to all vertices with an index between 0 and 1280."

It seems to me that when I define my GLSL Vertex Shader, I need to be able to access the index of the current vertex so that I can determine, using vertexColors, which colour, from colorPalette, to apply and pass through to the Fragment Shader by use of a varying.

How do I find the index of the current vertex?

Thanks for any help,

Phil.

P.S. I am very new to Open GLES 2.0, have never used OpenGL or OpenGLES before and am taking all my guidance from "OpenGLES 2.0 Programming Guide" and anything I can find on the internet.

P.P.S. Seems to me that Open GLES 1.x looked a lot easier :)

2
New Nintendo platform work perhaps or phone fun?Michael Dorgan

2 Answers

2
votes

Use gl_VertexID built-in attribute.

I honestly don't see how are you going to search the color (given the index) in you color array.

Instead, I would create a special buffer object for vertex color and draw color buffer into it (bound as a target Texture Buffer Object). A geometry shader in this case would generate line strips with desired color, like this: - create point at 0 - create point at 1280 - get color from the palette, pass it to fragment shader

This operation is pretty cheap for HW, would give you exact color for each vertex, based on the palette data you provide.

0
votes

Any chance you can apply a different shader directly when the new palette needs to be applied instead of attempting to count vertex indices which might not be available? Honestly, I don't believe GL supplies the index you are looking for, but I am by no means an expert in the area. I would do as I suggest and use multiple shaders instead and determine some other logical mean to apply those values.