开发者

How do I blend pixels in photoshop-like Screen mode in OpenGL?

I know glBlendFunc is the function call to specify a pixel blend mode.

I can do the Multiply Mode as in Photoshop, of which the formula is

C = A * B

where A is the source pixel, B is the destination pixel and C is final result.

Using glBlendFunc(GL_DST_COLOR, GL_ZERO) I'll get that effect.

So now my question is how to use the Screen Mode? The for开发者_Go百科mula of it is:

C = 1 - (1 - A) * (1 - B)


Didn't check, but the way to go is as follows.

The built-in computation that OpenGL does looks like:

C = A*s + B*d

Where you can choose the s and d.

Some algebra gives us

C = 1 - (1 - A) * (1 - B) = 
  = 1 - (1 - B) + A*(1 - B) = 
  = A*(1 - B) + B

Let

s = 1 - B
d = 1

and we get the value we want. So this should work:

glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ONE);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