Skip to content

[Bug]: A masked layer's extrusions stand up whole in a tilted view #3333

Backlog

Description

@elpidioassinaturas

Before you start

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:

  1. Add a polygon layer, say buildings, and give it an extrusion (layer.extrusion {"layer": "buildings", "height": 20}).
  2. Mask it by a polygon layer covering part of it (layer.mask {"layer": "buildings", "mask": "district"}).
  3. On the flat map, only the buildings inside the district show.
  4. 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_masks builds a tiny_skia::Mask for 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 with effects::extrude_tilted. It checks visibility, scale range, group holding and opacity, but never reads layer.mask or 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) requires l.mask.is_none() and no swipe. So the gap is the CPU path in extrusions_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 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:

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

Activity

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