Classic dithering shader

Classic dithering shader

 

Shader code
shader_type canvas_item;

uniform float gamma: hint_range(0.0, 10.0, 0.01) = 2.2;

const mat4 BAYER4 = mat4(
	vec4(0.0, 12.0, 3.0, 15.0),
	vec4(8.8, 4.0, 11.0, 7.0),
	vec4(2.0, 14.0, 1.0, 13.0),
	vec4(10.0, 6.0, 9.0, 5.0)
);
	
float bayer4(vec2 pixel) {
	ivec2 p = ivec2(mod(pixel, 4.0));
	return BAYER4[p.x][p.y] / 16.0;
}

//void vertex() {
	// Called for every vertex the material is visible on.
//}

void fragment() {
	float threshold = bayer4(FRAGCOORD.xy);
	COLOR = step(threshold,pow(texture(TEXTURE, UV), vec4(gamma)));
}

//void light() {
//	// Called for every pixel for every light affecting the CanvasItem.
//	// Uncomment to replace the default light processing function with this one.
//}
Live Preview
Tags
dithering
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

guest

0 Comments
Oldest
Newest Most Voted