Screentone – Black spaced pixels

This shader creates the screentone effect – lots of black dots put close together to create the illusion of being gray that you see in manga. I copied the screentone patterns from Lady Werewolf’s Screentone pack here.

Shader code
shader_type canvas_item;

bool is_white(float average, ivec2 pixel_pos){
	bool pixel_bools[] = {
		(pixel_pos.x)%4==0&&(pixel_pos.y+3)%4==0,
		(pixel_pos.x+2)%4==0&&(pixel_pos.y+1)%4==0,
		(pixel_pos.x+2)%4==0&&(pixel_pos.y+3)%4==0,
		(pixel_pos.x)%4==0&&(pixel_pos.y+1)%4==0,
		(pixel_pos.x+1)%4==0&&(pixel_pos.y+2)%4==0,
		(pixel_pos.x+3)%4==0&&(pixel_pos.y)%4==0,
		(pixel_pos.x+3)%4==0&&(pixel_pos.y+2)%4==0,
		(pixel_pos.x+1)%4==0&&(pixel_pos.y)%4==0,
		(pixel_pos.x+1)%4==0&&(pixel_pos.y+3)%4==0,
		(pixel_pos.x+3)%4==0&&(pixel_pos.y+1)%4==0,
		(pixel_pos.x+3)%4==0&&(pixel_pos.y+3)%4==0,
		(pixel_pos.x+1)%4==0&&(pixel_pos.y+1)%4==0,
		(pixel_pos.x)%4==0&&(pixel_pos.y+2)%4==0,
		(pixel_pos.x+2)%4==0&&(pixel_pos.y)%4==0,
		(pixel_pos.x+2)%4==0&&(pixel_pos.y+2)%4==0,
		true
	};
	bool result = false;
	int max_i = int(average*17.0);
	for (int i = 0; i < max_i; i++){
		result = result||pixel_bools[i];
	}
	return result;
}

void fragment() {
    vec4 cur_pixel = texture(TEXTURE, UV);
	ivec2 pixel_pos = ivec2(UV / TEXTURE_PIXEL_SIZE);
    float average = (cur_pixel.r + cur_pixel.g + cur_pixel.b) / 3.0;
	if(is_white(average, pixel_pos)){
		COLOR = vec4(1.0, 1.0, 1.0, cur_pixel.a);
	} else {
		COLOR = vec4(0.0, 0.0, 0.0, cur_pixel.a);
	}
}
Tags
manga, screentone
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 Exuin

Radial Speedlines

Gaussian Blur

Moving Rainbow Gradient

Related shaders

Screentone scene transition

Subscribe
Notify of
guest

2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
ANTON SIMKIN
ANTON SIMKIN
3 years ago

It seems it doesn’t work with GLE2. On the 4th line it says:
Array initialization is supported only on high-end platform!
Can you help with it?