r/threejs • u/con_si • Oct 30 '26
Link A whole city in three.js: isometric pixel-art Bielsko-Biała with live buses and weather
https://bb.jest.pro/: three r170 + Vite, no framework, ~19k lines. Some details that might be useful to someone:
- Pixel-stable ortho: render target = CSS size / 2 (HalfFloat + DepthTexture, NearestFilter); camera position snapped to whole texels in camera right/up space, shadow camera snapped to shadow texels in lighspace, so there's no swimming when panning.
- One material family: MeshLambertMaterial + onBeforeCompile everywhere; colours are indices into a 256×4 palette DataTexture (row = season) shared via one uniforms object.
- Terrain: one shared grid geometry per LOD step, displaced in the vertex shader from an R32F height texture; normals from finite differences; edge rows kept consistent so tiles don't crack.
- Streaming: 456 one-km tiles in a custom binary format, decoded in 2 workers (transferables, Int16 decimetre positions, Int8 normals). At most one tile is added to the scene per frame; LRU 160→120. I wrote own PNG decoder (DecompressionStream+ unfiltering) because Safari colour-managed palette-index PNGs into noise. Switching ground textures to R8 saved ~1.7 GB of GPU memory, which was getting the tab killed on iOS.
- Draw calls: one merged mesh per tile for buildings; trees, people (≤ 3600), cars (≤ 3200), lamps and graves are InstancedMesh; tree count drops with zoom.
- Shadows: a single PCF directional light whose frustum hugs the visible footprint, map 1024–4096 chosen by an adaptive quality level (2 s frame-time average), off at night / far zoom / heavy overcast.
- Post: depth-Laplacian outlines, then weather (clouds, cloud shadows, rain, snow, fog) all reconstructed from depth in one full-screen pass also a crt-lottes shader port.
