Skip to content

Commit 8107663

Browse files
b-luksfshaza2
andauthored
Clarify usage of the ImageFilter API for fragment shaders. (#12522)
_Description of what this PR is changing or adding, and why:_ - Suggest using the ImageFiltered class in addition to the BackdropFilter class. - Fix broken link to BackdropFilter page. - Call out the automatically-filled uniform values when using ImageFilter.shader. - Change the example code to not set a size uniform value. As called out above, this is incorrect and these set values are ignored. _Issues fixed by this PR (if any):_ _PRs or commits this PR depends on (if any):_ ## Presubmit checklist - [x] 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. - [x] If this PR is not meant to land until a future stable release, mark it as draft with an explanation. - [x] This PR follows the [Google Developer Documentation Style Guidelines](https://developers.google.com/style)—for example, it doesn't use _i.e._ or _e.g._, and it avoids _I_ and _we_ (first-person pronouns). - [x] This PR uses [semantic line breaks](https://github.com/dart-lang/site-shared/blob/main/doc/writing-for-dart-and-flutter-websites.md#semantic-line-breaks) of 80 characters or fewer. --------- Co-authored-by: Shams Zakhour <[email protected]>
1 parent ae0a642 commit 8107663

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

src/content/ui/design/graphics/fragment-shaders.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,21 +115,27 @@ void paint(Canvas canvas, Size size, FragmentShader shader) {
115115

116116
### ImageFilter API
117117

118-
Fragment shaders can also be used with the [`ImageFilter`][] API. This allows
119-
using custom fragment shaders with the [`BackdropFilter`][] class to apply
120-
shaders to already rendered content. [`ImageFilter`][] provides a constructor,
121-
[`ImageFilter.shader`][], for creating an [`ImageFilter`][] with a custom
122-
fragment shader.
118+
Fragment shaders can also be used with the [`ImageFilter`][] API.
119+
This allows using custom fragment shaders with the
120+
[`ImageFiltered`][] class or the [`BackdropFilter`][] class
121+
to apply shaders to already rendered content.
122+
[`ImageFilter`][] provides a constructor, [`ImageFilter.shader`][],
123+
for creating an [`ImageFilter`][] with a custom fragment shader.
124+
125+
Fragment shaders that use the `ImageFilter` API receive some
126+
values automatically from the engine. The `sampler2D` value at index 0
127+
is set to the filter input image, and the `float` values at indices 0
128+
and 1 are set to the image's width and height.
129+
Your shader must specify this constructor to accept these values (for example,
130+
a `sampler2D` and a `vec2`), but you should not set them from your Dart code.
123131

124132
[`ImageFilter`]: {{site.api}}/flutter/dart-ui/ImageFilter-class.html
125-
[`BackdropFilter`]: {{site.api}}/flutter/dart-ui/BackdropFilter-class.html
133+
[`ImageFiltered`]: {{site.api}}/flutter/widgets/ImageFiltered-class.html
134+
[`BackdropFilter`]: {{site.api}}/flutter/widgets/BackdropFilter-class.html
126135
[`ImageFilter.shader`]: {{site.api}}/flutter/dart-ui/ImageFilter/ImageFilter.shader.html
127136

128137
```dart
129138
Widget build(BuildContext context, FragmentShader shader) {
130-
final screenSize = MediaQuery.of(context).size;
131-
shader.setFloat(0, screenSize.width);
132-
shader.setFloat(1, screenSize.height);
133139
return ClipRect(
134140
child: SizedBox(
135141
width: 300,

0 commit comments

Comments
 (0)