← Back
engineering /

Building Arstid, a Ragnarok-like browser RPG

I got tired of waiting for Ragnarok Online 3, so I started making my own. Here's what's in it and how it's built.

A tilted, miniature-looking view of a pixel-art village in daytime, with thatched and tiled cottages around a cobbled square, a well, market stalls and small villagers walking dirt paths.

Arstid is a browser RPG I’ve been building on weekends since September. You wake up next to a lighthouse, walk down into a country of mills and gardens, and ten job levels later you pick between Swordsman and Mage. You can play it solo in the browser or on a small realm I host for up to 20 friends.

Why I’m building it

I grew up on Ragnarok Online. When the Ragnarok Online 3 gameplay trailer came out I watched it more times than I’d like to admit, and then I realised I’d probably be waiting years to actually play it. So I stopped waiting and started sketching my own version from that trailer.

It turned into something bigger than a sketch pretty quickly, because I wanted it to be my ideal Ragnarok-like game. That means a few things I care about more than anything else in this project.

  • No pay to win. Nothing that makes your character stronger can be bought. Gear comes from playing, trading and crafting.
  • Balanced. No class or build should be the only right answer, and every job should have a fight where it shines.
  • Skill matters. Two characters with the same level and gear should not play the same. Timing a parry, dodging the markings on the ground and typing a chant cleanly all make a real difference.
  • Everything else people love about MMORPGs. Partying up with friends, a world that’s nice to just walk around in, a shared story, a player market, and the feeling that the server is one place you all live in together.

Most of the engineering below exists to serve those goals. A server that decides everything is what keeps the game fair. The balance simulator is how I check that no build runs away with it. And typed chants are my favourite way to make a spell depend on the player as much as on their stats.

I already wrote about training its characters with reinforcement learning. This post is about everything around that. How the game is put together, the parts that took the longest to get right, and a few tricks I’m still a bit proud of.

The stack is small on purpose. Vanilla ES modules, three.js for rendering, Vite for the dev server and build, and a Node server with ws for multiplayer. No framework, no TypeScript, three runtime dependencies in total. After 90 commits the game is about 57,000 lines.

I should be upfront that I didn’t type most of those lines myself. Arstid is a vibe coding project. I build it together with Claude Code, describing what I want, playing the result and pushing back when something feels off. My job is mostly the design, the taste and the testing by hand. A short instructions file in the repo keeps the sessions on track. It explains the project layout, says which parts must stay free of rendering code, asks for small diffs and unit tests for pure logic, and tells it to leave the visuals and the feel to me, since I can judge those faster in the game than any script can.

The best overview is the trailer. Every frame of it is the real game, driven by a director script on a frozen clock.

A frame from the Arstid trailer, a pixel-art forest of orange and green autumn trees in warm evening light, letterboxed.
The trailer · 70 seconds, rendered frame by frame from the game itself. The attic, the field, gathering, the party, Old Mortar and a Cumulonimbus at the end. Also on YouTube.

A tour of the game

Coming in

The game opens in an attic at night. Someone is writing at a desk under a round window, there’s a staff leaning against the wall and the logo waits on the right. Press a key and you get a sign-in card, or you can play solo. Then the attic turns into oil paint, the paint lifts off stroke by stroke down to bare canvas, and the field gets sketched and painted back in around you.

A pixel-art attic at night seen from above, with a figure at a candle-lit desk under a round window and the Arstid sword logo on the right with the words press any key to continue.
The attic · the sign-in screen. It's a real 3D room baked into pixels like everything else.
Going in · the attic is painted away and the warm stones under the Lantern are painted in. The first line of the story waits at the bottom.

The paint is a Kuwahara filter turned along the picture’s edges, with bristle streaks and canvas texture on top. Both paintings are of the moving picture, so the world is already alive while it’s being painted in.

The world

The setting is a country of ten Reaches, climbed one after another, each sealed until the realm frees its Warden. Right now three of them exist.

Lanternfall is the first, and it’s the biggest. It runs from the rim, where the river Wend falls off the edge of the world, up to the Hearthspine wall and the sealed Second Stair. Danger rises as you walk toward the wall.

Place Levels What’s there
Dawnwatch Hill 1 The Threshold Lantern, where every new player arrives
Nettlecombe 1 to 3 The bakery, the mill, Hollis’s forge, the Noticeboard and the Clearing Council
Clover Downs 3 to 6 Open grass down to the river
The Mendbridge 3 to 6 The unfinished bridge and its works depot
Hearthstead 6 to 9 Orchards, hives and a farming valley
Amberwood 8 to 12 An amber forest, with quillwasps stripping the timber
The Far Bank 8 to 12 Old survey stakes and the gatehouse across the bridge
Second Stair Approach 10 to 14 A door taller than the mill, still sealed

