I have some questions relating to shaders and whether or not they can perform array lookups fast enough to use them to draw indexed color arrays
[li]Is this possible?
[/li][li]Would it be fast blitting pixels this way?
[/li][li]How would I do this effectivly?
[/li][li]Can you post a code example?
Are you talking about using glDrawArrays() to render (effectively) glDrawElements() batches?
Seems like that would prevent effective use of the post-vertex shader transform cache (to suppress needless vertex shader executions).
Or are you literally just talking about using an indirect lookup to fetch your vertex colors? Say, store a color index in your vertex color atttribute and then in the shader do a uniform, texture, or buffer lookup using that index. If so, then I would expect this to be pretty fast. Put it in the fastest memory you can afford to based on its size.
like using actual c# arrays as a indexed bitmap and palette and using shaders to look them up and draw them
I think there are lots of different solutions for this. A simple one would be to use two textures as data-sources. Your sample-image demonstrates, what i mean:
One texture (might have only 8bit per pixel), where the indices are stored, as in the upper of the three illustrations.
The second has only one row or column of pixels, containing the colors by index, like in the second illustration.
In the fragment shader, you can access the first one by the normal gl_TextCoord, to get the color-index, wich is the y-coordinate that you have to pick from the second one, to get the output-color.
The Fragment-shader might contain code like this:
float colorIndex = texture2D(Texture1, gl_TexCoord.st).r;
color = texture2D(Texture2, vec2(0, colorIndex));
This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.