Skip to content

Commit

Permalink
Add back and update Shockwave Filter
Browse files Browse the repository at this point in the history
  • Loading branch information
bbazukun123 committed Jan 2, 2024
1 parent 44bf1be commit 87caf19
Show file tree
Hide file tree
Showing 16 changed files with 481 additions and 6 deletions.
1 change: 1 addition & 0 deletions bundle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"@pixi/filter-radial-blur": "8.0.0",
"@pixi/filter-reflection": "8.0.0",
"@pixi/filter-rgb-split": "8.0.0",
"@pixi/filter-shockwave": "8.0.0",
"@pixi/filter-simple-lightmap": "8.0.0",
"@pixi/filter-tilt-shift": "8.0.0",
"@pixi/filter-twist": "8.0.0",
Expand Down
1 change: 1 addition & 0 deletions bundle/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export * from '@pixi/filter-pixelate';
export * from '@pixi/filter-radial-blur';
export * from '@pixi/filter-reflection';
export * from '@pixi/filter-rgb-split';
export * from '@pixi/filter-shockwave';
export * from '@pixi/filter-simple-lightmap';
export * from '@pixi/filter-tilt-shift';
export * from '@pixi/filter-twist';
Expand Down
2 changes: 1 addition & 1 deletion filters/ascii/src/ascii.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ struct AsciiUniforms {
struct GlobalFilterUniforms {
uInputSize:vec4<f32>,
uInputPixel:vec4<f32>,
uuInputClamp:vec4<f32>,
uInputClamp:vec4<f32>,
uOutputFrame:vec4<f32>,
uGlobalFrame:vec4<f32>,
uOutputTexture:vec4<f32>,
Expand Down
2 changes: 1 addition & 1 deletion filters/dot/src/dot.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ struct DotUniforms {
struct GlobalFilterUniforms {
uInputSize:vec4<f32>,
uInputPixel:vec4<f32>,
uuInputClamp:vec4<f32>,
uInputClamp:vec4<f32>,
uOutputFrame:vec4<f32>,
uGlobalFrame:vec4<f32>,
uOutputTexture:vec4<f32>,
Expand Down
2 changes: 1 addition & 1 deletion filters/glow/src/glow.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ struct GlowUniforms {
struct GlobalFilterUniforms {
uInputSize:vec4<f32>,
uInputPixel:vec4<f32>,
uuInputClamp:vec4<f32>,
uInputClamp:vec4<f32>,
uOutputFrame:vec4<f32>,
uGlobalFrame:vec4<f32>,
uOutputTexture:vec4<f32>,
Expand Down
2 changes: 1 addition & 1 deletion filters/rgb-split/src/rgb-split.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ struct RgbSplitUniforms {
struct GlobalFilterUniforms {
uInputSize:vec4<f32>,
uInputPixel:vec4<f32>,
uuInputClamp:vec4<f32>,
uInputClamp:vec4<f32>,
uOutputFrame:vec4<f32>,
uGlobalFrame:vec4<f32>,
uOutputTexture:vec4<f32>,
Expand Down
21 changes: 21 additions & 0 deletions filters/shockwave/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License

Copyright (c) 2013-2018 Mathew Groves, Chad Engler, Wei Zijun

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
25 changes: 25 additions & 0 deletions filters/shockwave/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# ShockwaveFilter

> PixiJS filter to apply a shockwave-type effect.
[View demo](https://filters.pixijs.download/main/demo/index.html?enabled=ShockwaveFilter)

## Installation

```bash
npm install @pixi/filter-shockwave
```

## Usage

```js
import {ShockwaveFilter} from '@pixi/filter-shockwave';
import {Container} from 'pixi.js';

const container = new Container();
container.filters = [new ShockwaveFilter()];
```

## Documentation

See https://filters.pixijs.download/main/docs/ShockwaveFilter.html
41 changes: 41 additions & 0 deletions filters/shockwave/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "@pixi/filter-shockwave",
"version": "8.0.0",
"main": "./dist/filter-shockwave.js",
"description": "PixiJS filter to apply a shockwave-type effect",
"author": "Mat Groves",
"contributors": [
"Matt Karl <[email protected]>"
],
"module": "./dist/filter-shockwave.mjs",
"exports": {
".": {
"import": "./dist/filter-shockwave.mjs",
"require": "./dist/filter-shockwave.js",
"types": "./index.d.ts"
}
},
"types": "./index.d.ts",
"homepage": "http://pixijs.com/",
"bugs": "https://github.com/pixijs/filters/issues",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/pixijs/filters.git",
"directory": "filters/shockwave"
},
"publishConfig": {
"access": "public"
},
"files": [
"dist",
"index.d.ts"
],
"peerDependencies": {
"pixi.js": "^8.0.0-X"
},
"devDependencies": {
"pixi.js": "^8.0.0-X",
"@tools/fragments": "8.0.0"
}
}
203 changes: 203 additions & 0 deletions filters/shockwave/src/ShockwaveFilter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
import { vertex, wgslVertex } from '@tools/fragments';
import fragment from './shockwave.frag';
import source from './shockwave.wgsl';
import {
Filter,
FilterOptions,
FilterSystem,
GlProgram,
GpuProgram,
PointData,
RenderSurface,
Texture,
UniformGroup,
} from 'pixi.js';

/**
* Options for ShockwaveFilter
* @memberof filters
*/
export interface ShockwaveFilterOptions
{
/**
* The `x` and `y` center coordinates to change the position of the center of the circle of effect.
* @default [0,0]
*/
center?: PointData;
/**
* The speed about the shockwave ripples out. The unit is `pixel-per-second`
* @default 500
*/
speed?: number;
/**
* The amplitude of the shockwave
* @default 30
*/
amplitude?: number;
/**
* The wavelength of the shockwave
* @default 160
*/
wavelength?: number;
/**
* The brightness of the shockwave
* @default 1
*/
brightness?: number;
/**
* The maximum radius of shockwave. less than `0` means the max is an infinite distance
* @default -1
*/
radius?: number;
}

/**
* A Noise effect filter.
*
* original filter: https://github.com/evanw/glfx.js/blob/master/src/filters/adjust/noise.js
* @memberof filters
* @author Vico @vicocotea
*/
export class ShockwaveFilter extends Filter
{
/** Default shockwave filter options */
public static readonly defaultOptions: ShockwaveFilterOptions & Partial<FilterOptions> = {
...Filter.defaultOptions,
/** The `x` and `y` center coordinates to change the position of the center of the circle of effect. */
center: { x: 0, y: 0 },
/** The speed about the shockwave ripples out. The unit is `pixel-per-second` */
speed: 500,
/** The amplitude of the shockwave */
amplitude: 30,
/** The wavelength of the shockwave */
wavelength: 160,
/** The brightness of the shockwave */
brightness: 1,
/** The maximum radius of shockwave. less than `0` means the max is an infinite distance */
radius: -1,
};

public uniforms: {
uTime: number;
uCenter: PointData;
uSpeed: number;
uWave: Float32Array;
};

/** Sets the elapsed time of the shockwave. It could control the current size of shockwave. */
public time: number;

/**
* @param options
*/
constructor(options: ShockwaveFilterOptions = {})
{
options = { ...ShockwaveFilter.defaultOptions, ...options };

const gpuProgram = new GpuProgram({
vertex: {
source: wgslVertex,
entryPoint: 'mainVertex',
},
fragment: {
source,
entryPoint: 'mainFragment',
},
});

const glProgram = new GlProgram({
vertex,
fragment,
name: 'shockwave-filter'
});

super({
gpuProgram,
glProgram,
resources: {
shockwaveUniforms: new UniformGroup({
uTime: { value: 0, type: 'f32' },
uCenter: { value: options.center, type: 'vec2<f32>' },
uSpeed: { value: options.speed, type: 'f32' },
uWave: { value: new Float32Array(4), type: 'vec4<f32>' },
})
},
});

this.time = 0;

this.uniforms = this.resources.shockwaveUniforms.uniforms;

Object.assign(this, options);
}

public override apply(
filterManager: FilterSystem,
input: Texture,
output: RenderSurface,
clearMode: boolean
): void
{
// There is no set/get of `time`, for performance.
// Because in the most real cases, `time` will be changed in ever game tick.
// Use set/get will take more function-call.
this.uniforms.uTime = this.time;
filterManager.applyFilter(this, input, output, clearMode);
}

/**
* The `x` and `y` center coordinates to change the position of the center of the circle of effect.
* @default [0,0]
*/
get center(): PointData { return this.uniforms.uCenter; }
set center(value: PointData) { this.uniforms.uCenter = value; }

/**
* Sets the center of the effect in normalized screen coords on the `x` axis
* @default 0
*/
get centerX(): number { return this.uniforms.uCenter.x; }
set centerX(value: number) { this.uniforms.uCenter.x = value; }

/**
* Sets the center of the effect in normalized screen coords on the `y` axis
* @default 0
*/
get centerY(): number { return this.uniforms.uCenter.y; }
set centerY(value: number) { this.uniforms.uCenter.y = value; }

/**
* The speed about the shockwave ripples out. The unit is `pixel-per-second`
* @default 500
*/
get speed(): number { return this.uniforms.uSpeed; }
set speed(value: number) { this.uniforms.uSpeed = value; }

/**
* The amplitude of the shockwave
* @default 30
*/
get amplitude(): number { return this.uniforms.uWave[0]; }
set amplitude(value: number) { this.uniforms.uWave[0] = value; }

/**
* The wavelength of the shockwave
* @default 160
*/
get wavelength(): number { return this.uniforms.uWave[1]; }
set wavelength(value: number) { this.uniforms.uWave[1] = value; }

/**
* The brightness of the shockwave
* @default 1
*/
get brightness(): number { return this.uniforms.uWave[2]; }
set brightness(value: number) { this.uniforms.uWave[2] = value; }

/**
* The maximum radius of shockwave. less than `0` means the max is an infinite distance
* @default -1
*/
get radius(): number { return this.uniforms.uWave[3]; }
set radius(value: number) { this.uniforms.uWave[3] = value; }
}
1 change: 1 addition & 0 deletions filters/shockwave/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './ShockwaveFilter';
Loading

0 comments on commit 87caf19

Please sign in to comment.