多个像素的 Alpha 混合公式是什么?

发布于 2024-07-05 17:25:42 字数 518 浏览 7 评论 0原文

我有许多 RGBA 像素,每个像素都有一个 alpha 分量。

所以我有一个像素列表: (p0 p1 p2 p3 p4 ... pn) 其中 p_0_ 是前面的像素,p_n_ 是最远的像素(在后面)。

最后一个(或任何)像素不一定是不透明的,因此生成的混合像素也可以以某种方式透明。 我从列表的开头到结尾进行混合,反之亦然(是的,它是光线追踪)。 因此,如果任何时候结果变得足够不透明,我都可以以足够正确的结果停止。 我将以这种方式应用混合算法: ((((p0 @ p1) @ p2) @ p3) ... )

谁能建议我一个正确的混合公式,不仅适用于 R、G 和 B,还适用于 A 组分?

UPD:我想知道对于确定的混合颜色过程,我们怎么可能有很多公式? 这是某种近似吗? 对我来说,这看起来很疯狂:公式并没有太大的不同,以至于我们真正获得了效率或优化。 谁能澄清这一点吗?

I have a number of RGBA pixels, each of them has an alpha component.

So I have a list of pixels: (p0 p1 p2 p3 p4 ... pn) where p_0_ is the front pixel and p_n_ is the farthest (at the back).

The last (or any) pixel is not necessary opaque, so the resulting blended pixel can be somehow transparent also.
I'm blending from the beginning of the list to the end, not vice-versa (yes, it is raytracing). So if the result at any moment becomes opaque enough I can stop with correct enough result.
I'll apply the blending algorithm in this way: ((((p0 @ p1) @ p2) @ p3) ... )

Can anyone suggest me a correct blending formula not only for R, G and B, but for A component also?

UPD: I wonder how is it possible that for determined process of blending colors we can have many formulas? Is it some kind of aproximation? This looks crazy, as for me: formulas are not so different that we really gain efficiency or optimization. Can anyone clarify this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

兲鉂ぱ嘚淚 2024-07-12 17:25:42

Alpha 混合是比您想象的更深入的主题之一。 这取决于 alpha 值在您的系统中的含义,如果您猜错了,那么您最终会得到看起来不错的结果,但会显示奇怪的伪影。

查看 Porter 和 Duff 的经典论文“合成数字图像”,了解精彩的内容可读的讨论和所有公式。 您可能需要“over”运算符。

听起来你正在做一些更接近体积渲染的事情。 有关公式和参考资料,请参阅图形常见问题解答,问题 5.16“如何我执行体积渲染?”。

Alpha-blending is one of those topics that has more depth than you might think. It depends on what the alpha value means in your system, and if you guess wrong, then you'll end up with results that look kind of okay, but that display weird artifacts.

Check out Porter and Duff's classic paper "Compositing Digital Images" for a great, readable discussion and all the formulas. You probably want the "over" operator.

It sounds like you're doing something closer to volume rendering. For a formula and references, see the Graphics FAQ, question 5.16 "How do I perform volume rendering?".

合约呢 2024-07-12 17:25:42

有多种可能的方法可以实现此目的,具体取决于 RGBA 值如何实际表示材质的属性。

这是一个可能的算法。 从最终像素颜色 lightr=lightg=lightb=0lightleft=1 开始;

对于遇到的每个 r、g、b、a 像素,评估:

lightr += lightleft*r*(1-a)
lightg += lightleft*g*(1-a)
lightb += lightleft*b*(1-a)
lightleft *= 1-a;

(RGBA 值在 0 和 1 之间标准化,我假设 a=1 表示不透明,a=0 表示完全透明)

如果遇到的第一个像素是蓝色不透明度为 50%,则 50% 的可用颜色设置为蓝色,其余部分未知。 如果接下来是不透明度为 50% 的红色像素,则剩余光的 25% 将设置为红色,因此该像素具有 50% 的蓝色和 25% 的红色。 如果接下来是不透明度为 60% 的绿色像素,则该像素为 50% 蓝色、25% 红色、15% 绿色,剩余 10% 的光。

与此功能相对应的物理材料是发光但部分不透明的材料:因此,堆栈中间的像素永远无法使最终颜色变暗:它只能阻止其后面的光增加最终颜色(通过变黑)并且完全不透明)。

There are various possible ways of doing this, depending on how the RGBA values actually represent the properties of the materials.

Here's a possible algorithm. Start with final pixel colours lightr=lightg=lightb=0, lightleft=1;

For each r,g,b,a pixel encountered evaluate:

lightr += lightleft*r*(1-a)
lightg += lightleft*g*(1-a)
lightb += lightleft*b*(1-a)
lightleft *= 1-a;

(The RGBA values are normalised between 0 and 1, and I'm assuming that a=1 means opaque, a=0 means wholly transparent)

If the first pixel encountered is blue with opacity 50%, then 50% of the available colour is set to blue, and the rest unknown. If a red pixel with opacity 50% is next, then 25% of the remaining light is set to red, so the pixel has 50% blue, 25% red. If a green pixel with opacity 60% is next, then the pixel is 50% blue, 25% red, 15% green, with 10% of the light remaining.

The physical materials that correspond to this function are light-emitting but partially opaque materials: thus, a pixel in the middle of the stack can never darken the final colour: it can only prevent light behind it from increasing the final colour (by being black and fully opaque).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文