1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-02-08 03:19:49 +00:00
Pixelorama/src/Shaders/FindPaletteColorIndex.gdshaderinc
Emmanouil Papadeas 1dcb696c35 Use texelFetch instead of texture for indexed mode shaders
Fixes various weird issues when palettes have empty slots, and removes unnecessary calculations.
2024-11-22 20:47:05 +02:00

14 lines
443 B
Plaintext

int find_index(vec4 color, int n_of_colors, sampler2D palette_texture) {
int color_index = 0;
float smaller_distance = distance(color, texture(palette_texture, vec2(0.0)));
for (int i = 0; i <= n_of_colors; i++) {
vec4 palette_color = texelFetch(palette_texture, ivec2(i, 0), 0);
float dist = distance(color, palette_color);
if (dist < smaller_distance) {
smaller_distance = dist;
color_index = i;
}
}
return color_index;
}