pixijs / filters

Collection of community-authored custom display filters for PixiJS

Home Page:https://pixijs.io/filters/docs/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Padding should be adjusted as Motion Blur velocity changes.

st3v0 opened this issue · comments

I've discovered that the padding needs to be adjusted as the velocity values change, otherwise the blur effect is clipped. I raised this possibility a few months back (#208) however got no response.

I've fixed my own motion blur filter by extending the existing velocityChanged method and calculated the padding based on the largest velocity value (I'm not sure if this is perfect but it seems to work fine for our needs).

velocityChanged() {
    this.uniforms.uVelocity[0] = this._velocity.x;
    this.uniforms.uVelocity[1] = this._velocity.y;
    // The padding will be increased as the velocity and intern the blur size is changed
    this.padding = ~~(Math.abs(this._velocity.x > this._velocity.y ? this._velocity.x : this._velocity.y)) + 1;
}

Seems reasonable. Good idea.

This formula is slightly incorrect, it should be;

this.padding = ~~(Math.max(Math.abs(this._velocity.x), Math.abs(this._velocity.y))) + 1;

This is because velocity moving in a negative direction could be greater then positive direction movement. For example, if vel.x=10 and vel.y=-1000 the original formula would return 11, when in reality the object is moving much faster along the y and the padding should be much greater, ie. => 1001

Let's add this, wanna make a PR @st3v0. You've pretty much done all the hardwork already