Modern web game development has an unspoken barrier to entry: hardware privilege. If you want to render an interactive 3D world in the browser today, the industry consensus is simple: boot up WebGL or WebGPU, pull in a multi-megabyte engine like Three.js or Babylon, spin up shader pipelines, and rely on client-side Just-In-Time (JIT) JavaScript compilers to chew through hundreds of thousands of vector operations per second.
That stack works wonders on an M3 MacBook or an iPhone 16. But what happens on the other 90% of the world's connected screens? What about low-cost classroom Chromebooks, older smart TVs, lightweight handhelds, in-flight entertainment systems, or resource-constrained embedded consoles?
On these devices, WebGL is frequently blacklisted by the OS vendor or completely absent. Canvas 2D runs in software mode, turning every ctx.drawImage() into an agonizing CPU bottleneck. CSS 3D transforms (matrix3d, perspective) trigger catastrophic software compositing passes. And worst of all, many lightweight browsers run WebKit or V8 in interpreter-only mode with JIT disabled for security or memory reasons.
Faced with these unforgiving constraints, we asked an audacious question: Could we build an interactive, Minecraft-style pseudo-3D voxel exploration engine (codename Project BrowserSpace) that runs at a silky 30–60 FPS using nothing more than hardware-accelerated 2D image decoders and a static pool of plain DOM <div> elements?
Here is the architectural journey of how we pulled it off—from diagnosing 65ms JavaScript sorting stalls to slashing DOM mutations by 71% and learning the delicate math of retro 2.5D projection.
1. The 90s Playbook: Emulating the Sega Saturn VDP1
When you cannot rasterize 3D polygons in real time, you turn to the golden age of arcade and console hardware. In the mid-1990s, before dedicated 3D geometry pipelines took over, machines like the Sega Saturn (via its VDP1 processor), the Neo Geo, and Nintendo's Mario Kart 64 rendered rich "3D" environments using hardware sprite scaling and multi-angle pre-rendering.
The core insight: while an underpowered device cannot calculate lighting, texture mapping, and perspective division across thousands of 3D vertices, its GPU can decode and blit compressed 2D bitmaps (like WebP) almost for free.
In BrowserSpace, we don't construct 3D mesh buffers. Instead, our build pipeline pre-renders every voxel block (Grass, Dirt, Stone, Wood, Brick, Glass) across 32 discrete yaw angles (11.25° increments) at a fixed elevation angle. We pack these 32 orientations into a single, compact WebP texture atlas (only 404 KB for 11 voxel types and 3 full billboard character mob sets):
// Atlas layout: 32 columns (angles) x 14 rows (blocks + mobs)
// WebP hardware decode: ~1.8 MB decoded VRAM footprint
const cellWidth = 96;
const cellHeight = 104;
const originX = 48; // Centered 3D centroid
const originY = 52;
At runtime, a block in the world is simply a candidate point $(X, Y, Z)$ transformed into camera space. We project its 3D center to 2D screen coordinates $(sx, sy)$, calculate perspective scale $s = \frac{f}{z}$, and assign it to a recycled DOM node from a pre-allocated pool.
2. The 65ms Sorting Trap & The O(N) Bucket Sort Breakthrough
In any 3D engine relying on 2D billboard sprites, objects must be drawn strictly in Painter's Algorithm order: farthest objects first, closest objects on top. Without a hardware Z-buffer, incorrect depth ordering causes catastrophic visual tearing where background mountains poke through the floor under your feet.
In our initial prototype, we used a textbook insertion sort across candidate buffers. On a modern dev laptop running V8 with TurboFan JIT, sorting 300 visible blocks took a negligible 0.6ms. But when we booted the engine on our target low-end testbed, the frame rate cratered to 6–9 FPS.
We built a microsecond-resolution stage profiler into the HUD, and the bottleneck immediately jumped off the screen:
- Stage 1 (3D Math & Culling): 6.84 ms
- Stage 2 (Depth Sorting): 65.82 ms (76% of total frame time!)
- Stage 3 (DOM Style Writes): 13.76 ms
Why did sorting take 65.82 ms? Because in an interpreter-only JavaScript engine without JIT compilation, an $O(N^2)$ insertion sort on 350 elements executes roughly 60,000 to 80,000 raw bytecode instructions. Every array index lookup, float comparison, and swap incurs interpreter overhead.
The Fix: We replaced comparison-based sorting with a zero-allocation, 1-pass $O(N)$ Integer Bucket Counting Sort. We quantize candidate depths into 256 discrete 0.1-meter buckets spanning 0.0m to 25.6m:
// Pass 1: Count frequency into 256 depth buckets (O(N) with zero comparisons)
bucketCounts.fill(0);
const depthScale = 10.0; // 0.1m resolution
for (let i = 0; i < candidateCount; i++) {
let b = (candDepth[i] * depthScale) | 0;
if (b > 255) b = 255;
bucketCounts[b]++;
}
// Pass 2: Prefix sum for descending Painter's order
let offset = 0;
for (let b = maxBucketNeeded; b >= 0; b--) {
bucketOffsets[b] = offset;
offset += bucketCounts[b];
}
// Pass 3: Place indices directly into sort buffer
for (let i = 0; i < candidateCount; i++) {
let b = (candDepth[i] * depthScale) | 0;
if (b <= maxBucketNeeded) {
let dest = bucketOffsets[b]++;
if (dest < poolLimit) sortIndices[dest] = i;
}
}
The result? Depth sorting plummeted from 65.82 ms down to 0.94 ms—a staggering 70x speedup that instantly catapulted frame rates from 9 FPS to 20+ FPS on low-end silicon.
3. The DOM Mutation Tax: Slashing Writes by 71.4%
With depth sorting conquered, the next major bottleneck became DOM Style Writes (clocking in at 15.22 ms on weak hardware). What exactly is a DOM style write?
Whenever JavaScript sets an inline style property (el.style.transform = ...), the browser must bridge the boundary between the JavaScript runtime and the native C++ layout engine (WebCore/Blink). WebKit allocates an internal string, runs the CSS parser, checks dirty bits against existing computed styles, and schedules layout recalculations.
In our early pool implementation, our render loop was mutating 7 distinct properties per visible node:
el.style.transformOrigin
el.style.transform
el.style.width
el.style.height
el.style.backgroundPosition
el.style.zIndex
el.style.display
For a pool of 384 nodes, that meant $384 \times 7 = \mathbf{2,688}$ cross-boundary C++ mutations every single frame! To slash this overhead, we executed a radical architectural cleanup:
- Static Layout in CSS: We moved
width: 96px; height: 104px; transform-origin: 0 0; into the static CSS stylesheet. JavaScript never touches element dimensions or origin points again (saving 1,152 writes/frame).
- Pre-Baked Painter's Z-Index: Since our bucket sort already orders candidates strictly from farthest to closest, DOM order is draw order! We initialize
node[i].style.zIndex = i + 1 once on boot, completely removing zIndex writes from the render loop (saving 384 writes/frame).
- Delta-State Visibility: Instead of setting
display = 'block' unconditionally, we track active pool limits and only toggle display when a slot transitions between active and dormant (saving ~384 writes/frame).
Now, our render loop mutates only 2 dynamic properties per slot: transform and backgroundPosition. Total DOM mutations plummeted from 2,688 down to 288 (at 144 pool) or 768 (at 384 pool)—cutting style write time from 15.22 ms down to 7.82 ms on our lowest-end device and 0.1 ms in standard browsers.
4. The "Foam Pit" Trap: Cylindrical Billboards vs. Rigid Lattices
One of the most fascinating graphic design hurdles we encountered involved voxel perspective alignment. In an early attempt to make adjacent cubes appear seamless when rotated, we experimented with calculating per-block view rays:
// The "Foam Pit" Experiment:
const rayAngle = Math.atan2(x1, z1);
const blockAngleIdx = Math.floor((yaw + rayAngle + PI/32) / (PI/16)) % 32;
Mathematically, this ensured that every block turned to face the camera point directly. In practice? It turned the world into what looked like a foam pit! Because cubes on the left edge rotated by $-20^\circ$ and cubes on the right rotated by $+20^\circ$, adjacent cubes twisted against one another like misaligned toy blocks, completely breaking the illusion of a solid world.
In computer graphics, a rigid orthogonal lattice (like Minecraft or real Lego bricks) requires Axonometric Consistency: all blocks in the world coordinate system must share the exact same yaw rotation matrix relative to the camera plane:
// The Rigid Grid Solution:
// All blocks share the unified camera yaw; only camera-facing entities (mobs) billboard!
candAngleIdx[candidateCount] = voxelAngleIdx;
When combined with our 32-angle atlas and sub-pixel seam sealing (a calibrated 4.5% scale overlap factor), the entire landscape snapped into place: flat terraces formed continuous horizontal lines, brick outpost walls aligned flush, and rotational diamond gaps vanished.
5. The Accessibility Mission: Why This Matters
At Newt Games, our engineering philosophy has always been grounded in accessibility. When we talk about accessible gaming, we often think of screen readers, remappable controls, and colorblind palettes—all of which are vital. But there is another fundamental dimension to accessibility: hardware equity.
Millions of potential players—especially kids in underserved school districts, communities relying on legacy Chromebooks, and families whose only internet screen is a decade-old smart TV—are entirely locked out of modern 3D web experiences. When an indie developer ships a WebGL game with a 45 MB bundle that demands 1.2 GB of VRAM, they are unintentionally writing off a huge portion of the global web.
Project BrowserSpace proves that with thoughtful constraints, respectful memory budgets (our entire engine runs in under 2.0 MB of JS heap), and classic arcade engineering, you can deliver responsive, grounded, physics-driven 3D exploration anywhere a browser window can open.
We're continuing to expand the testbed—adding macro-plane batching for distant horizons, animated APNG mobs, and multiplayer sync. Stay tuned for more updates as we push the limits of what pure web standards can do!