dmko Posted May 11, 2017 Share Posted May 11, 2017 I have some code which works just fine, but I'm not sure if there's a better way of drawing lines on the screen with a texture-brush and I also have a question about erasing Here's what I'm doing atm: SETUP Create a RenderTexture of a certain size ("renderTexture") Create a Sprite out of that, and add the Sprite to the stage ("viewSprite") Create a Container, don't add anything to it yet ("drawBuffer") Create an Array (or really object pool "pool") of sprites ("brushSprite") with the current brush texture (and other settings - color, size etc.). ("pool" - under the hood can grow, be reset when brush settings change, etc.) DRAW A LINE from p1:Point to p2:Point Calculate all the points we need to draw a line between the points (let's ignore this algorithm for now) Get that number of brushSprites from pool For each point - add a brushSprite to drawBuffer at that point When all the children are added, call renderer.render(drawBuffer, renderTexture, false); return all the used brushSprites to pool remove all the children from drawBuffer Here's my specific questions: Is adding the children to drawBuffer and then calling renderer.render() less often going to be more efficient than just renderer.render() each sprite directly? How can I sprinkle in an erase functionality to this? I'm only concerned about webgl if it matters, canvas support isn't absolutely necessary (and I mean true erase, like if there's an image underneath the viewSprite that image should bleed through - painting a solid color onto the renderTexture won't suffice Thanks! ivan.popelyshev 1 Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted May 14, 2017 Share Posted May 14, 2017 1. yes, a bit. It'll be batched. 2. sprite.blendMode = PIXI.BLEND_MODES.MULTIPLY, use black where you want to erase, white for pixels that you wont affect. You can also try to use ADD blendmode when you draw things: use white where you want to affect pixels and black where you dont want. Quote Link to comment Share on other sites More sharing options...
dmko Posted May 15, 2017 Author Share Posted May 15, 2017 Thanks... couldn't get it to work though, is just drawing black: https://codepen.io/anon/pen/oWyoxm?editors=0010 (it first paints a bunch of circles in random colors, and then tries to erase every other line - but you can see that every other line just gets painted black instead) I get it's not exactly what you wrote since the alpha pixels would need to be changed to white... but still - the black parts aren't erasing Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted May 15, 2017 Share Posted May 15, 2017 oh, right.. it paints black, not transparent We have to use this blendmode function: https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/blendFuncSeparate Pixi doesnt know how to do that, we need to override webglstate and other things that will use 4 parameters from webgl blendmodes instead of 2, then add special blendmode in "renderer.blendMode", please find it in pixi sources, its array of something like "(gl.ONE, gl.ONE)". We have to do some magic with 2 additional parameters "srcAlpha" and "dstAlpha". Sorry, I cant give you much of my time right now ping me in weekend? I wanted to do that improvement some time ago, we need it for multiple reasons, including your "drawing case" dmko 1 Quote Link to comment Share on other sites More sharing options...
dmko Posted May 15, 2017 Author Share Posted May 15, 2017 Thanks! Quote Link to comment Share on other sites More sharing options...
dmko Posted May 15, 2017 Author Share Posted May 15, 2017 Opened as an issue @ https://github.com/pixijs/pixi.js/issues/4027\ ivan.popelyshev 1 Quote Link to comment Share on other sites More sharing options...
dmko Posted May 22, 2017 Author Share Posted May 22, 2017 Forgot to ping you over the weekend, sorry! Very interested if/when you make progress though Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted May 22, 2017 Share Posted May 22, 2017 Yeah, I made https://github.com/pixijs/pixi.js/pull/4049 but i dont think it will be merged in v4 I'm waiting for @Mat Groves approvement. And I still dont know which blendmode you can use, but at least with that thing you can experiment! Try pass diferent constants as in https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/blendFunc , in "new BlendMode" first two are for RGB, third and fourth are for alpha. Also you can specify different blend equations. Binary is here: http://pixijs.download/dev-blendmodes-class/pixi.js 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.