Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@pixi/filter-glitch

Package Overview
Dependencies
Maintainers
3
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pixi/filter-glitch - npm Package Compare versions

Comparing version 4.2.0 to 5.0.0

dist/filter-glitch.mjs

116

dist/filter-glitch.js

@@ -1,9 +0,115 @@

/*!
* @pixi/filter-glitch - v4.2.0
* Compiled Fri, 05 Aug 2022 19:53:35 UTC
"use strict";/*!
* @pixi/filter-glitch - v5.0.0
* Compiled Fri, 23 Sep 2022 20:48:56 UTC
*
* @pixi/filter-glitch is licensed under the MIT License.
* http://www.opensource.org/licenses/mit-license
*/
var __filters=function(e,t,i,n){"use strict";var r=function(e,t){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])})(e,t)};Object.create;Object.create;var o=function(e){function o(n){var r=e.call(this,"attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\n\nuniform mat3 projectionMatrix;\n\nvarying vec2 vTextureCoord;\n\nvoid main(void)\n{\n gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}","// precision highp float;\n\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\n\nuniform vec4 filterArea;\nuniform vec4 filterClamp;\nuniform vec2 dimensions;\nuniform float aspect;\n\nuniform sampler2D displacementMap;\nuniform float offset;\nuniform float sinDir;\nuniform float cosDir;\nuniform int fillMode;\n\nuniform float seed;\nuniform vec2 red;\nuniform vec2 green;\nuniform vec2 blue;\n\nconst int TRANSPARENT = 0;\nconst int ORIGINAL = 1;\nconst int LOOP = 2;\nconst int CLAMP = 3;\nconst int MIRROR = 4;\n\nvoid main(void)\n{\n vec2 coord = (vTextureCoord * filterArea.xy) / dimensions;\n\n if (coord.x > 1.0 || coord.y > 1.0) {\n return;\n }\n\n float cx = coord.x - 0.5;\n float cy = (coord.y - 0.5) * aspect;\n float ny = (-sinDir * cx + cosDir * cy) / aspect + 0.5;\n\n // displacementMap: repeat\n // ny = ny > 1.0 ? ny - 1.0 : (ny < 0.0 ? 1.0 + ny : ny);\n\n // displacementMap: mirror\n ny = ny > 1.0 ? 2.0 - ny : (ny < 0.0 ? -ny : ny);\n\n vec4 dc = texture2D(displacementMap, vec2(0.5, ny));\n\n float displacement = (dc.r - dc.g) * (offset / filterArea.x);\n\n coord = vTextureCoord + vec2(cosDir * displacement, sinDir * displacement * aspect);\n\n if (fillMode == CLAMP) {\n coord = clamp(coord, filterClamp.xy, filterClamp.zw);\n } else {\n if( coord.x > filterClamp.z ) {\n if (fillMode == TRANSPARENT) {\n discard;\n } else if (fillMode == LOOP) {\n coord.x -= filterClamp.z;\n } else if (fillMode == MIRROR) {\n coord.x = filterClamp.z * 2.0 - coord.x;\n }\n } else if( coord.x < filterClamp.x ) {\n if (fillMode == TRANSPARENT) {\n discard;\n } else if (fillMode == LOOP) {\n coord.x += filterClamp.z;\n } else if (fillMode == MIRROR) {\n coord.x *= -filterClamp.z;\n }\n }\n\n if( coord.y > filterClamp.w ) {\n if (fillMode == TRANSPARENT) {\n discard;\n } else if (fillMode == LOOP) {\n coord.y -= filterClamp.w;\n } else if (fillMode == MIRROR) {\n coord.y = filterClamp.w * 2.0 - coord.y;\n }\n } else if( coord.y < filterClamp.y ) {\n if (fillMode == TRANSPARENT) {\n discard;\n } else if (fillMode == LOOP) {\n coord.y += filterClamp.w;\n } else if (fillMode == MIRROR) {\n coord.y *= -filterClamp.w;\n }\n }\n }\n\n gl_FragColor.r = texture2D(uSampler, coord + red * (1.0 - seed * 0.4) / filterArea.xy).r;\n gl_FragColor.g = texture2D(uSampler, coord + green * (1.0 - seed * 0.3) / filterArea.xy).g;\n gl_FragColor.b = texture2D(uSampler, coord + blue * (1.0 - seed * 0.2) / filterArea.xy).b;\n gl_FragColor.a = texture2D(uSampler, coord).a;\n}\n")||this;return r.offset=100,r.fillMode=o.TRANSPARENT,r.average=!1,r.seed=0,r.minSize=8,r.sampleSize=512,r._slices=0,r._offsets=new Float32Array(1),r._sizes=new Float32Array(1),r._direction=-1,r.uniforms.dimensions=new Float32Array(2),r._canvas=document.createElement("canvas"),r._canvas.width=4,r._canvas.height=r.sampleSize,r.texture=t.Texture.from(r._canvas,{scaleMode:i.SCALE_MODES.NEAREST}),Object.assign(r,o.defaults,n),r}return function(e,t){function i(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(i.prototype=t.prototype,new i)}(o,e),o.prototype.apply=function(e,t,i,n){var r=t.filterFrame,o=r.width,s=r.height;this.uniforms.dimensions[0]=o,this.uniforms.dimensions[1]=s,this.uniforms.aspect=s/o,this.uniforms.seed=this.seed,this.uniforms.offset=this.offset,this.uniforms.fillMode=this.fillMode,e.applyFilter(this,t,i,n)},o.prototype._randomizeSizes=function(){var e=this._sizes,t=this._slices-1,i=this.sampleSize,n=Math.min(this.minSize/i,.9/this._slices);if(this.average){for(var r=this._slices,o=1,s=0;s<t;s++){var f=o/(r-s),l=Math.max(f*(1-.6*Math.random()),n);e[s]=l,o-=l}e[t]=o}else{o=1;var a=Math.sqrt(1/this._slices);for(s=0;s<t;s++){l=Math.max(a*o*Math.random(),n);e[s]=l,o-=l}e[t]=o}this.shuffle()},o.prototype.shuffle=function(){for(var e=this._sizes,t=this._slices-1;t>0;t--){var i=Math.random()*t>>0,n=e[t];e[t]=e[i],e[i]=n}},o.prototype._randomizeOffsets=function(){for(var e=0;e<this._slices;e++)this._offsets[e]=Math.random()*(Math.random()<.5?-1:1)},o.prototype.refresh=function(){this._randomizeSizes(),this._randomizeOffsets(),this.redraw()},o.prototype.redraw=function(){var e,t=this.sampleSize,i=this.texture,n=this._canvas.getContext("2d");n.clearRect(0,0,8,t);for(var r=0,o=0;o<this._slices;o++){e=Math.floor(256*this._offsets[o]);var s=this._sizes[o]*t,f=e>0?e:0,l=e<0?-e:0;n.fillStyle="rgba("+f+", "+l+", 0, 1)",n.fillRect(0,r>>0,t,s+1>>0),r+=s}i.baseTexture.update(),this.uniforms.displacementMap=i},Object.defineProperty(o.prototype,"sizes",{get:function(){return this._sizes},set:function(e){for(var t=Math.min(this._slices,e.length),i=0;i<t;i++)this._sizes[i]=e[i]},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"offsets",{get:function(){return this._offsets},set:function(e){for(var t=Math.min(this._slices,e.length),i=0;i<t;i++)this._offsets[i]=e[i]},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"slices",{get:function(){return this._slices},set:function(e){this._slices!==e&&(this._slices=e,this.uniforms.slices=e,this._sizes=this.uniforms.slicesWidth=new Float32Array(e),this._offsets=this.uniforms.slicesOffset=new Float32Array(e),this.refresh())},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"direction",{get:function(){return this._direction},set:function(e){if(this._direction!==e){this._direction=e;var t=e*n.DEG_TO_RAD;this.uniforms.sinDir=Math.sin(t),this.uniforms.cosDir=Math.cos(t)}},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"red",{get:function(){return this.uniforms.red},set:function(e){this.uniforms.red=e},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"green",{get:function(){return this.uniforms.green},set:function(e){this.uniforms.green=e},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"blue",{get:function(){return this.uniforms.blue},set:function(e){this.uniforms.blue=e},enumerable:!1,configurable:!0}),o.prototype.destroy=function(){var e;null===(e=this.texture)||void 0===e||e.destroy(!0),this.texture=this._canvas=this.red=this.green=this.blue=this._sizes=this._offsets=null},o.defaults={slices:5,offset:100,direction:0,fillMode:0,average:!1,seed:0,red:[0,0],green:[0,0],blue:[0,0],minSize:8,sampleSize:512},o.TRANSPARENT=0,o.ORIGINAL=1,o.LOOP=2,o.CLAMP=3,o.MIRROR=4,o}(t.Filter);return e.GlitchFilter=o,Object.defineProperty(e,"__esModule",{value:!0}),e}({},PIXI,PIXI,PIXI);Object.assign(PIXI.filters,__filters);
*/Object.defineProperty(exports,"__esModule",{value:!0});var c=require("@pixi/core"),h=`attribute vec2 aVertexPosition;
attribute vec2 aTextureCoord;
uniform mat3 projectionMatrix;
varying vec2 vTextureCoord;
void main(void)
{
gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);
vTextureCoord = aTextureCoord;
}`,m=`// precision highp float;
varying vec2 vTextureCoord;
uniform sampler2D uSampler;
uniform vec4 filterArea;
uniform vec4 filterClamp;
uniform vec2 dimensions;
uniform float aspect;
uniform sampler2D displacementMap;
uniform float offset;
uniform float sinDir;
uniform float cosDir;
uniform int fillMode;
uniform float seed;
uniform vec2 red;
uniform vec2 green;
uniform vec2 blue;
const int TRANSPARENT = 0;
const int ORIGINAL = 1;
const int LOOP = 2;
const int CLAMP = 3;
const int MIRROR = 4;
void main(void)
{
vec2 coord = (vTextureCoord * filterArea.xy) / dimensions;
if (coord.x > 1.0 || coord.y > 1.0) {
return;
}
float cx = coord.x - 0.5;
float cy = (coord.y - 0.5) * aspect;
float ny = (-sinDir * cx + cosDir * cy) / aspect + 0.5;
// displacementMap: repeat
// ny = ny > 1.0 ? ny - 1.0 : (ny < 0.0 ? 1.0 + ny : ny);
// displacementMap: mirror
ny = ny > 1.0 ? 2.0 - ny : (ny < 0.0 ? -ny : ny);
vec4 dc = texture2D(displacementMap, vec2(0.5, ny));
float displacement = (dc.r - dc.g) * (offset / filterArea.x);
coord = vTextureCoord + vec2(cosDir * displacement, sinDir * displacement * aspect);
if (fillMode == CLAMP) {
coord = clamp(coord, filterClamp.xy, filterClamp.zw);
} else {
if( coord.x > filterClamp.z ) {
if (fillMode == TRANSPARENT) {
discard;
} else if (fillMode == LOOP) {
coord.x -= filterClamp.z;
} else if (fillMode == MIRROR) {
coord.x = filterClamp.z * 2.0 - coord.x;
}
} else if( coord.x < filterClamp.x ) {
if (fillMode == TRANSPARENT) {
discard;
} else if (fillMode == LOOP) {
coord.x += filterClamp.z;
} else if (fillMode == MIRROR) {
coord.x *= -filterClamp.z;
}
}
if( coord.y > filterClamp.w ) {
if (fillMode == TRANSPARENT) {
discard;
} else if (fillMode == LOOP) {
coord.y -= filterClamp.w;
} else if (fillMode == MIRROR) {
coord.y = filterClamp.w * 2.0 - coord.y;
}
} else if( coord.y < filterClamp.y ) {
if (fillMode == TRANSPARENT) {
discard;
} else if (fillMode == LOOP) {
coord.y += filterClamp.w;
} else if (fillMode == MIRROR) {
coord.y *= -filterClamp.w;
}
}
}
gl_FragColor.r = texture2D(uSampler, coord + red * (1.0 - seed * 0.4) / filterArea.xy).r;
gl_FragColor.g = texture2D(uSampler, coord + green * (1.0 - seed * 0.3) / filterArea.xy).g;
gl_FragColor.b = texture2D(uSampler, coord + blue * (1.0 - seed * 0.2) / filterArea.xy).b;
gl_FragColor.a = texture2D(uSampler, coord).a;
}
`;const d=class extends c.Filter{constructor(e){super(h,m),this.offset=100,this.fillMode=d.TRANSPARENT,this.average=!1,this.seed=0,this.minSize=8,this.sampleSize=512,this._slices=0,this._offsets=new Float32Array(1),this._sizes=new Float32Array(1),this._direction=-1,this.uniforms.dimensions=new Float32Array(2),this._canvas=document.createElement("canvas"),this._canvas.width=4,this._canvas.height=this.sampleSize,this.texture=c.Texture.from(this._canvas,{scaleMode:c.SCALE_MODES.NEAREST}),Object.assign(this,d.defaults,e)}apply(e,s,i,t){const{width:n,height:r}=s.filterFrame;this.uniforms.dimensions[0]=n,this.uniforms.dimensions[1]=r,this.uniforms.aspect=r/n,this.uniforms.seed=this.seed,this.uniforms.offset=this.offset,this.uniforms.fillMode=this.fillMode,e.applyFilter(this,s,i,t)}_randomizeSizes(){const e=this._sizes,s=this._slices-1,i=this.sampleSize,t=Math.min(this.minSize/i,.9/this._slices);if(this.average){const n=this._slices;let r=1;for(let o=0;o<s;o++){const a=r/(n-o),f=Math.max(a*(1-Math.random()*.6),t);e[o]=f,r-=f}e[s]=r}else{let n=1;const r=Math.sqrt(1/this._slices);for(let o=0;o<s;o++){const a=Math.max(r*n*Math.random(),t);e[o]=a,n-=a}e[s]=n}this.shuffle()}shuffle(){const e=this._sizes,s=this._slices-1;for(let i=s;i>0;i--){const t=Math.random()*i>>0,n=e[i];e[i]=e[t],e[t]=n}}_randomizeOffsets(){for(let e=0;e<this._slices;e++)this._offsets[e]=Math.random()*(Math.random()<.5?-1:1)}refresh(){this._randomizeSizes(),this._randomizeOffsets(),this.redraw()}redraw(){const e=this.sampleSize,s=this.texture,i=this._canvas.getContext("2d");i.clearRect(0,0,8,e);let t,n=0;for(let r=0;r<this._slices;r++){t=Math.floor(this._offsets[r]*256);const o=this._sizes[r]*e,a=t>0?t:0,f=t<0?-t:0;i.fillStyle=`rgba(${a}, ${f}, 0, 1)`,i.fillRect(0,n>>0,e,o+1>>0),n+=o}s.baseTexture.update(),this.uniforms.displacementMap=s}set sizes(e){const s=Math.min(this._slices,e.length);for(let i=0;i<s;i++)this._sizes[i]=e[i]}get sizes(){return this._sizes}set offsets(e){const s=Math.min(this._slices,e.length);for(let i=0;i<s;i++)this._offsets[i]=e[i]}get offsets(){return this._offsets}get slices(){return this._slices}set slices(e){this._slices!==e&&(this._slices=e,this.uniforms.slices=e,this._sizes=this.uniforms.slicesWidth=new Float32Array(e),this._offsets=this.uniforms.slicesOffset=new Float32Array(e),this.refresh())}get direction(){return this._direction}set direction(e){if(this._direction===e)return;this._direction=e;const s=e*c.DEG_TO_RAD;this.uniforms.sinDir=Math.sin(s),this.uniforms.cosDir=Math.cos(s)}get red(){return this.uniforms.red}set red(e){this.uniforms.red=e}get green(){return this.uniforms.green}set green(e){this.uniforms.green=e}get blue(){return this.uniforms.blue}set blue(e){this.uniforms.blue=e}destroy(){var e;(e=this.texture)==null||e.destroy(!0),this.texture=this._canvas=this.red=this.green=this.blue=this._sizes=this._offsets=null}};let l=d;l.defaults={slices:5,offset:100,direction:0,fillMode:0,average:!1,seed:0,red:[0,0],green:[0,0],blue:[0,0],minSize:8,sampleSize:512},l.TRANSPARENT=0,l.ORIGINAL=1,l.LOOP=2,l.CLAMP=3,l.MIRROR=4,exports.GlitchFilter=l;
//# sourceMappingURL=filter-glitch.js.map

17

index.d.ts

@@ -1,5 +0,5 @@

import type { CLEAR_MODES } from '@pixi/constants';
import type { CLEAR_MODES } from '@pixi/core';
import { Filter } from '@pixi/core';
import type { FilterSystem } from '@pixi/core';
import type { IPoint } from '@pixi/math';
import type { IPoint } from '@pixi/core';
import type { RenderTexture } from '@pixi/core';

@@ -14,3 +14,2 @@ import { Texture } from '@pixi/core';

* @extends PIXI.Filter
* @memberof PIXI.filters
* @see {@link https://www.npmjs.com/package/@pixi/filter-glitch|@pixi/filter-glitch}

@@ -66,3 +65,3 @@ * @see {@link https://www.npmjs.com/package/pixi-filters|pixi-filters}

* Must be initialized to something different than the default value.
*/
*/
private _direction;

@@ -75,7 +74,7 @@ /**

* @param {number} [options.fillMode=0] - The fill mode of the space after the offset. Acceptable values:
* - `0` {@link PIXI.filters.GlitchFilter.TRANSPARENT TRANSPARENT}
* - `1` {@link PIXI.filters.GlitchFilter.ORIGINAL ORIGINAL}
* - `2` {@link PIXI.filters.GlitchFilter.LOOP LOOP}
* - `3` {@link PIXI.filters.GlitchFilter.CLAMP CLAMP}
* - `4` {@link PIXI.filters.GlitchFilter.MIRROR MIRROR}
* - `0` {@link GlitchFilter.TRANSPARENT TRANSPARENT}
* - `1` {@link GlitchFilter.ORIGINAL ORIGINAL}
* - `2` {@link GlitchFilter.LOOP LOOP}
* - `3` {@link GlitchFilter.CLAMP CLAMP}
* - `4` {@link GlitchFilter.MIRROR MIRROR}
* @param {number} [options.seed=0] - A seed value for randomizing glitch effect.

@@ -82,0 +81,0 @@ * @param {boolean} [options.average=false] - `true` will divide the bands roughly based on equal amounts

{
"name": "@pixi/filter-glitch",
"version": "4.2.0",
"main": "dist/filter-glitch.cjs.js",
"bundle": "dist/filter-glitch.js",
"version": "5.0.0",
"main": "./dist/filter-glitch.js",
"description": "PixiJS filter to apply a glitch effect",
"author": "finscn <finscn@gmail.com>",
"module": "dist/filter-glitch.esm.mjs",
"module": "./dist/filter-glitch.mjs",
"exports": {
".": {
"import": "./dist/filter-glitch.esm.mjs",
"require": "./dist/filter-glitch.cjs.js",
"import": "./dist/filter-glitch.mjs",
"require": "./dist/filter-glitch.js",
"types": "./index.d.ts"
}
},
"types": "index.d.ts",
"types": "./index.d.ts",
"homepage": "http://pixijs.com/",

@@ -33,13 +32,9 @@ "bugs": "https://github.com/pixijs/filters/issues",

"peerDependencies": {
"@pixi/constants": "^6.0.0",
"@pixi/core": "^6.0.0",
"@pixi/math": "^6.0.0"
"@pixi/core": "^7.0.0-X"
},
"devDependencies": {
"@pixi/constants": "^6.0.0",
"@pixi/core": "^6.0.0",
"@pixi/math": "^6.0.0",
"@tools/fragments": "4.1.3"
"@pixi/core": "^7.0.0-X",
"@tools/fragments": "5.0.0"
},
"gitHead": "dc16782d00fffb8c02d30cc32146d9c6a40599cb"
"gitHead": "2bec8c5024e4086e5aada8e471820bddc8ede687"
}

@@ -23,2 +23,2 @@ # GlitchFilter

See https://pixijs.github.io/pixi-filters/docs
See https://filters.pixijs.download/main/docs/GlitchFilter.html

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc