Sign in to follow this  

Rendering Interleaved particle systems.

This topic is 4813 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

Hey All, I am wondering how to render particles where 2 (or more) systems are intersecting. I was going to implement my system using vertex buffers with one buffer per material. But I have thought of a use case in my game where i am likely to have a number of particle systems intersecting. And unfortunately some of the effects will not be possible with additive blending. A particular example is a vehicle explosion (the game is a c&c style 3d affair) where there might be a fireball, a central smoke column and smoke trails for various parts blown off. While trying to think of a solution I did consider just leaving it as is, where by I sort each array back to front and render the buffers one by one, the actual order of rendering the individual buffers is arbitrary. The problem is that, for example, flames on the floor several yards back from a column of heavy smoke are not going to be visible (or partially obscured) from the camera but depending on the order the vertex buffers are rendered the flame material may end up on top of the smoke. If i detect the intersection of two particle systems by bounding box, i can then prepare them differently so that the two systems are interleaved, sorted and rendered together, but i believe this would prevent me from using any sort of fast rendering, the only way i can think to achieve this is glBegin ... glEnd, but there is no way that this would give me any sort of accepable performance. Anyone know of anyway to either get round the situation or a way to render them at a decent speed? I have been having a look around for info but not been able to find much that addresses this problem, I had looked back through the forums but i appologise if this has been addressed and I missed it. Alex Particle engines are certainly fussy little things... [Edited by - aleks_1661 on October 1, 2004 5:51:29 AM]

Share this post


Link to post
Share on other sites
ok, here's the solution I've used to get around these problems:

Firstly, make sure *all* you particle images are on a single texture page so they can be rendered in one batch. Having more than one texture is just not worth it.

Now, use premultiplied alpha textures so that alpha-blended and additive particles can be rendered in the same batch without any state changes. The normal blend modes you're using are presumably as follows:

Alpha:
SrcBlend = SrcAlpha
DestBlend = InvSrcAlpha

Additive:
SrcBlend = One
DestBlend = One

With Premultiplied alpha, you use the following blend mode:
SrcBlend = One
DestBlend = InvSrcAlpha

Now, if you set SrcAlpha to 0 in the texture, you'll get additive because InvSrcAlpha is One. To get Alpha, you leave alpha in the texture as it should be, but you also multiply the colour by the alpha to make up for the lack of SrcBlend = SrcAlpha in the blend mode.

Once you've got that, just sort all your particles back-to-front and render them. You can probably optimise the sorting by testing if whole particle systems overlap in screen space.

HTH,

Matt Halpin

Share this post


Link to post
Share on other sites

This topic is 4813 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.

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