Vellmoor is Reach 2, a town of grey stone and archives up the Second Stair, with ink moths, a door that walked off its hinges and coats with nobody in them that only come out after dark. Sayward is Reach 3, a market town up the Third Stair. Both only open once the realm has released the Warden below them.

A grey cobbled avenue in a stone town with tall yellow-walled houses, green statues on plinths and a small wizard walking alone.
Vellmoor · Reach 2, the avenue below the Registry.
A stone market square with a glowing golden tiled floor in front of a tall house, lamp posts and a villager walking past.
Sayward · Reach 3, the market square.

The world is never still. One wind bends the grass, crops and trees in the vertex shader, and cloud shadows, pollen, leaves, chimney smoke, birds, hens and fireflies keep it moving. 22 named townsfolk walk daily routines, and you can walk into a few buildings, like Marta’s bakery, the mill, Mae’s house and the gatehouse on the far bank. The day lasts an hour of real time and is the same for everyone on the realm.

Classes and combat

Everyone starts as a Novice with a knife. At job level 10 you go to one of two guild masters. Aldric, at his drill yard west of Nettlecombe, makes Swordsmen, and Seliane, at her wagon in Amberwood, makes Mages. At job level 40 Swordsmen can become Knights and Mages can become Wizards, and there’s one High Wizard spell beyond that.

That’s 54 skills across five pages of a branching skill tree. Skills are data. Each one is a row in a table, and the simulation turns its kind into one of about a dozen behaviours like bolt, splash, field, nova, melee, wall, trap, ward or buff. A few lean on the world. Water Ball only works near the river, Fire Pillar waits underground until something walks over it, Charge Attack hits harder the further you ran, and Sweeping Lance needs a spear and a Crossbuck mount under you.

A parchment skill tree panel with Mage and Wizard skills connected by red lines, a detail card for Fire Bolt on the right and a skill bar along the bottom.
The skill tree · branches, what the next level changes and the skill bar, all in one panel.
A parchment inventory panel with item icons on the left, the character's equipment slots around a portrait in the middle and an item detail card on the right.
The satchel · eight equipment slots, weight, gear condition and the stats each piece changes.
A character record panel with the six stats STR AGI VIT INT DEX and LUK, derived attack and defence numbers, and equipped gear on the right.
The record · the six classic stats and every number derived from them.
A parchment map of Lanternfall with the river running down the middle, labelled places like Nettlecombe, Clover Downs and Mortar's Works, and tabs for Vellmoor and Sayward.
The map · one tab per Reach.

The rules follow the classic pre-renewal Ragnarok formulas, because that’s the version I loved. Ten attack elements against ten defence elements at four levels, the six stats with their rising cost, MATK from INT, variable cast time shortened by DEX, and attack speed from the weapon and AGI.

ASPD=200−weapon delay×(1−AGI250−DEX1000)\text{ASPD} = 200 - \text{weapon delay} \times \left(1 - \frac{\text{AGI}}{250} - \frac{\text{DEX}}{1000}\right)

The gap between two swings is then (200−ASPD)/50(200 - \text{ASPD}) / 50 seconds. A swing first rolls to land at 80+HIT−FLEE80 + \text{HIT} - \text{FLEE} percent, kept between 5 and 95, and then loses a share to hard defence and a flat amount to soft defence before the element table multiplies it. A critical skips the armour. One damage function serves both magic and physical attacks.

The part I added on top is what makes combat about the player. Every field monster has one elemental move with a visible tell and leaves an ailment if it lands, like Soaked, Scorched or Rooted. A monster’s swing gathers under a closing ring, so you can walk out of it if you’re paying attention. And a Swordsman whose slash lands just before a monster’s plain blow gets a perfect parry. No damage, no recovery, the skill’s cooldown is refunded, and against a boss it builds toward a break.

Old Mortar · a Swordsman against the first Warden. You can see the red warning rings before each slam, the stagger and the boss enraging.

There are five bosses so far. The Great Puddling is a water boss in the field. Old Mortar is the first Warden. You don’t kill a Warden, you release it, and once the realm has done that it never comes back. After that there’s a repeatable party trial against its Echo. The Clockwork Regent and The Unwritten guard Reaches 2 and 3. A Warden’s health scales with how many players are in its hall, keeping whatever share of damage has already been dealt.

A few more rules shape every fight.

  • Casting. A cast has a variable part that DEX shortens (instant at 150 DEX) and a fixed part that it doesn’t. After it there’s a short after-cast delay, separate from the skill’s own cooldown. Moving or taking a blow interrupts a cast. SP is paid when the cast starts, but if you call it off yourself you get it back.
  • Everyone swings. Daggers, swords, spears, staves and bare fists all have attack, reach and a swing rate. Running out of SP makes you worse, never helpless.
  • Recovery. HP ticks every 6 seconds and SP every 8. Getting hit stops both clocks for 10 seconds. Sitting down doubles what each tick restores and halves the wait. Food heals between fights, potions during them.
  • Weight. Your bag can carry a base amount plus 300 per point of STR. Past half full you stop recovering naturally, and past nine tenths you can’t swing or cast. A Knight on a Crossbuck carries another 1,000.
  • Elements. Wind ruins Water, Water drowns Fire, Fire burns Earth and Earth grounds Wind. Freezing a monster turns it into Water for a while, and petrifying it turns it into Earth, so one spell can set up the next.
  • Death. Online, a friend can bring you back with a Yggdrasil Leaf, standing beside you through a short rite. Walk away or get knocked down and the rite breaks.

