Particles... Particles

Community Forums/Showcase/Particles... Particles

N(Posted 2004) [#1]
Note: The comments at the top of LotusTest.bb should be completely disregarded.


Because particle systems/engines/whatever-the-heck-name-appeals-to-you's happen to be my favorite thing to write, I wrote another. I'm rather happy with it. Because I'm happy with it, I thought I'd put up a demo.

The demo showcases four effects: Fire, sparks, rocket-launching (with trailing flames and smoke and collision explosions), and explosions. Nothing special, but the source is included so you can mess with creating new/different effects.

This is a pseudo-single-surface particle system, each emitter has its own surface (I've considered combining duplicate emitters into single surfaces, but then there's the issue of blend modes and potentially changing textures..), and each particle goes into that surface. There's distance-based sorting for emitters with a their Sort flag set to True and a quick hackjob of culling (which seems to be broken at the moment, not sure why yet).

Anyhow, I'm going to stop myself from trying to get into describing the system itself and just let you stare at this picture a bit before eventually being tempted to click it. Which you will, because I control your every thought and action! Including the smart ones.

Source code download, 125kb



Rob(Posted 2004) [#2]
it's far better to have a single surface per emitter as they will be culled very easily offscreen. Much better performance in real game scenarios.

nice work too!


Ross C(Posted 2004) [#3]
That's a good idea Rob. Keep my surfaces in an array or something.

Anyway, nice work again Noel.


jfk EO-11110(Posted 2004) [#4]
kewl, thanks for sharing!


Picklesworth(Posted 2004) [#5]
nice! I have to compliment every part seperately:
The large fire effect which looks like the sun makes a lovely little lighting effect that I have been hoping someone would make for ages (so I could borrow it :D)
The rocket's trail is very high detail, and it is quite well done. A fine example of how your particle system can do moving emitters.
Finally, the sparks are another effect that is just perfect for my big game.
So, excellant job Noel! And thanks for sharing :D


N(Posted 2004) [#6]
dill: Glad to be of assistance :)

jfk: You're welcome.

Ross: Thanks.

Rob: Really? That's very interesting (to me, at least). I guess I won't have to worry about sticking everything in one single surface then. :) And thanks.


R0B0T0(Posted 2004) [#7]
Looking good Noel! It seems to me that a visually effective particle system is just as much about proper choice and usage of the particle images as it is about code. Looks like you're on the right track there.


N(Posted 2004) [#8]


That said, just stick this in an include or something and call the appropriate functions (there're only two, and they're fairly self explanatory).

;Explosions for the Lotus particle system.
;Media from the lps_test2.zip archive is required.
;InitExplosion()  -  Call this to initialize the required emitters.
;Explode(X,Y,Z)  -  Call this to create an explosion at X,Y,Z

;I'm still working on projectile explosions >:)

Global gExpSmoke,gExpSmokeTrail,gExpSpark,gExpFire

Function InitExplosion()
     Local Fire,Smoke,SparkMesh,SparkTex

     ;; Load textures.  And stuff.
     Fire = LoadTexture("fire.png",1+16+32)
     Smoke = LoadTexture("smoke.png",1+2+16+32)
     SparkMesh = LoadMesh("beam.3ds")
     RotateMesh SparkMesh,90,0,0
     ScaleMesh SparkMesh,.2,.2,.2
     HideEntity SparkMesh ;woops, forgot that
     SparkTex = LoadTexture("beam.png",1+16+32)

     If Not Fire Or Smoke Or SparkMesh Or SparkTex Then RuntimeError "Uh-oh!  Explosion couldn't be created due to one or more of the four intial variables being 0!  Papa had an oopsie!"

     gExpFire = CreateEmitter(Fire)
          SetEmitterLifeSpan gExpFire,50
          SetEmitterSizeFrom gExpFire,4,4,4
          SetEmitterSizeTo gExpFire,6.7,6.7,6.7
          SetEmitterColorFrom gExpFire,0,0,0,2
          SetEmitterColorTo gExpFire,255,255,255,0
          SetEmitterBlend gExpFire,3
          SetEmitterVelocity gExpFire,0,0,.025


     gExpSmoke = CreateEmitter(Smoke)
          SetEmitterLifeSpan gExpSmoke,96
          SetEmitterSizeFrom gExpSmoke,5,5,5
          SetEmitterSizeTo gExpSmoke,10,10,10
          SetEmitterColorFrom gExpSmoke,0,0,0,2
          SetEmitterColorTo gExpSmoke,192,192,192,0
          SetEmitterBlend gExpSmoke,3


     gExpSmokeTrail = CopyEmitter(gExpSmoke)
          SetEmitterLifeSpan gExpSmokeTrail,32
          SetEmitterSizeFrom gExpSmokeTrail,.5,.5,.5
          SetEmitterSizeTo gExpSmokeTrail,1.3,1.3,1.3
          SetEmitterWaitSpan gExpSmokeTrail,5
          SetEmitterAngle gExpSmokeTrail,-90,0,0
          SetEmitterAcceleration gExpSmokeTrail,0,0,.001


     gExpSpark = CreateEmitter(SparkTex)
          SetEmitterLifeSpan gExpSpark,40
          SetEmitterVelocity gExpSpark,0,0,.15
          SetEmitterAcceleration gExpSpark,0,0,.005
          SetEmitterAngleAcceleration gExpSpark,.04,0,0
          SetEmitterParticleMesh gExpSpark,SparkMesh
          SetEmitterSizeFrom gExpSpark,.9,.9,.3
          SetEmitterSizeTo gExpSpark,.3,.3,.9   ;reverse!
          SetEmitterViewMode gExpSpark,2
          SetEmitterColorFrom gExpSpark,255,228,209,1
          SetEmitterColorTo gExpSpark,255,138,0,0
          SetEmitterBlend gExpSpark,3
          SetEmitterTrail gExpSpark,gExpSmokeTrail

     Return True
End Function


Function Explode(X#,Y#,Z#)
     If Not gExpFire Or gExpSmoke Or gExpSmokeTrail Or gExpSpark Then RuntimeError "Explosion emitters not initialized"
     For N = 0 To 5
          Angle = Rand(359)
          Off = Rnd(-2,2)
          SetEmitterPosition gExpFire,X+Rnd(-2,2),Y+Rnd(-2,2),Z+Rnd(-2,2)
          SetEmitterAngle gExpFire,Angle,Angle,Angle
          CreateParticle gExpFire
     Next

     For N = 0 To 5
          Angle = Rand(359)
          SetEmitterPosition gExpSmoke,X+Rnd(-2,2),Y+Rnd(-2,2),Z+Rnd(-2,2)
          SetEmitterAngle gExpFire,Angle,Angle,Angle
          CreateParticle gExpSmoke
     Next

     For N = 0 To 7
          SetEmitterPosition gExpSpark,X+Rnd(-2,2),Y+Rnd(-2,2),Z+Rnd(-2,2)
          SetEmitterAngle gExpSpark,Rand(-80,10),Rand(359),45
          CreateParticle gExpSpark
     Next
     Return True
End Function



Kuron(Posted 2004) [#9]
Nice stuff Noel, thanks for sharing


R0B0T0(Posted 2004) [#10]
Hmmm... have you added extra parameters to the SetEmitterSizeFrom and SetEmitterSizeTo functions?


N(Posted 2004) [#11]
Ah yes, guess I'd have to update the old archive too. *proceeds to do so*


jhocking(Posted 2004) [#12]
Now the demo doesn't work. I get an error that there aren't enough parameters in those functions.

I'm looking forward to seeing this particle system. Please fix the demo code. And maybe add those explosions to the download zip.

ADDITION: I just looked at the compiled demo. The rocket is so cool! Please fix the download.


N(Posted 2004) [#13]
Should be fixed now. Also, the explosion code is included with the LotusTest.bb in the new archive.

jhocking: Re-download the lps_test2.zip. I apologize for this inconvenience :)


jhocking(Posted 2004) [#14]
Darn cross posting. Muchas gracias!

Sorry to be a pest, but now the rocket is gone. That was the best part! Also, pressing 1 freezes the demo.


Perturbatio(Posted 2004) [#15]
looks very nice indeed.


N(Posted 2004) [#16]
jhocking: Yeah, somehow I broke the rocket, so I removed it. Also, pressing 1 now stops it (for debugging purposes).

Comments at the top should be completely disregarded.


Edit: This'll probably be funner: I'm working on some code to let you launch the rocket, and it'll hit stuff and blow up. That'll be fun, methinks.

Edit2: And if you still want that first rocket, you can always download the executable.


Perturbatio(Posted 2004) [#17]
I get a MAV with the compiled exe


Picklesworth(Posted 2004) [#18]
the trail on the rocket is only gone when the explode function is called, if that's what you mean by "broke it". Same thing happens with the flare. Very cool explosion though!


N(Posted 2004) [#19]
Perturbatio:

(you'll still need the media from the source .ZIP)


You will need the media from lps_test2.zip, y'know. In other words, make sure the executable is in the same folder as the media (models, textures, etc.).

Edit: And now I can't play tech support anymore 'cause I've got to get off. And eat. And stuff.


N(Posted 2004) [#20]
The rocket is back. The executable won't be updated. Same archive, so just click the rocket.


N(Posted 2004) [#21]
Added particle bouncing (which relies on the next bit) and basic collisions. The sparks in the latest LotusTest.bb exhibit this behavior.


Perturbatio(Posted 2004) [#22]
You will need the media from ...


oops :)


jhocking(Posted 2004) [#23]
It would be awesome if you put back one rocket exhibiting the old behavior. The visual of the rocket flying in circles, doubling back into its own smoke trail, was very interesting and a neat demonstration of how visually effective the particle system can be.


N(Posted 2004) [#24]
Alright, it's back in there, just for you ;)


jhocking(Posted 2004) [#25]
Aw, now I feel special.


CyBeRGoth(Posted 2004) [#26]
Brilliant stuff!


N(Posted 2004) [#27]
To quote one of my sister's games: <stoned voice> "Haaapppy ddaaaaaay....." </stoned voice> ;)

I'll have another set of examples up sometime today. So far I've got a fountain and bullet casings (falling to the floor and bouncing a very tiny bit).

Anyone have any requests? Anything from features to examples, since right now I'm drawing a blank.


N(Posted 2004) [#28]
Added another test file: "Fountain.bb". It showcases an emitter that spits out bullet casings, a fountain (read the comment at the top of Fountain.bb for a quick bit of info), and some steam erupting from a pipe (the only reason that one is included is 'cause I wanted to test my wall model with it :P).

Oh yeah, and for some reason it runs slow as hell with Debug mode on, so just a warning to ye all.