Skip to content

Adds documentation for antialiasing with impeller#13370

Draft
gaaclarke wants to merge 5 commits into
flutter:mainfrom
gaaclarke:antialias-doc
Draft

Adds documentation for antialiasing with impeller#13370
gaaclarke wants to merge 5 commits into
flutter:mainfrom
gaaclarke:antialias-doc

Conversation

@gaaclarke
Copy link
Copy Markdown
Member

@gaaclarke gaaclarke commented May 6, 2026

This PR should only be landed after macOS impeller is switched to SDFs by default: flutter/flutter#183045

Description

This explains SDF rendering for macOS and covers antialiasing in general. The main things to communicate is the escape hatch if people want to implement their own SDFs and how to opt-in to SDFs on mobile devices.

Issues fixed by this PR

flutter/flutter#183043

PRs or commits this PR depends on

flutter/flutter#183045

Presubmit checklist

  • If you are unwilling, or unable, to sign the CLA, even for a tiny, one-word PR, please file an issue instead of a PR.
  • If this PR is not meant to land until a future stable release, mark it as draft with an explanation.
  • This PR follows the Google Developer Documentation Style Guidelines—for example, it doesn't use i.e. or e.g., and it avoids I and we (first-person pronouns).
  • This PR uses semantic line breaks
    of 80 characters or fewer.

@flutter-website-bot
Copy link
Copy Markdown
Collaborator

flutter-website-bot commented May 7, 2026

Visit the preview URL for this PR (updated for commit 76cc499):

https://flutter-docs-prod--pr13370-antialias-doc-17a96hc6.web.app

@gaaclarke gaaclarke requested a review from andywolff May 7, 2026 16:45
Comment thread sites/docs/src/content/perf/antialiasing.md
Copy link
Copy Markdown

@andywolff andywolff left a comment

Choose a reason for hiding this comment

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

LGTM. Contents and location of the new doc make sense to me.

Copy link
Copy Markdown
Contributor

@sfshaza2 sfshaza2 left a comment

Choose a reason for hiding this comment

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

Some smoothing out and one question for @gaaclarke.

Comment thread sites/docs/src/content/perf/antialiasing.md
Comment thread sites/docs/src/content/perf/antialiasing.md Outdated
Comment thread sites/docs/src/content/perf/antialiasing.md Outdated
Comment thread sites/docs/src/content/perf/antialiasing.md Outdated
Comment thread sites/docs/src/content/perf/antialiasing.md Outdated
Comment thread sites/docs/src/content/perf/antialiasing.md Outdated
Comment thread sites/docs/src/content/perf/antialiasing.md
Comment thread sites/docs/src/content/perf/antialiasing.md Outdated
@sfshaza2 sfshaza2 added the review.await-update Awaiting Updates after Edits label May 7, 2026
@gaaclarke gaaclarke requested a review from sfshaza2 May 7, 2026 22:59
@sfshaza2 sfshaza2 removed the review.await-update Awaiting Updates after Edits label May 11, 2026
only one fragment operation is calculated. This limits smoothing to edges.
Mobile phone GPUs have special hardware to optimize this process (
[Tiled rendering][]). It comes in varying degrees of how many samples to
consider.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not sure how you are defining "fragment operation". If it is "execution of a fragment program" then I don't think this is correct.

For any given pixel I believe it only performs one fragment shader operation on the center of a pixel for any pixel, whether it has all the same MSAA coverage or not. The only thing that MSAA adds is which of the sub-samples it propagates that single result to.

The text above implies that it only runs the fragment shader once for wholly enclosed interior pixels - and??? runs it multiple times for edge pixles? (I don't think it works that way).

[Tiled rendering][]). It comes in varying degrees of how many samples to
consider.

On desktop and mobile 4x MSAA is used for all rendering calls.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Perhaps mention the consequences of the MSAA #, such as "the quantization of the coverage for edge pixels is limited to the number of MSAA samples" (so edge pixels are always only one of 0%, 25%, 50%, 75%, or 100% covered with MSAA 4).

### Signed distance fields ([SDFs][])

Typically, hardware accelerated computer graphics define a series of points and
edges (a [mesh][]) and [shaders][]. Instead, SDF renders shapes in the fragment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"... and the color sample for pixels is either 0% or 100% the result of the fragment shader (color source?) for each pixel depending on whether it falls in the mesh or not"...?

edges (a [mesh][]) and [shaders][]. Instead, SDF renders shapes in the fragment
shader program as signed distance fields. Since the shape is defined in the
fragment shader the edges can be smoothed at the fragment level instead of
relying on the rasterization of a mesh.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"smoothed ... by computing the coverage of the shape over each individual pixel at a high resolution (or precision?) and used to proportionally apply the color sample to that pixel"...?

fragment shader the edges can be smoothed at the fragment level instead of
relying on the rasterization of a mesh.

On desktop, rendering with SDFs is enabled. On mobile platforms, SDFs are an
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"... enabled by default"?


This technique is prioritized on desktop because SDF rendering puts more demand
on the GPU and Flutter supports older mobile phones. Also, the physical pixel
sizes on desktop computers are typically bigger than those of mobile phones. So
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Desktop computers don't have pixels. ;)

"desktop displays"?

Perhaps provide some example statistics?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also, bigger in terms of field of view. Mobile phones are viewed closer than desktop displays, but their much higher pixel count still wins out in terms of pixel angular viewing angle thingy bopper...


### SDFs with the FragmentShader API

Standard primitive shapes in Flutter are drawn automatically with SDFs. If a
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

automatically -> by default unless the developer changes the "?antialiased?" setting in the Paint object...?


| No AA | MSAA 4x | MSAA 4x + SDF |
| ------------------------------------------- | ---------------------------------------------- | ------------------------------------------------------- |
| ![No AA](/assets/images/docs/perf/noaa.png) | ![MSAA 4x](/assets/images/docs/perf/msaa4.png) | ![MSAA 4x + SDF](/assets/images/docs/perf/msaa4sdf.png) |
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The images are subtle. One other option is to show a very slightly rotated line where the stepping is far more abrupt with MSAA and it is easy to see more steps with SDF.

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.

5 participants