Hatch

/*
FOR SCREEN POST-PROCESSING (GRAY SCALE AND DITHERING)
*/

shader_type canvas_item;

uniform sampler2D texture_screen : hint_screen_texture;
uniform sampler2D texture_noise;

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

void fragment() {
	
	COLOR = texture(texture_screen, SCREEN_UV);
	float avg = (COLOR.r + COLOR.g + COLOR.b) / 3.0;
	
	COLOR.rgb = vec3(avg);
	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);
	
	vec4 color = COLOR;
	
	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;
}
Shader code
/*
FOR 3D MODELS
*/

shader_type spatial;

//render_mode unshaded;

uniform sampler2D texture_hatch_1 : filter_linear;

void vertex() {
	
}

void fragment() {
	
	vec4 h1 = texture(texture_hatch_1, vec2(1.001f, sin(0.5)) * SCREEN_UV * 5.0);
	h1 *= h1 * h1 * h1;
	
	vec3 xnm = NORMAL;
	vec3 col = vec3(xnm.x + xnm.y + xnm.z) / 3.0;
	//col.x = round(col.x);
	//col.y = round(col.y);
	//col.z = round(col.z);
	
	col.rgb *= 2.1;
	col.rgb *= (floor(6.0 * col.rgb) * 4.0) / 9.0;
	
	ALBEDO.rgb = h1.rgb * col;//mix(h1.rgb, col, 0.7);
	
}

void light() {
	DIFFUSE_LIGHT = vec3(0.5f);
	DIFFUSE_LIGHT = vec3(floor(6.f * DIFFUSE_LIGHT) * 4.f) / 9.f;
}
Tags
dither, gray, hatch, manga, sketchy
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 qjpg

Accumulated light (3D)

Post-Processing, Grain PP effect and Palette Color

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments