Jump to content

Applying filter to a texture without clearing it


jfred1979
 Share

Recommended Posts

I am trying to do the following:

  1. draw some shapes to a Graphics object
  2. render those shapes to a RenderTexture without clearing it first, so that the shapes are "painted onto the texture"
  3. apply a filter (a blur, for example) to the RenderTexture without ever clearing it so the current blur is processing an already blurred texture from the previous frame 
  4. render to the screen
  5. repeat, never clearing the previously rendered display

This is basically continuously blurring the display so that the longer something has been displayed, the more blurred it gets. Here is where I am at so far:

class Project {
    constructor() {
        this.renderer = new PIXI.WebGLRenderer(window.innerWidth, window.innerHeight, { antialias: true });
        this.renderTexture = PIXI.RenderTexture.create(this.renderer.width, this.renderer.height);
        document.body.appendChild(this.renderer.view);

        this.stage = new PIXI.Container();
        this.canvas = new PIXI.Graphics();
        this.sprite = new PIXI.Sprite(this.renderTexture);
        this.blurFilter = new PIXI.filters.BlurFilter();

        this.stage.addChild(this.sprite);

        this.draw();
    }

    draw() {
        var mousePosition = this.renderer.plugins.interaction.mouse.global;

        this.canvas.clear();
        this.canvas.lineStyle(0);
        this.canvas.beginFill(0x666666);
        this.canvas.drawCircle(mousePosition.x, mousePosition.y, 50);

// Somehow apply a blur to this.renderTexture without clearing it so the next line renders the
// canvas on top of already blurred elements. This display will be fed into the next render
// cycle without being cleared so that the blurs are "additive".

        this.renderer.render(this.canvas, this.renderTexture, false);
        this.renderer.render(this.stage);
        requestAnimationFrame(this.draw.bind(this));
    }
}

 

Does this make sense? Am I on the right track?

 

Link to comment
Share on other sites

You dont have to refill `canvas` every time, just change its position. Draw circle at (0,0) one time and use `canvas.position.copy(mousePosition)`

You can apply filter to it, but filters of root element does not appear in renderTexture, you need to create one more container, add your graphics there, put filters in graphics, and render the container.

Please explain whether you want to blur whole image or blur that graphics mask. If you want that, you have to use that graphics as a mask for a sprtie with your renderTexture. There will be also a problem with "rendering texture over itself" so its possible that you need two render textures.

I'm very busy, I can help you with the code later if you try to use this advice :)

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...