# Navigation you can always see

In a 3D city, the buildings you paid for will hide the thing the driver needs. Our rule is that the route and the position marker are never occluded in chase mode, and holding that rule took three separate mechanisms: a depth-ignoring ghost of the marker, a route line drawn above the whole scene, and a shader that dissolves any geometry standing in the sightline. None of them is a trick you can apply once and forget, and one of them broke silently for a whole afternoon.

## Why is occlusion a navigation problem and not a rendering preference?

Because the moment a tower sits between the camera and the vehicle, the driver has lost the only two pieces of information that matter. A map can afford to hide a road behind a building. A navigation view cannot hide the route, because the route is the answer to the question being asked. The prettier the city gets, the more reliably it eats its own product.

The obvious fixes are all worse. Lowering the camera puts the route behind the next building instead of this one. Making buildings globally transparent throws away the depth cues that make a 3D city legible in the first place, and at night it looks like a wireframe. Culling buildings near the route leaves visible holes in the skyline. What is needed is a rule that removes exactly the geometry that is in the way, exactly while it is in the way.

## What are the three mechanisms?

A ghost, an overlay and a dissolve, layered so that each one covers the others' failure modes.

**The x-ray ghost of the position marker.** A second copy of the chevron is drawn with depth testing switched off, in translucent blue at 34% opacity, at a high render order so it composites last. It is always visible, through anything, by construction. This is the guarantee of last resort: even if every other mechanism fails, the driver can still see where they are.

**The route x-ray line.** The route is drawn twice. Once in the scene, and once as a pale blue x-ray copy that renders above the extruded city. On a flat corridor that copy is a MapLibre line layer added after the 3D layer with no `beforeId`. On a terrain corridor it cannot be, because MapLibre drapes line layers onto the terrain mesh as part of the ground, so the city drawn afterwards would cover it; there the copy is a three.js ribbon drawn with depth testing off at a render order of 9000, with the same widths and opacities. Its opacity is 40% in the day build and 22% in every other light preset, and its width interpolates from 1.6 px at zoom 14 to 6 px at zoom 19. That difference is deliberate: once the scene darkens, the same overlay reads much stronger and has to be pulled back.

**The occluder dissolve.** Every material in the 3D layer, facades, plinths, roofs, parapets, shopfront glazing, fascias, signs and tree canopies, gets a fragment shader injection that fades the fragment out based on where it sits relative to two capsules: one from the camera to the vehicle, and one from the vehicle to a point about 200 m further along the route.

## How does the dissolve avoid dissolving the city?

By asking whether the geometry is actually blocking, not merely nearby. The naive version fades anything within a radius of the camera-to-vehicle line, and in a street canyon that is both walls, so the buildings evaporate every time the route runs down a narrow street. The fix is a second term that compares the fragment's height against the height of the point on the sightline beside it, so a wall standing to one side of the view is damped out of the calculation while a mass standing above the line is not.

The shipped numbers, all tuned by eye against real drives:

| Term | Behaviour |
|---|---|
| Camera-to-vehicle capsule | Fully dissolved at 10 m from the line, clear past 24 m |
| Blocking damp | Fades out over a 4 m to 18 m height difference |
| Near-camera fade | Applies from 10 m to 22 m of the camera |
| Route-ahead capsule | 8 m to 20 m, with its own height damp |
| Ground storeys | Kept below 2 m, fading in to 7 m |
| Visibility floor | Never below 28%, so a dissolved building is a ghost, not a hole |

That 28% floor matters more than it looks. Fading to zero produces a gap in the skyline that reads as a bug; leaving a quarter of the building behind reads as glass. The earlier build used 15% and looked broken.

The fade is applied by discarding fragments against a dither pattern rather than by alpha blending, because alpha on thousands of instanced boxes means sorting them. The first dither was an 8 by 8 ordered matrix, which produced a fixed lattice that crawled against moving geometry and was clearly visible. It was replaced with interleaved gradient noise, which has no repeating cell to crawl against, and the dissolved region is additionally blended toward the fog colour so the edge softens rather than stippling.

The whole effect is gated on chase mode. Grab the camera and look around yourself, and the city goes solid again: at that point you are exploring, not driving, and occlusion is information rather than an obstacle.

## What made this harder than it should have been?

Two platform details, and one process failure.

The renderer does not hand a custom layer a camera position. It provides a combined projection matrix and no accessor for free-camera state, so the world-space camera position that both capsules need is reconstructed from the map centre, pitch, bearing, field of view, canvas height and metres per pixel. Small errors there are invisible, because the only consumers are a dissolve radius and a reflection streak.

Injected shaders also need their own program cache key. Without one, the engine can hand an injected material a cached, uninjected program, and the effect silently does nothing on some materials and not others. The key is a literal string that we bump whenever the injected source changes.

The process failure is the one worth writing down. There is no automated test for any of this. It is verified frame by frame in a browser, and during one revision a patch dropped a single variable declaration, which broke every injected shader and rendered a city with no buildings in it at all. A compile error would have been kinder. The effect can break silently and only a human looking at it will notice, which is a real weakness in a codebase that is otherwise heavily tested.

## The route also has to end somewhere

A related piece of the same problem: the route line behind the vehicle should not be there, because a driver does not need where they have been, and a bright ribbon trailing off the bottom of the screen competes with the one ahead. The route source carries line metrics, and a gradient is rewritten each frame so the travelled portion is dimmed and the remainder is full strength.

The first version cut the ribbon dead at the vehicle, which looked like the route had been amputated at the axle. It now carries a graduated stub of roughly 50 m behind the marker, so the ribbon visibly passes underneath the chevron and then dissolves. The gradient stops have to be strictly ascending or the whole expression is rejected, which is the sort of detail that costs an hour once.

## What still does not work

- **No test covers the occlusion shader.** It can regress silently and has.
- **The dissolve only covers our own layer.** Basemap building extrusions do not take the injection. Inside the demo corridor those are hidden anyway, so it does not show, but the technique is not general.
- **Everything here is tuned by eye.** The radii, the floor and the damp thresholds came from watching drives, not from a metric. There is no measurement of how often the route is occluded, before or after.
- **Route colouring by traffic condition is not built.** That needs real per-edge congestion data, and we would rather ship nothing than invent colours.
- **Phones see a recording, not the effect.** A coarse pointer with a screen under 768 px on its short side gets a captured drive rather than the live scene, because this render stack is exactly what crashes the browser on low-memory mobile GPUs. The dissolve is visible in the footage, but nothing on that page is computing it.

## Try it

Drive the London demo on a desktop browser and let it chase: buildings ahead of the vehicle open up, buildings beside it stay solid, and the marker stays visible through both. Then grab the camera and watch the city close again. The [demos documentation](/docs/demos) lists the flags, [the navigation camera write-up](/news/navigation-camera-3d) explains why the chase camera follows the snapped position rather than the raw fix, and [lane guidance](/news/lane-guidance) covers the other half of staying legible, which is what happens at the junction itself.

Map rendering derives from OpenStreetMap. Credit "© OpenStreetMap contributors" when you render or republish it.
