Skip to content

Instantly share code, notes, and snippets.

@erdavids
Last active March 30, 2024 20:29
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save erdavids/3cc909f68adb8e8b6589158e30819eff to your computer and use it in GitHub Desktop.
Save erdavids/3cc909f68adb8e8b6589158e30819eff to your computer and use it in GitHub Desktop.
shader_type canvas_item;
uniform vec4 color_1 = vec4(.0, .0, .0, 1.0);
uniform vec4 color_2 = vec4(0.5, 0.5, 0.5, 1.0);
void fragment() {
vec4 colors[2] = {color_1, color_2};
float min_diff = -1.0;
vec4 min_color = vec4(0.0, 0.0, 0.0, 1.0);
vec2 uv = SCREEN_UV;
vec4 temp = textureLod(SCREEN_TEXTURE, uv, 0.0);
min_diff = 1000.0;
for (int i = 0; i < colors.length(); i++) {
float curr_dist = distance(colors[i], temp);
if (curr_dist < min_diff) {
min_diff = curr_dist;
min_color = colors[i];
}
}
COLOR.rgb = min_color.rgb;
}
@BaddRadish
Copy link

not sure how to credit you, so i'm linking back here. please let me know if this is not available for public use.

@benergize
Copy link

Hello! I've taken this great shader and made a tool to let you add colors to the palette with a color picker. I've also added the capability to do the comparisons via YUV to get more optically intuitive color matching, as well as fixing Godot 4.2 compatibility. The tool is here: https://www.qiuet.uk/files/colorhelper.html. I'm well intentionedly/hopefully assuming an open source license here, but let me know if that's not the case, and I'll modify the tool to be compliant with whatever terms are required. Hope this is helpful for people, and thank you for this shader code!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment