Jump to content

Need faster result than pixel() to get filter output


jpvaillancourt
 Share

Recommended Posts

I have a very simple graphics with a custom filter that creates a Noise + basic sin calculation to create a wave displacement map. I need to get the result of only one channel and I'm currently using :

renderer.extract.pixels()

But it is VERY slow. Is there a way to get the data output directly from the shader instead? I'm not sure if I'm explaining well enough...

In other words, I would like to have the gl_FragColor of each pixels directly after the filter calculation. I'm pretty sure it should be possible instead of waiting for the Renderer to calculate the exact same result based on the position of the graphics, and then extracting it.

I have search for several hours everywhere...

Here's what I have at the moment (in Typescript), but the pixel() consume 49% of the tick duration.

private createTextureDeformer() : void {
        this._pixiApp = new PIXI.Application(this.textureResolution + 1, this.textureResolution + 1, {
            transparent : <any> "notMultiplied",
        });

        var uniforms : any = {};
        uniforms.u_time = {
            type : 'f',
            value : 0
        };

        uniforms.u_size = {
            type : 'i',
            value : this.textureResolution
        };


        this._textureFilter = new PIXI.Filter(null, this.getTextureDeformerShader(), uniforms);

        var graphics : PIXI.Graphics = new PIXI.Graphics();
        graphics.drawRect(0, 0, this.textureResolution, this.textureResolution);

        graphics.filters = [this._textureFilter];
        this._pixiApp.stage.addChild(graphics);

        if(this.debug) {
            document.body.appendChild(this._pixiApp.view);
            this._pixiApp.view.id = 'pixi-canvas';
        }

        this.renderTextureDeformer(0);
    }

private renderTextureDeformer(delta : number) : void {
        this._textureFilter.uniforms.u_time += delta / 1000;
        this._texturePixels = this._pixiApp.renderer.extract.pixels() as Uint8Array;
    }

 

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...