DEPT47 GAMES

Devlog / No. 38

Getting a 3D Godot game into the browser: what I changed

No. 38Nov 15

TECH

Two shots of the ruins at 11 m from the same angle. Left: the download version. Right: the browser version
The ruins at 11 m. Left: the download version. Right: the browser version.

Nov 15

Getting a 3D Godot game into the browser: what I changed

Technically Fishing is a first-person spearfishing game made in Godot 4. The beta also runs in the browser, on this site and on itch.io. This entry is for other developers: here’s what I changed to get a 3D Godot game running there.

First, I exported without threads. A threaded web build needs SharedArrayBuffer, and that needs special headers from the server. Without threads, the same files run wherever you put them. On itch.io, it runs without turning on the SharedArrayBuffer option.

Second, rendering. The browser uses the Compatibility renderer (WebGL 2). It has no volumetric fog and no decals, and my screen effect for light shafts didn’t carry over either. So the browser build has its own replacements: the water’s color and density come from depth alone, 24 thin panels lined up with the sun stand in for the light shafts, and the cracks in the rock are drawn on flat planes. The download version is unchanged.

Third, size. Before exporting, a script makes web-only copies of the textures and music. Textures are capped at 2048 px (1024 px for models), uncompressed textures become WebP (except UI and text), and the music becomes 96 kbps MP3. This happens in a separate working copy, so the download version keeps its own assets. I also left out what the beta doesn’t use, like the Steam integration. The result is a 172 MB data file and an engine file of about 40 MB. itch.io allows up to 200 MB per file, so it fits.

Fourth, the first wait. Loading takes a while, so the opening movie plays in an HTML video on top of the page while the engine loads behind it. The page switches over only when both the movie has ended and the game’s title screen is ready. Only the one movie that matches the browser’s language is downloaded.

Fifth, the second visit. In my tests, itch.io’s file server sent the full 172 MB again on every visit. The files come with a long cache time and a new URL for each upload, but when the browser asked “has this changed?”, it got the whole file back instead of a short “not modified”. So the page now registers a small service worker. While a file is within its cache time, the service worker uses the stored copy without asking, and it deletes files from older uploads. Now, from the second visit on, the data and engine files both load from the browser’s storage, with 0 bytes downloaded.

You can try the result from Play on this site.

▶ Play the beta in your browser

Back to top