2D Cell/Toon Style Shader

There are plenty of toon-style shaders for 3D Godot projects, but I really struggled to find anything that would give a similar effect that would work in 2D and was compatible with Godot 4 shader language. This is literally the first shader I’ve ever written, and I’m sure it’s full of errors (and I still don’t really understand shaders) but I figured it wouldn’t hurt to share here, in case there are other newbie devs looking for help solving the same problem.

Thanks to @StayAtHomeDev and the Godot docs for inspiration.

Shader code
shader_type canvas_item;

uniform sampler2D gradient_fallof;

void light() {
	float calculated_light_value = max(0.0, dot(NORMAL, LIGHT_DIRECTION));
	float sample = clamp(calculated_light_value * LIGHT_ENERGY, 0.05, 0.95);
	vec4 shaded_texture = texture(gradient_fallof, vec2(sample, 0));
	LIGHT = vec4(LIGHT_COLOR.rgb * COLOR.rgb * shaded_texture.rgb, LIGHT_COLOR.a);
}
Tags
2d, cel, cell, light, lighting, shadow, toon
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

Toon Style 3D Water Shader – No textures needed

Tilemap cell UV

Line pattern cell shading

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments