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

Chore: Kawase Blur Filter Deprecations #426

Merged
merged 3 commits into from
Feb 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 47 additions & 5 deletions src/kawase-blur/KawaseBlurFilter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Filter, GlProgram, GpuProgram, TexturePool } from 'pixi.js';
import { deprecation, Filter, GlProgram, GpuProgram, TexturePool } from 'pixi.js';
import { vertex, wgslVertex } from '../defaults';
import fragment from './kawase-blur.frag';
import source from './kawase-blur.wgsl';
Expand Down Expand Up @@ -29,7 +29,7 @@ export interface KawaseBlurFilterOptions
* Sets the pixel size of the filter. Large size is blurrier. For advanced usage.
* @default {x:1,y:1}
*/
pixelSize?: PointData;
pixelSize?: PointData | number[] | number;
}

/**
Expand Down Expand Up @@ -61,8 +61,32 @@ export class KawaseBlurFilter extends Filter
private _blur!: number;
private _quality!: number;

constructor(options?: KawaseBlurFilterOptions)
constructor(options?: KawaseBlurFilterOptions);
/**
* @deprecated since 6.0.0
*
* @param {number|number[]} [blur=4] - The blur of the filter. Should be greater than `0`. If
* value is an Array, setting kernels.
* @param {number} [quality=3] - The quality of the filter. Should be an integer greater than `1`.
* @param {boolean} [clamp=false] - Clamp edges, useful for removing dark edges
* from fullscreen filters or bleeding to the edge of filterArea.
*/
constructor(blur?: number | number[], quality?: number, clamp?: boolean);
constructor(...args: [KawaseBlurFilterOptions?] | [(number | number[])?, number?, boolean?])
{
let options = args[0] ?? {};

if (typeof options === 'number' || Array.isArray(options))
{
// eslint-disable-next-line max-len
deprecation('6.0.0', 'KawaseBlurFilter constructor params are now options object. See params: { strength, quality, clamp, pixelSize }');

options = { strength: options as number | [number, number] };

if (args[1] !== undefined) options.quality = args[1];
if (args[2] !== undefined) options.clamp = args[2];
}

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

const gpuProgram = GpuProgram.from({
Expand Down Expand Up @@ -93,7 +117,7 @@ export class KawaseBlurFilter extends Filter

this.uniforms = this.resources.kawaseBlurUniforms.uniforms;

this._pixelSize = options.pixelSize ?? { x: 1, y: 1 };
this.pixelSize = options.pixelSize ?? { x: 1, y: 1 };

if (Array.isArray(options.strength))
{
Expand Down Expand Up @@ -210,7 +234,25 @@ export class KawaseBlurFilter extends Filter
* @default {x:1,y:1}
*/
get pixelSize(): PointData { return this._pixelSize; }
set pixelSize(value: PointData) { this._pixelSize = value; }
set pixelSize(value: PointData | number[] | number)
{
if (typeof value === 'number')
{
this.pixelSizeX = this.pixelSizeY = value;

return;
}

if (Array.isArray(value))
{
this.pixelSizeX = value[0];
this.pixelSizeY = value[1];

return;
}

this._pixelSize = value;
}

/**
* The size of the pixels on the `x` axis. Large size is blurrier. For advanced usage.
Expand Down
Loading