garage44.eu/jeroen/cartopolis

logclone: git clone https://garage44.eu/jeroen/cartopolis.git

.. /docs/notes/lit-windows.md

raw


topic: lit-windows triggers: [building_windows.rs, building_windows.wesl, lod22.rs, osm_buildings.rs, "lit windows", "windows at night", "night", "3dbag windows", "facade", sky.rs, update_window_glow, WindowGlow] updated: 2026-08-26

The 3DBAG buildings had no windows, and the reason was a despawn

Two lanes draw buildings. osm_buildings extrudes OSM footprints and has built real emissive window quads for a long time (WindowGlow, push_wall_windows, sky::update_window_glow). lod22 streams 3DBAG LoD2.2 meshes and had none.

That would be a small gap except for one line in osm_buildings: over any cell lod22_covers() reports, it despawns its own detail patch and never refetches it, because the real meshes are the only buildings there. 3DBAG covers the Netherlands. So the window feature existed, was correct, and was never once visible in the country the app is built around — measured 2026-08-26 with a --time 22 capture over Groningen that came back completely black except for street labels and a few lamps.

systems::building_windows is the missing half, written for the lane that has to serve it. docs/notes/parked-vehicles.md is the sibling case: content the map data already implied and nothing drew.

Why a shader and not quads

A z14 LoD2.2 cell is thousands of buildings and ~240k triangles. Four floors of window quads on each is tens of megabytes of extra mesh per cell, on the lane that already owns the largest assets in the app and the documented device-loss churn (docs/notes/upload-bursts.md). Nothing is stored: the pattern is computed per fragment from the wall's own normal and position, so it costs no vertex, no upload and no residency — and it reaches every building rather than the patch around the camera that the quad path was limited to.

This is the same call systems::grass states as a rule ("generated, not scattered") and globe_ocean makes for the ocean ("a BRDF split, not water").

The lattice has to divide the floating origin

The shader has no stable per-vertex anchor to work from. water.wesl uses UV0 in anchor metres and grass.wesl reconstructs one from MeshTag; neither is available here, because lod22 dedupes its vertices and a shared corner vertex belongs to two walls with different tangents, so no per-vertex coordinate can serve both.

So it reads world_position — which jumps by a whole WORLD_CELL_EDGE (10,000 m) when big_space recentres — and the lattice is chosen to divide that jump exactly:

latticepitchsteps per 10 kmhash periodperiods
windows across2.5 m4,00032125
windows up3.125 m3,20032100
occupancy block25 m4001625

Both the index step and its hash period have to come out whole, or the pattern changes when you fly 10 km — every window in the city relighting at once, with nothing in any log. building_windows::tests pins both rows; do not change a pitch without redoing that arithmetic.

Two hashes, not one

A per-window hash alone gives every facade in the city the same fraction of lit windows. The first tuned capture showed what that looks like: correct, and unmistakably decoration rather than a city. Real streets have whole dark buildings standing between the lit ones.

So a second, coarser hash on a 25 m block — roughly one building's footprint, taken on horizontal position only so all four walls of a building agree — decides how lively the block is, and the window hash is tested against that. A dead block lights about one window in twelve, the liveliest about half. Neither end is 0 or 1: a wholly black building reads as missing, and a wholly lit one is the thing this exists to prevent.

Measured

What the streaks on a gable wall are, and are not

Night captures show thin vertical light streaks on walls seen nearly edge-on. They are correct projection, not an artefact, and two rounds of captures were spent before that was measured rather than guessed: at 40 m a 1.55 m window is ~30 px tall, and at ~10° incidence its 1.35 m width projects to ~4 px. A 4×30 px sliver is what a real window looks like from there.

Two fixes were attempted against them and neither is the cause. Both were kept anyway, on their own merits, and their comments say so:

Known limits