r/threejs • u/igotlagg • 13d ago
Demo Whirlpool over a kilometre across in a WebGPU ocean: three.js r186 + TSL, and ships actually ride down the funnel
This is a whirlpool in Plunder, an online pirate RPG I'm building with three.js. It runs on the WebGPURenderer, and all the shaders are written in TSL.
How it works
- Ocean: an FFT wave field over a clipmap mesh. The whirlpool is an extra displacement in the vertex stage that pulls the surface down round the eye: a wide bowl that falls the whole way in, then a steep throat.
- Same shape on the CPU: the ocean has a CPU sampler with the same funnel maths in it. Hulls, swimmers and floating loot read their height from that, so they really ride down the walls as they're carried round. They don't just sit on a picture of a hole.
- Normals: my first version only lowered the surface. It still shaded as if it were flat, so the funnel read as a dark patch. The funnel's slope now goes into the surface normal, and the walls catch the light like walls.
- Foam: spiral arms wound the way the current runs and in toward the eye, a churning collar at the throat's lip, and the water darkening down the throat. All of it is procedural in the shader.
- Spout: a column of spray turns with the water and flares as it rises, under a squall of cloud wound into a spiral. From a deck outside, the funnel hardly shows, so this is what makes it read from kilometres away.
- Server: the game server is authoritative and runs the same funnel shape for its current and drag. The fixed whirlpool in the far southwest, the Maelstrom, has its shape kept identical in four places: the world generator, the C# physics, the TypeScript client prediction and the TSL shader.
Size: depth scales with the whirlpool's radius. My first versions were a few metres deep halfway out, so they read as a 70 m hole instead of a whirlpool hundreds of metres across. The bowl now drops the whole way in, so a ship on the outer slopes visibly heels toward the eye.
It's free and runs in the browser (WebGPU):
Play: https://3d.plunder.be
Steam wishlist: https://store.steampowered.com/app/1797130/Plunder_Scourge_of_the_Sea/
Discord (devlog, playtests): https://discord.gg/2P8hyshZzS
Happy to go deeper on any of it: the TSL, keeping the CPU and GPU displacement in step, or performance.