question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pixi BlurFilter showing interference from other sprites.

See original GitHub issue

Hi, I’m having problems blurring images with transparent backgrounds. I’m animating multiple sprites with transparent backgrounds. The edges of each sprite seem to pick up the colour from the sprites around them as they move. The colour doesn’t always correspond to the sprite itself, so I’m assuming it picks up the other sprites’ colours somehow.

I’m running this on Pixi 5.1.5 on Chrome 78, Mac Mojave. Unfortunately I can’t show a link as it’s a client project I can’t share, but I’ve attached a screenshot of the effect, which I’m hoping will help identify.

Some excerpts of what I’m hoping are the relevant bits of code. Please let me know if anything else would be useful!

Initialising:

// Create a Pixi Application
this.pixi.app = new this.pixi.Application({
    antialias: true,
    transparent: true
});

// Add the Pixi created canvas to the HTML document
this.stage.appendChild(this.pixi.app.view);

// Canvas setup
this.pixi.app.renderer.autoDensity = true;
this.pixi.app.renderer.resize(window.innerWidth, window.innerHeight);

// Add sprites
this.pixi.loader.add(this.shapeURLs)
    .load((loader, resources) => this.setupShapes(loader, resources));

Setting up sprites:

this.pixi.container = new this.pixi.Container();

for (let i = 0; i < this.requiredShapes; i++) {
    let shapeSprite;
    const texture = resources[`${this.shapesDirectory}/shape${this.shapes[i].shapeNum}-blur-0.png`].texture;
    shapeSprite = new this.pixi.Sprite(texture);
    shapeSprite.anchor.set(0.5, 0.5);
    shapeSprite.resolution = 2;
    shapeSprite.alpha = 0;

    this.shapes[i].filter = new this.pixi.filters.BlurFilter(8);
    shapeSprite.filters = [this.shapes[i].filter];

    this.shapes[i].sprite = shapeSprite;
    this.pixi.container.addChild(shapeSprite);

    shapeSprite.scale.set(this.minScale, this.minScale);
}

this.pixi.app.stage.addChild(this.pixi.container);

and from the render function:

this.shapes[i].cycleTime = timestamp - this.shapes[i].cycleStartTime;

// Fade the shape in right at the start
const alphaVal = this.shapes[i].cycleTime / 1000 > 1 ? 1 : this.shapes[i].cycleTime / 1000;
if (this.shapes[i].alpha !== alphaVal) {
    this.shapes[i].alpha = alphaVal;
    this.shapes[i].sprite.alpha = alphaVal;
}

if (this.shapes[i].cycleTime >= this.shapes[i].duration) {
    this.shapes[i].cycleStartTime = timestamp;
} else {
    const fractionComplete = this.shapes[i].cycleTime / this.shapes[i].duration;

    // Set the z which will be used to project 3d position to 2d
    this.shapes[i].z = this.maxZ - this.maxZ * fractionComplete;

    /*
    * The zFocusPoint is the point in a shape's motion towards the screen at
    * which it should be in focus. pauseForNTextures is how many textures' worth
    * we'll keep it in focus (setting the pause by a number of textures requires
    * less calculation than setting it as a decimal).
    */
    const zFocusPoint = 0.65;
    this.shapes[i].filter.blur = this.maxBlur - this.maxBlur * fractionComplete / zFocusPoint;

    // Scale the shape up to full scale
    const scale = this.minScale + (1 - this.minScale) * fractionComplete * fractionComplete; // easeInQuad
    this.shapes[i].sprite.scale.set(scale, scale);
}
Screenshot 2019-12-02 at 21 13 27 Screenshot 2019-12-02 at 21 25 55

Thanks in advance!!!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
ivanpopelyshevcommented, Dec 8, 2019

OK, temporary solution is here: https://www.pixiplayground.com/#/edit/kuhrhc4jG5QnRRtIfwGwk

Basically i went here: https://github.com/pixijs/pixi.js/blob/dev/packages/filters/filter-blur/src/BlurFilterPass.js#L88

and changed true to false

function blurFilterPassApply(filterManager, input, output, clear)
{
    if (output)
    {
        if (this.horizontal)
        {
            this.uniforms.strength = (1 / output.width) * (output.width / input.width);
        }
        else
        {
            this.uniforms.strength = (1 / output.height) * (output.height / input.height);
        }
    }
    else
    {
        if (this.horizontal) // eslint-disable-line
        {
            this.uniforms.strength = (1 / filterManager.renderer.width) * (filterManager.renderer.width / input.width);
        }
        else
        {
            this.uniforms.strength = (1 / filterManager.renderer.height) * (filterManager.renderer.height / input.height); // eslint-disable-line
        }
    }

    // screen space!
    this.uniforms.strength *= this.strength;
    this.uniforms.strength /= this.passes;

    if (this.passes === 1)
    {
        filterManager.applyFilter(this, input, output, clear);
    }
    else
    {
        const renderTarget = filterManager.getFilterTexture();
        const renderer = filterManager.renderer;

        let flip = input;
        let flop = renderTarget;

        this.state.blend = false;
        // changed false to true here
        filterManager.applyFilter(this, flip, flop, true);

        for (let i = 1; i < this.passes - 1; i++)
        {
            renderer.renderTexture.bind(flip, flip.filterFrame);

            this.uniforms.uSampler = flop;

            const temp = flop;

            flop = flip;
            flip = temp;

            renderer.shader.bind(this);
            renderer.geometry.draw(5);
        }

        this.state.blend = true;
        filterManager.applyFilter(this, flop, output, clear);
        filterManager.returnFilterTexture(renderTarget);
    }
}

PIXI.filters.BlurFilterPass.prototype.apply = blurFilterPassApply;
0reactions
bigtimebuddycommented, Jun 17, 2020

@jteutenberg can you make a Pull request to fix that in the pixi-filters repo?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pixi BlurFilter showing interference from other sprites. #6257
Hi, I'm having problems blurring images with transparent backgrounds. I'm animating multiple sprites with transparent backgrounds.
Read more >
Blur of one sprite "spills" into the blur of another - Pixi.js
I am trying to use pixi.js for an interactive slide show to blur the upcoming and previous images (as sprites).
Read more >
PIXI.filters.BlurFilter - PixiJS API Documentation
PIXI.filters.BlurFilter. The BlurFilter applies a Gaussian blur to an object. The strength of the blur can be set for the x-axis and y-axis...
Read more >
Is it possible to apply a blur filter to a sprite with a mask, but ...
Is there any way to blur the sprites image, but keep the mask crisp, masking out the result of the blurred image? javascript...
Read more >
11958297 files 8600432 settings 8347444 us 5796345 in
... preview 37691 window 37561 wp 37317 ragnarok 37161 other 37081 most 37066 netfx 36928 standard 36885 port 36844 ads 36776 korean 36727...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found