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: Pixelate Filter Tweaks #431

Merged
merged 2 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
17 changes: 5 additions & 12 deletions src/pixelate/PixelateFilter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Filter, GlProgram, GpuProgram, Point, UniformGroup } from 'pixi.js';
import { Filter, GlProgram, GpuProgram, Point } from 'pixi.js';
import { vertex, wgslVertex } from '../defaults';
import fragment from './pixelate.frag';
import source from './pixelate.wgsl';
Expand All @@ -15,20 +15,11 @@ type Size = number | number[] | Point;
*/
export class PixelateFilter extends Filter
{
/** Default values for options. */
public static readonly DEFAULT_SIZE: Size = 10;

/**
* @param {Point|Array<number>|number} [size=10] - Either the width/height of the size of the pixels, or square size
*/
constructor(size: Size)
constructor(size: Size = 10)
{
size = size ?? PixelateFilter.DEFAULT_SIZE;

const pixelateUniforms = new UniformGroup({
uSize: { value: new Float32Array(2), type: 'vec2<f32>' },
});

const gpuProgram = GpuProgram.from({
vertex: {
source: wgslVertex,
Expand All @@ -50,7 +41,9 @@ export class PixelateFilter extends Filter
gpuProgram,
glProgram,
resources: {
pixelateUniforms,
pixelateUniforms: {
uSize: { value: new Float32Array(2), type: 'vec2<f32>' },
},
},
});

Expand Down
Loading