# OpenGL Accelerating interleaved Particle Systems

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

## Recommended Posts

Hey All, ------------------------------------------------------------ Quick Appology - I decided to move this to OpenGL rather than the 'Graphics' forum, since I am using opengl and I need info that is specific to the API.. ------------------------------------------------------------ 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 alone. 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 particle system 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 should not be visible (or at least partially obscured) from the camera but depending on the order the vertex buffers are rendered the flame material may end up being rasterised on top of the smoke particles. I realise that if i detect the intersection of two particle systems by bounding box test, 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. Thanks, Alex

cross post

##### Share on other sites
Hence the apology at the begining...

I am begining to think that the only way to get good results is to render occluded systems individually and then render the remaining systems grouped by materials. building the scene up from back to front. Or just give it up as a bad idea and hope that the resulting scene wont look to bad with a few overlaps.

----------------------------------------------

Just found a way of doing it nicely, http://www.gamedev.net/community/forums/topic.asp?topic_id=216773

basicly if i use premultiplied alpha based images then i dont have to change blend modes and if i place all the particle images into a single texture (either at run-time or before hand) then i can pass all the particles as a single vertex array. cushty!

[Edited by - aleks_1661 on October 5, 2004 5:05:03 AM]

##### Share on other sites
Why not have a particle render manager to do the rendering. The particle manager would just represent the sorts of particle systems at work (smoke, flames) and they would pass positions, sizes and textures of the billboards to the particle renderer. This would then sort (since you're inputting the particles one by one you can use insertion sort, or in any case some fast sorting method) the particles by depth value and then render them.

##### Share on other sites
All that is implemented but the problem I want to try and address is what to do when two particle systems are intersecting, unless you use additive blending (as most systems do for corona's sparks etc) you have to mix the two sets of particles together to avoid one type overdrawing the other incorrectly.

ie imagine looking vertically down at a set of billboarded polys
         --   --      --    ==  ==             ==  == --        ==  ==    --      --   --   --             -- particle type 1       ==    ==                == particle type 2          ^          |        Camera       =-====--==-----    < this shows what type would be visible                                in each column

with out rendering the particles all mixed into one vertex array
you will be essentially doing the following
         --   --      --                --         <= particle type 1 rendered first                  --      --   --   --                ==  ==     ==  ==             render the second particle type.        ==  ==       <= particle type 2 will overdraw type 1       ==    ==                ^           |         Camera       ======-===-==--  < the visible particles     =-====--==-----  < this is what should be seen

If using vertex arrays you can only have one material per buffer, which means i cannot change material mid render. And using glBegin/glEnd is slow.

If i could combine a number of particle textures into a single texture then by varying the texture co-ords i can effectivly render particles with more than one 'material' in a single buffer. And extending that by using the premultiplyed alpha technique mentioned above i can actually give the appearance of more than one material and more than one blend mode per buffer. Though i have read up on premultiplyed alpha and it can give particles a dark edge beause the colours become darker as the alpha value of a pixel decreases.

ok, i think that ascii diagram is going to confuse, ill have to try to make an image to show what i mean..

1. 1
2. 2
3. 3
Rutin
21
4. 4
5. 5
gaxio
10

• 14
• 30
• 13
• 11
• 11
• ### Forum Statistics

• Total Topics
631778
• Total Posts
3002310
×