Particle alpha blending

Started by
15 comments, last by theagentd 9 years, 7 months ago

I want to render some soft round particles. Currently I'm rendering white quads with an alpha value calculated as:


float alpha = 1.0f - clamp(length(position), 0.0f, 1.0f);

The blending function looks like:


glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

But the particles seem to subtract from each other around the outside (dark halo):

[attachment=24091:example.jpg]

Advertisement

Are you sorting the particles by depth and rendering them back-to-front?

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Are you sorting the particles by depth and rendering them back-to-front?

These aren't 3D particles. Just a bunch of random 2D sprites.

Are you sure the RGB channel is fully white. Have you deactivated the depth buffer?

Are you sure the RGB channel is fully white. Have you deactivated the depth buffer?

The code is basically just:

float alpha = 1.0f - clamp(length(position), 0.0f, 1.0f);
frag_color = vec4(1.0f, 1.0f, 1.0f, alpha);

There is no depth buffer, depth test is disabled.

Feels like exact moment to try premultiplied alpha.

At least blending should be additive to avoid that darkening.

I don't understand what the issues is. Isn't this blending mode the equivalent of:


new_color = lerp(current_color.rgb, old_color.rgb, current_color.a);

There's plenty of blending modes. Interpolation is just one of them, and it looks like not suitable for this case.

There's plenty of blending modes. Interpolation is just one of them, and it looks like not suitable for this case.

If the functionality of GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA was identical to the code I posted, then I would not be having the issue displayed in my image.

This is realy weird. I'm 99% sure that the operation is associative if all particles have the same solid color.

Have you tried rendering the image without alpha blending just to be sure? From the fragment shader you have posted, this should not be the problem but you never know...

Could this be a backbuffer precision error?

This topic is closed to new replies.

Advertisement