Jump to content
  • Advertisement
Sign in to follow this  
cbjurado

Particles - Additive Blending problem revisited

This topic is 5015 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 am satisfied with the looks of the particles I wanted. See screenshot. It uses additive blending. The problem of additive blending is that when you have something bright colored at the background (e.g. white), your particles will add to those colors and lose their distinct color. Example, if I have a white background, you could not see any of the particles. That limits me to have sufficiently dark-colored objects around. I can't have a snowy map or have a very bright sky. I want them to still show and still look the same above. Filtered blending also doesn't work. Aside from not getting cool looks, you get visual artifacts unless you do the dreaded depth-sorting (which I do not intend to use). Someone please help me with a good solution.

Share this post


Link to post
Share on other sites
Advertisement
Well, adding something to white will always get you white, so you'll need a blending mode that can darken what's behind it.

I use this for a dark smoke particle :

pDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_ZERO );
pDevice->SetRenderState( D3DRS_DESTBLEND,D3DBLEND_INVSRCCOLOR );

Of course, this becomes sort-dependent.

This approach above essentially acts as a mask that darkens the background by the amount of the foreground.

I think what you really want is srcalpha, invsrcalpha, but then you have to sort that as well.

Share this post


Link to post
Share on other sites
My gut instinct is that you're pretty much stuck - if you want fancier blending modes then sorting becomes pretty much required - and the 'overbright' problem with additive is a fairly fundamental drawback.

If you want dark particles over light backgrounds (smoke over snow for example) you could use subtractive (or signed) blending. That should be order-independant as well and give you a little more flexibility.

Share this post


Link to post
Share on other sites
I know nothing about graphics programming like this, but something came to mind and I figured I'd share it:

Since the problem is that your background color affects the particle color, why not control your background color? Sure you say, but I want snowy maps. Well, a maybe possible solution that comes to mind is to render the particle to a texture with an alpha channel based on something {like the density of each particle at that point, so the center will be fully opaque), and then blit that to the main image with alpha blending. This would keep the colors you like on any background. The white particles would be the only problem really, and I'm not sure what you could do about those other than maybe decrease the transparency a bit in a bigger radius than normal, so the edges would have a tint of the chosen background color.

You'd have to do sorting for each big particle, rather than each component of each particle, which should be much, much faster.

If that isn't acceptable, I don't think there is a solution within your requirements.

Share this post


Link to post
Share on other sites
Hmm... I think Extrarius might have something there. Draw your particles (additively) into a separate buffer (initially black), and then draw the whole buffer over the screen using the inv-source-colour blend mode. No sorting needed, and handles saturated backgrounds. :)

Share this post


Link to post
Share on other sites
That could work for 2D but I am working in 3D. You'll have problems with the depth buffer. The idea of rendering to a texture will not work since the depth test process is skipped. For example, if the particle is behind a wall, it would still show.

Share this post


Link to post
Share on other sites
You can also use the depth buffer when rendering to texture. In D3D you can do this by using SetDepthStencilSurface method. If you can afford rendering the depth values for the scene again it might be worth doing so to a lower resolution depth surface and also render particles to a lower resolution texture. If you got loads of particles it might save you some fillrate.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!