Skip to content

Instantly share code, notes, and snippets.

@jimmyjonezz
Created January 3, 2020 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimmyjonezz/b1f3387e714b7d4dd7419d5f47c6ab77 to your computer and use it in GitHub Desktop.
Save jimmyjonezz/b1f3387e714b7d4dd7419d5f47c6ab77 to your computer and use it in GitHub Desktop.
switch color palette
shader_type canvas_item;
uniform float precision;
uniform float hue;
const mat3 rgb2yiq = mat3(vec3(0.299, 0.587, 0.114), vec3(0.595716, -0.274453, -0.321263), vec3(0.211456, -0.522591, 0.311135));
const mat3 yiq2rgb = mat3(vec3(1.0, 0.9563, 0.6210), vec3(1.0, -0.2721, -0.6474), vec3(1.0, -1.1070, 1.7046));
void fragment() {
vec3 yColor = rgb2yiq * texture(SCREEN_TEXTURE, SCREEN_UV).rgb;
float originalHue = atan(yColor.b, yColor.g);
float finalHue = originalHue + hue;
float chroma = sqrt(yColor.b * yColor.b+yColor.g * yColor.g);
vec3 yFinalColor = vec3(yColor.r, chroma * cos(finalHue), chroma * sin(finalHue));
COLOR = vec4(yiq2rgb * yFinalColor, 1.0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment