Skip to content

Adds documentation for antialiasing with impeller - #13370

Open
gaaclarke wants to merge 6 commits into
flutter:mainfrom
gaaclarke:antialias-doc
Open

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

Conversation

@gaaclarke

@gaaclarke gaaclarke commented May 6, 2026

Copy link
Copy Markdown
Member

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

flutter-website-bot commented May 7, 2026

Copy link
Copy Markdown
Collaborator

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

@andywolff andywolff left a comment

Copy link
Copy Markdown

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.

@sfshaza2 sfshaza2 left a comment

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.

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.

@flutter-website-bot

Copy link
Copy Markdown
Collaborator

Staged preview of the updated docs.flutter.dev site (updated for commit 1a138ad):

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

@flutter-website-bot

Copy link
Copy Markdown
Collaborator

Staged preview of the updated flutter.dev site (updated for commit 1a138ad):

https://flutter-dev-230821--www-pr13370-antialias-doc-sg22jgt2.web.app

@sfshaza2 sfshaza2 left a comment

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.

I know this is still in draft form, but this looks great, @gaaclarke! LGTM, for when you are ready to land.

@parlough

parlough commented Aug 20, 2026

Copy link
Copy Markdown
Member

@gaaclarke @flar Is this relevant as of 3.47? Is it ready to land?

@gaaclarke

Copy link
Copy Markdown
Member Author

@gaaclarke @flar Is this relevant as of 3.47? Is it ready to land?

Yes it's relevant, please land it.

@gaaclarke
gaaclarke marked this pull request as ready for review August 20, 2026 17:51
@gaaclarke
gaaclarke requested a review from a team as a code owner August 20, 2026 17:51

@gemini-code-assist gemini-code-assist Bot left a comment

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.

Code Review

This pull request introduces a new documentation page detailing Impeller's anti-aliasing techniques, specifically Multisample Anti-Aliasing (MSAA) and Signed Distance Fields (SDFs), and integrates it into the sidebar and the main Impeller documentation. The review feedback focuses on enhancing the clarity, grammar, and technical accuracy of the new page, including several suggestions for improved phrasing, formatting, and professional tone. Additionally, the reviewer requests clarification on whether the SDF configuration is iOS-only or if there is an equivalent setup for Android.

Comment on lines +20 to +22
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.

medium

The line break inside the parentheses before the link [Tiled rendering][] is awkward. Adjusting the line break improves readability while adhering to the 80-character semantic line break limit.

Suggested change
Mobile phone GPUs have special hardware to optimize this process (
[Tiled rendering][]). It comes in varying degrees of how many samples to
consider.
Mobile phone GPUs have special hardware to optimize this process
([Tiled rendering][]). It comes in varying degrees of how many samples to
consider.

[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.

medium

Add a comma after "mobile" for better readability and grammatical correctness.

Suggested change
On desktop and mobile 4x MSAA is used for all rendering calls.
On desktop and mobile, 4x MSAA is used for all rendering calls.

Comment on lines +28 to +32
Typically, hardware accelerated computer graphics define a series of points and
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.

medium

Improve clarity, grammar, and technical accuracy:

  • Hyphenate "hardware-accelerated".
  • Clarify "SDF renders" to "Impeller renders ... using signed distance fields (SDFs)" since SDF is the representation, not the renderer.
  • Add a comma after the introductory conditional clause ("Since the shape is defined in the fragment shader,").
Suggested change
Typically, hardware accelerated computer graphics define a series of points and
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.
Typically, hardware-accelerated computer graphics define a series of points and
edges (a [mesh][]) and [shaders][]. Instead, Impeller renders shapes in the
fragment shader program using signed distance fields (SDFs). 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.

Comment on lines +37 to +40
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
any imperfection will be more evident there.

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.

medium

Refine the phrasing for a more professional and technical tone:

  • Use "places higher demands on" instead of "puts more demand on".
  • Use "larger" instead of "bigger" for pixel sizes.
  • Avoid starting a sentence with "So" in technical documentation; combine the clauses to improve flow.
Suggested change
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
any imperfection will be more evident there.
This technique is prioritized on desktop because SDF rendering places higher
demands on the GPU, and Flutter supports older mobile phones. Also, the physical
pixel sizes on desktop computers are typically larger than those of mobile
phones, making any imperfections more noticeable.

Comment on lines +54 to +56
do so with the [FragmentShader API][]. Using the [drawPath()][] is sufficient
for most use cases without resorting to high quality SDF rendering. Not all
drawn paths are guaranteed to result in SDF rendering though.

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.

medium

Improve phrasing and grammar:

  • Remove the unnecessary article "the" before [drawPath()][].
  • Hyphenate "high-quality" when used as a compound adjective.
  • Avoid ending the sentence with "though" to maintain a professional tone.
Suggested change
do so with the [FragmentShader API][]. Using the [drawPath()][] is sufficient
for most use cases without resorting to high quality SDF rendering. Not all
drawn paths are guaranteed to result in SDF rendering though.
do so with the [FragmentShader API][]. Using [drawPath()][] is sufficient
for most use cases without resorting to high-quality SDF rendering. However,
not all drawn paths are guaranteed to result in SDF rendering.

Comment on lines +61 to +64
### Enabling SDFs on iOS

SDFs can be enabled on iOS by adding a new field to the `Info.plist` for the
project.

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.

medium

The section only describes how to enable SDFs on iOS. Since the PR description mentions opting in to SDFs on "mobile devices" (plural), please clarify if there is an equivalent configuration for Android (e.g., in AndroidManifest.xml), or explicitly state if this feature is currently iOS-only.

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.

6 participants