PIXI.filters.TopFilter = class extends PIXI.Filter { constructor(uniforms = {}) { var vertexSrc = ` attribute vec2 aVertexPosition; attribute vec2 aTextureCoord; uniform mat3 projectionMatrix; uniform mat3 translationMatrix; uniform mat3 uTransform; varying vec2 vTextureCoord; void main(void) { gl_Position = vec4((projectionMatrix * translationMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0); vTextureCoord = (uTransform * vec3(aTextureCoord, 1.0)).xy; } `; var fragmentSrc = ` varying vec2 vTextureCoord; uniform sampler2D texture; uniform sampler2D texture2; uniform sampler2D disp; // uniform float time; // uniform float _rot; uniform float dispFactor; uniform float effectFactor; // vec2 rotate(vec2 v, float a) { // float s = sin(a); // float c = cos(a); // mat2 m = mat2(c, -s, s, c); // return m * v; // } void main(void) { vec2 uv = vTextureCoord; vec4 disp = texture2D(disp, uv); vec2 distortedPosition = vec2(uv.x + dispFactor * (disp.r*effectFactor), uv.y); vec2 distortedPosition2 = vec2(uv.x - (1.0 - dispFactor) * (disp.r*effectFactor), uv.y); vec4 _texture = texture2D(texture, distortedPosition); vec4 _texture2 = texture2D(texture2, distortedPosition2); vec4 finalTexture = mix(_texture, _texture2, dispFactor); if(uv.x < .05) { finalTexture *= uv.x/.05; } if(uv.x > .95) { finalTexture *= (1.0-uv.x)/.05; } if(uv.y < .05) { finalTexture *= uv.y/.05; } if(uv.y > .95) { finalTexture *= (1.0-uv.y)/.05; } gl_FragColor = finalTexture; // gl_FragColor = disp; } `; super( null, // vertex shader fragmentSrc, // fragment shader uniforms // uniforms ); } };