Tutorials & Guides / Particles, a GG tutorial series.

Author
Message
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 12th Oct 2018 19:58
You may have heard something regarding new particle control commands in Lua, whether it be Lee's brief announcement about an extra command to attach particles to an entity or my own announcements and demos. Well these commands are in the Beta and will probably all be in a public release some time soon so I'm going to start in on a series of tutorial posts.

I'm going to aim this at the absolute complete beginner level:

What exactly is a 'particle'? Well in 3D engines a 'particle' is really just a small simple object that rather than being positioned by hand or by the physics interactions, is created on the fly and positioned according to a simple set of rules.

What does that mean in GG terms?
Currently a 'particle' in GG (to be precise a 'ravey_particle' as there are others ) is actually a 'camera orientated quad' or to put it another way a small flat square always facing the camera. Onto this is projected an image generated from a sprite sheet. The sprite sheet can contain many images which can either be played as an animation or simply have one selected at random.

But that's just a 'decal' isn't it?
Well yes, and no, it is the exact same principal as a 'decal' but a 'decal' is usually a statically positioned object (unless you move them about under script control as I've amply demonstrated in the past) and they are also usually quite detailed. A decal for example may be used for pasting a sign on a wall or something similar so needs to be high definition.
A 'particle' otoh can be just a small fuzzy blob (in fact for most fancy effects that is what works the best!), using an animated image is *not* the norm for most particle systems, particles are also designed to be used in multiples, many many multiples in most cases whereas a 'decal' is normally a single use beast.

So how does it work?
First you have to define an 'emitter', this is a particle generating object, all it does is pump out new particles.
There are really just two types of emitter (at least at the moment!) one type is attached to the player position, basically as the player moves around so does the emitter, the second type is attached to an entity, if the entity moves so does the emitter.
Once an emitter is defined it will start pumping out particles until it is destroyed but the way it pumps out the particles can be controlled via Lua commands, this means that by for example changing the frequency of the emitter or the max particles it can produce you can effectively switch it on and off under script control!

What would I use a particle emitter for?
One simple example would be to have smoke from a chimney, for a static building you could use a simple static decal, but what if you wanted to have a wind effect? Or maybe instead of a static chimney it is a vehicle smoke stack? In these cases (and just because it looks a lot better!) you can use a particle emitter.

To Be Continued:


Been there, done that, got all the T-Shirts!
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 12th Oct 2018 20:33 Edited at: 12th Oct 2018 20:37
Ok, so I mentioned that 'particles' are "created on the fly and positioned according to a simple set of rules", what exactly are these rules?
Each particle emitter that is created is first set up with a bunch of parameters controlling how the particles are emitted, here is a list of those parameters:
frequency : This is the rate at which new particles are created in milliseconds, so a value of 20 would mean the emitter will produce new particles every 1/50th of a second (or quicker that the period the human eye can actually distinguish!).

life : This is simply how long the particle should exist for, again in milliseconds.
offset : The position relative to the emitter position that a particle should start from.
speed : How fast the particle should move (and the direction as this is a vector).
scale : How big to display the particles.
rotation : The rotation speed of the particle (remember it is camera facing so this is +ve for clockwise -ve for anticlockwise).
alpha : How see-through the particle is (this is actually very important as we'll see later).
animspeed : Bit weird to get your head round to begin with, if you have 64 frames in the sprite sheet the a value of 1 would be 64 FPS, if you have 16 frames then 1 would be 16 FPS. If you wanted a 64 frame sheet to animate at 32 FPS then the value would be 0.5.

There are a couple of other control variables but before covering those I want to expand on the 'rules' I mentioned first.

For some of the variables above you don't specify a single value, what you do is specify a range of values and for each particle emitted the emitter chooses a random value between them.
For offset there is offsetMinX, offsetMinY, offsetMinZ, offsetMaxX, offsetMaxY and offsetMaxZ.
For example if you wanted a particle to be emitted above the emitter position by 200 units you could set offsetMinY and offsetMaxY to 200 and that will do the trick, but much more interesting is when you want to have the particles start somewhere above 200, say within 50 units, then you simply set offsetMinY to 200 and offsetMaxY to 250. Now each particle will pop into existance at a random position within the specified points.
(if using the 'player position' type of emitter and you set the offset values to -200, 200, -200, 200, 250, 200 then the particles would all pop into existance in a box above the players head, no matter where the player goes. Good for snow or rain or volcanic ash falls.)

Some variables have a 'start' and 'end' specification, for example if you specified scaleStartMin and scaleStartMax as 1 and scaleEndMin andscaleEndMax as 10 then the particles would all pop into existance as 1x1 square size and would grow to 10x10 square size at the endo of the life period.

To Be Continued.
Been there, done that, got all the T-Shirts!
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 12th Oct 2018 21:02 Edited at: 12th Oct 2018 21:26
Right back at the beginning I mentioned two 'types' of emitter, how do we select these types?
The (new) Lua command ParticlesAddEmitterEx() (don't blame me, Lee named it ) creates an emitter that is relative to an entity or an entity 'limbindex' (whatever that is, presumably useful for weapons?). The last 4 parameters for this command are entity, limbindex, particleimage, imageframe. If entity is set to -1 then the emitter will be 'player centric', i.e. the variables in the first 28 parameters are relative to th eplayer position, otherwise the specified entity id (and limbindex is specified) position is used.

Hold on a minute what are those last two all about? Well this command allows you to specify which image file to use and the number of frames it contains. There are 3 particle sheets loaded by default, 0 is 'flare', 1 is 'smoke' and 2 is 'flame', but that is a bit limiting so you can load your own sheets (or any of the others dotted around the gameguru files) using the Lua command:
ParticlesLoadImage( <path+file> , slot)

For example:
ParticlesLoadImage( "gamecore\\decals\\sparks\\decal.dds", 3 )
would load the 16 frame sparks decal into particleimage slot 3 so you could then specify a particle emitter using it.

If you need to allocate the first unused slot you would use:
local imageFile = ParticlesLoadImage( "gamecore\\decals\\sparks\\decal.dds" )

time for an example script.

Attach the attached to an an active entity, a crate iow .

To Be Continued.
Been there, done that, got all the T-Shirts!

Attachments

Login to view attachments
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 12th Oct 2018 22:21 Edited at: 12th Oct 2018 22:38
Another example, this time of an emitter attached to an entity (attach it to a crate ).

Homework:
1) Both of these examples are using existing sprite sheets, try making your own and changing the scripts to load those.

2) Try changing the emitter parameters to create other effects.

3) Use any of the following Lua commands to change the emitter behaviour in real time:

