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を効果的に使用していないと確信しています:)
どんな助けでも大歓迎です!