-
-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add back and update Shockwave Filter
- Loading branch information
1 parent
44bf1be
commit 87caf19
Showing
16 changed files
with
481 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './ShockwaveFilter'; |
Oops, something went wrong.