Skip to content

feat(*): add blur filter support for canvas renderer#7

Merged
stepancar merged 2 commits intomasterfrom
feat/add-blur-filter-for-canvas-renderer
Apr 7, 2026
Merged

feat(*): add blur filter support for canvas renderer#7
stepancar merged 2 commits intomasterfrom
feat/add-blur-filter-for-canvas-renderer

Conversation

@stepancar
Copy link
Copy Markdown
Contributor

@stepancar stepancar commented Apr 7, 2026

airbnb/lottie-web#3189
Currently, the canvas renderer does not support the blur effect.

Before
Screenshot 2026-01-10 at 03 31 07

After
Screenshot 2026-01-10 at 03 32 19

Here, I’m using ctx.filter = 'blur(20px)'. I also experimented with ctx.filter = 'url(#svgFilter)', and that works as well.

https://github.com/airbnb/lottie-web/compare/master...stepancar:lottie-web:feat/blur-filter?expand=1

The only issue with that approach is that scaling becomes tricky, so I decided to go with the simpler solution as a first step.

@Tommy-Hu
Copy link
Copy Markdown

Tommy-Hu commented Apr 7, 2026

Cool! I just created a new dual-filter blur shader in my game a couple days ago! Let me review this!

var sigmaY = (dimensions == 2) ? 0 : sigma; // eslint-disable-line eqeqeq
var maxSigma = Math.max(sigmaX, sigmaY);

this.filterString = maxSigma > 0 ? 'blur(' + maxSigma + 'px)' : '';
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@stepancar This is fine but I'm curious, is it possible to use Kawase Dual Filter blur? Gaussian blur is very expensive to compute since it needs ~3+ render target switches on the GPU, which is a lot of overhead. Kawase Dual Filter is I assume due to memory consideration, the output of the blur filter will not be cached to memory for all the frames in the lottie?

Image

@stepancar
Copy link
Copy Markdown
Contributor Author

stepancar commented Apr 7, 2026

@Tommy-Hu Kawase Dual Filter is not supported by the Canvas 2D API, nor is it supported by SVG. It might be possible to implement it using an additional WebGL context, but the overhead of transferring from 2D to WebGL would likely negate any benefits.

@stepancar stepancar merged commit 2e2a666 into master Apr 7, 2026
@stepancar stepancar deleted the feat/add-blur-filter-for-canvas-renderer branch April 7, 2026 18:44
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.

2 participants