bobGL

07-19-2007, 08:50 PM

I would like to reproduce the following Blend Mode from Photoshop, how can I do it?

Darken, Multiply, Overlay

Tks in advance...

Darken, Multiply, Overlay

Tks in advance...

View Full Version : Blending Mode

bobGL

07-19-2007, 08:50 PM

I would like to reproduce the following Blend Mode from Photoshop, how can I do it?

Darken, Multiply, Overlay

Tks in advance...

Darken, Multiply, Overlay

Tks in advance...

Korval

07-19-2007, 09:50 PM

What do these operations do?

k_szczech

07-19-2007, 11:25 PM

Blend mode works in the following way:

sourceColor * sourceFactor + destinationClor * destinationFactor.

To implement multiply you should set:

sourceFactor = GL_DST_COLOR, destinationFactr = GL_ZERO

I don't know exact maths behind darken and overlay.

Additilnally, you can use shaders to perform some advanced operations on sourceColor, but shaders do not have ccess to destinationColor.

sourceColor * sourceFactor + destinationClor * destinationFactor.

To implement multiply you should set:

sourceFactor = GL_DST_COLOR, destinationFactr = GL_ZERO

I don't know exact maths behind darken and overlay.

Additilnally, you can use shaders to perform some advanced operations on sourceColor, but shaders do not have ccess to destinationColor.

sqrt[-1]

07-20-2007, 01:16 AM

To do some of the more complicated blending you will need to do some fancy shader work with a copy of the scene as a lookup texture.

The math is:

multiply a * b

screen 1 - (1 - a) * (1 - b)

darken min(a, b)

lighten max(a, b)

difference abs(a - b)

negation 1 - abs(1 - a - b)

exclusion a + b - 2 * a * b

overlay a < .5 ? (2 * a * b) : (1 - 2 * (1 - a) * (1 - b))

hard light b < .5 ? (2 * a * b) : (1 - 2 * (1 - a) * (1 - b))

soft light b < .5 ? (2 * a * b + a * a * (1 - 2 * b)) : (sqrt(a) * (2 * b - 1) + (2 * a) * (1 - b))

dodge a / (1 - b)

burn 1 - (1 - a) / bThis comes from:

http://www.blackpawn.com/blog/?p=94

http://www.pegtop.net/delphi/articles/blendmodes/

The math is:

multiply a * b

screen 1 - (1 - a) * (1 - b)

darken min(a, b)

lighten max(a, b)

difference abs(a - b)

negation 1 - abs(1 - a - b)

exclusion a + b - 2 * a * b

overlay a < .5 ? (2 * a * b) : (1 - 2 * (1 - a) * (1 - b))

hard light b < .5 ? (2 * a * b) : (1 - 2 * (1 - a) * (1 - b))

soft light b < .5 ? (2 * a * b + a * a * (1 - 2 * b)) : (sqrt(a) * (2 * b - 1) + (2 * a) * (1 - b))

dodge a / (1 - b)

burn 1 - (1 - a) / bThis comes from:

http://www.blackpawn.com/blog/?p=94

http://www.pegtop.net/delphi/articles/blendmodes/

remdul

07-20-2007, 06:38 AM

If you have trouble understanding how the blending functions work, this program may help:

http://home.planet.nl/~buijs512/_temp/blendfunc.zip

(Note: The BlendEquation stuff doesn't work, I never found out what it does.)

I never understood why OpenGL supports relatively few blend modes. Is there a technical reason for this?

http://home.planet.nl/~buijs512/_temp/blendfunc.zip

(Note: The BlendEquation stuff doesn't work, I never found out what it does.)

I never understood why OpenGL supports relatively few blend modes. Is there a technical reason for this?

bobGL

07-20-2007, 07:59 AM

tks alot sqrt[-1],

now after some digs, I can't figure out how to implement theses equations... whithout having to pass by a shader...

Any other suggestion?

now after some digs, I can't figure out how to implement theses equations... whithout having to pass by a shader...

Any other suggestion?

k_szczech

07-20-2007, 09:31 AM

You need to use shader as described by sqrt[-1].

There is no other way for complex per-pixel math (unless you want to do it on CPU).

There is no other way for complex per-pixel math (unless you want to do it on CPU).

Korval

07-20-2007, 12:08 PM

I never understood why OpenGL supports relatively few blend modes. Is there a technical reason for this?It supports plenty of blending modes. In GL 2.1, there are 4 basic blending functions (add, subtract, min & max), with blend parameters. Parameters can be separated between RGB and A, and there's even an extension to separate the entire blend function between RGB and A.

What it doesn't have is arbitrary computation in the blend stage. There are whispers that this will eventually be opened up in the future.

What it doesn't have is arbitrary computation in the blend stage. There are whispers that this will eventually be opened up in the future.

sqrt[-1]

07-20-2007, 06:10 PM

Well you can do Darken and Multiply with standard OpenGL.

Overlay is the only one that requires a shader.

Multiply(as described above) = sourceFactor = GL_DST_COLOR, destinationFactr = GL_ZERO, blendEquation = GL_FUNC_ADD (default)

Darken = sourceFactor = GL_ONE, destinationFactr = GL_ONE, blendEquation = GL_FUNC_MIN

Overlay is the only one that requires a shader.

Multiply(as described above) = sourceFactor = GL_DST_COLOR, destinationFactr = GL_ZERO, blendEquation = GL_FUNC_ADD (default)

Darken = sourceFactor = GL_ONE, destinationFactr = GL_ONE, blendEquation = GL_FUNC_MIN

bobGL

07-21-2007, 07:42 AM

I have to admit that you blow me away sqrt[-1] with theses equations... ;) and now Im think about using them all (except overlay because of what you mention above). So for the others do you have the source, dest. and blendequation?

Tks in advance,

Cheers!

Tks in advance,

Cheers!

sqrt[-1]

07-21-2007, 04:47 PM

The only other obvious ones you can without a shader are lighten and difference

lighten = sourceFactor = GL_ONE, destinationFactr = GL_ONE, blendEquation = GL_FUNC_MAX

difference = sourceFactor = GL_ONE, destinationFactr = GL_ONE, blendEquation = GL_FUNC_SUBTRACT

The modes screen and negation might be possible with simple combiners and multiple passes, but the rest really need a shader/CPU manual processing.

lighten = sourceFactor = GL_ONE, destinationFactr = GL_ONE, blendEquation = GL_FUNC_MAX

difference = sourceFactor = GL_ONE, destinationFactr = GL_ONE, blendEquation = GL_FUNC_SUBTRACT

The modes screen and negation might be possible with simple combiners and multiple passes, but the rest really need a shader/CPU manual processing.

bobGL

07-22-2007, 07:32 PM

allright, what else? ;)

knackered

07-23-2007, 05:16 PM

in other words, give him the exact code he can paste into his app.

bobGL

07-30-2007, 06:16 PM

knackered... you got it ;)

Korval

07-30-2007, 06:29 PM

knackered... you got itUm, I don't think you took that the way he meant it. I'm fairly certain he meant it as a form of derision for someone who was unwilling/unable to convert the English description into acceptable code.

And while I don't exactly agree with the way he expressed it, I have to agree with the derision itself. You're a programmer; your "job" is to covert that into actual code.

And while I don't exactly agree with the way he expressed it, I have to agree with the derision itself. You're a programmer; your "job" is to covert that into actual code.

Powered by vBulletin® Version 4.2.3 Copyright © 2018 vBulletin Solutions, Inc. All rights reserved.