Skip to content

Commit

Permalink
Chore: Motion Blur Filter Deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
bbazukun123 committed Feb 8, 2024
1 parent 9d610bb commit 3e84b3e
Showing 1 changed file with 38 additions and 7 deletions.
45 changes: 38 additions & 7 deletions src/motion-blur/MotionBlurFilter.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Filter, GlProgram, GpuProgram } from 'pixi.js';
/* eslint-disable max-len */
// eslint-disable-next-line camelcase
import { deprecation, Filter, GlProgram, GpuProgram, ObservablePoint, PointData, v8_0_0 } from 'pixi.js';
import { vertex, wgslVertex } from '../defaults';
import fragment from './motion-blur.frag';
import source from './motion-blur.wgsl';

import type { PointData } from 'pixi.js';

export interface MotionBlurFilterOptions
{
/**
Expand Down Expand Up @@ -51,11 +51,36 @@ export class MotionBlurFilter extends Filter

private _kernelSize!: number;

constructor(options?: MotionBlurFilterOptions)
constructor(options?: MotionBlurFilterOptions);
/**
* @deprecated since 8.0.0
*
* @param {PIXI.ObservablePoint|PIXI.PointData|number[]} [velocity=[0, 0]] - Sets the velocity of the motion for blur effect.
* @param {number} [kernelSize=5] - The kernelSize of the blur filter. Must be odd number >= 5
* @param {number} [offset=0] - The offset of the blur filter.
*/
constructor(velocity?: number[] | PointData | ObservablePoint, kernelSize?: number, offset?: number);
constructor(...args: [MotionBlurFilterOptions?] | [(number[] | PointData | ObservablePoint)?, number?, number?])
{
let options = args[0] ?? {};

if (Array.isArray(options) || ('x' in options && 'y' in options) || options instanceof ObservablePoint)
{
// eslint-disable-next-line max-len
deprecation(v8_0_0, 'MotionBlurFilter constructor params are now options object. See params: { velocity, kernelSize, offset }');

const x = 'x' in options ? options.x : options[0];
const y = 'y' in options ? options.y : options[1];

options = { velocity: { x, y } };

if (args[1]) options.kernelSize = args[1];
if (args[2]) options.offset = args[2];
}

options = { ...MotionBlurFilter.DEFAULT_OPTIONS, ...options };

const gpuProgram = new GpuProgram({
const gpuProgram = GpuProgram.from({
vertex: {
source: wgslVertex,
entryPoint: 'mainVertex',
Expand All @@ -66,7 +91,7 @@ export class MotionBlurFilter extends Filter
},
});

const glProgram = new GlProgram({
const glProgram = GlProgram.from({
vertex,
fragment,
name: 'motion-blur-filter',
Expand Down Expand Up @@ -96,8 +121,14 @@ export class MotionBlurFilter extends Filter
* @default {x:0,y:0}
*/
get velocity(): PointData { return this.uniforms.uVelocity; }
set velocity(value: PointData)
set velocity(value: PointData | number[])
{
if (Array.isArray(value))
{
deprecation(v8_0_0, 'MotionBlurFilter.velocity now only accepts {x, y} PointData type.');
value = { x: value[0], y: value[1] };
}

this.uniforms.uVelocity = value;
this._updateDirty();
}
Expand Down

0 comments on commit 3e84b3e

Please sign in to comment.