Skip to content

[Bug]: Shaded Relief lights a bottom-up raster from the mirrored direction #1798

Closed

Description

@elpidioassinaturas

Before you start

  • I searched the existing issues and did not find a duplicate.
  • This is a bug report, not a usage question.

What happened?

Shaded Relief on the map lights a raster stored bottom up (a positive pixel height, the first row the southernmost, as some COGs are) as if it were north up. A slope facing south, lit from the north, is drawn brighter than flat ground instead of darker. The light comes from the mirrored azimuth, north–south. A raster stored right to left (a negative pixel width) would be mirrored east–west the same way.

The cause is in the draw path. crates/render/src/raster.rs builds the 3×3 window in grid order and passes r.cell_size_m(), which is unsigned, to rustgis_map::raster::hillshade (crates/map/src/raster.rs). That function takes the window's first row as north and its first column as west. analysis::rasterops::hillshade already handles this with the transform's signs (terrain_on, * r.transform.pixel_width.signum() and * -r.transform.pixel_height.signum()), and has a test for it (terrain_faces_the_right_way_on_a_bottom_up_grid). The map's hillshade doesn't.

Steps to reproduce

The same terrain, a slope rising to the north, stored both ways and drawn as Shaded Relief lit from the north (azimuth 0, altitude 45). On main (780e071), as a unit test in crates/render/src/raster.rs:

let rows: Vec<Vec<f32>> = (0..10).map(|r| vec![(9 - r) as f32 * 300.0; 10]).collect();
let north: Vec<f32> = rows.concat();
let south: Vec<f32> = rows.iter().rev().flatten().copied().collect();
// north up: origin_y 0.1, pixel_height -0.01; bottom up: origin_y 0.0, pixel_height 0.01
// same Crs::LonLat, pixel_width 0.01, drawn with `draw` at the centre, nearest sampling

The pixel is 159 north up and 230 bottom up. Flat ground lit at 45° is 180, so the south-facing slope should be darker than that, as 159 is.

Expected behavior

The same terrain draws the same whichever way its rows are stored, as the analysis hillshade already does.

How are you running RustGIS?

Built from source

Version

main 780e071

Operating system, browser and graphics

Windows 11

Sample data

The test above; any COG written bottom up.

Proposed fix

In the draw path, give hillshade the window in geographic order. Either flip the window's rows when pixel_height > 0 and its columns when pixel_width < 0, or pass signed cell sizes and use them in the slope, as terrain_on does. Then add a test that draws both orientations and compares them, like the one above.

The cast shadows of #1796 follow the transform's signs already, so on a bottom-up raster they currently disagree with the hillshade. This fix brings the two together.

🤖 Generated with Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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