# Particles Engine

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

## Recommended Posts

Hello hello , im trying to build my own particles engine ( as some of you suggested ), and i got some questions 1) any *performances" tips is welcome . ANY :) 2) I cant find how the others are getting blending to do what they whant ! ( what i want is -> in the center of my FX ( where there is more aprticles ), it appear ~ white ; i noticed ppl use ( gl_scr_alpha , gl_one ) . but a ) i tried, it doesnt do what its suposed to do b ) it seems to sux if i draw my FX OVER a textured quad . 3) I reaally need some performance adives ;) Thx !!

##### Share on other sites
I personally use additive blending when I try to simulate flames or bright particles, for that glBlendFunc(GL_ONE, GL_ONE) does the trick for me.
I can't think of too many performance tips, if you're using immidiate calls it's time to switch to VA or dynamic VBO's. You can always give the ARB_point_sprite a run and see whether that boosts performance or not (even though it seems broken on certain hardware like when you introduce custom texture coordinates to Radeon 9700s).
Now can you post a screenshot visually describing the "hideous" :D result mentioned in b?
I have other suggestions about building a nice particle engine since I've done the same just few weeks ago, let me know if you need any further help.
Peace dude.

##### Share on other sites
re , (GL_ONE , GL_ONE ) doesnt do the trick for me :)
i seend 2 source of particule engine ( nehe's and a french one ) , both very simple, they use ( GL_SRC_ALPHA , GL_ONE ), i tried taht too ... didnt worked :/
I may me missing something :/

im not familliar with this vocabulary , immediate calls = glbegin(), glend() ?
if yes, yup that's what im using .
I dont know what VA and VOB stand for, but im sure i can find ;) ill check that .

Concerning the FX over my texture, it isnt "hideous" , it's just blending with my texture witch isnt cool ^^ anyway, the pb is the same w/o texture, i cant find the "missing" parameter that blend correctly .

( i.e i want that when their is many particles on the same spot, it does become lighter . )

AS im just starting this , ill certainly need further help :) thx a lot .

##### Share on other sites
stupid question, but are you actually enabling blending? glEnable(GL_BLEND)?

##### Share on other sites
First: you need to enable blending (see above post)

As for Performance: When particles die don't deallocate the memory just flag them as 'dead' and recycle those dead particles to respawn new ones when needed.
NOTE: a simpler particle system might get away with just re-initialising particles that die to avoid the overhead of finding and flagging dead particles.

VA = Vertex array
VBO = vertex buffer object
Both of these can be used to increase performance over immeadiate mode (glBegin and glEnd)

ARB_point_sprite is (likely to be) faster but much less flexible

Why not build your system with the flexibility to choose the blending criteria rather than hard-coding it.

##### Share on other sites
offcourse i have enabeled blending ;) but i cant find a way to get the result i want .

When particles die, i just change their life value from 0 to 1 :) so no reallocations .

ill check VA ; VBO seems a little complicated .
im still lost ;o)
ty anyways

##### Share on other sites
i have an architecturally sound particle system that relies on heavy use of virtual functions if you're interested. unfortunately its not built with performance in mind.

if you want performance don't allocate and re-allocate particles, simple flag them as dead or not.
also use fixed sized arrays (boost::multi_array).

good luck :)

##### Share on other sites
hehe i already said that i flag them :)
and yeah i was using a vector ...forgot that iterator is the slow !
Im using a "normal" tab, with fixe size .
I got 275 fps, ( 200 with vector)-> only 6000 particles .. i have many optimisations to do :p but thats not my first goal :) my first goal is too get those fucking particle to get lighter when their are a lot on the same space .^^

thx anyway :)

##### Share on other sites
see my website below ive been working on a particlesystem designer recently (theres an oldishish screenshot there), u can change the textures/blending etc during runtime which helps u achieve the look u want
* point_sprite is useless (i recently removed it from my game) the only reason u would want to use it is if youre drawing >10,000 tiny particles
*the thing that tends to kill preformance in particles is the overdraw (not the number of particles) this comes cause usually u have depthwrites off, blending on thus the same pixel onscreen can be overdrawn many many rimes, ways of improving this are texturecompression alphatest etc

##### Share on other sites
One possible cause is: To make the particle system go to white as more particles overlap each other, you need the particles to have at least a small amount of each of the R, G, and B components. If your particle was say, red (255, 0, 0) then red plus a bunch more red is still red. But if you have something like (255, 1, 1) then a bunch of those will eventually add to (255, 255, 255).

##### Share on other sites
Ill chek it @ zdzeek

@ll0377 , Yup, yur right, i think its the trick :) but i got some wierd issue when i try that :
(255,1,0 ) makes ALL my particles (!!!???) go yellow ( 255,255,0)
(255,1,1) makes ALL my particles !! go white ( 255,255,255) ...
I dont understand why ! ...

