Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
swampthang

Motion Blur offering

Recommended Posts

I've seen lots of posts on Stack Overflow as well as here regarding animating motion blur. I wanted to share my codepen in case it helps someone else or spurs a thought that leads to a better solution. It's not the pithiest code and I'm sure I'll end up tweaking it once I get it into my Electron app. 

 

The only thing I noticed, and it's not as big of a deal to me since I'm using an Electron app that only uses Chromium, but FireFox isn't showing the underlying elements. If you run inspector you can see that they're being animated and positioned properly but they don't show up. Not sure what the issue is. If I use createElementNS to create the div elements it doesn't utilize the blur filter in Chrome. But, if I don't use createElementNS to create the filters, it doesn't work in Chrome. 

 

Thoughts?

See the Pen dRYXjO by swampthang (@swampthang) on CodePen

  • Like 2
Link to comment
Share on other sites

Looks good! Did you come across any good resources?

 

Here's a motion blur demo I made for @PointC using Pixi. The logic should work the same if somebody wanted to use it with svg or canvas.

 

See the Pen a01012b229e6e2ace239cb83a754b64f by osublake (@osublake) on CodePen

 

 

 

  • Like 4
Link to comment
Share on other sites

Back in the day Flash SWF output was perfect for this type of effect. But now canvas is the best choice for non CSS motion blur. Also SVG displacement map and turbulence can work with noised image.

 

But you can create fake Motion blur with CSS using a mix of box-shadow and text-shadow adjusting the spread and color alpha, since CSS Filters is not that widely supported.

 

GSAP CSS Motion blur effect:

 

See the Pen QNGQaN by jonathan (@jonathan) on CodePen


Or using a straight CSS animation motion blur effect:

 

See the Pen pqdni by jonathan (@jonathan) on CodePen

 

Happy Tweenning :)

 

 

  • Like 4
Link to comment
Share on other sites

1 hour ago, OSUblake said:

Looks good! Did you come across any good resources?

 

Hey, Blake. Resources for what, the motion blur? 

Link to comment
Share on other sites

20 minutes ago, swampthang said:

 

Hey, Blake. Resources for what, the motion blur? 

 

Yeah. Most of the articles I've come across seem to be pretty complicated.

Link to comment
Share on other sites

The biggest issue for me was being able to make sure it made it to the canvas. Also, in the app, there could be multiple instances of this animation, each in its own foreignObject. So, I needed to be sure I could place the filters inside the foreign object itself and have them work, which they did in Chrome.

 

The only attributes I needed to control were the feOffset's dx and dy and feGaussianBlur's stdDeviation so I didn't really need to dig too deep. I didn't want to have to include another library either. Using staggerFromTo works well for me because I can tween the attributes along with the motion of the elements.

 

What I came up with works fine for me but for general web use, it might need some tweaking.

  • Like 1
Link to comment
Share on other sites

I'm a little surprised that having the filters in a foreignObject works. I thought that was kind of like a separate scope, and separate from the SVG. Maybe that's what the problem in Firefox is.

 

But the easiest way to render filters in canvas is to use canvas. I don't think a lot of people know that you can use CSS and SVG filters with canvas.

context.filter = "url(#svgFilter) blur(10px) sepia(60%)";
context.font = "36px Oswald";
context.fillText("Hello, World!", 50, 100);

 

 

 

 

 

 

 

  • Like 2
Link to comment
Share on other sites

That's pretty awesome, Blake. You're probably right on the FireFox issue. I have been able to add the animation to my app. Here's an MP4 that was exported from it. It animates in from the left and out to the right. This is an example of what I'm using GSAP to pull off. It is amazing.

 

 

This one animates vertically. Note that the blur filter picks up the actual letters, even though the filter is on the div inside the foreignObject before exporting to MP4. I use FFMPEG to create a PNG sequence and use it as the input.

 

 

Link to comment
Share on other sites

That looks really good! Is that all this app is going do?

 

I'm also really surprised at the real-time performance of your demo. Gaussian blurs are usually pretty slow to render.

Link to comment
Share on other sites

The app is mainly a text animation app. But it's become an app that allows you to import videos and audio as well as images. The name of it is Kinetic Text Animator. The dotcom URL is the name of the app. (Didn't want to post a link) 

 

The thing is, GSAP powers the timeline and ALL the animations. Anyone who wonders about the power of GSAP need wonder any longer. It's awesome. 

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

Blake, one of our users created this video using the app. The motion blur is visible but greatly reduced in the export. You might be right about the "iffy-ness" of using filters in the foreignObject...

 

 

Link to comment
Share on other sites

I don't know if this is the main source of the problem, but I see cropping going on in that video and your CodePen demo. Filters are applied to an area, which by default are set to -10% for x and y, and 120% for width and height. Any part of the blur or offset that extends beyond the defined filter area will be cropped.

 

It might also help defining filterUnits.

https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/filterUnits

Link to comment
Share on other sites

Thanks, Blake. Will play with filter settings. 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×