Created
October 2, 2018 07:53
-
-
Save xphere/1e42434ec6bf90eddab1cee4e16e4fef to your computer and use it in GitHub Desktop.
Godot 4-color shader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shader_type canvas_item; | |
render_mode blend_mix; | |
uniform vec4 color_1 = vec4(0.784313725, 0.788235294, 0.262745098, 1.0); | |
uniform vec4 color_2 = vec4(0.490196078, 0.521568627, 0.152941176, 1.0); | |
uniform vec4 color_3 = vec4(0.000000000, 0.415686275, 0.000000000, 1.0); | |
uniform vec4 color_4 = vec4(0.015686275, 0.243137255, 0.000000000, 1.0); | |
uniform float offset = 0.5; | |
float to_grayscale_average(vec4 pixel) | |
{ | |
return (pixel.r + pixel.g + pixel.b) / 3.0; | |
} | |
float to_grayscale_luminosity(vec4 pixel) | |
{ | |
return 0.21 * pixel.r + 0.72 * pixel.g + 0.07 * pixel.b; | |
} | |
vec4 colorize(float grayscale) | |
{ | |
if (grayscale > offset * 1.5) { | |
return color_1; | |
} | |
if (grayscale > offset) { | |
return color_2; | |
} | |
if (grayscale > offset * 0.5) { | |
return color_3; | |
} | |
return color_4; | |
} | |
void fragment() { | |
vec4 pixel_color = texture(SCREEN_TEXTURE, SCREEN_UV); | |
COLOR = colorize(to_grayscale_luminosity(pixel_color)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment