Search code examples
iosopengl-esfragment-shadervertex-shader

Particle Sprites are slightly accumulating pixels where alpha is 0%


I am rendering particles with a Vertex and Fragment shader.

In my vertex shader I am clamping the alpha component of the output fragment color:

highp float alpha = clamp(rotatedTexture.a, 0.01, 0.05);
highp vec4 base = vec4(vShade.r, vShade.g, vShade.b, alpha);
fragmentColor = base;

The value for rotatedTexture.a is read in from the following PNG - I have made absolutely sure that there are no edges in the bitmap - anything that resembles a square should not be drawn.

enter image description here

But, you can see squares rendered - even though the effect is slight - they are definitely there. I highlighted one sprite with a black border (two good examples are a large green and pink sprite overlapping each other in the lower right corner).

Since I am clamping the alpha to 5% percent, and since there are clearly no hard edges with my texture's alpha - how can it possibly be drawing hard edges? Note that I am seeing the same thing with different textures.

enter image description here


Solution

  • enter image description here

    Whatever your texture alpha is, your clamp function returns 0.1 to 0.5 because you set so.

    If your texture alpha is zero, your clamp function returns 0.1 or

    if your texture alpha is over 0.5, it returns 0.5