Skip to content

[Bug]: Shaded Relief ignores Bilinear resampling: its light is one value per DEM cell, blocky at large scales, high DPI and in tilted views #1880

Closed

Description

@elpidioassinaturas

What happens

A Shaded Relief layer set to Bilinear resampling (raster.resampling {"type": "bilinear"}) still draws its light in square blocks, one per DEM cell. The colour ramp is smoothed, but the hillshade and the cast shadows are not. At a large scale, a high DPI or in a tilted view, where a cell covers several pixels, the relief looks pixelated. This is the coarsest thing in a tilted terrain export today.

Why

Pass1::rows (crates/render/src/raster.rs:702) truncates the source position to a cell, let cell = (c as i64, row as i64). The relief branch then works the hillshade out from that cell's 3 × 3 window (line 750) and reads the cast-shadow grid at the same index (line 752). The Bilinear branch just above samples the band values between cells, but the light is never interpolated. Resampling::Bilinear is documented as "Blend the four nearest pixels: smooth, for continuous data" (crates/map/src/raster.rs:1259), and a DEM's relief is continuous data.

How to reproduce

rustgis-cli run --data mde_utm.tif \
  --cmd 'raster.symbology={"type":"shadedRelief","azimuth":315,"altitude":45,"zFactor":1.5}' \
  --cmd 'raster.resampling={"type":"bilinear"}' \
  --cmd 'map.goToXY={"lon":-43.55,"lat":-20.24,"scale":8000}' \
  --cmd 'share.exportMap={"path":"plano.png","width":1600,"height":1100,"dpi":288}'

Any DEM of 30 m cells works. At 1:8,000 and 288 dpi a cell covers about 33 px, and the blocks are plain. Setting Bilinear changes almost nothing: a tilted export of this DEM at 288 dpi differs from Nearest in 0.003% of its pixels.

Proposal

With Bilinear, interpolate the light the way the values already are: work out the light of the four cells around the sample point (hillshade × what the cast shadows leave) and blend them bilinearly. Nearest stays exactly as today.

Choices in this proposal

  • Interpolate the light, not the heights. Blending the four cells' light gives a continuous surface with the same values at cell centres as today. Working the hillshade out from bilinear heights would change its values everywhere, not only between centres.
  • The cast-shadow light is blended with it. It is read per cell too, so it would stay blocky otherwise.
  • One place works out a cell's light. A helper returns a cell's lights, and the blend calls it for the four cells. Sky visibility ([Feature]: Shaded Relief with soft cast shadows and sky visibility #1782 part 2, PR feat(raster): Shaded Relief dims its ambient light by the sky each cell sees (#1782, part 2) #1871), which adds an ambient light per cell, then comes out smooth through the same blend.
  • Only with Bilinear. Nearest keeps today's pixels, so existing projects drawn with Nearest don't change.
  • Clamped at the raster's edge, as the band sampling is. A no-data or masked cell is left out of the blend and the other weights are scaled up, so the edge of a clipped DEM doesn't darken.

Measured (local prototype)

I tried this in a local build (four calls of the existing per-cell light, blended). Busy 16-thread Windows PC, so the times are indicative. CPU time of the whole rustgis-cli run, 4 runs each:

Export at 288 dpi Today Light blended Cost
Flat, 1:8,000, 4800 × 3300 px 28.3–31.8 s 32.4–34.2 s about +10–15%
Tilted 65°, 1:60,000, 4800 × 3300 px 16.7–18.5 s 27.0–27.8 s about +55%

The light of each cell is worked out four times. Keeping each cell's light for the rows being drawn would bring that down to about once. I haven't tried that.

flat map, 1:8,000, 288 dpi, Bilinear; before (left) and with the light blended (right)

Flat map, 1:8,000, 288 dpi, Bilinear; before (left) and with the light blended (right).

tilted 65°, 288 dpi, a close crop; before and after

Tilted 65°, 288 dpi, a close crop; before and after.

DEM: Copernicus DEM GLO-30, © DLR e.V. and Airbus, provided under COPERNICUS by the European Union and ESA.

Alternatives considered

  • Bilinear by default for Shaded Relief. That changes every existing map. It could follow this fix as a separate decision.
  • Supersampling the export. It smooths the block edges but keeps the blocks.

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions