Joncom Posted January 18, 2017 Share Posted January 18, 2017 Hello. I put together a water ripple effect demo:http://commins.ca/pixijs-ripple/ Each time you click, a new set of ripples is created. However, a brief flash of black occurs each time a new filter is added to the stage.filters array! But I must add the filters to this array for there to be any effect, so... I am really doomed to have this ugly flicker? <!DOCTYPE html> <html> <head> <title>PixiJS Ripple</title> <script src="pixi.min.js"></script> </head> <body> <script> var stage = new PIXI.Container(); var renderer = PIXI.autoDetectRenderer(512, 512); document.body.appendChild(renderer.view); // load assets PIXI.loader .add("background.jpeg") .add("map.png") .load(setup); var ripples = []; function setup() { // background var bg = new PIXI.Sprite(PIXI.loader.resources["background.jpeg"].texture); bg.anchor.set(0.5); bg.scale.set(0.6); bg.position.set(renderer.view.width/2, renderer.view.height/2); stage.addChild(bg); // add new ripple each time mouse is clicked renderer.view.addEventListener('mousedown', function(ev) { ripples.push(new Ripple(ev.clientX, ev.clientY)); stage.filters = ripples.map(function(f) { return f.filter; }); }, false); gameLoop(); } function gameLoop() { requestAnimationFrame(gameLoop); // update ripples for(var i=0; i<ripples.length; i++) { ripples[i].update(); } renderer.render(stage); } function Ripple(x, y) { // sprite this.sprite = new PIXI.Sprite(PIXI.loader.resources["map.png"].texture); this.sprite.anchor.set(0.5); this.sprite.position.set(x, y); this.sprite.scale.set(0.1); stage.addChild(this.sprite); // filter this.filter = new PIXI.filters.DisplacementFilter(this.sprite); } Ripple.prototype.update = function() { this.sprite.scale.x += 0.025; this.sprite.scale.y += 0.025; } </script> </body> </html> Quote Link to comment Share on other sites More sharing options...
TheBoneJarmer Posted January 18, 2017 Share Posted January 18, 2017 (edited) I fear this is something inside Pixi. I know that flicker, it is black because WebGL does not recognize a texture. But don't mind those technical details. As for a solution, definitely report this to the developer of Pixi to start with. And as for that flicker hmm. I do knot know yet. I will use your code and download Pixi to see if I can solve it. EDIT: Found no solution unfortunately. But what I did notice was that the ripple flickering appears after the first time. Because the first time no flickering appears. I do not know Pixi well enough to find a workaround but if I have to guess, this is unavoidable. Again, try contacting the pixi developer and tell him he got a bug in his image displacement shader that causes a black flickering. Edited January 18, 2017 by TheBoneJarmer Found some sort of solution Quote Link to comment Share on other sites More sharing options...
Joncom Posted January 18, 2017 Author Share Posted January 18, 2017 Thanks for looking into it @TheBoneJarmer. I opened an issue on Github:https://github.com/pixijs/pixi.js/issues/3609 Quote Link to comment Share on other sites More sharing options...
mspanish Posted February 23, 2017 Share Posted February 23, 2017 This is a lovely filter! Exactly what would be super cool in my app teaching autistic children to read (I'm using an underwater bg for the first few scenes). Did you find any answers? Quote Link to comment Share on other sites More sharing options...
Joncom Posted February 23, 2017 Author Share Posted February 23, 2017 Woops. I had previously updated the demo with the fix, and then accidentally replaced it with the broken version again. Should working working now. Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted February 24, 2017 Share Posted February 24, 2017 11 hours ago, Joncom said: Woops. I had previously updated the demo with the fix, and then accidentally replaced it with the broken version again. Should working working now. That 's how you scared me Quote Link to comment Share on other sites More sharing options...
ClusterAtlas Posted February 25, 2017 Share Posted February 25, 2017 Very awesome! It can also be used as a shockwave effect, just increase its speed! Quote Link to comment Share on other sites More sharing options...
Joncom Posted March 5, 2017 Author Share Posted March 5, 2017 On 2/24/2017 at 0:02 AM, ivan.popelyshev said: That 's how you scared me Haha, yeah sorry about that ^^ ivan.popelyshev 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.