
photoshop like blending
Posted Sunday, 7 February, 2010 - 00:52 by meno inhi
i started recently to use opentk and learn a bit opengl. im not very good at this yet but with the help of some pages of this site i managed to draw pictures on the screen (yeah).
now i want to implement photoshop like blending modes (multiply, screen, lighten etc).
currently im using this code:
GL.Enable(EnableCap.Blend); GL.Color4(color.R, color.G, color.B, color.A); BlendingFactorSrc src = BlendingFactorSrc.SrcAlpha; BlendingFactorDest dest = BlendingFactorDest.OneMinusSrcAlpha; BlendEquationMode mode = BlendEquationMode.FuncAdd; switch(blendMode) { default: // Blendmode alpha (default) break; } GL.BlendEquation(mode); GL.BlendFunc(src,dest);
this works fine for alpha blending. i can use the alpha values stored in the picture and modify color and alpha in the program.
so now i want implement for example the multiply mode which is sourceColor * destinationColor.
i would write:
BlendingFactorSrc src = BlendingFactorSrc.DestColor; BlendingFactorDest dest = BlendingFactorDest.Zero;
this works also fine as long as i dont change the color/alpha value in the program. i guess it does not work because it would need the alpha information already stored in the texture instead of assigning it via opengl.
im probably doing something wrong.
i want to achieve a photoshop like behavior. basically i need to have a alpha blendmode applied and then using the result to multiply. or am i totally wrong?
sorry im very confused. maybe you could clear things up.
thanks in advance


Comments
Re: photoshop like blending
Multiply blend is usually defined like you said, DestColor & Zero. When you say it does not work, what doesn't work?Screenshots could also help (current vs desired result).
Re: photoshop like blending
thanks for the answer.
i probably wasnt clear enough.
this is how it is currently:
as you see, the transparent areas of the image are only transparent when using alpha blending. also the new alpha value assigned via GL.Color4 is only used in alpha blending. but i want to have that taken in account with multiply, too.
like this (photoshopped)
Re: photoshop like blending
This might help with the black-regions (which should be transparent instead):
A quick search indicates that Photoshop tends to pre-multiply the alpha-channel. What happens if you use this as your vertex color?
Re: photoshop like blending
yay thanks. that works. i now do it this way
i think it works fine. i will try other blendmodes in a similar way. thanks.