Averno: Engineering a 3D Shooter for the Browser

How Averno bakes its light in a web worker, takes keyboard, gamepad and touch input through one model, and scales its cost with one quality setting. With measured download sizes and bake times, and the two fixes that cut the download by about a third.

Averno is a free 3D shooter that runs in the browser. You fly a mining ship in any direction through a dead colony, destroy three reactors, and escape before each one blows. It is a side project, but it has the same constraints as product work: it must load fast, feel smooth on a phone, and accept every kind of input. This note is about those constraints, not about the game design.

The stack

Averno uses Three.js on WebGL 2 for the 3D world, and React for the menus and the HUD. Collision and the light bake use three-mesh-bvh. The post-processing uses the postprocessing library, and all sound goes through the Web Audio API. A Python script builds the robots in Blender. Cloudflare serves the game.

Light that costs nothing at run time

Real-time shadows from many lights are too expensive for a phone. So Averno computes most of the light one time, when a level loads, and stores it in each vertex. A web worker does this work, so the menu stays responsive while it runs.

The load path. The level starts to load as soon as the page opens, behind the title menu.
  • What the bake computes. Direct light with shadows, one bounce, and ambient occlusion for each vertex. It also bakes a light probe at the centre of each level segment, so robots and pickups match the light of the room around them.
  • How it stays fast. The worker builds a BVH of the level and casts its rays against it. The number of samples for each vertex follows the quality setting.
  • How it moves the data. The worker sends the result back as transferable buffers, so the browser does not copy it. A small shader change in the standard PBR material reads the baked light from a vertex attribute. Dynamic lights from shots and explosions still add on top.
  • When it starts. The first level starts to load and bake as soon as the page opens. The title menu shows a progress line, “Tracing the light”, and the player can read the menu or change settings in the meantime.

One input model

Averno takes input from a keyboard and mouse, a gamepad, or touch controls on a phone. The game code does not ask which device the player uses. One input class collects every source into one snapshot for each frame: movement on each axis, look, fire, and a list of one-time actions such as “next weapon” or “map”.

  • The mouse uses pointer lock with raw, unadjusted movement. Some browsers reject that option, so the game asks again without it. If that also fails, the game pauses and does not leave the player with a cursor that steers nothing.
  • The gamepad has a dead zone of 0.15 on each stick, and a button press counts as an action only on the frame when it goes down.
  • On a touch device, the defaults change: medium quality, auto-level on, and a full view without the cockpit frame. The player can change each of them.
  • The frame time that the simulation uses has a limit of 1/20 s. A long pause, such as a background tab, cannot move the ship through a wall.

Quality profiles

One setting controls the cost of a frame and the cost of the load. Each profile sets the pixel ratio, the anti-aliasing, the number of dynamic lights, the particles and debris, the texture size, and the bake quality. High uses 1024 px textures and a pixel ratio of up to 2. Medium and low use 512 px textures, with a pixel ratio of up to 1.5 and 1. A touch device starts on medium, so a phone downloads half of the texture data.

Assets made from code

A build script makes every texture from noise: albedo, normals, a map of occlusion, roughness and metalness, and emission for lava and screens. It writes each one as a WebP file at 1024 and 512 px. The robots come from a Python script in Blender, exported as glTF. The sound effects are synthesized in code into audio buffers, and the music plays live through Web Audio, from scales and chord progressions in the code. There are no recorded sound files.

What I measured

I measured the live game at averno.aliabbas.net in headless Chromium on an Apple M1 Max laptop, with an empty cache and 3 runs for each profile. Sizes are the bytes that went over the network. The desktop profile uses high quality; the phone profile is an emulated touch device, which starts on medium quality.

  • Total download before you can play: 2,762 KB on the desktop, and 2,318 KB on the phone.
  • JavaScript: 393 KB. CSS: 8 KB. Fonts: 68–78 KB.
  • Textures: 876 KB at high quality, and 442 KB at medium.
  • Models: 1,405 KB, the largest part on both profiles.
  • Light bake of the first level, in the worker: 2.3 s at high quality and 1.6 s at medium, on the M1 Max.

I did not measure the frame rate. Headless Chromium draws WebGL in software, so its frame times say nothing about a real GPU. I also did not measure the bake on a real phone. Its CPU is slower than the laptop’s, so the bake takes longer there.

What the numbers changed

The measurements showed two problems, and both were about bytes, not about the renderer.

The models were not compressed

The nine models (the robots, the reactor, a pod and the cockpit) were plain glTF, and Cloudflare does not compress glTF files, so they went over the network at full size. A build step now packs them with meshopt compression. It keeps every position exact and quantizes only the normals and texture coordinates. Normals move by 0.3° on average and 1.1° at most.

The first version broke the cockpit. The packer stores identical vertex data one time, so the loader gave one geometry to several meshes. The cockpit bends each part’s geometry in place, so the shared parts moved twice and two gauge housings disappeared from view. A screenshot comparison found it. Now, when a model loads, the game gives each mesh its own geometry again and turns the packed attributes back into plain floats. Screenshots of the same scene before and after the fix differ in fewer than 0.03% of pixels, and those pixels are random particles.

The browser checked every file on every visit

Models and textures had fixed names, so the server told the browser to check each one again on every visit. They now go through the Vite build, which puts a content hash in each file name. A file at a given URL never changes, so the server tells the browser to keep it for a year.

The result, measured the same way:

  • Models: 1,405 KB → 507 KB (−64%).
  • First visit: 2,762 KB → 1,877 KB on the desktop (−32%), and 2,318 KB → 1,429 KB on the phone (−38%).
  • Repeat visit: 40 requests to the server → 2. Before, the browser checked every file and got “not modified” back. Now it asks only for the page and the icon.
  • The cost: 16 KB more JavaScript, for the meshopt decoder.

For the repeat visit, I ran the old version in the local Workers runtime, which sends the same cache headers as Cloudflare. All other numbers come from the live game.

Try it

Play Averno (opens in a new tab) on a computer or a phone. Your progress saves on your device.

Comments

Sign in to write a comment.

Loading

Ali Abbas