-
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
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,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 | ||
|
sfshaza2 marked this conversation as resolved.
Outdated
|
||
| 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 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. | ||
|
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. 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). |
||
|
|
||
| On desktop and mobile 4x MSAA is used for all rendering calls. | ||
|
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. 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 is done by defining a series | ||
| of points and edges (a [mesh][]) and [shaders][]. SDF rendering instead renders | ||
|
sfshaza2 marked this conversation as resolved.
Outdated
|
||
| 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 | ||
|
sfshaza2 marked this conversation as resolved.
Outdated
|
||
| shader there is an opportunity to smooth out edges at the fragment level instead | ||
| of relying on the rasterization of a mesh. | ||
|
sfshaza2 marked this conversation as resolved.
Outdated
|
||
|
|
||
| On desktop, rendering with SDFs is enabled. On mobile platforms SDFs is an | ||
| option whose default value is false. | ||
|
sfshaza2 marked this conversation as resolved.
Outdated
|
||
|
|
||
| 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 | ||
|
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. Desktop computers don't have pixels. ;) "desktop displays"? Perhaps provide some example statistics?
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. 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... |
||
| 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 | ||
|
sfshaza2 marked this conversation as resolved.
Outdated
|
||
| 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.
|
||
|
|
||
| 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 | ||
Uh oh!
There was an error while loading. Please reload this page.