Godot canvas shaders for organic 2D visuals
godotshadersgdshader2dproceduralsdf
In a 2D Godot game built from simple nodes (ColorRect, Area2D), organic visuals (leaves, bark,
pinecones, background trees) should come from canvas_item shaders on a few nodes, not from more nodes.
Learned on Fall, a painterly autumn descent game, after a failed node-based attempt had to be reverted.
Shader over nodes
- A
ColorRectcannot taper, curve or dissolve. Adding 8 to 14 leaf rects, 2 to 4 sub-branch rects and 2 to 5 twig rects per branch (about 25 nodes x 30 branches = 750+ ShaderMaterial nodes) hurt performance and still looked like rectangles. Reverted. - Spawning tall tree trunks as world-space nodes made dark pillars that cluttered the play corridor. Background trees belong in the parallax background shader.
- Node budget: about 2 to 3 children per platform, 3 to 4 parts per enemy, zero new world-space nodes for
background decoration. Use
GPUParticles2Donly for active effects, not static decoration.
Techniques that worked
- UV zones in one rect: make a branch's rect 45 px taller (collision unchanged) and split UV.y: 0 to
0.45 is a leaf canopy (hash-seeded radial blobs, FBM-torn edges, mood-reactive palette), 0.45 to 1 is
bark. Every existing bark calculation must be remapped with
bark_uv_y = (UV.y - 0.45) / 0.55, or bark bleeds into the canopy. - Tip dissolve: noise-displaced
smoothstepon alpha at UV.x 0 and 1 so platforms do not end in hard rectangle edges. - Per-instance identity without extra uniforms: seed hashes from the instance's base color.
- Teardrop SDF mask for a pinecone:
alpha = smoothstep(r, r * 0.9, length(centered * vec2(1.0, 1.25))), value noise for surface texture, top lightingmix(1.1, 0.85, UV.y). - Background side trees: a function in the parallax shader draws 3 partial trees per screen edge, never deeper than UV.x 0.25 / 0.75 so the central corridor stays clear, alpha 0.18 to 0.45 so they are never mistaken for platforms; reuse the existing sway function.
- Stable decorations: seed by a quantized coordinate (
floor(uv.y * 20.0)) so blobs do not drift. - Wind sway should be gust-driven and aperiodic (mostly still, noise peaks propagating sideways every 4 to 6 s, fast ease-in, slow ease-out), not a sine wave.
- Paper texture: coarse (uv x 150) plus fine (uv x 400) noise at about 0.03 to 0.05 strength, never
animated, and in world/UV space rather than
SCREEN_UVso it does not swim when the camera moves. - Bloom pulse with speed:
sin(TIME * 9.42) * speed_ratio * 0.15(about 1.5 Hz, at most 15%). - Simple animation may need no shader: a crow's wing flap is
scale.y = 0.5 + abs(sin(t * 8.0)) * 0.5.
Shader language gotchas
returninsidefragment()is illegal and fails compilation; wrap the body in anifinstead.outparameters in shader functions are valid;continueinforloops is valid.- Set mood or state uniforms when the material is created, not only from a change signal, or new instances render one frame with the default value.
Process
Draft visual changes as a plan with node budgets and techniques, review it, then implement. Reject proposals that add geometry nodes for organic shapes, add a fourth parallax layer, or change UV layouts without remapping. See Painterly (watercolor) art direction for a 2D game.