我正在尝试优化用 GLSL(在 iPhone 上运行)编写的调色板映射着色器。我的实现当然很幼稚,但我对 OpenGL 完全陌生......这是它的外观摘要:
#define COLOR_BLACK vec4(0.0, 0.0, 0.0, 1.0)
#define COLOR_WHITE vec4(1.0, 1.0, 1.0, 1.0)
(... total of 16 colors)
highp vec4 color = texture2D(inputImageTexture, samplePos );
highp float distances[16];
distances[0] = distance(color, COLOR_BLACK);
distances[1] = distance(color, COLOR_WHITE);
(... total of 16 distance calculations)
(... find smallest colour distance)
mediump vec4 finalColor;
if (colorDistance == distances[0]) {
finalColor = COLOR_BLACK;
} else if (colorDistance == distances[1]) {
finalColor = COLOR_WHITE;
(... total of 16 comparisons)
gl_FragColor = finalColor;
这工作正常,但它相当慢。我确定我在这里没有有效地使用 OpenGL :)
任何帮助表示赞赏!