如何在OpenGL中以类似photoshop的屏幕模式混合像素?

xzh*_*zhu 6 opengl

我知道glBlendFunc是指定像素混合模式的函数调用.

我可以像Photoshop 一样进行乘法模式,其公式为

C = A * B
Run Code Online (Sandbox Code Playgroud)

其中A是源像素,B是目标像素,C是最终结果.

使用glBlendFunc(GL_DST_COLOR,GL_ZERO)我会得到那个效果.

所以现在我的问题是如何使用屏幕模式?它的公式是:

C = 1 - (1 - A) * (1 - B)
Run Code Online (Sandbox Code Playgroud)

ybu*_*ill 7

没检查,但是要走的路如下.

OpenGL的内置计算看起来像:

C = A*s + B*d
Run Code Online (Sandbox Code Playgroud)

你可以在哪里选择s和d.

一些代数给了我们

C = 1 - (1 - A) * (1 - B) = 
  = 1 - (1 - B) + A*(1 - B) = 
  = A*(1 - B) + B
Run Code Online (Sandbox Code Playgroud)

s = 1 - B
d = 1
Run Code Online (Sandbox Code Playgroud)

我们得到了我们想要的价值.所以这应该工作:

glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ONE);
Run Code Online (Sandbox Code Playgroud)