The Green GameBoy Look 4.x

origin GameBoy Look shader is 3.x

updated it to 4.x

Shader code
shader_type canvas_item;

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

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;
	}
}
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

Gameboy Look

Ultimate Gameboy (Color) Shader

Gameboy Color Palette Shader

Subscribe
Notify of
guest

1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
kuinashi101
kuinashi101
1 month ago

Performance improving here:

float when_eq(float x, float y) {
 return 1.0 – abs(sign(x – y));
}

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

vec4 maxC4(vec4 a, vec4 b, vec4 c, vec4 d){
 return max(a, max(b, max(c, d)));
}

void fragment(){
vec4 cW = whiteColor;
  vec4 cLG = lightGreyColor;
  vec4 cDG = darkGreyColor;
  vec4 cB = blackColor;
   
  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));
   
  cW *= when_eq( whiteDistance, min4(whiteDistance, lightGrayDistance, darkGrayDistance, blackDistance));
  cB *= when_eq( blackDistance, min4(whiteDistance, lightGrayDistance, darkGrayDistance, blackDistance));
  cDG *= when_eq( darkGrayDistance, min4(whiteDistance, lightGrayDistance, darkGrayDistance, blackDistance));
  cLG *= when_eq( lightGrayDistance, min4(whiteDistance, lightGrayDistance, darkGrayDistance, blackDistance));
  COLOR = min( maxC4(cW, cB, cLG, cDG), whiteColor );
   

}

Last edited 1 month ago by kuinashi101