Opengl预乘alpha图像渲染过程

Opengl预乘alpha图像渲染过程,opengl,premultiplied-alpha,Opengl,Premultiplied Alpha,我已经学习OpenGL2.0渲染工具一段时间了,下面是一些关于alpha渲染的个人理解,我想知道它们是否正确: 假设我有一个PNG(32位)文件(无预乘alpha图像),只有一个像素(src图像) 这里有四个示例,每个示例有四列。 以第2行为例: 1. The PNG image is red but half transparent so the rgba should be (255, 0, 0, 128) 2. The texture info is passed to frag shad

我已经学习OpenGL2.0渲染工具一段时间了,下面是一些关于alpha渲染的个人理解,我想知道它们是否正确:

假设我有一个PNG(32位)文件(无预乘alpha图像),只有一个像素(src图像)

这里有四个示例,每个示例有四列。 以第2行为例:

1. The PNG image is red but half transparent so the rgba should be (255, 0, 0, 128)
2. The texture info is passed to frag shader and the value for glFragColor shoud be (1.0, 0.0, 0.0, 0.5)
3. When rendering the src color to GPU OpenGL will try to bend it with the dst color
4. let's say the dst color is (0, 0, 0, 255) and blend func for dst is GL_ONE_MINUS_SRC_ALPHA
5. if the blend func for dst is GL_SRC_ALPHA, the final pixel rendered will be (0.5, 0.0, 0.0, 0.75)
6. if the blend func for dst is GL_ONE, the final pixel rendered will be (1.0, 0.0, 0.0, 1.0)
(6)的结果肯定是错误的,因为透明度损失,而(5)的结果应该是好的


这就是为什么我应该用GL_SRC_ALPHA表示非预乘ALPHA图像,用GL_ONE表示预乘ALPHA图像。

呃,什么?要点(5)和(6)应与src混合系数有关。不管怎样,dst系数仍然是1-srcα。你能澄清一下你认为什么是src和dst吗?你的解释使我相信你可能会感到困惑;src是片段着色器的输出,dst是帧缓冲区中已经存在的内容。我的理解是:程序首先加载PNG并将其转换为纹理,然后纹理信息被传递到v&f着色器,frag着色器的输出应该是“src”(在我的情况下),然后“src”将与“dst”混合(帧缓冲区中的内容),最后输出是我在屏幕上看到的内容~
1. The PNG image is red but half transparent so the rgba should be (255, 0, 0, 128)
2. The texture info is passed to frag shader and the value for glFragColor shoud be (1.0, 0.0, 0.0, 0.5)
3. When rendering the src color to GPU OpenGL will try to bend it with the dst color
4. let's say the dst color is (0, 0, 0, 255) and blend func for dst is GL_ONE_MINUS_SRC_ALPHA
5. if the blend func for dst is GL_SRC_ALPHA, the final pixel rendered will be (0.5, 0.0, 0.0, 0.75)
6. if the blend func for dst is GL_ONE, the final pixel rendered will be (1.0, 0.0, 0.0, 1.0)