If the data that calculated IN SHADER is not premultiplied, blend should be
Its possible to detect not-premultipied data by "R>A" or "G>A" or "B>A" condition, but its better to just give user options.
In PixiJS we have three options, not two:
===
https://pixijs.download/dev/docs/PIXI.html#ALPHA_MODESNO_PREMULTIPLIED_ALPHA aka
NPM=0
Source is not premultiplied, leave it like that. Option for compressed and data textures that are created from typed arrays.
REMULTIPLIED_ALPHA aka
PMA=1
Source is already premultiplied Example: spine atlases with _pma suffix.
PREMULTIPLY_ON_UPLOAD aka
UNPACK=2
Source is not premultiplied, premultiply on upload. Default option, used for all loaded images.
===
UNPACK is called only for 2.
For both 1 and 2 we use regular pma blend [ONE, ONE_MINUS_SRC_ALPHA]
For 0 blend is
[SRC_ALPHA, ONE_MINUS_SRC_ALPHA, ONE, ONE_MINUS_SRC_ALPHA] , two extra alues for alpha itself <-- IMPORTANT!
Also sometimes we pass that thing to shader uniform so shader can change data received from texture and work with PMA if it needs it.
For example, this line was ported to ALL spine runtimes, not just pixi/webgl :
https://github.com/pixijs/pixi-heaven/blob/fa5c059637060779f2b4915eadc36c3ec687dc91/src/twotint/sprites/HeavenBatchRenderer.ts#L48 . "
vDark.a" is 0 for NPM and 1 for PMA, the rest of params are two tints - dark and light. Thus, shader produces PMA result for PMA texture and NPM for NPM.
Ivan.
среда, 7 декабря 2022 г. в 08:00:04 UTC+3, Kenneth Russell: