Jump to content

Pixi Shader Texture size


spiraloops
 Share

Recommended Posts

Hello everyone !
I'm pretty new in PixiJS and i can't figure out how to do this :
Have a texture passed to a shader through uniforms and resize its sprite without "jumps" :
https://jsfiddle.net/spiraloops/zohpru02/
(try to resize it...)

What i want to have :
https://jsfiddle.net/spiraloops/k5wfmqu1/1/

My final intention is to perform video masking with resize. So I need the two textures (video and mask) to resize the same way...

Link to comment
Share on other sites

Why dont you just use pixi sprite mask over video? Filters in pixi-v4 are not so easy: https://github.com/pixijs/pixi.js/wiki/v4-Creating-Filters ,  and coordinates are not so easy to calculate, because 1. you need to position textures somehow 2. PIXI uses temporary pow2-sized texture to deal with a filter.

There's built-in SpriteMaskFilter that you can use: https://github.com/pixijs/pixi.js/tree/dev/src/core/renderers/webgl/filters/spriteMask 

 

var spriteMask = new PIXI.Sprite(xxx);
var videoSprite = new PIXI.Sprite(yyy);

stage.addChild(videoSprite);
stage.addChild(spriteMask);
videoSprite.mask = spriteMask;

//now set up sizes for those sprites - make positions and sizes exactly the way you want them!

You can do it directly: 

var spriteMask = new PIXI.Sprite(xxx);
var videoSprite = new PIXI.Sprite(yyy);

stage.addChild(videoSprite);
stage.addChild(spriteMask);

var maskFilter = new SpriteMaskFilter(spriteMask);
videoSprite.filters = [maskFilter];


//now set up sizes for those sprites - make positions and sizes exactly the way you want them!

 

Also you can create your own fiulter based on SpriteMaskFilter source. Just use same Vert and Frag shaders code but with different calculations of pixel color.

var vert = 
`
VERT CODE HERE
`;

var frag = `
FRAG CODE HERE
`;


class MyMaskFilter extends PIXI.Filter
{
    /**
     * @param {PIXI.Sprite} sprite - the target sprite
     */
    constructor(sprite)
    {
        const maskMatrix = new PIXI.Matrix();

        super(vert, frag);

        sprite.renderable = false;

        this.maskSprite = sprite;
        this.maskMatrix = maskMatrix;
    }

//copied from spriteMaskFilter
    apply(filterManager, input, output)
    {
        const maskSprite = this.maskSprite;

        this.uniforms.mask = maskSprite._texture;
        this.uniforms.otherMatrix = filterManager.calculateSpriteMatrix(this.maskMatrix, maskSprite);
        this.uniforms.alpha = maskSprite.worldAlpha;

        filterManager.applyFilter(this, input, output);
    }
}

 

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