Repository navigation
Description
Before you start
- I searched the existing issues and did not find a duplicate.
What happens
A polygon layer with an extrusion and a layer.mask shows only the part inside the mask on the flat map. Tilt the view, and the whole layer stands up: every extruded feature, inside the mask or not.
Steps:
- Add a polygon layer, say buildings, and give it an extrusion (
layer.extrusion {"layer": "buildings", "height": 20}). - Mask it by a polygon layer covering part of it (
layer.mask {"layer": "buildings", "mask": "district"}). - On the flat map, only the buildings inside the district show.
- Tilt the view (pitch > 0). Every building stands up, including those outside the district.
Why
On main (70a4f4d), crates/render/src/lib.rs:
- Masks are built for the flat pass only.
layer_masksbuilds atiny_skia::Maskfor each masked or swiped layer, and the flat layer pass applies it. - The tilted extrusion pass skips them.
extrusions_tilted(line 4304) draws every visible extruded polygon layer witheffects::extrude_tilted. It checks visibility, scale range, group holding and opacity, but never readslayer.maskor the swipe divider. Nothing in the tilted frame masks it afterwards. - Only the CPU path is affected. The GPU path is not taken for these layers:
gpu_may_turn(line ~3691) requiresl.mask.is_none()and no swipe. So the gap is the CPU path inextrusions_tilted.
This was found in the review of #3327 (masking a layer by a raster's values, part of #3147). There, CodeRabbit pointed out that raster masks don't reach the tilted extrusions. They inherit the gap above; the PR doesn't add it.
What should happen
A tilted view should show the same features a flat view shows. A masked layer's extrusions should stand up only inside its mask, for both kinds:
- a polygon mask;
- a raster mask ([Feature]: Mask a layer by another raster's values (slope, height or any raster), with a soft edge #3147), once it lands.
A swiped layer should stand up only on its side of the divider.
Proposed fix
Mask the tilted extrusions per feature, by footprint, in extrusions_tilted:
- Polygon mask: stand up only the features whose footprint lies inside the mask polygons. Test on the footprint's centroid, so a feature crossing the edge is drawn whole or not at all.
- Raster mask ([Feature]: Mask a layer by another raster's values (slope, height or any raster), with a soft edge #3147): test the raster's value at the same point, against the mask's range.
- Swipe: test the point against the divider.
The rows that pass go to effects::extrude_tilted as today, so the GPU path's rule (gpu_may_turn keeps masked layers off it) can stay as it is.
Per feature is better here than masking pixels. A screen-space mask would cut the upper walls of a building inside the mask where they rise past the mask's edge on screen, and a building would look sliced. Per feature, a building stands up whole or not at all.
The alternative is pixel masking: draw the layer on a pixmap of its own (the function already does this below full opacity), build the mask on the ground warped into the view, and apply it. It cuts features exactly at the edge, as the flat map does. But it slices walls, and it costs a second warp per masked layer.
Tests
- A tilted frame of an extruded, polygon-masked layer, checked by pixels: a building outside the mask isn't drawn, and one inside is.
- The same with a swiped layer.
- The same with a raster mask, once [Feature]: Mask a layer by another raster's values (slope, height or any raster), with a soft edge #3147's part 1 is in main.
Activity