Repository navigation
Kyle/elevation example - #647
Closed
kylebarron wants to merge 4 commits into
Closed
kylebarron wants to merge 4 commits into
kylebarron wants to merge 4 commits into
Conversation
Designs a 2D example that streams USGS 3DEP 1-meter lidar DEMs from the public National Map bucket and computes hillshade, slope, and tinted relief on the GPU, with an interactive sun angle. Hillshade is the first convolutional shader module in the project, which collides with per-tile independent fetching: the 3x3 Horn kernel has no neighbors at tile edges, producing a visible seam grid. The spec resolves this in application code with a one-texel halo — a (tileWidth + 2) square texture — backed by a shared decoded-tile cache, so the 8 neighbors are decoded once and shared across up to 9 halo assemblies rather than refetched per tile. Verified against the bucket: CORS is open with working range GETs, the cells are valid COGs with overviews, and internal tile size (256 vs 512), nodata, and UTM zone all vary across vintages, so none may be hardcoded. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Introduces `examples/experimental/` for examples that demonstrate what deck.gl-raster makes possible but whose architecture has not yet been reviewed and endorsed, and moves the USGS 3DEP hillshade example into it. The published URL deliberately omits the `experimental/` segment. An example deploys to `/examples/<name>/` either way, so promoting one out of `experimental/` is a pure `git mv` that breaks no bookmarks. The docs workflow takes the same view via `basename`, and each example's Vite `base` and gh-pages publish path stay free of the segment. The workflow's example loop needed a package.json guard: the bare `examples/experimental/` directory matches `examples/*/` but is not a package, and the step runs under `bash -e`, so the `node -p` command substitution would otherwise abort the entire docs build. `ControlPanel` gains an `experimental` prop that renders a badge beside the title and a caveat in the body, so every future example in this lane is labelled consistently rather than hand-rolling the notice. Also switches the default Grand Canyon cell from `x39y400` to `x40y400`. Measured against the coarsest overview, `x39y400` carries real data over only ~35% of its extent and rendered as islands of terrain in a void — the lidar acquisition followed the canyon rather than the plateau. `x40y400` covers Phantom Ranch and the Colorado River through the Granite Gorge at ~97%, with elevations from 734 m at the river to 2285 m at the rim, which also sets honest colormap bounds. Co-Authored-By: Claude Opus 5 <[email protected]>
Replaces the Yosemite frame with one from the example's default cell, `x40y400`, showing the Colorado River and the side canyons below the rim. The card now matches what the example opens on. Co-Authored-By: Claude Opus 5 <[email protected]>
kylebarron
added a commit
that referenced
this pull request
Oct 7, 2026
…reographic COGs (#694) * ci: build examples under examples/experimental Add `examples/experimental/*` to the pnpm workspace and to the docs workflow's example build loop. The loop skips directories without a package.json: `examples/experimental/` itself matches `examples/*/`, and a failed `node -p` would abort the step under `bash -e`. Both hunks are byte-identical to the ones in #647, so the two branches merge cleanly in either order. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(examples): add experimental custom projection example Render COGs in arbitrary planar map projections (Arctic and Antarctic polar stereographic, Equal Earth, Web Mercator), with no basemap. Polar data can't be shown in Web Mercator at all, and choosing a projection is routine in GIS workflows. deck.gl merged experimental support for this as `_CustomProjectionView` (visgl/deck.gl#10741), but it ships with deck.gl v10. The example uses a stand-in on deck.gl 9.4's `OrthographicView` with the same options and `{center, zoom}` view state, so moving to the official view is an import swap in the example plus a globe-detection fix in deck.gl-raster (see the README). - `src/custom-projection/`: the view, viewport and controller stand-in. Common space and zoom match upstream, and so do `preproject`, `postUnproject`, `projectFlat` and `projectionSignature`. - `src/projected-cog-layer/`: `ProjectedCOGLayer`, a `COGLayer` that selects tiles in the map CRS and has `RasterLayer` mesh each tile in map meters (`coordinateSystem: "cartesian"`). Domain-aware culling and trimming, pole and antimeridian handling, and LOD measured on screen. - Vector context (coastlines, graticule, domain outline) is projected on the CPU. - Data: GEBCO 2026, the NASA Explorer Base Map (native EPSG:3031), EOxCloudless, and ITS_LIVE ice velocity (EPSG:3031 and EPSG:3413). No library code changes. Co-Authored-By: Claude Opus 5.5 <[email protected]> * add app experimental box * clean up app wording * cleaner labels * perf(examples): cut pole mesh cost in custom projection example Zooming in over a pole was slow: a view at zoom 8 meshed 1.15M triangles and spent ~26 s in proj4. The reprojector measures error in source pixels as if they were square, but lng/lat pixels near a pole are only cos(lat) as wide as they are tall on a polar map, so it kept splitting triangles to fix sub-screen-pixel column errors. - Stretch each geographic tile's pixel grid horizontally by the pixels' aspect ratio on the map before meshing (columnErrorScale). RasterLayer only uses `width` to size the mesh grid, so passing width * scale with matching transforms reweighs column error without changing UVs. The ratio is measured in the output map, so it also holds for Equal Earth. - Stop meshing geographic tiles at 89.5° instead of one row from the pole, which halves the remaining pole triangles. Over the pole at zoom 8: 1.15M -> 31k triangles, ~26 s -> 0.7 s of meshing. Visible map-space error is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]> * cleaner label * update README * add experimental section to docs --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
kylebarron
added a commit
that referenced
this pull request
Oct 28, 2026
> [!NOTE] > This PR was written by Claude (Claude Code), not by @kylebarron. Adds `examples/experimental/pmtiles-terrain`. It computes relief shading on the GPU from [Mapterhorn](https://mapterhorn.com/)'s global terrain, read straight from one PMTiles archive by `RasterTileLayer`. The archive is `planet.pmtiles`: 356 GB covering zooms 0-12, as Terrarium-encoded 512 px lossless WebP. It shows three things: 1. **deck.gl-raster reads PMTiles too.** Any tiled source works, not only COG and Zarr. 2. **Hillshade is computed live on the GPU.** The sun is a slider, and moving it fetches nothing. 3. **Reads are merged.** A clustered PMTiles archive keeps a view's tiles together in the file, so the range reader merges them into a few streamed requests. A "Merge requests" switch compares that with one request per tile. This becomes the hillshade example. It ports and reviews #647's Horn kernel, halo and modes; #647 stays parked. Ref #647. The design is in [`dev-docs/specs/2026-10-27-pmtiles-terrain-design.md`](https://github.com/developmentseed/deck.gl-raster/blob/64702126264eec1cf1ff30a4ec182f2f02436531/dev-docs/specs/2026-10-27-pmtiles-terrain-design.md) and the [example's README](https://github.com/developmentseed/deck.gl-raster/blob/64702126264eec1cf1ff30a4ec182f2f02436531/examples/experimental/pmtiles-terrain/README.md). ## Built on the range reader It reads PMTiles through `@developmentseed/range-reader` (#806) and uses #809's protected `_abortUnwantedLoads` hook, both on main. Outside the example, the PR changes only the spec, one docs entry, the card image and lockfile additions. ## How it works - **No loaders.gl.** The example uses the `pmtiles` library directly. `@loaders.gl/pmtiles` takes only a URL or a `Blob`, so its reads can't merge; it calls `getZxy` without a signal; and it pins `pmtiles` 3.x. - **`RangeReaderSource`** implements `pmtiles`' `Source` on the range reader. - Tile-data reads use the `data` purpose; the header and directories use `metadata`. - Bytes are copied out, because the reader's are views into shared buffers. - A replaced archive is caught with `pmtiles`' own `etag` check. - **`PMTilesSource extends RasterSource`** describes a 512 px WebMercatorQuad grid bounded to the archive. - The layer takes its `tilesetDescriptor`; question 10 of the Sources spec stays as it is. - If `RasterTileLayer` learns to take a `source`, this plugs in there. - **Halo.** Each tile is a 514 x 514 `r32float` texture whose outer ring comes from its eight neighbors. - Nothing is fetched for a halo. A tile loads only itself and draws at once, its ring filled from the neighbors that have loaded. - A side whose neighbor hasn't loaded repeats the tile's own edge. That neighbor isn't in view, so neither is the side. - When a neighbor loads later, the tile rewrites only its ring, four strips one texel wide. - `TileBorders` keeps each loaded tile's border (8 KiB, not 1 MiB), so a tile still finds a neighbor's border after deck.gl has unloaded the neighbor. - **Ground cell size is computed per fragment** from Mercator latitude. One value per tile would make the shading jump 7% between z6 tile rows near 46°N. - **Exact decoding.** There's no premultiplied alpha or color conversion. Pixels are read back the way MapLibre reads DEM tiles: through a canvas, or through `VideoFrame` when canvas reads are altered. Where neither gives exact bytes, tiles fail with a message in the panel instead of drawing wrong elevations. - **`PMTilesTerrainLayer`** exists only to turn on #809's protected `_abortUnwantedLoads` hook, because the example raises `maxRequests`. It can go once a public prop exists. ## Measured The opening view at the Matterhorn: 12 tiles. - Each mode was measured cold, two or three times, from a toggle of the switch after the basemap had loaded, in headed Chrome 156. - Times come from polling the readout, so they're +/- 0.25 s. | Connection | Mode | HTTP requests | Data | All tiles drawn | | --- | --- | --- | --- | --- | | fast | per tile | 14 | 1.9 MB | 1.9 s | | fast | merged | **7** | 2.0 MB | 1.2-1.9 s | | 150 ms round trips, 20 Mbit/s | per tile | 14 | 1.9 MB | 2.1-2.3 s | | 150 ms round trips, 20 Mbit/s | merged | **7** | 2.0 MB | **1.8-1.9 s** | The merged opening view is seven requests: - one 64 KiB header block; - one 64 KiB block holding the leaf directory; - five tile-data requests: 951 KB and 303 KB (one run of eight adjacent tiles, split by the reader's 1 MiB request cap), 305 KB (two tiles), 166 KB and 160 KB. Mapterhorn serves over HTTP/2, so merging saves more requests than time. Decoding takes about 1.25 ms per tile on the main thread. **Halos without fetches.** At first, each tile also fetched its eight neighbors for its halo. Kyle found the example slow, and filling halos only from neighbors that load anyway made it faster: | Measured | Fetching neighbors | Loaded neighbors only | | --- | --- | --- | | Opening view, merged | 4.8 MB | **2.0 MB** | | Opening view, merged, 150 ms round trips | all drawn at 2.9 s | **all drawn at 1.8-1.9 s** | | One-screen pan, fast | 13 tiles fetched for 6 shown, 1.57 MB | **6 tiles, 0.91 MB**, all drawn at 0.6 s | | One-screen pan, 150 ms round trips | last tile at 1.27 s | **last tile at 0.93 s** | ## Verified - **Tests:** the example's 82 tests, typecheck, Biome and `vite build`. Before the halo change, `deck.gl-raster` (251) and `range-reader` (99) also passed on #809's head. - **Headed Chrome:** - All four modes render. - Moving the sun or changing the mode fetches nothing. - There are no seams at tile edges or between tile rows at z5 (the Himalaya). - After the halo change, full-resolution crops across tile edges and a corner show no seams. Every opening view rewrote 29 rings: one per pair of adjacent tiles, counting diagonals, among its 4 x 3 tiles. - Tilted to 60° at z12.5 and 65° at z9.6, no seams were visible. - Across the antimeridian (Taveuni, Fiji, at z12), the rings read back from the GPU equal the neighbors' edge columns exactly. Hillshade still shows a faint line at 180°, and it comes from the data: there, the step between Mapterhorn's two edge columns is 20-60% of the steps beside it, while at other tile edges it matches them. - With canvas noise simulated, decoding switches to the `VideoFrame` path. - **Headed Firefox 155 with `privacy.resistFingerprinting`:** canvas reads come back random and `VideoFrame` is undefined. Tiles fail with the panel message; before the fix they drew random stripes. ## Review A fresh reviewer found four Important issues, and I raised two minors to Important. All are fixed, each verified by a failing test or browser check first. - **A drawn tile's halo reads were never cancelled.** Fixed then with a signal per halo, released when the tile unloaded. The halo change has since removed those reads. - **A replaced archive could leave `pmtiles` unable to read it** until reload. Fixed by using `pmtiles`' own `etag` check. - **Each cached tile kept its 1 MiB halo array alive.** luma.gl keeps `createTexture`'s `data` prop, so the array is now uploaded with `writeData`. The COG layers do the same: [`render-pipeline.ts`](https://github.com/developmentseed/deck.gl-raster/blob/98bf4ebad9988b6ddd001e32517517afefd09afd/packages/deck.gl-geotiff/src/geotiff/render-pipeline.ts#L207-L208) and [`multi-cog-layer.ts`](https://github.com/developmentseed/deck.gl-raster/blob/98bf4ebad9988b6ddd001e32517517afefd09afd/packages/deck.gl-geotiff/src/multi-cog-layer.ts#L908-L909). - **The stats poll rebuilt every tile's sublayers about four times a second** while tiles loaded. The readout now polls on its own; tileset `setOptions` calls during a pan load went from 4 to 0. - **Firefox with fingerprinting resistance drew random stripes as terrain.** Tiles now fail, and the panel says why. Also found in the browser: #647's shader takes `atan(0, 0)` on flat ground, and the resulting NaN drew lakes black. It's fixed here, but #647 still has it. ## Open questions - Should there be a WebAssembly WebP decoder as a fallback, so Firefox with fingerprinting resistance (and probably Safari private browsing) can draw tiles? It would be a new dependency. - Should there be an issue for the COG layers keeping `createTexture`'s `data`? - `pmtiles` caches failed directory fetches, so a network blip blanks a region until reload. That's upstream behavior and isn't filed. <details> <summary>Calls made without asking</summary> - Built on #809's newest head rather than the head named in the plan. Cost if wrong: one `rebase --onto`. - Tests use hand-derived literal values. - Borders are kept after their tiles unload, up to 2048 (16 MiB). Cost if wrong: memory, or seams where a forgotten neighbor's border is missing. - Added tests beyond the plan: the counting `FetchSource`, `getUniforms` (proven by a mutation), a released tile's refine, and `getZxy` returning nothing. - Two comment fixes in #647's small modules: ASCII, and Terrarium units. - Gave `TerrainDerivative` explicit uniform and binding types. - `loadTerrariumElevation` lives in `get-tile-data.ts`. - The experimental badge sits inline in the panel title, because `ControlPanel` has no `experimental` prop on this base. - A refined halo repaints through `map.triggerRepaint`. Cost if wrong: a refined ring could show a frame late. - Retuned the colormap ranges so valleys don't look like water: [500, 4500], [2000, 8850], [0, 2800] and [400, 3000]. - The layer allows `null` tiles, and `renderTile` draws nothing for them. - Fixed `atan(0, 0)` on flat ground. - Verified in my own headed Chrome over CDP, because the chrome-devtools profile was busy. - Each opened archive gets its own range reader, so both sides of the switch start cold. - Timed every pass from a toggle after the basemap loaded. An earlier run timed from page load was confounded by the basemap still loading, so it's excluded. - Captured a fresh 1800 x 1013 docs card. - Raised the stats-poll and canvas-fallback minors to Important. - **Superseded by review fixes:** - warning once and falling back to a distorted canvas; - adopting a new validator after one mismatch; - simulating the Firefox check in Chrome. - **Left as is:** - deck.gl's default tile cache size. Cost: hundreds of MiB of GPU memory on large high-DPR screens. - Blockiness past z12 wasn't checked. Cost: possibly blocky shading at zooms 13-14. - The colormap range follows the chosen place, not the current view. Cost: a poor range after panning far. - Borders can survive an archive swap. Cost: a stray seam right after a swap. - Safari is untested. Its private browsing would now get the error message. - StrictMode opens the archive twice in development. - A few unused deck.gl dependencies, copied from titiler-cog. - A ring is rewritten once per neighbor that loads after its tile, up to eight times. Cost: four small `writeData` calls each. - Where tiles of two zoom levels meet, the finer tile's neighbor at its own zoom may never load, so that side keeps a repeated edge. The tilted views above stayed at one tile zoom, so I didn't see it happen. - Decoding stays on the main thread. Cost: about 15 ms for the 12-tile opening view. </details> <details> <summary>Deferred minors</summary> - The center texel isn't clamped at the tile edge, which could draw a speck there. None was seen. - `performance.measure` entries pile up over a session. </details> 🤖 Written by [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Fable 5.1 <[email protected]>
Member
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a vibe-coded example for rendering a terrain COG. This came from discussions at FOSS4G with @hobu.
This is a draft because I haven't read and corrected the initial claude output yet.
In particular, the hardest problem is that, as a convolutional shader, we need to fill in edge pixels from neighboring tiles, lest we want to have seams visible across tiles. Claude implemented a solution but I haven't read it yet.
Designs a 2D example that streams USGS 3DEP 1-meter lidar DEMs from the
public National Map bucket and computes hillshade, slope, and tinted
relief on the GPU, with an interactive sun angle.
Hillshade is the first convolutional shader module in the project, which
collides with per-tile independent fetching: the 3x3 Horn kernel has no
neighbors at tile edges, producing a visible seam grid. The spec resolves
this in application code with a one-texel halo — a (tileWidth + 2) square
texture — backed by a shared decoded-tile cache, so the 8 neighbors are
decoded once and shared across up to 9 halo assemblies rather than
refetched per tile.
Co-Authored-By: Claude Opus 5 (1M context) [email protected]