Open p0nce opened 4 years ago
But it gets much harder with scale
since circles won't stay circles, this is actually supported in browsers. (EDIT: it worked, but wouldn't work if shearing was allowed)
vec2f
as alternative whenever possible.Reference for possible composite operations: https://www.w3schools.com/tags/playcanvas.php?filename=playcanvas_globalcompop
Is globalCompositeOperation implementable?
source-over
the only one we support.
dest = dest * (1 - alpha) + alpha * src
. If we do that on black, we obtain alpha * source color
.RGBA(source-red * source-alpha, source-green * source-alpha, source-blue * source-alpha, source-alpha)
not clear all blitters will give thatRGBA(source-red, source-green, source-blue, source-alpha)
instead of premultiplied? (or, we could unpremultiply lol)source-atop
: alpha of source should be premultiplied with alpha of dest.
source-in
: alpha of destination multiplied with alpha of source, and alpha of source should be multiplied with alpha of dest.
source-out
: alpha of dest taken instead of alpha of source
lighter
: take max of dest and alpha*src (not sure what happens to alpha)
copy
: only consider source
xor
: alpha is down to zero if both alpha are 1
All explained in https://ssp.impulsetrain.com/porterduff.html
From my understanding:
Implemented sourceOver, add, subtract. We don't follow html spec here, in that background alpha is always assumed to be opaque (= 255). (EDIT: added lighten and darken modes too) Eventually we could also add globalAlpha which also breaks the fast path. Well that's 5 interesting modes without unpremultiply or redo the blitters.
dg2d
, which is like in a browser Behaviour observed in both Chrome and Firefox.On second
fillRect
center of gradient is translated vs the first rectangle. It is indeed more intuitive on use. This will also allow to reuse gradients over several dirty rects.I do'nt know how to do it in case of scale(x, y) with x different from y as then it's not circles anymore.