How does alpha blending work, mathematically, pixel-by-pixel?

前端 未结 2 1421
执笔经年
执笔经年 2020-12-22 00:39

Seems like it\'s not as simple as RGB1*A1 + RGB2*A2...how are values clipped? Weighted? Etc.

And is this a context-dependent question? Are there different algorit

2条回答
  •  庸人自扰
    2020-12-22 01:10

    I don't know about OpenGL, but one pixel of opacity A is usually drawn on another pixel like so:

    result.r = background.r * (1 - A) + foreground.r * A
    result.g = background.g * (1 - A) + foreground.g * A
    result.b = background.b * (1 - A) + foreground.b * A
    

    Repeat this operation for multiple pixels.

提交回复
热议问题