Skip to main content

Module hillshade

Module hillshade 

Source
Expand description

hillshade layers over raster-dem sources: a CPU port of MapLibre GL JS’s two-pass hillshading.

  1. DEMData: each DEM tile image is decoded into a stride dim + 2 buffer whose 1 px border repeats the edge pixels, then is backfilled from the neighbouring tiles that are loaded (MapLibre backfills only from tiles it has, i.e. the view’s covering tiles).
  2. hillshade_prepare.fragment.glsl: per DEM pixel, the Sobel x / y slope from the 3 × 3 neighbourhood, vertically exaggerated below z15, stored in an RGBA8 texture as deriv / 8 + 0.5.
  3. hillshade.fragment.glsl: per screen pixel, the slope texture sampled LINEAR (or NEAREST with resampling: nearest), corrected for the Mercator scale at the pixel’s latitude and shaded by hillshade-method (standard, basic, combined, igor, multidirectional), blended premultiplied. Tiles are placed with MapLibre’s pixel-aligned raster matrix.

Structs§

DemTiles
DEM tiles of one raster-dem source at the zoom MapLibre covers the view with, and the source’s unpack vector (redFactor, greenFactor, blueFactor, baseShift).

Functions§

draw_layer
Draw a hillshade layer from dem into fb (device pixels) for the view bbox at width × height CSS pixels, scale zoom zoom. nearest: the source’s texture filter (see source_nearest).
source_nearest
Whether the slope textures of source are sampled NEAREST. MapLibre prepares one texture per DEM tile, shared by every hillshade layer of the source, and sets its filter when the first layer (in style order) with an offscreen pass creates it: that layer’s resampling applies to all.
unpack_vector
The unpack vector of a raster-dem source (DEMData’s constructor).