Expand description
hillshade layers over raster-dem sources: a CPU port of MapLibre GL
JS’s two-pass hillshading.
- DEMData: each DEM tile image is decoded into a stride
dim + 2buffer 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). - 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. - hillshade.fragment.glsl: per screen pixel, the slope texture sampled
LINEAR(orNEARESTwithresampling: nearest), corrected for the Mercator scale at the pixel’s latitude and shaded byhillshade-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-demsource at the zoom MapLibre covers the view with, and the source’s unpack vector (redFactor,greenFactor,blueFactor,baseShift).
Functions§
- draw_
layer - Draw a
hillshadelayer fromdemintofb(device pixels) for the viewbboxatwidth × heightCSS pixels, scale zoomzoom.nearest: the source’s texture filter (seesource_nearest). - source_
nearest - Whether the slope textures of
sourceare sampledNEAREST. 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’sresamplingapplies to all. - unpack_
vector - The unpack vector of a
raster-demsource (DEMData’s constructor).