Skip to content

Core: Add support for colorized SDF fill patterns - #4551

Open
deniial00 wants to merge 8 commits into
maplibre:mainfrom
deniial00:sdf-fill-pattern
Open

Core: Add support for colorized SDF fill patterns#4551
deniial00 wants to merge 8 commits into
maplibre:mainfrom
deniial00:sdf-fill-pattern

Conversation

@deniial00

@deniial00 deniial00 commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Description

Implements Support colorized SDF fill patterns.

When a fill-pattern references an SDF image, the renderer now:

  • Uses fill-color as the pattern foreground color.
  • Supports constant and data-driven colors.
  • Applies fill-opacity.
  • Supports the antialiased fill-outline path.
  • Keeps existing RGBA pattern rendering unchanged.

Implementation

  • Allows fill-color together with fill-pattern in the bundled style specification.
  • Preserves SDF metadata through ImagePosition and the pattern atlas.
  • Tracks whether each fill layer uses SDF patterns.
  • Passes the SDF state to the fill-pattern shaders.
  • Adds SDF alpha evaluation and antialiasing for OpenGL, Metal, Vulkan, and WebGPU.
  • Triggers relayout when an image changes between RGBA and SDF.
  • Emits a warning when SDF and non-SDF patterns are mixed within one layer.
  • Documents the SDF foreground-color behavior in the style specification and generated Android and Darwin APIs.

No public API changes are required.

Testing

  • Added unit tests for SDF metadata preservation.
  • Added backend-independent tests for per-layer pattern-type tracking and mixed-pattern warnings across buckets.
  • Added a render test covering:
    • Constant SDF color
    • Data-driven SDF colors
    • fill-opacity
    • Antialiased outlines
    • Unchanged RGBA pattern rendering
  • Locally verified the Metal build, relevant unit tests, and the SDF fill-pattern render test.
  • Locally verified the WebGPU/wgpu build and focused render test.
  • Compiled the affected OpenGL core and test objects. The full backend and platform matrix, including Vulkan, is left to CI.

Related work

AI assistance

OpenAI Codex was used for implementation review, warning deduplication, regression testing, and generated documentation checks. The contributor has reviewed and verified the submitted changes before marking this draft ready for review.

Fixes #4526

@github-actions github-actions Bot added build Related to build, configuration or CI/CD android iOS core Changes that affect the C++ core of MapLibre Native OpenGL Issues related to the OpenGL renderer backend Vulkan WebGPU labels Sep 3, 2026
@deniial00
deniial00 marked this pull request as ready for review September 3, 2026 21:24
Comment thread scripts/style-spec-reference/v8.json

@louwers louwers left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Could you make sure all the render tests from the MapLibre GL JS PR are ported?

Also, let's wait with merging this until the MapLibre GL JS PR is merged.

I'm kicking off a workflow run, please ping me if you need another one.

@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Bloaty Results (iOS) 🐋

Compared to main

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.1% +12.4Ki  +0.1% +16.0Ki    TOTAL

Full report: https://maplibre-native.s3.eu-central-1.amazonaws.com/bloaty-results-ios/pr-4551-compared-to-main.txt

@deniial00

deniial00 commented Sep 6, 2026

Copy link
Copy Markdown
Contributor Author

@louwers maplibre/maplibre-gl-js#8239 has now been merged, and all four render tests from it are ported here. The fixes for the Linux, WebGPU, and Vulkan failures are also pushed. Could you kick off another workflow run when you have a chance? Thanks!

@github-actions

github-actions Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Bloaty Results 🐋

Compared to main

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.1%  +249Ki  +0.2% +59.8Ki    TOTAL

Full report: https://maplibre-native.s3.eu-central-1.amazonaws.com/bloaty-results/pr-4551-compared-to-main.txt

Compared to d387090 (legacy)

    FILE SIZE        VM SIZE    
 --------------  -------------- 
   +56% +64.5Mi  +477% +28.5Mi    TOTAL

Full report: https://maplibre-native.s3.eu-central-1.amazonaws.com/bloaty-results/pr-4551-compared-to-legacy.txt

@github-actions

github-actions Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Benchmark Results ⚡

Benchmark                                                          Time             CPU      Time Old      Time New       CPU Old       CPU New
-----------------------------------------------------------------------------------------------------------------------------------------------
OVERALL_GEOMEAN                                                 -0.0024         -0.0017             0             0             0             0

Full report: https://maplibre-native.s3.eu-central-1.amazonaws.com/benchmark-results/pr-4551-compared-to-main.txt


bool shouldWarnAboutMixedSDFPatterns(const std::string& layerID) {
static std::mutex mutex;
static mln::unordered_set<std::string> warnedLayers;

@louwers louwers Sep 7, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any way to avoid these static variables?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in d5a7656. The warning suppression set now belongs to each FillBucket, so there are no function-local statics or mutex. The test verifies that repeated mismatches warn once within a bucket and that separate buckets do not share warning state.

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

Labels

android build Related to build, configuration or CI/CD core Changes that affect the C++ core of MapLibre Native iOS js-parity OpenGL Issues related to the OpenGL renderer backend Vulkan WebGPU

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support colorized SDF fill patterns

2 participants