@bitruvius/raster
v0.3.1
Published
Bitruvius raster visualization: colormaps, hillshade and 3D terrain rendering on WebGL2
Readme
@bitruvius/raster
Turn a decoded elevation raster into something you can see.
A decoder hands you a Float32Array of scalar values with a width and a height.
That is correct and completely unreadable. This package turns it into a colour
ramp, shaded relief, or a 3D heightmap, with no opinion about where the numbers
came from.
Why it is separate
Visualization has no reason to know whether the values arrived as LERC, as a
GeoTIFF, or out of your own solver, so tying it to a decoder would mean writing
the same colour ramp again for the next format. Everything here takes a plain
Float32Array plus dimensions.
The transforms are pure functions with no canvas, no GL context and no DOM, so
they run in a worker or in Node as readily as on a page. Only TerrainRenderer
touches WebGL2.
Three paths
| Path | What it does |
| --- | --- |
| colormapRaster | Normalize against zMin/zMax and apply a ramp, giving RGBA bytes for a canvas, ImageData or texture upload. |
| hillshadeRaster | Shaded relief by Horn's 3x3 slope with Lambert illumination, the construction GIS tools use, as RGBA grayscale. |
| buildTerrainMesh and TerrainRenderer | A centered 3D heightmap with per-vertex colour and faceted screen-space-derivative shading. Viewer-agnostic: it draws through a ViewerAdapter and a FrameState, so it is not bound to any one map. |
buildGeoTerrainMesh is the georeferenced variant, for a raster that carries an
extent rather than being a bare grid.
Use it
import { colormapRaster, hillshadeRaster, turbo } from '@bitruvius/raster';
// values: Float32Array of length width * height
const rgba = colormapRaster(values, { width, height, zMin, zMax, colormap: turbo });
const shade = hillshadeRaster(values, { width, height, azimuthDeg: 315, altitudeDeg: 45 });
canvas.getContext('2d')!.putImageData(new ImageData(rgba, width, height), 0, 0);Pass a mask (one byte per pixel, 1 valid, 0 nodata) and masked pixels come
back fully transparent, rather than as a misleading colour at the bottom of the
ramp.
A ramp is just (t: number) => [r, g, b], so turbo and grayscale ship here
and your own is a one-liner.
Trademarks
Esri and LERC are trademarks of Environmental Systems Research Institute, Inc. The Turbo colour ramp originates with Google LLC and is used under Apache-2.0. All other marks are the property of their respective owners.
These names are used solely to describe the data formats this software interoperates with. Bitruvius is not affiliated with, sponsored by, or endorsed by any of them, and no such relationship is implied.
License
Proprietary. The full terms ship as LICENSE inside this package, and are readable
before installing at cdn.bitruvius.com/legal/sdk-license-v1.txt.
© Bitruvius, Inc.