ParticlesSetSpeed( emitterId, speedMinX, speedMinY, speedMinZ, speedMaxX, speedMaxY, speedMaxZ )

ParticlesSetOffset( emitterId, offsetMinX, offsetMinY, offsetMinZ, offsetMaxX, offsetMaxY, offsetMaxZ )

ParticlesSetScale( emitterId, scaleStartMin, scaleStartMax, scaleEndMin, scaleEndMax )

ParticlesSetAlpha( emitterId, alphaStartMin, alphaStartMax, alphaEndMin, alphaEndMax )
Been there, done that, got all the T-Shirts!

Attachments

Login to view attachments
PM
Pirate Myke
Forum Support
14
Years of Service
User Offline
Joined: 31st May 2010
Location: El Dorado, California
Posted: 12th Oct 2018 22:31
Cool. Thanks.
Will check this out after work.
Intel(R) Core(TM)2 Quad CPU Q6600 @ 2.40GHz, 2400 Mhz, 4 Core(s), 4 Logical Processor(s), 8gb RAM, Nvidia gtx660, Windows 7 Pro 64bit, Screen resolution 1680 x 1050.

OldFlak
GameGuru TGC Backer
9
Years of Service
User Offline
Joined: 27th Jan 2015
Location: Tasmania Australia
Posted: 12th Oct 2018 22:47
Oh my goodness, I was going to have Sunday off - was!

This is really cool AmenMoses!

Thanks

Reliquia....
aka OldFlak
Intel(R) Core(TM) i3-4160 @ 3,60GHz. 8GB Ram. NVidia GeForce GTX 750. Acer 24" Monitors x 2 @ 1920 x 1080. Windows 10 Pro 64-bit.
PM
GraPhiX
Forum Support
19
Years of Service
User Offline
Joined: 15th Feb 2005
Playing:
Posted: 13th Oct 2018 09:54
Excellent stuff @Amenmoses really informative my knowledge on the party-tickles and what can be done with them is all thanks to your tuition so thank you kind sir
Welcome to the real world!
Main PC - Windows 10 Pro x64 - Core i7-7700K @4.2GHz - 32GB DDR4 RAM - GeForce GTX 1060-6G 6GB - 1TB NVe SSD
Test PC - Windows 10 Pro x64 - G4400 @3.3GHz - 16GB DDR3 RAM - GeForce GTX 950 2GB - 500GB SSD
Laptop - Helios 300 Predator - i7 7700HQ - 32GB - Nvidia GTX1060 6GB - 525GB M2 - 500 SSD - 17.3" IPS LED Panel - Windows 10 Pro x64
Various Tutorials by me
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 13th Oct 2018 13:52
Next thing to cover, as it's real simple, the ParticlesSetWindVector( xv, zv ) command.

I've added 'wind' to the previous example so you can see how it works.

The 'wind' vector will act upon *all* particles and simply adds a movement factor to mimic a constant wind. With a bit of clever coding you can have the vector change over time to mimic gusts etc.

So how many particles can we have?
Currently 1000 on screen at once, to see what this looks like add the attached script to a crate, extract it and paste another 24 down on the map.
When you test this you should find a constant stream of bubbles from each of the 25 crates, now count the bubbles, only joking .

If you add some more you will discover at some point that the constant stream becomes a sort of pulse effect, this is due to hitting the 1000 particles limit.

You can have up to 100 emitters active, each of which can have by default a maximum of 100 particles (this can be changed from Lua) which can be spawned at a maximum rate of 50 particles at once.

As a matter of interest, if you do try out the 25 crates test above have a look at the frame rate you get, I don't see any dip below 60 FPS on my system. I suspect that lower spec CPUs may not be able to cope as well but would be interested to see any results you get.


Been there, done that, got all the T-Shirts!

Attachments

Login to view attachments
PM
OldFlak
GameGuru TGC Backer
9
Years of Service
User Offline
Joined: 27th Jan 2015
Location: Tasmania Australia
Posted: 13th Oct 2018 15:38
This is very cool stuff AmenMoses.

Is it possible to attach an emitter to an object when it is destroyed and just play one random burst. Would be good to mimic an explosion on objects in the air where they don't need to affect the world around them.

Reliquia....
aka OldFlak
Intel(R) Core(TM) i3-4160 @ 3,60GHz. 8GB Ram. NVidia GeForce GTX 750. Acer 24" Monitors x 2 @ 1920 x 1080. Windows 10 Pro 64-bit.
PM
GraPhiX
Forum Support
19
Years of Service
User Offline
Joined: 15th Feb 2005
Playing:
Posted: 13th Oct 2018 16:01
@reliquia stay tuned
Welcome to the real world!
Main PC - Windows 10 Pro x64 - Core i7-7700K @4.2GHz - 32GB DDR4 RAM - GeForce GTX 1060-6G 6GB - 1TB NVe SSD
Test PC - Windows 10 Pro x64 - G4400 @3.3GHz - 16GB DDR3 RAM - GeForce GTX 950 2GB - 500GB SSD
Laptop - Helios 300 Predator - i7 7700HQ - 32GB - Nvidia GTX1060 6GB - 525GB M2 - 500 SSD - 17.3" IPS LED Panel - Windows 10 Pro x64
Various Tutorials by me
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 13th Oct 2018 18:52
If you find your particle effects all start to look like smoke the most likely reason is that GG needs restarting. When you escape out of test mode GG doesn't do a complete clean up! In particular (pun intended) the sprite sheets are still loaded from the previous run, so when you load new ones it uses the next empty slot until eventually it runs out of slots, this isn't fatal as it will simply fall back to using the default smoke effect.

So remember to restart GG occasionally just to clean everything up.
Been there, done that, got all the T-Shirts!
PM
PCS
8
Years of Service
User Offline
Joined: 7th Jul 2016
Playing:
Posted: 14th Oct 2018 00:46
with what build does this work.?
it does not work if i try it.
Windows 7 Professional 64-bit
Intel(R) Pentium(R) CPU G3260 @ 3.30GHz (2 CPUs), ~3.3GHz RAM 16GB NVIDIA GeForce GT 730
DirectX Version: DirectX 11
OldFlak
GameGuru TGC Backer
9
Years of Service
User Offline
Joined: 27th Jan 2015
Location: Tasmania Australia
Posted: 14th Oct 2018 01:41 Edited at: 14th Oct 2018 01:43
Quote: "with what build does this work.?"

Only in beta I think.

Quote: "@reliquia stay tuned "


Keenly indeed

Reliquia....
aka OldFlak
Intel(R) Core(TM) i3-4160 @ 3,60GHz. 8GB Ram. NVidia GeForce GTX 750. Acer 24" Monitors x 2 @ 1920 x 1080. Windows 10 Pro 64-bit.
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 14th Oct 2018 18:31 Edited at: 14th Oct 2018 18:32
Probably still only in the Beta then, not sure when Lee is putting out a new PP, should be soon.

