Hi KaiHH,
thank you for your help.
So I used the alpha to coverage technique as it is written in your link.
To be able to use this technique I must first use the anti-aliasing multi-sample (4x at least),
and I have to render directly to the screen, not to an FBO.
First, I delete these lines in fragment shader : (alpha testing)
if (textureColour.a<0.5)
{
discard;
}
I enable GL13.GL_SAMPLE_ALPHA_TO_COVERAGE and disable it before and after rendering my triangles.
like this:
GL11.glEnable(GL13.GL_SAMPLE_ALPHA_TO_COVERAGE);
// render
GL11.glDisable(GL13.GL_SAMPLE_ALPHA_TO_COVERAGE);
The result is as follows:
Then I use the function fwidth () in my fragment shader to average colors.
The fwidth () function returns the sum of the pixel’s partial derivatives for a value, usually described as the equivalent of abs (ddx (value)) + abs (ddy (value)). Those two functions, ddx () and ddy (), are partial derivative functions.
Like this:
textureColour.a = (textureColour.a - 0.4) / max(fwidth(textureColour.a), 0.0001) + 0.5;
0.4 and 0.5 are taken arbitrarily.
The result is as follows:
thirdly, I add this line (before the last one) to manage the cases of disappearance of the intensity of the triangle when the mipmaping level is high (lowest resolutions of pictures)
like this:
float mipmapLevel = textureQueryLod(modelTexture, pass_textureCoords).x;
textureColour.a *= 1 + max(0, mipmapLevel) * 0.0;
so this :
if (textureColour.a<0.5)
{
discard;
}
became :
float mipmapLevel = textureQueryLod(modelTexture, pass_textureCoords).x;
textureColour.a *= 1 + max(0, mipmapLevel) * 0.0;
textureColour.a = (textureColour.a - 0.4) / max(fwidth(textureColour.a), 0.0001) + 0.5;
in my fragment shader with alpha to coverage enabled.
Hope this post can be useful for others ...