a bit of a redundant answer but the incomplete Book of Shaders is one I love, not that I know much about shaders, but its a good starting resource, though it sounds like it maaay be too basic for u.
post
thought I was on !spotthesniper@lemmy.blahaj.zone for a moment
The Book of Shaders is a good base. What helped me most for 2D in Godot was pairing it with two short pages in the official docs: "Your first 2D shader" and the CanvasItem shader reference (it lists what COLOR, UV, TEXTURE and SCREEN_UV mean in Godot, which most general shader books don't cover).
Your two examples are nice first exercises:
Grayscale, as a material on any Sprite2D or TextureRect:
shader_type canvas_item;
uniform float amount : hint_range(0.0, 1.0) = 1.0;
void fragment() {
float g = dot(COLOR.rgb, vec3(0.299, 0.587, 0.114));
COLOR.rgb = mix(COLOR.rgb, vec3(g), amount);
}
Blur of everything behind a ColorRect (handy for pause menus):
shader_type canvas_item;
uniform sampler2D screen_tex : hint_screen_texture, filter_linear_mipmap;
uniform float blur : hint_range(0.0, 5.0) = 2.0;
void fragment() {
COLOR = textureLod(screen_tex, SCREEN_UV, blur);
}
The second one reads mipmaps of the screen, so it is cheap but a bit blocky at high values. A proper Gaussian blur samples neighbours in two passes, which is a good next step once these make sense.
Reading small, complete shaders also helped me more than long chapters. godotshaders.com has a lot of 2D ones. Disclosure: I make a small 2D shader pack for Godot 4, and the free Lite version has two effects with commented source if you want more examples to pick apart: https://trungcaolenam.itch.io/shader-pack-lite-for-godot-4
I've been meaning to go over https://filip.rachunek.com/shaders-in-godot-4/ShadersExcerpt.pdf
all 8 comments