Spells you type

This is the system I enjoyed building most, and the one people ask about first. Every spell with a cast time has a chant, a line of words the caster has to speak before the spell leaves their hands. There are two ways to speak it, typed or recited, and you switch between them in Settings. Typing is the default on a keyboard. Reciting is the default on touch screens.

Blizzard, typed · "North wind, bury them in white." I typed "burry" on purpose. It's marked as a slip, the chant drops to 90% and the spell still lands at 95%.

When you type, a panel opens over the skill bar with the chant in it, and you type it word by word, pressing Space after each one. A one-word bolt is just Ignis!. Bigger spells are a sentence or two. Each typed word is graded as clean, a slip or broken.

  • Case, accents and punctuation are ignored, so SOL ARDERE. and sol ardere are the same.
  • The distance is Levenshtein, except two swapped neighbouring letters count as one slip instead of two edits, like in Damerau’s version. Typing “teh” is one mistake, not two.
  • How many slips a word allows depends on its length. Words up to two letters allow one, longer words allow one per four letters. Past that it’s a different word.
  • A clean word is worth 1, a slip 0.7 and a broken word 0. A fully clean chant is called resonant and lands at full strength. Slips weaken the spell, give it a chance to miss and make ground spells drift.
  • Too many broken words, three in a row or nine seconds of silence and the chant collapses, taking the SP with it.

Typed letters go to the chant and never to the game, so typing a “w” or a “d” never walks your character off. Esc abandons a chant and gives the SP back.

Reciting is the other way. Your character speaks the chant on their own, one word after another, with the words laid over a normal cast bar. A recited chant never slips, never misses and never collapses. In exchange it takes 50% longer to cast and the spell lands 30% weaker. I think of it as rote magic, spoken correctly but without conviction.

That trade is on purpose. Reciting means nobody is locked out of playing a Mage, whether they’re on a phone, don’t type fast or just don’t want to type in a fight. Typing is never required. It’s what earns a spell its full strength, so a player who types cleanly under pressure gets more out of the same character, which is exactly the “skill matters” goal from the start of this post. Typing well is only ever rewarded once, though. A clean typed chant lands at 100%, not more.

Meteor Fall · "Stars of the upper dark, fall upon this ground." Typed clean, so it resonates.

The High Wizard’s Cumulonimbus goes further. Its chant calls the storm, and then a second chant, the litany, holds it. The storm lives only as long as your voice does. Stop for too long and it slips its leash. Get through every line before the storm spends itself and the last words, FULGUR REGIS, CADE!, call down one violet stroke. Recited, the litany speaks itself at a steady pace that DEX speeds up, down to a quarter of a second per word.

Cumulonimbus · recited this time. The field goes dark, the rain comes in and lightning walks the circle while the litany holds it.

There are also the Solar Rites, forbidden meteor spells built line by line where each line is a part of the spell. “Bind heat to stone” is literally the line that makes the meteor burn. You can press Enter to release a rite early as whatever smaller spell its lines have built so far. The longest one, the Crown of the Falling Sun, is 190 words with a point of no return, ASTRA CADENT. Once that’s spoken, nothing can stop it, not even Esc. They’re sealed in the current build, saved for later progression.

Like the rest of the simulation, the chant rules are pure data and functions, so the server grades the same way the browser does, and the tests can check every chant without a keyboard.

Story and people

The main road is a chain of quests that starts with Pip, a girl with a ledger too large for her arms, and runs through work orders, the job change, the keystone and the Mendbridge down into Mortar’s Works. There are 35 story quests in all, spread over four acts, with 20 cutscenes. Beside the main road run twelve side stories, like a coat nobody claimed, a recipe with too much salt or a woman who wanted no monument. They open one at a time, a while after the last, so the journal never fills up at once.

A conversation with Seliane of the Survey Guild in an autumn forest. Her line reads, Magic is mostly bookkeeping. A source, a shape, a release.
Seliane · the Mage guild master. "Magic is mostly bookkeeping."
A conversation with Aldric of the Swordsman Guild beside a windmill. His line reads, Boots first. Then the blade.
Aldric · the Swordsman guild master, with the Knight quest skills in his replies.

Conversations type out letter by letter with a small sound per letter, and you pick numbered replies with the keyboard or the mouse. The guild trials use the real quest logic. Aldric’s oath of chivalry for Knights is a written exam, and a wrong answer starts the paper again.

