Updated to PixiJS v5.
This commit is contained in:
+16
-10
@@ -15,7 +15,7 @@
|
||||
* }).setup().run()
|
||||
*
|
||||
* // Add a video sprite
|
||||
* const sprite = new PIXI.Sprite(PIXI.Texture.fromVideo("assets/blurfilter.mp4"))
|
||||
* const sprite = new PIXI.Sprite(PIXI.Texture.from("assets/blurfilter.mp4"))
|
||||
* sprite.width = app.size.width
|
||||
* sprite.height = app.size.height
|
||||
* app.scene.addChild(sprite)
|
||||
@@ -41,10 +41,15 @@ export default class BlurFilter extends PIXI.Filter {
|
||||
}
|
||||
|
||||
apply(filterManager, input, output) {
|
||||
let renderTarget = filterManager.getRenderTarget(true)
|
||||
let renderTarget = filterManager.getFilterTexture()
|
||||
this.tiltShiftXFilter.apply(filterManager, input, renderTarget)
|
||||
this.tiltShiftYFilter.apply(filterManager, renderTarget, output)
|
||||
filterManager.returnRenderTarget(renderTarget)
|
||||
filterManager.returnFilterTexture(renderTarget)
|
||||
|
||||
// let renderTarget = filterManager.getRenderTarget(true)
|
||||
// this.tiltShiftXFilter.apply(filterManager, input, renderTarget)
|
||||
// this.tiltShiftYFilter.apply(filterManager, renderTarget, output)
|
||||
// filterManager.returnRenderTarget(renderTarget)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -121,19 +126,23 @@ class TiltShiftAxisFilter extends PIXI.Filter {
|
||||
|
||||
uniform mat3 projectionMatrix;
|
||||
|
||||
varying vec2 vVertexPosition;
|
||||
varying vec2 vTextureCoord;
|
||||
|
||||
void main(void) {
|
||||
gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);
|
||||
vVertexPosition = aVertexPosition;
|
||||
vTextureCoord = aTextureCoord;
|
||||
gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);
|
||||
}
|
||||
`
|
||||
|
||||
const fragment = `
|
||||
|
||||
varying vec2 vVertexPosition;
|
||||
varying vec2 vTextureCoord;
|
||||
|
||||
uniform vec4 filterArea;
|
||||
uniform sampler2D uSampler;
|
||||
|
||||
uniform int shape;
|
||||
uniform vec4 rectangle;
|
||||
uniform vec3 circle;
|
||||
@@ -146,15 +155,12 @@ class TiltShiftAxisFilter extends PIXI.Filter {
|
||||
}
|
||||
|
||||
void main(void) {
|
||||
// textureCoord to pixelCoord
|
||||
vec2 pixelCoord = vTextureCoord * filterArea.xy - vec2(4.0, 4.0); // FIXME: There's a shift of 4 * 4 pixels, don't know why...
|
||||
|
||||
bool inside = false;
|
||||
|
||||
if (shape == 1) {
|
||||
inside = distance(pixelCoord, circle.xy) <= circle.z;
|
||||
inside = distance(vVertexPosition, circle.xy) <= circle.z;
|
||||
} else if (shape == 2) {
|
||||
inside = pixelCoord.x >= rectangle.x && pixelCoord.x <= rectangle.z && pixelCoord.y >= rectangle.y && pixelCoord.y <= rectangle.w;
|
||||
inside = vVertexPosition.x >= rectangle.x && vVertexPosition.x <= rectangle.z && vVertexPosition.y >= rectangle.y && vVertexPosition.y <= rectangle.w;
|
||||
}
|
||||
|
||||
if (inside) {
|
||||
|
||||
Reference in New Issue
Block a user