Good book for 2D shaders?
Can someone recommend an ebook with some fun shaders? I’m still learning the concepts. Maybe Gaussian blur or grayscale filters. Not interested in 3D yet.
Good book for 2D shaders?
Can someone recommend an ebook with some fun shaders? I’m still learning the concepts. Maybe Gaussian blur or grayscale filters. Not interested in 3D yet.
I was disappointed at first because that sounds awesome, but your link didn’t work. Then I spotted the spelling mistake.
Oops, fixed that
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.
Oh yeah! I started reading this the other day.
I’ve been meaning to go over filip.rachunek.com/…/ShadersExcerpt.pdf
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: …itch.io/shader-pack-lite-for-godot-4
3D doesn’t make shaders much more difficult. Doing things outside of per-pixel-math, does.
Practically this means a blur is extremly hard to pull off, while grayscale is super easy, and a 3D noise, for example, is only marginally more difficult.
I can recommend Shadertoy as a good motivator, once you finished the book of shaders and want to start strech your legs a bit.
thought I was on !spotthesniper@lemmy.blahaj.zone for a moment