In Part 1, we proved that you could pull 60 FPS 3D voxel exploration out of non-JIT browsers using an $O(N)$ integer bucket counting sort and a pooled array of plain DOM <div> elements. But as soon as we implemented a trailing third-person camera—the iconic Mario Kart 64 and Zelda: Ocarina of Time style view where the camera orbits behind the player—we ran straight into one of the most stubborn visual paradoxes in computer graphics: the Billboard Wobble.
Here is how we solved it—abandoning real-time matrix transforms, designing an offline 2,336-sprite pre-rendered affine cache, eliminating texture bleeding, and discovering the delicate balance of heterogeneous memory budgeting on resource-constrained embedded screens.
1. The Rotation Paradox: Cardboard Cutouts & The Foam Pit
In classic axonometric 2.5D games (like SimCity 2000 or RollerCoaster Tycoon), the camera is locked to fixed isometric angles ($0^\circ, 90^\circ, 180^\circ, 270^\circ$). Because the projection is parallel and the viewpoint never changes smoothly, flat pre-rendered sprites align into airtight bricks.
However, when a player expects continuous camera rotation in third person, orthographic sprites break down completely:
- The Spinning Cardboard Cutout: If every cube uses the same 2D orthographic sprite and rotates uniformly, cubes at in-between angles (like $22.5^\circ$ or $45^\circ$) do not foreshorten along the line of sight. Instead, they spin in place like individual spinning tops.
- The Sawtooth Diamond Gap: Adjacent blocks that should form a contiguous flat terrace pull apart, exposing diamond-shaped black holes into the void below.
- The Cylindrical Foam-Pit: When we attempted to calculate individual ray angles to each block to rotate them toward the camera, cubes twisted against their neighbors at conflicting angles—turning the landscape into a disordered foam pit.
True 3D perspective requires that every visible edge converges toward unified vanishing points. But without WebGL or Canvas, how could we achieve perspective without burning the CPU?
2. The CSS 3D Trap: Why matrix3d Collapsed
Naturally, the first instinct of any modern web developer is CSS 3D transforms: transform-style: preserve-3d; transform: matrix3d(...);. If the browser's native compositor can project 3D planes, surely that solves the problem?
On modern Apple Silicon or high-end desktop GPUs, CSS 3D works beautifully. But on our target testbeds—embedded WebKit devices, legacy smart TVs, and ultra-cheap mobile chipsets—the results were fatal:
- Hardware Unimplementation: Many embedded WebKit implementations quietly drop
preserve-3d, flattening the 3D scene into a chaotic 2D jumble.
- Software Compositor Choke: On GPUs without unified memory, creating 300+ 3D compositing layers forces the browser into a software rasterization fallback, plummeting frame rates from 60 FPS down to 4–8 FPS.
- Memory Bloat: Each CSS 3D layer requires backing store allocations, pushing heap and layer memory past 150 MB—instantly triggering the OS out-of-memory watchdog.
We realized: the 2D DOM pool architecture must stay pure 2D (translate3d(x, y, 0) scale(...)). Any 3D distortion must be pre-calculated offline.
3. The Pre-Baked Affine Cache: Perspective Without Math
Our breakthrough was treating the texture atlas not merely as a collection of block icons, but as an offline spatial affine cache. We asked: How does a cube actually distort when viewed through a perspective camera?
For any cube near the player, its projected shape is governed by three factors:
- Camera Yaw ($\theta$): The horizontal orbiting angle around the world.
- Relative Grid Position $(gx, gz)$: The offset from the camera's optical focal point (from $-1$ to $+1$ block in X and Z).
- Depth Distance ($Z$): The distance from the camera lens, which governs perspective flattening.
By simulating the exact 3D camera projection in Python during the build step, we rasterize each cube face with perspective-warped quadrilaterals, shading each face with outward 3D surface normals ($\mathbf{N} \cdot \mathbf{V}_{\text{cam}} > 0$).
At runtime, the browser does zero polygon math and zero matrix inversions. It simply looks up the pre-baked warped sprite for $(b_{id}, \text{yaw}, gx, gz)$, assigns the background position, and applies a simple 2D GPU scale: finalScale = (nomZ / depth) * (fl / baseFL). The 2D DOM compositor stitches these sprites together with sub-pixel precision into an airtight, rigid 3D world!
4. Heterogeneous Memory Budgeting & The 4096 Ceiling
Pre-rendering every possible angle and position across all 11 voxel types could easily explode texture memory into hundreds of megabytes. To keep the engine within an ultra-lean 4096 × 4096 px texture ceiling and under 1.5 MB WebP, we implemented Heterogeneous Block-Tiered Budgeting:
| Tier |
Blocks |
Yaw Resolution |
Spatial Grid |
Distance Tiers |
Sprites / Block |
| Tier 1 (Primary Terrain) |
Grass, Dirt |
32 angles (11.25°) |
3 × 3 local (9 pos) |
Near (3.6m) + Far (8.0m) |
352 sprites |
| Tier 2 (Structural) |
Stone, Wood, Leaves |
16 angles (22.5°) |
3 × 3 local (9 pos) |
Near (3.6m) + Far (8.0m) |
176 sprites |
| Tier 3 (Compact Accents) |
Brick, Oven, Ruby, Glass, Sand, Water |
16 angles (22.5°) |
3 × 3 local (9 pos) |
Near (3.6m) + Far (8.0m) |
176 sprites |
| Entities (Mobs) |
Player, Zombie, Skeleton |
16 angles (22.5°) |
Billboard Centroid |
Fixed 3.6m scale |
16 sprites |
In total, 2,336 pre-warped sprites are packed into a single 3,876 × 4,018 px atlas with uniform 68 × 98 px cells. WebP compresses this entire massive 3D projection cache down to just 1.31 MB (2.8 MB PNG), consuming less than 65 MB of decoded VRAM—well within the hardware limits of legacy devices!
5. Portability: Running on Vintage XP Laptops & Beyond
One of the most exciting aspects of this pure 2D DOM architecture is its extraordinary backward compatibility. Because Project BrowserSpace avoids WebGL and CSS 3D transforms entirely, it can run on systems where modern 3D engines are completely unthinkable:
- Windows XP Laptops (Chrome 49 / NW.js 0.14.7): Older Intel GMA 950 and Core 2 Duo systems lack modern WebGL drivers, but have full hardware Direct3D 9 support for CSS 2D
transform: translate3d(...) scale(...).
- Low-Power ARM Devices: Raspberry Pi 2/3, cheap Android TV sticks, and handhelds decode the WebP sprite sheet once on boot, after which rendering is a pure $O(1)$ blit with under 1.5ms of JavaScript execution per frame.
- Zero JIT Requirement: The runtime candidate projection and bucket sort use pre-allocated typed arrays (
Int16Array, Float32Array) with zero garbage collection allocations, maintaining a rock-solid 60 FPS in interpreter-only mode.
By marrying 1990s console sprite-scaling ingenuity with modern web standards, Project BrowserSpace proves that true 3D immersion doesn't require gigabytes of VRAM or bleeding-edge silicon—just the right mathematical perspective.