ColorPalette.gdshader 460 B

1234567891011121314151617181920212223
  1. shader_type canvas_item;
  2. const float EPSILON = 0.0001;
  3. uniform int palette_size : hint_range(1, 20) = 0;
  4. uniform vec3 palette_in[20] : source_color;
  5. uniform vec3 palette_out[20] : source_color;
  6. void fragment()
  7. {
  8. if (COLOR.a > 0.0)
  9. {
  10. for (int i = 0; i < palette_size; ++i)
  11. {
  12. vec3 diff = abs(COLOR.xyz - palette_in[i]);
  13. if (diff.x < EPSILON && diff.y < EPSILON && diff.z < EPSILON)
  14. {
  15. COLOR.xyz = palette_out[i].xyz;
  16. break;
  17. }
  18. }
  19. }
  20. }