(as I said it the very first paragraph of the thread, I've just realised )
Been there, done that, got all the T-Shirts!
PM
Blacknyt46
8
Years of Service
User Offline
Joined: 29th Feb 2016
Location:
Posted: 16th Oct 2018 09:57
I was all pumped to try this out! And then this
Quote: "Only in beta I think"
What the?
Jim C
Pirate Myke
Forum Support
14
Years of Service
User Offline
Joined: 31st May 2010
Location: El Dorado, California
Posted: 16th Oct 2018 15:17
You can always email Lee for beta access.

Lee@thegamecreators.com

Intel(R) Core(TM)2 Quad CPU Q6600 @ 2.40GHz, 2400 Mhz, 4 Core(s), 4 Logical Processor(s), 8gb RAM, Nvidia gtx660, Windows 7 Pro 64bit, Screen resolution 1680 x 1050.

OldFlak
GameGuru TGC Backer
9
Years of Service
User Offline
Joined: 27th Jan 2015
Location: Tasmania Australia
Posted: 17th Oct 2018 06:39
Hi all

Been messing with this awesome addition to the engine.

This is just so cool AmenMoses - great stuff.

FYI:
I have been messing around making decals and playing with all the settings in the scripts, with the intent to get a fire\smoke thing happening.
Using two emitters one for fire, one for smoke - I wanted to have the fire going up and the smoke getting caught in the breeze a little.

One thing I have found is that if you use an emitter without the wind factor and also one that has the wind factor in the same level, both will mimic the wind factor. Lol - sounds like a riddle...

Reliquia....
aka OldFlak
Intel(R) Core(TM) i3-4160 @ 3,60GHz. 8GB Ram. NVidia GeForce GTX 750. Acer 24" Monitors x 2 @ 1920 x 1080. Windows 10 Pro 64-bit.
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 17th Oct 2018 19:02 Edited at: 17th Oct 2018 19:03
The wind factor is global, i.e. applies to all emitters. Maybe as a future addition I could add a flag to disable the wind effect for a specified emitter, will look into it.
Been there, done that, got all the T-Shirts!
PM
OldFlak
GameGuru TGC Backer
9
Years of Service
User Offline
Joined: 27th Jan 2015
Location: Tasmania Australia
Posted: 18th Oct 2018 05:07
Ok, cool - we wait in anticipation

Reliquia....
aka OldFlak
Intel(R) Core(TM) i3-4160 @ 3,60GHz. 8GB Ram. NVidia GeForce GTX 750. Acer 24" Monitors x 2 @ 1920 x 1080. Windows 10 Pro 64-bit.
PM
Avenging Eagle
19
Years of Service
User Offline
Joined: 2nd Oct 2005
Location: UK
Posted: 18th Oct 2018 14:03 Edited at: 18th Oct 2018 14:04
Are particles subject to any collision? Like if I set up some rain outside, can it detect buildings and coverings and whatnot and not rain inside?

If not, some sort of 'deflectors' system would be fantastic. A way of setting meshes as surfaces particles could bounce off. I remember seeing this functionality in some visual effects software several years ago and it looks great.

AE
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 18th Oct 2018 18:53
No collision, it would have to be 'faked' somehow.

To stop it raining inside for example you would probably have to create a zone which when the player enters it the particles emitters do not, you could attach the emitters to a hidden object that simple follows the player around but stops outside the 'exclusion zone'.

That way you could go indoors then look out at the rain.

It is feasible although probably not very practical to use small simple shapes for the particles instead of 'camera facing quads', maybe spheres, then they would be able to interact with the environment but I doubt you could have enough of them active to mimic rain.

I have a Lua script that does something similar for leaves blowing around but it is really tricky to get realistic behaviour as you can't actually have a 'leaf' collision shape!
Been there, done that, got all the T-Shirts!
PM
granada
Forum Support
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 18th Oct 2018 21:44
This is great reading A M thank for putting it up

Dave
Windows 10 Pro 64 bit
GeForce GTX 1050 Ti
AMD FX (tm)-9590 Eight-core Processor
31.96 GB RAM
1920x1080,60 Hz
PM
Avenging Eagle
19
Years of Service
User Offline
Joined: 2nd Oct 2005
Location: UK
Posted: 19th Oct 2018 18:50
Quote: "To stop it raining inside for example you would probably have to create a zone which when the player enters it the particles emitters do not, you could attach the emitters to a hidden object that simple follows the player around but stops outside the 'exclusion zone'."


Why do the emitters have to follow the player around? Can't those hidden objects just be immobile and placed in the sky to only rain down on specific areas? I guess that would look a bit weird to not have rain coming down on the roof of the building but it might work in certain scenarios.

AE

AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 19th Oct 2018 19:37
They could but then you would need to switch between them as the player moves around and it would be quite hard to make it seamless.

I suppose it could be done in a similar way to the way dynamic lights work, i.e. only the nearest emitter objects to the player are triggered and as the player moves away from them they switch off.
Been there, done that, got all the T-Shirts!
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 19th Oct 2018 20:10


Just a teaser to show what we can do at present.
Been there, done that, got all the T-Shirts!
PM
OldFlak
GameGuru TGC Backer
9
Years of Service
User Offline
Joined: 27th Jan 2015
Location: Tasmania Australia
Posted: 19th Oct 2018 23:19
Hi all

Great stuff as always - really exciting stuff.

I have been testing smoke decals on one of my maps - which seam to working be fine. However when you get about half way through the map, I get this slow-motion effect happening - like player moving slowly, gun re-load in slow-motion, happens for a bit then stops.

If I remove the emitter it doesn't happen.

Haven't changed the scripts yet to test it, but I am guessing we should turn emitters off when player is not within range to see them active?

Anyways, awesome stuff all this - thanks for great work AM and Graphix.

Reliquia....

aka OldFlak
Intel(R) Core(TM) i3-4160 @ 3,60GHz. 8GB Ram. NVidia GeForce GTX 750. Acer 24" Monitors x 2 @ 1920 x 1080. Windows 10 Pro 64-bit.
PM
Teabone
Forum Support
18
Years of Service
User Offline
Joined: 8th Jun 2006
Location: Earth
Posted: 20th Oct 2018 05:37
I hope i can finally get some time to play around with these new lua commands
Twitter - Teabone3 | Youtube - Teabone3 | Twitch - Teabone3 | TGC Assets - Store Link | Patreon - Teabone3

i7 -2600 CPU @ 3.40GHz - Windows 7 - 8GB RAM - Nivida GeForce GTX 960
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 24th Oct 2018 19:22
Look at the ParticlesDeleteEmitter command, i.e. create the emitters as you need them, player enters a zone for example, and delete them when no longer required.
The performance hit depends a lot on how powerful your CPU is, a modern i5 or i7 will handle them fine, older duo's or AMD CPU's will have a harder time of things.
Been there, done that, got all the T-Shirts!
PM
Corno_1
GameGuru Tool Maker
14
Years of Service
User Offline
Joined: 3rd Nov 2010
Location:
Posted: 8th Oct 2019 21:23
Quote: "Just a teaser to show what we can do at present."

Is there any chance to get a demo map with scripts to show some cool stuff
Ebe Editor Free - Build your own EBE structures with easy and without editing any text files
Thread and Download
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 8th Oct 2019 21:48
I think we already did that, the search facility doesn't seem to be working at present but I'm pretty sure GraPhiX released the fireworks demo in the thread at some point last November.

Btw, the fireworks demo we did would work much better now that Preben fixed a few GG issues.
Been there, done that, got all the T-Shirts!
PM
JC LEON
14
Years of Service
User Offline
Joined: 22nd Apr 2010
Location:
Posted: 9th Oct 2019 21:04
any links about topic you mentioned?
PC Specs:
AMD QUADCORE 880K @4.5GHZ, 32GB RAM DDR3 1600, M/B ASUS A88XM-PLUS
SVGA NVDIA 1660GTX 6GB , SSD KINGSTON A400 1TB, 2X HHD SEAGATE BARRACUDA 4TB
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 9th Oct 2019 21:58
https://forum.game-guru.com/thread/220163#msg2607030
Been there, done that, got all the T-Shirts!
PM
JC LEON
14
Years of Service
User Offline
Joined: 22nd Apr 2010
Location:
Posted: 10th Oct 2019 09:46 Edited at: 10th Oct 2019 09:47
thanks

but there isnt any link in that topic sadly..
PC Specs:
AMD QUADCORE 880K @4.5GHZ, 32GB RAM DDR3 1600, M/B ASUS A88XM-PLUS
SVGA NVDIA 1660GTX 6GB , SSD KINGSTON A400 1TB, 2X HHD SEAGATE BARRACUDA 4TB
PM
Corno_1
GameGuru Tool Maker
14
Years of Service
User Offline
Joined: 3rd Nov 2010
Location:
Posted: 11th Oct 2019 16:04
I did my homework
I created a sandstorm
Ebe Editor Free - Build your own EBE structures with easy and without editing any text files
Thread and Download
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 20th Nov 2019 20:46
https://forum.game-guru.com/thread/220055#msg2622747

Probably a good place to put a link to the particles tester script.
Been there, done that, got all the T-Shirts!
PM

Login to post a reply

Server time is: 2024-12-21 17:09:43
Your offset time is: 2024-12-21 17:09:43