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

Add backdrop blur filter #446

Merged
merged 7 commits into from
Mar 6, 2024

Conversation

minetoblend
Copy link
Contributor

@minetoblend minetoblend commented Feb 22, 2024

Adds a backdrop blur filter which will blur the background behind an object and then draw the object on top of it, creating a frosted glass-like look.

The filter tries to reuse as much of the original BlurFilter as possible. Currently it needs to access a private field of FilterSystem to get ahold fo the backTexture, so a change in pixi.js exposing the backTexture as public is probably required.

For the demo, this filter relies on the objects being transparent, so it won't have an effect without lowering the fish' alpha.
Also missing a screenshot config for the docs currently since that relies on the transparent fish.

blendRequired in combination with padding will currently crash the webgpu renderer, so I'm setting padding to 0 right now, once that's fixed that can be removed.

The final blend probably needs some adjustments, I'm pretty sure it won't work with a transparent background currently. The final blend pass uses the input texture as a mask, discarding every pixel with an alpha of 0, there may be a better way of doing that.

Screenshot 2024-02-22 123647
Screenshot 2024-02-20 140732

Copy link
Member

@bigtimebuddy bigtimebuddy left a comment

Choose a reason for hiding this comment

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

Awesome super useful filter.

src/backdrop-blur/BackdropBlurFilter.ts Outdated Show resolved Hide resolved
src/backdrop-blur/BackdropBlurFilter.ts Show resolved Hide resolved
src/backdrop-blur/BackdropBlurFilter.ts Outdated Show resolved Hide resolved
@bigtimebuddy
Copy link
Member

bigtimebuddy commented Feb 23, 2024

The only other missing piece is adding a screenshot (see ./scripts/screenshots/) and adding it to the Readme. These are useful thumbnails in the docs too. If you don't want to do that, I can add it later.

@minetoblend
Copy link
Contributor Author

I'm not entirely sure on how to do the screenshots since I need the fish to be transparent for the filter to show up. Should I add an extra config option to the screenshots script to lower the opacity?

@bigtimebuddy
Copy link
Member

Yeah, I think we need to add some other option to the screenshots that involves adding another surface on-top. Maybe just drawing a circle or something and adding the filter to that.

@bigtimebuddy bigtimebuddy merged commit d0e7a8a into pixijs:main Mar 6, 2024
1 check passed
@bigtimebuddy
Copy link
Member

@minetoblend thanks for this. I was messing around with this filter and noticed something interesting. For rectangular shapes, it creates this inner drop-shadow. I did not expect that here.

https://jsfiddle.net/bigtimebuddy/wjkd8gra/

Screen Shot 2024-03-06 at 7 19 44 PM

@bigtimebuddy
Copy link
Member

Applying a filterArea seems to help: https://jsfiddle.net/bigtimebuddy/nshq51v6/

@reececomo
Copy link

Weirdest timing 😆 pixijs/pixijs#10201 (reply in thread)

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.

3 participants