Living in the Reach

Fighting is only part of it. A lot of the game is the slower stuff around it.

A wizard fishing from the bank of a wide blue river next to an unfinished stone bridge pier, with a prompt saying Waiting for a bite.
Fishing · at the Mendbridge. Strike when the float goes under.
A wizard felling a marked oak in a forest of green and amber trees, with a progress bar reading Felling marked oak.
Felling · a marked oak in Amberwood.
  • Gathering. Fell timber, quarry stone and ore, fish and pick herbs. Tools wear down and get mended. Spots get worked out and move, so a spent one starts growing somewhere else.
  • Crafting. 24 recipes. The works bench turns logs and ore into planks, nails and dressed stone, Marta’s oven turns fish and herbs into stew and salve, and Hollis’s forge makes blades and staves. Crafted gear carries its maker’s name.
  • Gear condition. Weapons and armour wear with use and with death, going from Sound to Worn, Battered and Broken. Refining is safe up to +3, and past that a failure knocks the piece back one level instead of destroying it. I never liked losing gear to a bad roll.
  • The Noticeboard. 31 kinds of hand-written contracts get pinned up through the day, like errands, deliveries, hunts, surveys and party jobs. The board is shared by the whole realm.
  • The Mendbridge. The realm builds the bridge together by bringing the crews what the plans need. It’s one shared project for every player, and it’s what opens the far bank.
  • Boxes left for tomorrow. Eleven one-time boxes are hidden around the Reach, each with a line about who left it. Nothing marks them on the map.

Playing together

Online, you can invite people to a party or ask to join theirs, and the leader picks how experience is shared (evenly or by your own cut) and how loot goes (in turns or finder keeps). Chat has party, map and whisper channels. You can trade with anyone standing next to you, and it only goes through once both sides agree to the same offer. The Noticeboard in Nettlecombe doubles as a player market where you list gear and goods at a fixed price and collect what sold later. NPC shops only sell basics on purpose, so good gear comes from other players.

Sound

Apart from one piano track, every sound is synthesized live in the browser. Monsters have voices that follow their shape and size, each of the ten elements has its own sound, and a cast is a rising charge in its element’s colour. Walk toward the river and the water gets louder on its side of the screen. Walk into Nettlecombe and you hear the mill, the bakery and the hearths.

Tech stack

Layer What I use
Game client Plain JavaScript modules, no framework
Rendering three.js, custom shaders and a post-processing pass
Sound The Web Audio API, all synthesized except one music track
Build and dev server Vite
Game server Node.js with ws for WebSockets
Saves and accounts SQLite through Node’s built-in SQLite module, passwords hashed with scrypt
Hosting My own Windows PC behind a Cloudflare Tunnel
About page Static HTML, CSS and JS on Cloudflare
Tests Node’s built-in test runner and Playwright
Balance and AI A headless battle simulator, and PyTorch for reinforcement learning
Trailers Headless Chromium and ffmpeg

The game itself is about 57,000 lines, with another 15,000 lines of tests beside it. It splits into a few parts.

  • The simulation. Movement, combat, monsters, quests, progression and saves. It runs in the browser and on the server.
  • Rules and data. The element table and the damage formulas, plus plain tables of skills, items, monsters, people, quests and every spell’s words.
  • Game systems. Gathering, crafting, the Noticeboard, the shared works, the boss trial, trading and the market.
  • The world. Each region’s layout, height, paths and collision, with its look kept separately.
  • Networking. The wire format both sides share, the realm server and the online client.
  • Rendering and sound. Building models, baking them into sprites, the post effects, the spell effects, the mixer and every sound.
  • The interface. The HUD, the panels, dialogue, menus and input.

The rest of this post is about how the main pieces of that work.

One simulation, four places

The most important piece of the project is the simulation. It holds the whole simulation, meaning movement, combat, skills, quests, monsters and loot. It has one hard rule. It never touches the DOM, three.js or audio.

That rule is what lets the same code run in four places.

  • In the browser when you play solo.
  • On the server, which runs one copy per connected player.
  • In the balance simulator, which throws bot parties at monsters across hundreds of seeds.
  • In the RL environment, which is why a policy trained headless plays the same way in the real client.

Anything that only matters for looks lives elsewhere, in the rendering, sound and interface code. The skills, items, people and story are plain tables, so adding a skill usually starts with adding a row.

The server

Multiplayer is server-authoritative. The client sends what the player wants to do, and only the server decides what actually happens.

The server ticks at a fixed 20 Hz using the accumulator loop from Glenn Fiedler’s “Fix Your Timestep”. A timer fires every 10 ms, adds the real elapsed time to a bucket, and runs as many 50 ms steps as the bucket holds. The bucket is capped at 250 ms, so if Windows decides to stall the process for a second the world skips ahead instead of trying to catch up in one huge burst.

Every action that comes in goes through a validator before it gets anywhere near the game. It’s a whitelist. A cast has to name a skill that exists, its target has to be a valid point and its chant mode has to be one of the two that exist. A move is exactly two numbers. Anything else is dropped. Since the wire format is shared too, the client and the server can never disagree about what a valid message looks like.

Snapshots

The server simulates at 20 Hz but only publishes every second tick, so 10 snapshots a second. Each player gets their own slice of the world. Only players, monsters and spell effects within 64 units of them are included, plus their party members wherever they are. This is usually called interest management.

After the first full snapshot, everything is sent as a delta against the slice that player got last time. The diff is shallow, one level per entity, and something walking out of range arrives as a removal. Floats are rounded to three decimals before encoding, which does more for the packet size than I expected.

A few smaller rules made the server a lot calmer.

  • If a player sends no input for 250 ms, their character stops. A dropped connection never leaves someone running into a wall forever.
  • Any mutation is written to disk before the snapshot that reports it goes out. A trade is never confirmed on screen and then lost in a crash.
  • A disconnected character stays in the world for 30 seconds before it’s saved and removed, so a quick reconnect drops you back in the middle of the fight.
  • If a client’s event queue grows past 2,048 entries, the server closes that connection instead of letting one slow browser eat memory.

Making your own character feel instant

Other players are drawn by interpolating between snapshots, and that looks fine. Your own character was a problem. Writing the 10 Hz positions straight into the player made the wizard jump three rendered frames at a time, while everyone else on screen moved smoothly.

The fix is standard client-side prediction and server reconciliation. The client keeps its own copy of the movement code (the same one the server runs, since it comes from the shared simulation) and moves your character every frame. Every input gets a sequence number. When a snapshot arrives, the client resets to the server’s position, throws away the inputs the server has already acknowledged, and replays the rest, each one for as long as it was actually held.

The part that made the biggest difference was what happens to the leftover gap. Instead of snapping to the corrected spot, the client keeps drawing the character where it already was and lets the error decay exponentially.

e←e⋅exp⁡(−9 Δt)e \leftarrow e \cdot \exp(-9\,\Delta t)

Here ee is the gap between where the character is drawn and where the server says it is, and Δt\Delta t is the time since the last frame in seconds. The arrow means the gap gets replaced by a smaller version of itself every frame. exp⁡(−9 Δt)\exp(-9\,\Delta t) is a number just below 1, so each frame keeps most of the gap and shaves a little off, and the 9 sets how fast it shrinks. Since it depends on Δt\Delta t, the gap shrinks at the same speed whatever the frame rate.

In practice the gap halves about every 77 ms, so a small correction is gone in a handful of frames and you never see it. Below a couple of millimetres the error is dropped. If the gap is bigger than 2 units, something really went wrong (a route the server refused, a lost input) and sliding would look worse than snapping, so it snaps.

Saves and accounts

Characters live in SQLite through Node’s built-in SQLite module, which is why the server needs Node 22.13 or newer. It runs in WAL mode with full sync. Passwords are hashed with scrypt and compared in constant time. Accounts are invite-only. One admin command gives me a single-use invite that expires after seven days.

Rendering, or how to fake a 3D world

Arstid looks like a hand-drawn pixel diorama, but almost nothing in it was drawn by hand. Every house, tree, villager and monster is a small 3D model built in code. The trick is that the camera never rotates. Because of that, each model only ever needs to be seen from one angle.

So the game photographs it once. At load, the game renders each model from the exact camera angle the game uses, for every animation frame and direction, and quantizes the result into a pixel sprite sheet with an outline. It’s the same idea the pre-rendered sprites of the 90s were built on, done in the browser on startup. You get the hand-made look and a tiny draw-call budget at the same time.

The village of Nettlecombe in daylight, seen from above at a tilt, with cottages, gardens, a cobbled square and a well.
Day · Nettlecombe at noon. Every building and villager here is a baked sprite on a flat quad.
The same village at night, dark blue, with orange pools of lamplight on the paths and lit cottage windows.
Night · the same spot an in-game evening later. The lamps and windows light the sprites through baked normal sheets.

A few problems came up once everything was flat.

  • Feet in the ground. The near corner of anything with a footprint gets photographed below its origin, so on a flat quad that bottom strip sinks under the grass and gets cut off by the depth test. Houses lost their doorsteps to a hard green line. Since the projection is orthographic, I can move a vertex along the view axis without the image shifting by a single texel. So only the bottom strip of each sprite leans toward the camera until it sits on the ground, and the rest keeps its honest depth.
  • Lights at night. Flat sprites can’t take a three.js light. Next to each colour sheet the baker also writes a normal sheet, and each sprite shades itself against a short list of point lights like lamps, windows and the player’s own glow. By day the list is empty and the work is skipped.
  • Trees in the way. Anything taller than 3.2 units that stands between the camera and the player dithers away in a small patch around them, so you never lose your character behind a gable.
  • Load time. Baking every sheet at startup got slow once the world grew. Now sheets are baked as you approach them. Anything in sight is baked right away, nearby things one at a time while there’s nothing better to do, and far away places wait until somebody goes there.

Game postfx

The baked sprites are only half of the look. The other half is everything I paint on top of them, some of it inside the scene and some of it in a post pass after the scene is drawn. Turn all of it off and Arstid looks like a tidy but rather flat 3D village. Turn it on and it looks like a toy town under glass.

To show what each piece does, I recorded the middle of Nettlecombe, the first town, with everything switched off and then switched the layers back on one at a time, a few seconds apart. Once they’re all on, the clock runs forward into night. The game has a little debug switchboard for exactly this, so it’s the real renderer the whole way through, on a frozen clock, one frame at a time.

Layer by layer · Nettlecombe's square, from the raw scene to the full look, then on into night. The chip in the corner names the layer that just went on.
Nettlecombe's square drawn raw, evenly sharp from edge to edge, with flat bright colours and no shadows, haze or vignette.
Raw · the baked sprites and the ground, drawn straight to the canvas.
The same square with every layer on, sharp only in a band across the middle and softly blurred above and below, warmer, with glowing highlights, a darkened rim and a cloud shadow on the ground.
Everything on · the same frame with all the layers below.

The video adds things in the order that’s easiest to see, which isn’t the order the GPU runs them in. On the GPU it goes like this.

  1. The scene. Sprites, ground, shadows, fog, cloud shadows and particles all draw into one small render target.
  2. Bloom. three.js’s UnrealBloomPass at half that size.
  3. The grade. One big fragment shader of my own that does the blur, the light shafts, the colour and every effect that reacts to gameplay, then writes the final sRGB pixel.

So the whole post chain is two passes. Early on I tried a separate pass per effect, and every extra full-screen pass cost more than the effect inside it.

Raw scene

This is the scene drawn straight to the canvas at full resolution, with nothing after it. The sprites are already shaded, since the baker photographed them with lights, but the ground has no shadows, nothing moves in the wind and every part of the picture is equally sharp. It’s honest and a bit lifeless. I keep it one switch away because it’s the fastest way to tell whether an ugly pixel comes from the world or from the grade.

Sun shadows

A sprite is a photo of something standing up, so it can’t cast a shadow the normal way. Instead, when a sheet is baked, the game treats the sprite as a cut-out standing in the plane through its feet, facing the lens, and throws every opaque texel along the sun direction onto the ground. That gives a mask in the shape of the shadow. It’s a cheat, since a gable that stands back from that plane throws its shadow from slightly the wrong place, but it’s the right size, it falls the right way and it costs one pass over the texels per sheet, once.

All those masks share one colour and blend, so they’re packed into a shadow atlas and each tile of the world draws all of its shadows in one draw call. A tiny vertex shader stretches each shadow quad along the sun direction, which is how the shadows get longer as the sun goes down without baking anything again.

Wind sway

Grass, flowers and trees bend in a vertex shader. The top of each plant leans along the wind by a mix of two sine waves, with the phase taken from its world position so neighbours lean together and a gust visibly rolls across the field. The part I like is the last line. The offset is snapped to the pixel grid before it’s applied.

Δx=round⁡(30 x)30\Delta x = \frac{\operatorname{round}(30\,x)}{30}

Here xx is how far the top of the plant wants to move in world units, and 30 is the number of pixels per world unit. Without the snap, a blade of grass slides by fractions of a pixel and turns to mush once it’s scaled up. With it, the blade steps from texel to texel the way hand-drawn animation does.

Pixel buffer

This is the step that turns the post chain on. The scene now renders into a small buffer whose height is the zoom times 30 pixels per world unit, so one sprite texel always covers exactly one buffer pixel, however far the camera is pulled back. At this zoom that’s 570 pixels tall. The buffer is then scaled up with nearest-neighbour filtering to fill the canvas, and every intermediate target in the chain uses nearest sampling too, or the upscale would smear the pixel grid back into soup.

Everything after this runs in that small buffer, which makes it cheap. It’s also why the blur and the bloom look chunky and painterly instead of smooth like in a modern 3D game.

Quality settings work by changing the buffer, not by skipping effects. Performance mode draws at 24 pixels per unit instead of 30, which makes the pixels chunkier but keeps the picture sharp.

Tilt-shift blur

This is most of the miniature look. A real tilt-shift lens keeps only a thin band of the scene in focus, and our eyes read that as a tiny model seen up close. So the grade keeps a sharp band across the screen, centred a little above the middle where the player stands, and blurs more and more towards the top and bottom.

d=smoothstep⁡(∣y−0.52∣−0.141−0.14)d = \operatorname{smoothstep}\left(\frac{|y - 0.52| - 0.14}{1 - 0.14}\right)

yy is the pixel’s height on screen, from 0 at the bottom to 1 at the top. 0.52 is the centre of the sharp band and 0.14 is half its height. dd is 0 inside the band and rises to 1 at the edges of the screen. The blur radius is dd times 2.6% of the screen height, so the lens looks the same at every zoom.

The blur itself takes 20 samples in a golden-angle spiral, which covers a disc evenly without the cross or grid patterns you get from simpler kernels. Each sample is weighted by its own brightness.

w=1+3.2 L3w = 1 + 3.2 \, L^3

LL is the sample’s brightness from 0 to 1. Dark samples count once and bright ones count up to four times, so a white flower or a lamp in the soft zone spreads into a round blob of light like real bokeh, instead of a grey smudge.

Bloom

Bloom makes anything bright bleed a soft glow into its surroundings. I set it much lower and wider than a game normally would, with the brightness threshold at 0.62 and a wide radius, because the look I was after is a sunlit haze over every pale surface rather than a glow saved for spell effects. It reacts to the world too. A passing cloud takes about a third of it away, and at night it leans in a little so every lamp gets a halo.

Light shafts

From each pixel the shader takes 8 steps towards the sun’s position on screen and adds up whatever it finds that is already brighter than 0.66, each step counting a bit less than the one before. The sum comes back as a faint warm light on the pixel. It’s a very cheap version of god rays, and it ties the sky to the ground through the trees and rooftops.

The camera never turns, so the sun’s position on screen only changes when the zoom does. It’s computed on resize and never per frame. The shafts get longer and redder in the golden hour, weaker under cloud and are gone after dark.

Colour grade

The grade is where the frame gets its storybook print feel.

  • Saturation goes up by 14%, felt mostly in the mid tones.
  • Lift. The blacks are raised 2% towards a warm cream, so shadows read as coloured ink instead of holes. At night the lift goes cool and shallow, or the dark would look like milk.
  • Contrast is applied in log space around mid grey, c′=0.18 (c/0.18)1.05c' = 0.18 \, (c / 0.18)^{1.05}, so mid grey stays put while lights and darks spread apart a little. A gamma of 0.94 then sinks the mid tones slightly.
  • A highlight shoulder, c/(1+max⁡(c−1,0))c / (1 + \max(c - 1, 0)), rolls bright values off smoothly instead of clipping them to flat white. Bloom and glowing spell cores need it, or they turn into white stickers.

The time of day lives here too. Golden hour pushes the light towards amber and the shadows towards rose. At night the field loses its colour to moonlight blue, but anything bright enough to be a light keeps its own colour, which is what makes the lamps pop at the end of the video.

Vignette and grain

The edges of the frame get darker with distance from the centre, which pulls the eye to the middle and helps the toy box feel. Then one pixel of animated noise goes on everywhere. It’s only 1.5% strong and you’d never notice it on its own, but it stops the flat palette areas from banding after bloom and the grade have pushed them around.

Fog

The fog is plain three.js scene fog, which fades distant things towards a hazy colour. With the camera fixed at one tilt it mostly touches the top of the screen, where the ground is furthest from the lens. Each region tints it a little differently, so the Downs and Amberwood don’t share the same air.

Cloud shadows

A big sheet with a soft cloud texture drifts across the land, draped over the terrain so hills don’t poke up through their own shade. It’s drawn at 34% opacity and fades out towards its edges, so you never see the rectangle. Each cloud is about 65 units across. Any bigger and one cloud would cover the whole screen and stop reading as a shadow.

The cloud cover where the player stands also feeds the grade. When a cloud passes over you, the whole frame dims by up to 10%, slides towards the cool end of the warm and cool split, and loses some bloom, so a passing cloud really does take the shine off the field.

Pollen, leaves, birds and smoke

The living layer is a handful of particle fields. Each one is about a hundred points drifting in a box around the camera that wraps around, so the same motes follow you anywhere in the world. They’re sized in world units and drawn into the post buffer, so they get the same chunky pixels, blur and bloom as everything else. Pollen catches the light shafts and the chimney smoke leans with the same wind the grass is bending in.

The passage

Every seven minutes on the wall clock, an enormous shadow crosses the Reach. Nobody in the story will tell you what it is yet. It’s drawn the same way as the cloud shadows, only much bigger, and it pushes the grade’s cloud cover up as it goes by, so the light drops and cools for a few seconds while it slides over the town, and the ambience sound reacts to it too. Since it runs off the wall clock, everyone on a realm sees it at the same moment.

Dusk into night

