0

Basically I want the following blend function:

newFragColor = SrcColor * SrcAlpha * DstAlpha + DstColor * (1-(SrcAlpha * DstAlpha))

Can I achieve that somehow using glBlendFunc and glBlendEquation?

The left side of the addition is easy - for that I just need to premultiply the fragment color with the fragment alpha and then use GL_DST_ALPHA as the first parameter to glBlendFunc. But how can I achieve the right side of the addition?

matthias_buehlmann
  • 4,641
  • 6
  • 34
  • 76
  • I don't think you can achieve this with the built-in blending. However, this is a strange equation to perform. Perhaps include in your question the kind of the effect you're trying to achieve, and then somebody can come up with how to best approximate it with the built-in blending operations. – Yakov Galka Aug 01 '21 at 22:51
  • Looking at your equation, I think there is a chance that you're trying to perform a regular blending of a semi-transparent texture over another semitransparent texture. If that's the case, the equation is not quite right. The correct formulae for that can be found on [wikipedia](https://en.wikipedia.org/wiki/Alpha_compositing). To implement that in OpenGL you want to store your `Src` **AND** `Dst` textures in a pre-multiplied format, then use `glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)`; the result will also be premultiplied. – Yakov Galka Aug 01 '21 at 23:02

0 Answers0