All examples · Experiments · As Markdown, for AIs

Grass

What this example shows

A meadow of about 37,000 blades that sway in travelling gusts. WASD or the arrows roll the ball through it, and space jumps. The grass parts round the ball, stays trodden where it went and slowly stands back up, and a landing flattens a ring round it. Glowing orbs wander over the meadow: roll into the low ones, jump for the high ones. Left alone, the ball drives itself. V, or the button at the top right, shows what bends each blade: red is the ball and its trail, blue the wind.

Every blade is the same shape of 7 vertices, made once with createGeometry and drawn as instances: the meadow is 100 chunks, each a createMeshInstances that places, sizes and colours its blades, so the engine can leave out the chunks out of view. Each blade's seed rides in its instance's own numbers, and the hook reads it and where the blade is planted (ctx.instance, ctx.origin). Everything moves in the vertex hook of one mesh3d material, written for both cards: nothing changes on the CPU. The trail is a picture over the whole meadow, the material's trail map, that says at each place which way the grass lies and how far: the game paints it where the ball goes and fades it as the grass stands up, and the vertex hook reads it at the root of each blade, so the trail is as long as the ball makes it. The hook also says every blade faces up (surfaceNormal), so the grass is lit by the engine itself, sun, orbs and the ball's shadow included, as a thin blade with no dark side; each blade is its triangles twice, one set for each side, so both are lit that way. The orbs are additive 3D particles with a point light each.

Starting
Starting
—