##### Share on other sites
Sounds to me like your using floats.
glColor3f uses floats in the range of 0 - 1 (any number >1 is locked to 1)
glColor3i is in the range 0 - 255 (this is what you want!!!!)

##### Share on other sites
Quote:
 Original post by Ey-Lord(255,1,0 ) makes ALL my particles (!!!???) go yellow ( 255,255,0)(255,1,1) makes ALL my particles !! go white ( 255,255,255) ...I dont understand why ! ...

let's check out why you get that behaviour:

Say for simplicitys sake that you have 255 particles all bunched together.

If each particle is RGB(255,1,0) that means they are
R: 255 G: 1 B: 0
If you add all 255 of those together, how can the blue channel ever get any contents? Adding the channels together separately doesn't magically make that 0 blue channel grow. That's why you need at least 1 in all channels.

If each particle is RGB(255,1,1) that means they are
R: 255 G: 1 B: 1

Add 255 of those and you'll have R: 255 G: 255 B: 255 since there is something in each channel that can add up. Then you get a white glow in the center of the mass of particles.

##### Share on other sites

Other performance tips:

1. Don't use virtuality for things like Update and Render methods - I know it's hard to write flexible and clean system without virtual methods, but (as that article shows) it's not impossible.

2. Don't allocate / deallocate memory on heap, ie. every particle is created by new, and is deleted when it's dead. Use pools instead.

3. Don't use immediate mode if you're rendering more than 100 particles each run. Sort particles by texture they're using and send them all in one call of glDrawArrays (or sth similiar).

HTH

##### Share on other sites
I fixed the color problem , i was using glcolor4d ... now i use 4f and range value 0 - 1 . works fine

I just got some problem with the initialisations but ill fix that alone i think .

1) im at the beggining, i dunno really with what i will end up ( what kind of design ( technically seapking - dude i need some more precise vocabulary on thi - ) ) .

2 ) What are pools ?

3) That's the next thing im gonna check :)

thx !!

##### Share on other sites
Here's a snapshot of what my particles setup file looks like:

<Particles  acceleration =   "1.0"            maxSpread    =  "3.14"            progress     =   "0.0"            lifeTime     =  "1.25"            delay        =   "2.0"            speed        =   "4.0"            count        =   "200"             fade         =  "true"            spin         = "false">  <Size   start = "2.0" end = "5.0" />    <Color  r =   "0.2" g =  "0.2" b =    "0.9" />    <Texture  type        = "TEXTURE_2D"            path        = "particle.jpg"             mode        = "MODULATE"            mipmap      = "false">    <Wrap   s           = "CLAMP_TO_EDGE"            t           = "CLAMP_TO_EDGE" />    <Blend  source      = "ONE"             destination = "ONE" />    <Filter mag         = "LINEAR"             min         = "LINEAR" />  </Texture>  <PathSpline>  <Spline close = "true" cycle = "10.0">    <Point x =  "-24.7599" y = "96.8863" z = "0"  />    <Point x =  "-47.965" y = "87.746" z = "0"  />    <Point x =  "-68.1797" y = "73.1541" z = "0"  />    <Point x =  "-84.1578" y = "54.0136" z = "0"  />    <Point x =  "-94.9173" y = "31.4755" z = "0"  />    <Point x =  "-99.7636" y = "6.8721" z = "0"  />    <Point x =  "-98.3704" y = "-17.9795" z = "0"  />    <Point x =  "-90.7558" y = "-41.9926" z = "0"  />    <Point x =  "-77.5486" y = "-63.1365" z = "0"  />    <Point x =  "-59.7742" y = "-80.1689" z = "0"  />    <Point x =  "-38.1097" y = "-92.4535" z = "0"  />    <Point x =  "-14.0949" y = "-99.0017" z = "0"  />    <Point x =  "10.8982" y = "-99.4044" z = "0"  />    <Point x =  "35.2093" y = "-93.5965" z = "0"  />    <Point x =  "57.2087" y = "-82.0193" z = "0"  />    <Point x =  "75.7356" y = "-65.3002" z = "0"  />    <Point x =  "89.5671" y = "-44.4717" z = "0"  />    <Point x =  "97.7779" y = "-20.9638" z = "0"  />    <Point x =  "99.9276" y = "3.80343" z = "0"  />    <Point x =  "95.8749" y = "28.4255" z = "0"  />    <Point x =  "85.8443" y = "51.2909" z = "0"  />    <Point x =  "70.5056" y = "70.9152" z = "0"  />    <Point x =  "50.8075" y = "86.1313" z = "0"  />    <Point x =  "27.9151" y = "96.0247" z = "0"  />    <Point x =  "3.30315" y = "99.9454" z = "0"  />  </Spline>  </PathSpline></Particles>