Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🌫️ This PR aims to bring blur capabilities to Iced
blur_example.mov
This PR also introduces very basic sub-surface compositing support for the
iced_wgpu
backend. Note that tiny-skia appears to have no support for blurring, so the plan is to not support it at this time.NOTE: The internals of this PR are very likely to change with upcoming layering changes. This PR mostly aims to get feedback on a) the
blur
widget API, and b) sub-surface compositing in Iced in general.Implementation details
A few changes were needed in our rendering backend, as it was mostly set up with only the viewport's texture as a render attachment in mind!
The
blur
widgetA
Blur
widget can be used to wrap anyElement
, like so:Where
10
here represents the blur "radius". I chose to implement it as its own widget vs an appearance attribute (like how it's done on web) to allow for the most flexibility. Feedback welcome!A new
iced_wgpu::layer::Kind
**This could be done any number of ways; first I tried just adding a blur option to the existing layer which worked fine, but thought this approach was more readable.
I've adjusted
iced_wgpu::Layer
to have akind
field,Immediate
orDeferred
(naming suggestions welcome :P). Alayer::Kind::Immediate
is rendered to the viewport's surface immediately. Alayer::Kind::Deferred
must first render everything within the layer to its ownSurface
, and that will be composited onto the viewport's surface later.** This is very likely to be completely reworked after layering changes!
The
Composite
pipeline (name TBD)This is just a general purpose pipeline which can be used to composite any sub-surface onto the viewport's texture. The general idea is that if we want to do any sort of layer
Effect
we first must render it to acomposite::Surface
, and that will be used to sample from in theComposite
pipeline. In terms of blur, this is necessary as it is much faster to do each blur pass (horizontal & vertical) on a downsampled texture and then upsample it back up to the proper size.I abstracted it out into its own pipeline as it's more general purpose than just for blur, but originally had it as just part of the blur pipeline. If we don't think this is useful could move it back again! 🤷
That's about it in terms of details. Max blur time for large images caps out at around ~150µs on my various rigs which I believe should be fast enough for its use case in Iced 😉
iced_wgpu::Backend
changesMostly just needed to change things to be able to be relative to any texture size vs just the viewport, nothing too crazy here. Made an abstraction over
wgpu::RenderPass
that we might be unnecessary.Outstanding TODOS
blur
package to make sure that meshes are blurring properly.Outstanding Questions
Let me know what you think! Note again that the internals of this implementation will probably change quite a bit after upcoming layering changes to Iced.