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);
}