-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Adds documentation for antialiasing with impeller #13370
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
gaaclarke
wants to merge
3
commits into
flutter:main
Choose a base branch
from
gaaclarke:antialias-doc
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+77
−0
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| --- | ||
| title: Impeller anti-aliasing | ||
| description: How does Impeller perform anti-aliasing? | ||
| --- | ||
|
|
||
| Aliasing is the visual artifacts that result from drawing geometry to a grid of | ||
| pixels (rasterization). Impeller employs a couple of techniques to smooth out | ||
| the mapping to raster graphics (anti-aliasing). | ||
|
|
||
| ## Techniques | ||
|
|
||
| ### Multisample anti-aliasing (MSAA) | ||
|
|
||
| [MSAA][] is a global anti-aliasing technique that operates on the whole contents | ||
| of the screen. It is an optimization over rendering the whole screen at a larger | ||
| scale and shrinking it down ([SSAA][]). Instead of doing the fragment operation | ||
| for each fragment in a region, if it is determined they have the same coverage, | ||
| 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. | ||
|
|
||
| On desktop and mobile 4x MSAA is used for all rendering calls. | ||
|
|
||
| ### Signed distance fields ([SDFs][]) | ||
|
|
||
| Typically, hardware accelerated computer graphics is done by defining a series | ||
| of points and edges (a [mesh][]) and [shaders][]. SDF rendering instead renders | ||
| the shape of things in the fragment shader program using SDFs to define the | ||
| shape of the object being drawn. Since the shape is defined in the fragment | ||
| shader there is an opportunity to smooth out edges at the fragment level instead | ||
| of relying on the rasterization of a mesh. | ||
|
|
||
| On desktop, rendering with SDFs is enabled. On mobile platforms SDFs is an | ||
| option whose default value is false. | ||
|
|
||
| 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. | ||
|
|
||
| ## Working with anti-aliasing | ||
|
|
||
| ### SDFs with the FragmentShader API | ||
|
|
||
| Standard primitive shapes in Flutter will be drawn automatically with SDFs. If | ||
| a Flutter developer wants to define their own custom graphics with SDFs they can | ||
| 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. | ||
|
|
||
| An example of rendering SDFs with the FragmentShader API can be found at | ||
| [`simple_sdf`][]. | ||
|
|
||
| ### Enabling SDFs on iOS | ||
|
|
||
| SDFs can be enabled on iOS by adding a new field to the `Info.plist` for the | ||
| project. | ||
|
|
||
| ```xml | ||
| <key>FLTEnableSDFs</key> | ||
| <true/> | ||
| ``` | ||
|
|
||
| [MSAA]: https://en.wikipedia.org/wiki/Multisample_anti-aliasing | ||
| [SSAA]: https://en.wikipedia.org/wiki/Supersampling | ||
| [Tiled rendering]: https://en.wikipedia.org/wiki/Tiled_rendering | ||
| [SDFs]: https://en.wikipedia.org/wiki/Signed_distance_function | ||
| [mesh]: https://en.wikipedia.org/wiki/Polygon_mesh | ||
| [shaders]: https://en.wikipedia.org/wiki/Shader | ||
| [FragmentShader API]: /ui/design/graphics/fragment-shaders | ||
| [drawPath()]: {{site.api}}/flutter/dart-ui/Canvas/drawPath.html | ||
| [`simple_sdf`]: {{site.github}}/flutter/samples/tree/main/simple_sdf | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional nit:
If I weren't familiar with the problem, I'm not sure I would understand what issue is being described here.
What visual artifacts?
An image or two could add a lot of value here. Maybe we could pull from some of the issues we've been solving for impeller macOS. But that will only help once folks get to this page.
To improve the chances that a search for the issue would land devs on this page, it may also help to add a few other descriptions of aliasing. Artifacts is a good term, but maybe adding a few synonyms could help, such as jagged/rough/hard edges ("jaggies"), stair-stepping, spatial sampling errors