Godot Version
Godot 4.5
Question
I’m working on a retro-styled game where a lot of visual effects are done via palette swapping. Recently, I’ve finally decided to rework the shader so that it doesn’t have both the original colors array and the original colors image, as that has always seemed redundant to me. However, I can’t get the colors from the palette image to be read correctly.
Original palette:

Old shader, all colors replaced correctly:

New shader, half of the colors failed to replace:

void fragment() {
vec4 palette[] = {color0, color1, color2, color3, color4, color5, color6, color7};
int color_count = textureSize(original_palette, 0).x;
for (int i = 0; i < min(color_count, 8); i++) {
vec4 color_orig = texture(original_palette, vec2(float(i) / float(color_count - 1), 0));
if (COLOR == color_orig) {
COLOR = palette[i];
}
}
The only part I can think of that might have anything wrong is the texture division, as the rest seems to work fine. color0-7 are vec4’s, original_palette is a sampler2D.