xzhu
xzhu

Reputation: 5755

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 formula of it is:

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

Upvotes: 7

Views: 1191

Answers (1)

Yakov Galka
Yakov Galka

Reputation: 72519

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);

Upvotes: 8

Related Questions