Mixing alpha with multiple textures leaves a color border

The next problem: I have two textures, and I want to combine these two into a new texture. Thus, one texture is used as the background, the other is superimposed. The overlay texture is initialized with glClearColor (1.0, 1.0, 1.0, 0.0). Objects are drawn on the texture, these objects have alpha values.

Now the blend between the two textures leaves a white frame around the objects. The border comes from the fact that the background color in the second texture is white, right?

How can I use alpha blending where I donโ€™t need to think about the background color of the overlapping texture?

+1
source share
4 answers

I myself solved the problem, but many thanks to all of you guys!

The problem was this: to combine both textures, I used glblend (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA), which does not work because OpenGL uses pre-multiplied alpha values. Mixing with glblend (GL_ONE, GL_ONE_MINUS_SRC_ALPHA) works as the original term will now be: 1 * src_alpha * src_color!

+5
source

How can I use alpha blending where I donโ€™t need to think about the background color of the overlapping texture?

You can not; your blend function includes a background color because it really cannot be a โ€œbackgroundโ€. You render several objects to the texture, so the "background" color can actually be the displayed object.

It is best to minimize exposure. There is no particular need for the background color to be white. Just make it black. This will not cause artifacts to disappear; he hopefully just makes it less visible.

The simple fact is that blending in graphics cards is simply not designed to perform the kinds of compositions you make. It works best when what you mix is โ€‹โ€‹opaque. Even if there are layers of transparency between the opaque surface and what you are rendering, it still works.

But if the background is actually transparent, without a full opaque color, the math just stops working. You will receive artifacts; the question is how noticeable they will be.

If you have access to more advanced equipment, you can use some shader-based software mixing methods. But this will have an impact on performance.

+1
source

Although I think that you are likely to get better results with a black background, as Nikol Bolas noted. But you have to double check your mix functions, because, as you point out, this SHOULD NOT matter ...

1.0 * 0.0 + 0.734 * 1.0 = 0.734 

What I really don't understand is why is your base texture completely transparent? Is this intended? If you don't mix textures and then use them somewhere else, initialization in Alpha = 1.0 is the idea of โ€‹โ€‹the test.

0
source

Before you draw a transparent texture, make sure that you turn off the depth record (therefore, one transparent texture cannot โ€œblockโ€ the other, preventing its parts from drawing). To do this, just call glDepthMask(false) . After you finish drawing transparent objects, call glDepthMask(true) to restore normal depth.

0
source

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


All Articles