Color reduction and dither

Reduces the values per RGB-channel.

Can use a checkerboard-dither with variable intensity.

 

Original image in screenshots

Shader code
shader_type canvas_item;

uniform float colors : hint_range(1.0, 16.0);
uniform float dither : hint_range(0.0, 0.5);

void fragment()
{
	vec4 color = texture(TEXTURE, UV);
	
	float a = floor(mod(UV.x / TEXTURE_PIXEL_SIZE.x, 2.0));
	float b = floor(mod(UV.y / TEXTURE_PIXEL_SIZE.y, 2.0));	
	float c = mod(a + b, 2.0);
	
	COLOR.r = (round(color.r * colors + dither) / colors) * c;
	COLOR.g = (round(color.g * colors + dither) / colors) * c;
	COLOR.b = (round(color.b * colors + dither) / colors) * c;
	c = 1.0 - c;
	COLOR.r += (round(color.r * colors - dither) / colors) * c;
	COLOR.g += (round(color.g * colors - dither) / colors) * c;
	COLOR.b += (round(color.b * colors - dither) / colors) * c;
}
Tags
dither color 8bit
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)

Dither Gradient Shader

Earthbound-like battle background shader w/scroll effect and palette cycling

guest
0 Comments
Inline Feedbacks
View all comments