JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/pixi.js/4.8.2/pixi.min.js"></script>
<body>
<img id="grid_img" style="display: none"...
JavaScript
var app = new PIXI.Application(800, 250, {
backgroundColor: 0x1099bb
});
document.body.appendChild(app.view);
// create filter
var fragSrc = `
precision mediump float;
varying vec2 vTextureCoord;
uniform float intensity;
uniform sampler2D uSampler;
uniform vec4 filterArea;
uniform vec2 dimensions;
void main()
{
vec2 p = vTextureCoord;
float prop = filterArea.x / filterArea.y;//screen proroption
vec2 m = vec2(0.5, 0.5 );//center coords
vec2 d = p - m;//vector from center to current fragment
vec2 d2 = vec2(d.x, d.y/prop); //vector with fixed aspect ratio
float r = length(d2);// sqrt(dot(d2, d2)); // distance of pixel from center
float power = ( 2.0 * 3.141592 / (2.0 * length(m)) ) * (intensity)/50.;
vec2 uv;
if(intensity < 0.)
{
uv = vTextureCoord;
//Apply implosion
uv = uv + power * log(length(d2))* normalize(d2);
}
else if(intensity > 0.)
{
uv = vTextureCoord;
//Apply bulge
uv = uv + power * log(length(d2))* normalize(d2);
}
else
{
uv = vTextureCoord;
}
vec3 col = texture2D(uSampler, uv).xyz;//Second part of cheat
//for round effect, not elliptical
gl_FragColor = vec4(col, 1.0);
}
`.split('\n').reduce((c, a) => c + a.trim() + '\n');
var filter = new PIXI.Filter(null, fragSrc );
filter.apply = function(filterManager, input, output)
{
// this.uniforms.dimensions[0] = input.sourceFrame.width
//this.uniforms.dimensions[1] = input.sourceFrame.height
this.uniforms.intensity = app.renderer.plugins.interaction.mouse.global.x/app.renderer.width - 0.5;
// draw the filter...
filterManager.applyFilter(this, input, output);
}
// load image
var img = document.getElementById("grid_img");
var texture = PIXI.Texture.from(img);
var sprite = new PIXI.Sprite(texture);
var maincontainer = new...