All examples · Shaders · As Markdown, for AIs

Sand tracks

What this example shows

A ball rolling over sand presses a track into it, pushing the sand aside into low banks, and the wind slowly evens it all out again. WASD or the arrows roll it, R smooths the sand. Left alone, the ball rolls by itself.

The game never touches the sand's geometry. It paints the sand's shape into a grey picture made with createPixels: middle grey is untouched, darker is pressed down, lighter is pushed up. Each frame it sends only the square the ball touched, with updatePixelTexture(texture, region); the wind evens out the whole picture and sends it all. The sand's material reads that picture in its vertex hook, as its tracks map, and moves the plane by it, so shaping the sand costs a few pixels a frame instead of new geometry. The track is read at a place worked out from each corner's position, so its sides are measured, and lit, as sides, and they cast shadows because the shadow moves its corners the same way. Packed sand is darker, by how pressed it was, through carry.

Starting
Starting
—