How to mix pixels in Photoshop mode in OpenGL mode?

I know that glBlendFunc is a function call to set the pixel blending mode.

I can do "Multiply" , as in Photoshop, whose formula

C = A * B 

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

Using glBlendFunc (GL_DST_COLOR, GL_ZERO) . I get this effect.

So now my question is how to use Screen Mode ? His formula:

 C = 1 - (1 - A) * (1 - B) 
+6
source share
1 answer

Not tested, but a way to go as follows.

The built-in calculation that looks in OpenGL is as follows:

 C = A*s + B*d 

Where you can choose s and d.

Some algebra gives us

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

Let be

 s = 1 - B d = 1 

and we get the desired value. Therefore, this should work:

 glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ONE); 
+7
source

Source: https://habr.com/ru/post/888400/


All Articles