Jump to content

Possible problem with handling of transparency with Additive blending


Recommended Posts

I don't know if this is a bug or not, but the way alpha is used in the Additive blending mode seems odd to me.

 

If I have an opaque lower layer and an upper layer with partially-transparent pixels and the Additive blending mode, I would expect (or at least hope) the blending equation would be something like:

 

Cimage = Clower + (Aupper * Cupper) / 255

 

Where C is a color component (R, G, or B ) and A is alpha.

 

For many color combinations it is, but in other cases it's quite different. For instance if the lower layer color is (20, 20, 20) and the upper layer color is (255, 255, 255) with an alpha of 85, the image color is (98, 98, 98) whereas the above equation gives (105, 105, 105).

 

If the Additive blending mode is working as intended, I would very much appreciate knowing the actual blending equation it uses.

 

(I hate that smiley-face-with-sunglasses that happens automatically on the forum when a right paren follows a B. Useless and annoying!)

 

 

  • Upvote 1
Link to comment
Share on other sites

6 hours ago, ReMake said:

The Additive blending mode uses a very simple formula:

 

That's how two opaque pixels are blended, but what if one of the pixels is semi-transparent? How does alpha affect the blending? That's what my question is about.

 

Of course, both pixels could be semi-transparent, but I'm mostly concerned with the case where the upper layer is semi-transparent and the lower layer is opaque. Off hand, I believe the full equation should be more or less:

Cimage = (Alower * Clower + Aupper * Cupper) / 255

(The part that makes me say "off hand" is that if the layers are merged, I think the colors need to be adjusted to account for the combined alpha.)

Link to comment
Share on other sites

I think I've figured out why Additive mode gives the results it does. And while the method for blending is in a sense logical, I don't think it's ideal.

 

I believe the semi-transparent pixel in the upper layer is Additive blended with the opaque pixel in the lower layer, then combined with the lower-layer pixels using normal alpha blending. The problem (if I may call it that) is that the result of the Additive blending is clamped to 255 before the pixels are alpha blended. rather than after. Perhaps that's necessary to be consistent for all the blending modes.

 

For the example I gave in my original comment, where the lower layer color is (20, 20, 20) and the upper layer color is (255, 255, 255) with an alpha of 85:

 

The Additive blended color component is 275, which is clamped to 255. Then, 0.667 * 20 + 0.333 * 255 => 98

 

I'm still slightly confused, because I believe Screen mode behaves in a similar fashion, and Screen mode should never overflow in the first step, before the alpha blending. (I think I was mistaken about that.)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...