Night Garden runs in a WebGL2 canvas with Three.js. The terrain is a mesh, and the plants and sparks are point sprites. JavaScript handles input and camera motion. GLSL controls how the plants are lit and how they dissolve and reappear.
Stack
- WebGL2, Three.js and GLSL
- Seeded terrain, flower sprites, and shader-driven particle currents
- Next.js, React, and Canvas 2D lettering
Seeded terrain and plant sprites
A fixed seed makes plant placement repeatable at each density. The generator samples the terrain height, leaves a winding lane, and adds clusters along the banks and foreground. A BufferGeometry stores each plant’s position, size, family, and variation.
A Canvas 2D texture atlas holds sharp and soft versions of the plants. The vertex shader sizes each point by camera depth. The fragment shader selects its atlas tile and blends toward the soft row for distant plants.
Camera and pointer lighting
The camera advances along the same curve that shapes the lane. It samples the terrain for its height and aims farther down the path. Pointer coordinates are normalized to the canvas and smoothed before the shader applies a screen-space light falloff around them.
Scatter and regrowth
Hover or keyboard focus on the arrow raises a shared scatter value and slows the camera. The flower shader reduces petal opacity as the spark shader moves points from projected flower heads into four overlapping currents.
Once the interaction ends, the sparks linger for about a second. Both shaders use the same regrowth function to stagger the return. It combines projected position, variation across the beds, and the wind phase sampled at release so nearby patches settle at different times.
Rendering budget and fallback
The compact layout generates fewer plants, and the renderer caps pixel density on both layouts. It skips drawing while the canvas is outside the viewport or the tab is hidden. A local WebP stays visible until WebGL draws successfully and remains in place when reduced motion is enabled or WebGL is unavailable.
The regrowth shader
This excerpt from scatterAt sets when each patch returns. The flower and spark shaders use the same result, so the sparks fade as the petals reappear.
float arrival = clamp(
.48 + view.x * .24 + ribbon * .12 + bedVariation * .15,
.16, .83
);
float settled = smoothstep(
arrival - .13, arrival + .16, regrowth.x
);
return mix(scatter, regrowth.z * (1. - settled), regrowth.y);
