2d crosshatching for textures with normal maps

I went down a rabbit hole first learning shaders, so I thought I would share my first attempt at one. Wanted to use this one for a project but it doesn’t really achieve the look I was shooting for, not mention that it doesn’t work for more than 1 light and requires a normal map (which means you should be using CanvasTexture on the sprite2d node). I’m really posting this in hopes that someone might be able to make a more robust version that actually looks good. Also make sure to have a CanvasModulate Node in the scene. The hatch_texture has the most thick hatching on the red channel, the next on the green channel and the lightest hatching on the blue channel.

Shader code
shader_type canvas_item;

uniform sampler2D hatch_texture;
uniform float hatch_scale = 1.0;

void light() {
	vec2 uv = UV * hatch_scale;
	uv = mod(uv, 1.0f);
	float result;
	float brightness = max(dot(NORMAL, LIGHT_DIRECTION), 0.0f);
	if (brightness > 0.50f) {
		brightness = 1.0f;
		result = 1.0f;
	} else if (brightness > 0.4f) {
		brightness = 0.66f;
		result = (1.0f - texture(hatch_texture, uv).b);
	} else if (brightness > 0.0f) {
		result = (1.0f - texture(hatch_texture, uv).g);
	} else {
		brightness = 0.0f;
		result = (1.0f - texture(hatch_texture, uv).r);
	}
		LIGHT = result * texture(TEXTURE, UV);
}
Tags
2d, Crosshatching
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

2D Specular Maps

Extensible Color Palette (Gradient Maps) Now with Palette Blending!

Palette Swap using two textures

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments