Pixi.js: does blendMode support XOR?

Created on 29 Sep 2019  路  14Comments  路  Source: pixijs/pixi.js

Most helpful comment

Done, build is here: https://pixijs.download/dev-blendmode-xor/pixi-legacy.js (and pixi.js is there too)

Demo of all composition modes, including missed XOR: https://www.pixiplayground.com/#/edit/bWeh8BX~4XaD5jslgtb_3

please clone it if you change , we dont have "lock" feature yet :(

I found this thing when I was reading https://ciechanow.ski/alpha-compositing/ . I knew everything except XOR.

All 14 comments

image

@hajimehoshi
Phaser 3 support XOR only in canvas mode.
image

WebGL in Pixi v5 is a priority.
You can't do it in WebGL mode with blendFunc, but there are https://github.com/pixijs/pixi-picture , it can be used for implementing custom blend modes, but you must port it on v5;)

@eXponenta thanks
Are there any plans to add support XOR later

@hajimehoshi
Phaser 3 support XOR only in canvas mode.

You have the wrong number :-)

Are there any plans to add support XOR later

Nobody asked that before :) Do you have equation for it that takes into account alpha (premultiplied or not)?

Are there any plans to add support XOR later

Nobody asked that before :) Do you have equation for it that takes into account alpha (premultiplied or not)?

@ivanpopelyshev
not yet = =
hope you can add support for that, thanks

@huangjianke without equation it is will be not soon

I think its something like "if (alpha1>alpha2) color1 else color2" in non-premultiplied case.

You are right, we are missing one blendMode that can be done according to https://de.wikipedia.org/wiki/Porter-Duff_Composition. I'm making new demo for XOR :)

Good catch!

@ivanpopelyshev
Wow, Great job
it will help me a lot
thanks 馃槣

Done, build is here: https://pixijs.download/dev-blendmode-xor/pixi-legacy.js (and pixi.js is there too)

Demo of all composition modes, including missed XOR: https://www.pixiplayground.com/#/edit/bWeh8BX~4XaD5jslgtb_3

please clone it if you change , we dont have "lock" feature yet :(

I found this thing when I was reading https://ciechanow.ski/alpha-compositing/ . I knew everything except XOR.

its merged. build is here : pixijs.download/dev/pixi.js

@ivanpopelyshev
hey, When will this fix be released馃ぃ馃ぃ馃ぃ

@ivanpopelyshev
I did this on my own long time ago

array[_const.BLEND_MODES.SOURCE_OUT]           = [gl.ONE_MINUS_DST_ALPHA, gl.ZERO]; 
       array[_const.BLEND_MODES.SOURCE_IN]               = [gl.DST_ALPHA, gl.ZERO];        
array[_const.BLEND_MODES.DESTINATION_OUT] = [gl.ZERO,  gl.ONE_MINUS_SRC_ALPHA];     
array[_const.BLEND_MODES.DESTINATION_IN]      = [gl.ZERO, gl.SRC_ALPHA];

however in my experience this actually generates shadow effects that if you save the curren image and use it as a texture several times it gets darker and darker. This means that the blend is not clean maybe because of the premultiplied.

image

image

How would be the non premultiplied formulae for those blends?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

madroneropaulo picture madroneropaulo  路  3Comments

neciszhang picture neciszhang  路  3Comments

zcr1 picture zcr1  路  3Comments

samueller picture samueller  路  3Comments

sntiagomoreno picture sntiagomoreno  路  3Comments