Once every layer is on, the video winds the clock forward from mid morning to night in about nine seconds, so you can see the same stack react to the time of day. Nothing new is switched on for this part except the lights that only exist after dark.

  • Golden hour. The grade warms the light to amber and the shade to rose, the light shafts run longer and redder, and the sun shadows stretch up to 2.1 times their noon length.
  • The veil. The dark itself isn’t done in the grade. A night colour is multiplied into every sprite and the ground inside the scene, underneath the lights, so a lamp can still be bright in the middle of it. The grade then drains the leftover colour towards moonlight blue.
  • Lamps. Each lamp lights the sprites around it through the normal sheets the baker wrote, from a list of at most 8 lights picked per frame, nearest first. Windows glow in the buildings’ own sprites and fireflies and moths come out round the lamps.
  • The lens leans in. Bloom goes up by about a third so every lamp carries a halo, and the vignette gets a quarter stronger so the edges of the frame sink into the dark.

What the video doesn’t show

Most of the grade is reactive and only shows up in a fight.

  • Chromatic aberration. When the camera shakes, the red and blue channels split apart, scaled by the shake squared. At rest it’s invisible.
  • Zoom blur. The heaviest blows drag every pixel towards the point of impact for an instant.
  • Impact frames. On the biggest hits the frame collapses to two inks for a few frames, with comic-style focus lines raking in towards the blow, and flips negative halfway through, like a held panel in a manga.
  • Low HP. The rim of the frame bleeds red and the middle desaturates, pulsing like a heartbeat. You can read your health without looking away from the field.
  • Flash and bleach. A level up floods the frame with colour, and the boss’s Crown burns it out to white gold for a couple of seconds.

All of these are uniforms in the same grade shader, and each one is skipped when it’s at zero. That’s why I could keep adding them without adding passes.

The day lasts 60 real minutes and is read off the wall clock, so everyone on a realm stands under the same sky without a single byte on the wire. The grade, the sky, the ambience and the sound all read the same numbers from one shared day clock, which is the only reason the lamps come on at the moment the light starts to go.

Sound in code

Every sound effect is synthesized at runtime with the Web Audio API. Each effect is a small recipe of oscillators, filtered noise and an envelope, kept in a table just like the skills, so adding a sound is adding a row. Because a recipe is a function, a bolt’s pitch can follow its element and a monster’s voice can follow its species.

The mixer is a fairly classic graph. Voices go into a world, UI, ambience or music bus, then a master, then a limiter, with a reverb send on the side. The fixed camera helped here too. Since the camera never orbits, the mapping from a world position to left and right in stereo is a constant computed once at load.

Testing

I check visuals, feel and audio by hand, because I’m faster at that than any script. Everything else has tests.

  • Unit tests. 716 tests using Node’s built-in test runner. They cover formulas, combat, skills, progression, the story, the wire protocol and the server realm’s rules. Because the simulation, the bake queue and the chant grader are all pure, they’re easy to test without a browser.
  • Browser suites. A set of Playwright runs for dialogue, inventory, spell visuals, typed chants and audio. The audio one measures a real audio graph instead of just checking that nothing threw.
  • Multiplayer and load. One suite runs the realm rules over real sockets, another puts real browsers on a real server, and a load test points many socket clients at one server. The server also logs its own p95 tick time and memory every five seconds.
  • The balance simulator. It runs bot parties against monsters across many seeds in a worker pool and writes an HTML report of every build in every area at three skill levels, with anything suspicious flagged. This is where most balance changes start.
  • The test place. A disposable, fully unlocked world with enemy staging, every skill and piece of gear, quest presets and a pause and step button. There’s a shared multiplayer version too. None of it ships, since it only exists in development builds.

Hosting from my PC

The realm runs on my Windows PC. To reach friends without opening router ports I use a Cloudflare Tunnel, which carries HTTPS and WebSocket traffic straight to the local server.

There are two ways to start it. One command uses a temporary quick tunnel and prints a random link, which is good for a one-off evening. The permanent one is a named tunnel on play.arstid.dev, and a second command wraps a whole evening of hosting into one. It takes a backup, builds, starts the server and the tunnel, and takes a second backup when I press Ctrl+C.

One small detail I like. The script waits until the tunnel client logs its first registered edge connection before it prints the link. Before I added that, the first friend to click usually got a 502.

The about page at arstid.dev is separate. It’s static HTML, CSS and JS with no build step, served as static assets from a Cloudflare Worker.

Come play

Looking back, the best call I made early on was keeping the game logic separate from everything visual. It felt like extra work at the time, but it’s the reason multiplayer, the balance simulator and the RL agents were possible at all. It also helps with the goals I started with. Since the server decides everything, there’s no place for a paid shortcut, and since I can run any fight a few hundred times, I can actually check whether something is balanced.

Arstid is in beta now. On beta weekends the realm at play.arstid.dev opens for invited players, and your character stays from one weekend to the next. It’s still unfinished and things change between weekends, so what you notice really does shape what I work on next.

If you want to try it, send me a message and I’ll get you an invite. You can watch the trailer and read more about the world at arstid.dev. I’d love to see you at the Lantern.

Keep reading

All posts ↗
ESC
↑↓ navigate ↵ open