Jump to content
  • Advertisement
Sign in to follow this  
Chris_F

Particle alpha blending

This topic is 1327 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
Advertisement

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Feels like exact moment to try premultiplied alpha.

At least blending should be additive to avoid that darkening.

Edited by vstrakh

Share this post


Link to post
Share on other sites

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);
Edited by Chris_F

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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?

Edited by Madhed

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!