Skynet is right, this will be fixed just with a change of glBlendFunc.
From your description I thought the cloud texture was all white, with alpha used to define the cloud silhouette, which works with classic alpha.
But the kind of artefact you have if exactly caused by having black over transparent regions : the interpolation between black+transparent and white+opaque gives grey+semitransparent.
This is a case best handled by premultiplied alpha, with
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
Now I have another challenge. Clouds get drawn correct.
My program has another function which sets the alpha for a image. So when I reduce the alpha of a cloud nothing happens.
Even a alpha value of 0 still shows the cloud.
According to that equation I expected a change when changing source alpha:
(RsSr+RdDr, GsSg+GdDg, BsSb+BdDb, AsSa+AdDa)
I did not forgot, I tried to give the minimum information to fix the described problem
I assume that after reading Tom’s page, Andreas K would get a high level grasp of how pre-multiplied alpha works… I guess he did not.
@Andreas K: To avoid rebuilding the texture for each alpha change, you can either :
in fragment shader, divide color by default alpha (the one from the texture), then multiply by alpha modulation, keeping premultiplied alpha blend func.
put all white instead of black in the cloud texture, and go back to classic blend func
Gents thanks a lot for the fast replies!
The software is a 2D game engine. Will get back to the user
who provided me the cloud image and ask to change black to white.
In parallel I will try to understand option a). Have no experience with the fragment shader and how to configure.
Doing GLSL seem complex at first, but it allows a lot of freedom to do complex stuff easily.
Anyway, you can do solution b) from within your code, whithout having to change the cloud file.
At load time, for each texel, divide color by its alpha (putting black for alpha=0 of course).
In fact it is good practice to know for each image file if it has premultiplied alpha or not.
At load time, for each texel, divide color by its alpha (putting black for alpha=0 of course).
Why divide? Its “pre-multiplied” alpha. Presumed he is using 255 as opaque and 0 for fully transparent pixels, he needs to divide the alpha by 255 and then use that as factor to multiply RGB with. The alpha channel of the texture remains as is.
Sorry I am wrong, it is not possible to properly un-premultiply when alpha=0, black is not a good value obviously… This works only post-interpolation, ie on the fragment shader.
@skynet : this is to go from “premultiplied alpha” texture, to “classic blending” rendering.
If we cannot find a blending which fits all situations I might
introduce two blendings in the game engine.
The classic blending is default and used in the game-editor and by default in the engine.
Per script command blending can be changed to the one u proposed.