Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@bdero
Copy link
Member

@bdero bdero commented Aug 20, 2022

Speeds up the blur in apps we're testing by another 3x or so.

The directional gaussian blur pass has several new assumptions:

  1. A second blur is always present to process the image,
  2. both blur passes have the same sigma,
  3. and the blur directions are perpendicular (within the snapshot transform space).


// Compute the blur radius in the Y direction by projecting it onto the basis
// vectors.
// Note that this assumes both passes of the blur have the same sigma and are
Copy link
Member

Choose a reason for hiding this comment

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

I might be misunderstanding, but the API does allow the x and y direction to have different sigmas like here: https://api.flutter.dev/flutter/dart-ui/ImageFilter/ImageFilter.blur.html.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, the framework supports distinct sigmaX/Y values. That said, I would guess the vast majority of blur usages have either both values the same, or one value as zero.

Copy link
Member Author

Choose a reason for hiding this comment

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

Whoops, I've been staring at this code for too long. It might be time to refactor this blur to combine the passes and make these optimizations easier.

Copy link
Member Author

Choose a reason for hiding this comment

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

Realized combining the blurs won't really simplify the optimizations because we need to support blurring in arbitrary directions relative to the texture. The input texture can be an arbitrarily complex Contents that was transformed in interesting ways before it was rendered to a texture.

Also, it would be nice to continue supporting arbitrary single direction blur since we could one day expose this to users who want to do high fidelity motion blurs. :)

@bdero bdero marked this pull request as draft August 20, 2022 22:13
@bdero bdero force-pushed the bdero/symmetrical-blur-scale branch from 6737b76 to 532d4b0 Compare August 22, 2022 23:05
@bdero bdero marked this pull request as ready for review August 22, 2022 23:12
@bdero
Copy link
Member Author

bdero commented Aug 22, 2022

Fixed this up and it should be good to go. It's now rebased on top of #35615.

bdero added 2 commits August 24, 2022 13:52
Stop information loss on first pass

Add secondary sigma param to directional gaussian blur
@bdero bdero force-pushed the bdero/symmetrical-blur-scale branch from 532d4b0 to 56db529 Compare August 24, 2022 21:02
blur->SetBlurStyle(blur_style);
blur->SetTileMode(tile_mode);
blur->SetSourceOverride(source_override);
blur->SetSecondarySigma(secondary_sigma);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: considerjust having a method that takes both sigmas so this doesn't get forgotten in a refactor.

Copy link
Member Author

Choose a reason for hiding this comment

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

Whoops, I merged too quickly and missed this comment. I forgot to mark it private, but this param should be hidden as an implementation detail and never be used when making a 1D blur directly (only the factory for the 2D blur should ever use it), whereas the regular sigma param should remain as part of the API.

Copy link
Contributor

Choose a reason for hiding this comment

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

You could have the second parameter be optional defaulted to zero right?

This is a nitpick though. It's ok to ignore if you think it should be.

Copy link
Contributor

@dnfield dnfield left a comment

Choose a reason for hiding this comment

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

I haven't verified this against the app but LGTM assuming it's visually good.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

No open projects
Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants