Convert Color

detect background color and convert to select color

Shader code
shader_type canvas_item;

uniform sampler2D screen_texture : hint_screen_texture, filter_nearest;

uniform vec4 black : source_color = vec4(0.067, 0.012, 0.067, 1.0);
uniform vec4 blue : source_color = vec4(0.365, 0.373, 0.776, 1.0);
uniform vec4 green : source_color = vec4(0.431, 0.82, 0.541, 1.0);
uniform vec4 white : source_color = vec4(0.898, 0.914, 0.91, 1.0);



void fragment() {
	vec4 new_color = texture(screen_texture, SCREEN_UV, 0.0);
	
	if (new_color.a > 0.0)
	{
		if(distance(new_color, black) < 0.1)
		{
			COLOR = blue;
		}

		if(distance(new_color, blue) < 0.1)
		{
			COLOR = green;
		}
		if(distance(new_color, green) < 0.1)
		{
			COLOR = white;
		}
	}
}
The shader code and all code snippets in this post are under CC0 license and can be used freely without the author's permission. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

Related shaders

color splash (show only one color)

Select Color Range

CGA 4-Color Shader

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments