Gameboy Look

A simple shader which gives your game a gameboy look.

Shader code
shader_type canvas_item;

uniform vec4 whiteColor : hint_color = vec4(0.961, 0.980, 0.937, 1.0);
uniform vec4 lightGreyColor : hint_color = vec4(0.549, 0.749, 0.039, 1.0);
uniform vec4 darkGreyColor : hint_color = vec4(0.18, 0.451, 0.125, 1.0);
uniform vec4 blackColor : hint_color = vec4(0.0, 0.247, 0.0, 1.0);

float min4(float a, float b, float c, float d){
	return min(a, min(b, min(c, d)));
}

void fragment(){
	vec4 currentColor = texture(SCREEN_TEXTURE, SCREEN_UV);
	
	float blackDistance = distance(currentColor, vec4(vec3(0.0), 1.0));
	float whiteDistance = distance(currentColor, vec4(vec3(1.0), 1.0));
	float lightGrayDistance = distance(currentColor, vec4(vec3(0.666, 0.666, 0.666), 1.0));
	float darkGrayDistance = distance(currentColor, vec4(vec3(0.333, 0.333, 0.333), 1.0));
	
	if (
		whiteDistance == min4(whiteDistance, lightGrayDistance, darkGrayDistance, blackDistance)
	)
	{
		COLOR = whiteColor;
	}
	else if (
		blackDistance == min4(whiteDistance, lightGrayDistance, darkGrayDistance, blackDistance)
	)
	{
		COLOR = blackColor;
	}
	else if (
		darkGrayDistance == min4(whiteDistance, lightGrayDistance, darkGrayDistance, blackDistance)
	)
	{
		COLOR = darkGreyColor;
	}
	else if (
		lightGrayDistance == min4(whiteDistance, lightGrayDistance, darkGrayDistance, blackDistance)
	)
	{
		COLOR = lightGreyColor;
	}
	else{
		COLOR = whiteColor;
	}
}
Tags
2d, color effect, effect
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.

More from Grau

Aberration Vignette – Phasmophobia effect

PS1/PSX Model

Gamma Correction

Related shaders

The Green GameBoy Look 4.x

Ultimate Gameboy (Color) Shader

Gameboy Color Palette Shader

Subscribe
Notify of
guest

3 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
CJ Lewis
3 years ago

Thanks for posting

inc0der
2 years ago

This is a great little shader, super simple yet really good for making some retro style games. Thanks for sharing!

junior
junior
5 months ago

Corregido 4.x:

shader_type canvas_item;

uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear_mipmap;

uniform vec4 whiteColor = vec4(0.961, 0.980, 0.937, 1.0);
uniform vec4 lightGreyColor = vec4(0.549, 0.749, 0.039, 1.0);
uniform vec4 darkGreyColor = vec4(0.18, 0.451, 0.125, 1.0);
uniform vec4 blackColor = vec4(0.0, 0.247, 0.0, 1.0);

float min4(float a, float b, float c, float d) {
   return min(a, min(b, min(c, d)));
}

void fragment() {
   vec4 currentColor = texture(SCREEN_TEXTURE, SCREEN_UV);

   float blackDistance = distance(currentColor, vec4(vec3(0.0), 1.0));
   float whiteDistance = distance(currentColor, vec4(vec3(1.0), 1.0));
   float lightGrayDistance = distance(currentColor, vec4(vec3(0.666, 0.666, 0.666), 1.0));
   float darkGrayDistance = distance(currentColor, vec4(vec3(0.333, 0.333, 0.333), 1.0));

   if (whiteDistance == min4(whiteDistance, lightGrayDistance, darkGrayDistance, blackDistance)) {
       COLOR = whiteColor;
   } else if (blackDistance == min4(whiteDistance, lightGrayDistance, darkGrayDistance, blackDistance)) {
       COLOR = blackColor;
   } else if (darkGrayDistance == min4(whiteDistance, lightGrayDistance, darkGrayDistance, blackDistance)) {
       COLOR = darkGreyColor;
   } else if (lightGrayDistance == min4(whiteDistance, lightGrayDistance, darkGrayDistance, blackDistance)) {
       COLOR = lightGreyColor;
   } else {
       COLOR = whiteColor;
   }
}