Skip to content

Conversation

@donmccurdy
Copy link
Member

@donmccurdy donmccurdy commented Dec 2, 2025

Description

DRAFT - for discussion.

Currently label screen-space size is derived from label.font x label.scale, while SDF size (used to display the font in WebGL) is fixed at 48px:

const SDFSettings = {
/**
* The font size in pixels
*
* @type {number}
* @constant
*/
FONT_SIZE: 48.0,

The idea explored by this PR is to use SDFSettings.FONT_SIZE as a minimum, scaling up the glyph size to match the maximum font size present in the label collection. Increasing label font size should then never result in deteriorating quality. Note that .scale does not change the size of the SDF glyph, and could still magnify a low-resolution glyph, but I think that's acceptable.

Two big tradeoffs:

  1. Texture atlas size. Large font sizes require larger glyphs and a larger atlas. Using the max font size (not all requested font sizes) is a compromise so that only one font size is stored in the atlas at a time. I expect that label sizes larger than 48px are rare, so most users will continue to have current SDF size (48px) unchanged. That said, I'd be open to the argument that each unique size should be stored; in a collection with many small labels (and, say, 1000+ characters in some languages) and only 1–2 very large labels, it would reduce atlas size to store each label's glyphs at exactly the requested font size.

  2. Custom measureText() implementation performance. We iterate over pixels to compute glyph bounding boxes, and becomes slower as glyph sizes increase. For example, a 30-character label at fontSize=400px spends 100ms in rebindAllGlyphs compared to 25ms at fontSize/48px. Perhaps this could be resolved separately by Investigate writeTextToCanvas and measureText function #9767. I think it's only a minor issue at this stage.

Preview:

fontSize=12 fontSize=48 fontSize=144
fontSize=12 fontSize=48 fontSize=144

Issue number and link

Testing plan

TODO

Author checklist

  • I have submitted a Contributor License Agreement
  • I have added my name to CONTRIBUTORS.md
  • I have updated CHANGES.md with a short summary of my change
  • I have added or updated unit tests to ensure consistent code coverage
  • I have updated the inline documentation, and included code examples where relevant
  • I have performed a self-review of my code

PR Dependency Tree

This tree was auto-generated by Charcoal

@github-actions
Copy link

github-actions bot commented Dec 2, 2025

Thank you for the pull request, @donmccurdy!

✅ We can confirm we have a CLA on file for you.

character,
label._fontFamily,
label._fontStyle,
label._fontSize,
Copy link
Member Author

Choose a reason for hiding this comment

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

TODO: This line was included to force updates in the texture atlas, but managing the glyph cache correctly would take more investigation.

@javagl
Copy link
Contributor

javagl commented Dec 3, 2025

Mentioning that "custom measureText" triggered some memories about #11747 . It should be easy (nearly trivial) to replace it, and IIRC that PR was already pretty complete, but ... there have been ~"some pixels somehow been different in some cases", with no clear reasoning for what is "better" or "worse", so it was abandoned. Maybe with all the other recent fixes in this area, it's really trivial now.

@donmccurdy
Copy link
Member Author

@donmccurdy donmccurdy force-pushed the fix/label-responsive-sdf-size branch from 8d8da7b to 8aeafac Compare January 7, 2026 19:33
@donmccurdy donmccurdy changed the base branch from main to refactor/remove-custom-measureText January 7, 2026 19:33
@donmccurdy donmccurdy force-pushed the refactor/remove-custom-measureText branch from a8ce35e to 6f1487b Compare January 8, 2026 15:10
@donmccurdy donmccurdy force-pushed the fix/label-responsive-sdf-size branch from 9b547a2 to d9c1565 Compare January 8, 2026 15:10
Base automatically changed from refactor/remove-custom-measureText to main January 9, 2026 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Label outline aliasing

3 participants