Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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)
like image 965
xzhu Avatar asked May 18 '11 09:05

xzhu


1 Answers

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);
like image 145
Yakov Galka Avatar answered Sep 19 '22 23:09

Yakov Galka