Sign in to follow this  
Mephs

Additive particle blending

Recommended Posts

Hey all, I'm having a little problem with the blending of my particles. I've checked out some existing threads on the topic, but they don't quite seem to solve my problem unfortunately. Now I know that additive blending uses the blending states Src - D3DBLEND_ONE Dest - D3DBLEND_ONE but my problem is that the blending looks clearer and more "correct" when blended over a black background (as you would expect). If you throw in a coloured background, then particles with a dark colour tend to get more of the background blended into them. So white particles become opaque, while red particles are see through. Now I could make do with this, but I'd really prefer if particles worked as follows and I'm having difficulty getting them to do so! I'd like the end effect to be equivalent to drawing the particles over a black background and then rendering the result with standard (D3DBLEND_SRCALPHA, D3DBLEND_INVSRCALPHA) blending. This would basically mean that the particles additively blend with one another, but use a standard blend over the game world. The only way I can think to do this is to first render the particles entirely in black (fading with standard alpha blending). Then to render the particles again over this background. This should then give the behaviour of letting the particle texture control the opacity, while still allowing particles to add to the final colouir intensity. Of course the problem is that this involves rendering particles twice, which is undesirable. Now I've tried every combination of blend modes you can think of to try and do this more efficiently, but I'm beginning to wonder if there actually is no such way to emulate this behaviour purely through blend modes. So would anyone have any helpful hints at all?! Thanks a lot! Steve

Share this post


Link to post
Share on other sites
Ok, couple things:

-Don't know if this applies here, but for additive particle effects with particles that have an alpha channel and/or alpha values on their vertices, I've had success with src SRCALPHA dest DESTALPH, as opposed to dest INVSRCALPHA. I guess I haven't tested it too extensively, but I haven't had the problem I think you're describing.

-If that doesn't work, you could render your particles additively blended with each other to a texture, then render that texture on a quad to your scene. Takes a little more time and memory than just rendering them normally, but shouldn't be as slow as rendering every particle twice.

Share this post


Link to post
Share on other sites
Thanks for the reply!

I'll try with the destination as DEST_ALPHA, but I don't think this will quite achieve the effect I'm after.

In my case, the game world will be rendered with alpha 1.0. So this would mean that the background would always contribute it's full colour to the pixel, this is exactly equivalent to blend mode D3DBLEND_ONE.

So, if I render a single red particle over the background, it would effectively be modulated with the background (50% transparency) rather than fade from opaque to clear as it should do. Sure, I can cure this by rendering more particles so that the background contributes less to the final colour, but again I'd rather render as few particles as possible to achieve the effect!

I'd thought of the render to texture method too, but I think this would unfortunately not work too well as my graphics card lacks a decent fillrate, and even with alpha testing enabled, there would still be a fair bit of alpha blending to do (when rendering to texture and when blitting the resultant texture).

Anyhoo I appreciate the help, but I think I'm still stuck!!

Cheers,

Steve

Share this post


Link to post
Share on other sites
Well.... blow me down, I was wrong!! It actually works as intended!! I'm not quite sure how that is, but I guess I must have not accounted for something.

Screenie incoming.......

*EDIT* Hmm, actually I still seem to have the problem of red particles (or green or blue) not being fully opaque of on their own, but it does seem to have helped with the intensity of the effects, so it's a start at least... screenshot still on its way...!

Pic 1
Pic 2

[Edited by - Mephs on May 29, 2005 5:42:42 PM]

Share this post


Link to post
Share on other sites
Yeah, I guess so. I think the problem first arose when I tried to create smoke. I realised that dark colours are barely visible as particles, but when rendered on a black background a blue particle or red particle is as opaque as any other, and I guess that is what I'm trying to achieve, but if the way that people generally do it is to ignore this factor, then I guess perhaps I should too :P.

The problem originally occurred in trying to add a smoke effect, which I now know really needs subtractive blending anyway, but I guess I'd considered that the dark particle opacity problem may prevent me from creating other types of effects in future, but I guess I could always get around that problem by using different blend modes such as subtractive.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this