Skip to content
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

How to use textures as input? #1

Closed
MindStudioOfficial opened this issue May 23, 2022 · 6 comments
Closed

How to use textures as input? #1

MindStudioOfficial opened this issue May 23, 2022 · 6 comments
Assignees
Labels

Comments

@MindStudioOfficial
Copy link

Hi, I am trying to use these shaders for image processing. I've read in the flutter documentation that sampler2D is a valid uniform as an input to the shader. However I cannot find a way to generate that uniform in dart since it is not just a double. Is there a specific type for that exposed in the API?

@felixblaschke felixblaschke self-assigned this May 24, 2022
@felixblaschke
Copy link
Owner

I haven't tried it myself, but from documentation you should be able to pass List<ImageShader> into the shader(...) of the FragmentProgram. See: https://api.flutter.dev/flutter/dart-ui/FragmentProgram/shader.html

And ImageShader can be created from an Image, which should be straight forward: https://api.flutter.dev/flutter/dart-ui/ImageShader-class.html

If you are successful, it would be cool to report back your experience or a minimalist example (e.g. link to Git repo).

@MindStudioOfficial
Copy link
Author

Thats exactly what I could not find. Thanks a lot. I will report back soon.

@MindStudioOfficial
Copy link
Author

MindStudioOfficial commented May 24, 2022

I've done it! Thanks a lot. Feel free to use any of this as an example in your project:

https://github.com/MindStudioOfficial/texshader_test

@felixblaschke
Copy link
Owner

Well done! Now we can also use RepaintBoundary to post-process the rendered ui 😄
See: https://api.flutter.dev/flutter/rendering/RenderRepaintBoundary/toImage.html

@MindStudioOfficial
Copy link
Author

Oh wow, I didn't even think of that.

But then you would need to overlay the processed image of the ui on top of the ui. Do gestures and such still work behind the ShaderPainter?

@felixblaschke
Copy link
Owner

Yes you can place AbsorbPointer (https://api.flutter.dev/flutter/widgets/AbsorbPointer-class.html) where you like.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants