-
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
Changes from all commits
68e69c5
bb96228
7581f25
0e74068
76cc499
1a138ad
d077fcb
cccd033
06cfadf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,78 @@ | ||||||||||||||||||||||
| --- | ||||||||||||||||||||||
| 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). The artifacts show up as jagged or rough edges on | ||||||||||||||||||||||
| shapes. Impeller employs a couple 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 | ||||||||||||||||||||||
|
sfshaza2 marked this conversation as resolved.
|
||||||||||||||||||||||
| scale and shrinking it down ([SSAA][]). Instead of doing the fragment operation | ||||||||||||||||||||||
| for each sub-sample, the calculation for the pixel is duplicated across the | ||||||||||||||||||||||
| sub-samples where a bounds check happens. 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. | ||||||||||||||||||||||
|
gaaclarke marked this conversation as resolved.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ### 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 | ||||||||||||||||||||||
|
gaaclarke marked this conversation as resolved.
|
||||||||||||||||||||||
| 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. | ||||||||||||||||||||||
|
gaaclarke marked this conversation as resolved.
Comment on lines
+27
to
+31
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Improve clarity, grammar, and technical accuracy:
Suggested change
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| On desktop, rendering with SDFs is enabled by default. On mobile platforms, SDFs | ||||||||||||||||||||||
| are an option that defaults to 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 | ||||||||||||||||||||||
|
gaaclarke marked this conversation as resolved.
|
||||||||||||||||||||||
| any imperfection will be more evident there. | ||||||||||||||||||||||
|
Comment on lines
+36
to
+39
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Refine the phrasing for a more professional and technical tone:
Suggested change
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ### Examples | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| | No AA | MSAA 4x | MSAA 4x + SDF | | ||||||||||||||||||||||
| | ------------------------------------------- | ---------------------------------------------- | ------------------------------------------------------- | | ||||||||||||||||||||||
| |  |  |  | | ||||||||||||||||||||||
|
gaaclarke marked this conversation as resolved.
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ## Working with anti-aliasing | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ### SDFs with the FragmentShader API | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| Standard primitive shapes in Flutter are drawn by default 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. | ||||||||||||||||||||||
|
sfshaza2 marked this conversation as resolved.
Comment on lines
+53
to
+55
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Improve phrasing and grammar:
Suggested change
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| 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. | ||||||||||||||||||||||
|
Comment on lines
+60
to
+63
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ```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`]: https://github.com/flutter/samples/tree/main/simple_sdf | ||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.