-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[compositing] Question: How to properly blend and composite isolated groups #440
Comments
I'm not familiar enough with the spec to quote from it, but here's how your example should behave:
Expressed with compositing functions "normal(dest, source)" and "difference(dest, source)", the final color is computed as follows:
Here,
Kind of unrelated to the main point of this issue, but this sentence doesn't make sense to me. Separability is about the calculations of a single compositing step - it describes whether the calculations can be done independently for the R, G, and B color components. It doesn't have any impact on what to do for other elements in the group. |
Your code is giving me the correct result for your example, if used as follows: const A = new Color(255, 255, 255, 1.0);
const B = new Color(0, 128, 0, 0.25);
const C = new Color(255, 0, 0, 0.5);
const AB = flattenColors(B, A);
const ABC = flattenColors(C, AB, "difference") I think the one thing it's missing is the final unpremultiplication at the end of |
Thanks for that explanation. It looks like I misread what separable blend modes was (I though it meant the blend mode was applied separately per composite layer, not per color component of RGB). So it seems that the mix-blend-mode is only applied when the groups are blended together? I tried to follow that through with adding a color D to the example and tried to then see if that would work: <div id="A" style="background-color: rgba(255, 255, 255, 1.0);">
<div id="B" style="background-color: rgba(0, 128, 0, 0.25);">
<div id="C" style="background-color: rgba(255, 0, 0, 0.5); mix-blend-mode: difference;">
<div id="D" style="background-color: rgba(0, 0, 255, 0.25);">Test Element</div>
</div>
</div>
</div>
That almost worked but wasn't quite the right color. I tried |
Oh, So we need to divide the rgb values by the final alpha value? |
That's right. |
Sweet! Thanks for the help. Doing that makes the four color example work now. |
This is defined in CSS Color 4: 13.2. Interpolating with alpha:
|
Looks like all is well then? Closing the issue. |
https://drafts.fxtf.org/compositing-1/#groups
TL;DR: how should isolated groups be blended and composited together? would it be possible to add explicit algorithms and diagrams showing how to composite and blend multiple isolated groups?
I work on axe-core and we are trying to implement support for
mix-blend-mode
when calculating an elements background color. We've been using the spec to add all the blending algorithms needed to run this calculation, but we've run into a problem trying to calculate compositing of the background colors.From what I understand from the spec, without
mix-blend-mode
(i.e.mix-blend-mode: normal
), background colors are composited together from bottom-up order. That is, using the following HTML we would blend element A and B together, then the result of that blend would be blended with element C, giving the result ofrgb(223, 112, 96)
(following the formulas of simple alpha compositing with blending substituted from https://drafts.fxtf.org/compositing-1/#blending). A visual inspection of this result compared to the browser shows that they are the same.However, once
mix-blend-mode
is applied to an element, things are different. From the spec I understand that this should create an isolated group sincemix-blend-mode
creates a stacking context, however what I'm not clear on from the spec is how to then composite an isolate group with other groups. The section on groups has a bit of explanation, but it is unclear to me what that algorithm looks like.If we take the same HTML as before and add
mix-blend-mode: difference
to element C, what it sounds like should happen is that there are now two groups: an isolated group containing element C, and the root group containing element A, B, and the isolated group.From the paragraph, it sounds like the groups are first composited separately onto their initial backdrop, then again onto the group backdrop.
So we start with the root group (since it is the group backdrop of the isolated group) and composite element A and B onto the root groups initial backdrop of white (so blending white and element A, then the result of that with element B). Since
mix-blend-mode: difference
is a separable blend mode, we usemix-blend-mode: normal
for these blendings. The result would bergb(191, 233, 191)
. As the root group has no group backdrop, we stop there.Next we go to the isolated group. It's initial backdrop is transparent black, so we composite element C onto that using
mix-blend-mode: difference
. That results inrgb(128, 0, 0, 0.5)
. Then we blend this color with the group backdrop, which is the composite of the root group, sorgb(191, 233, 191)
usingmix-blend-mode: normal
(from what I gather from effect of group isolation on blending). The final result of the color isrgb(160, 117, 96)
. However a visual inspection of the browser shows that this is not the case.I've tried a few different combinations of trying to blend the two different groups, but nothing seems to work out correct. Further confusing to me is when there is just a single element with
mix-blend-mode: difference
, nothing changes about the color, which to me means that transparent black isn't being applied to the isolated group at all. It's not until I add white as the background of thebody
orhtml
element does themix-blend-mode
take affect.So how should these groups blend and composite together? Would it be possible to add explicit algorithms and diagrams showing how to composite and blend multiple isolated groups? That to me would be the most helpful in understanding what should happen. Multiple diagrams showing where the transparent black should be inserted into a stack of colors, how groups blend together, etc.
Thanks for your help.
PS. You can see our code for blending here.
The text was updated successfully, but these errors were encountered: