spiraloops Posted October 3, 2017 Share Posted October 3, 2017 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... Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted October 3, 2017 Share Posted October 3, 2017 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); } } Quote Link to comment Share on other sites More sharing options...
spiraloops Posted October 4, 2017 Author Share Posted October 4, 2017 Thanks ivan !! I've programmed my own filter based on the SpriteMaskFilter source and it works like a charm ! ivan.popelyshev 1 Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted October 5, 2017 Share Posted October 5, 2017 Btw, you can also assign blendmode to that filter, if you need to blend it differently with background. 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.