Skip to content

Conversation

@jonahwilliams
Copy link
Contributor

@jonahwilliams jonahwilliams commented Dec 3, 2022

Adds documentation on usage of the fragment program API.

Fixes flutter/flutter#107929

Presubmit checklist

@jonahwilliams jonahwilliams marked this pull request as ready for review December 5, 2022 18:07
@@ -0,0 +1,228 @@
---
title: Writing and using Fragment Shaders
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBD: how do I link this from elsewhere in the website?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To link TO this page, you would use the following text:

For more information, check out [Writing and using fragment shaders][fragment-shaders]

[fragment-shaders]:  {{site.url}}/development/ui/advanced/shaders

## Canvas API

Fragment shaders can be used with most Canvas APIs that accept either solid
colors or gradients via a [Paint] object. And will cover an area determined
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check the first two sentences here. Not sure what they're saying.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what I'm trying to say is:

You can use shaders with most canvas APIs.
The shader works in the same way that a solid color or gradient works when applied to a shape
It doesn't work with certain APIs, like how a LinearGradient is ignored if set on the paint passed to drawImage

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you make this change, @jonahwilliams? The suggested text is clearer.

### Performance Considerations

When targeting the Skia backend loading the shader may be expensive, since it
must be compiled to the appropriate platform specific shader. If you intend to
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
must be compiled to the appropriate platform specific shader. If you intend to
must be compiled to the appropriate platform specific shader at runtime. If you intend to

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


```

## Authoring Shaders
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe frontload pointers to tutorials on writing shaders?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this will get a generated table of contents

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering what kind of tutorials you mean, @zanderso

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ones listed down under "Other resources". My thought was to make it clear that this doc isn't intended to be a general tutorial on writing shaders.

jonahwilliams added 2 commits December 5, 2022 12:41
@jonahwilliams
Copy link
Contributor Author

@sfshaza2 PTAL. I'd like to merge this change before the next stable so that I can update some class documentation in the flutter repo to point to it

Copy link
Contributor

@sfshaza2 sfshaza2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Phew! This one was a doozy!

@@ -0,0 +1,228 @@
---
title: Writing and using Fragment Shaders
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To link TO this page, you would use the following text:

For more information, check out [Writing and using fragment shaders][fragment-shaders]

[fragment-shaders]:  {{site.url}}/development/ui/advanced/shaders

Copy link
Contributor

@sfshaza2 sfshaza2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, as this is a new page, can you add it to the sidenav? To do that, edit src/_data/sidenav.yml.

@jonahwilliams
Copy link
Contributor Author

@sfshaza2 I've updated this PR with most of your suggestions + a few comments/questions

Copy link
Contributor

@sfshaza2 sfshaza2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a few minor quibbles, but nothing to hold up landing this, when you're ready. LGTM

Co-authored-by: Shams Zakhour (ignore Sfshaza) <[email protected]>
@jonahwilliams
Copy link
Contributor Author

Thanks for all of the help on this one @sfshaza2 !

@jonahwilliams jonahwilliams merged commit 6605ead into main Dec 13, 2022
@jonahwilliams jonahwilliams deleted the add_shader_doc branch December 13, 2022 22:23
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.

Document writing custom shaders on the website

4 participants