eloise


Learning about Particles

Scripting Particles: llParticle system.

The particle system in lsl looks a little daunting at first, but is actually, with a little time and effort NOT that hard to use. To use it well, however, involves a level of artistic ability as well as the base scripting skills both in terms of tweaking the parameters and using the right texture for the job.

I have added videos of the scripts in use. They are sometimes slightly amended from the scripts you see… in particular the colours are made greyer so they stand out against the white backdrop, and the speeds are sometimes reduced a little. You should also note that the originals look a lot less pixealted than this… taking movies and updating them is not that great for the picture quality.

Rather than diving into a long list of what all the parameters are (which you can see here, on the wiki this tutorial will start with simple particle system and gradually add refinements. You can skip ahead if you want to.

I want to start making particles
I want to tweak the colour of the particles
I want the particles more spread out
I want to tweak the alpha (transparency) of the particles
I want to make the particles fall (snow, rain, showers etc.)
I want the make the particles have a different texture
I want the make the particles in a different shape than this explosion thing…
I want the particles to follow someone/things
I want the particles to blow in the wind
I want the particles to change colour/alpha
I want the particles to change size
I want to change size, colour AND follow the wind (and rise too – let’s make some smoke!)
I want to get rid of these pesky particles
Bringing it all together – making your particles really dance.

_______
I want to start making particles

We’re going to make a script that produces 10 grey-white ‘balls of light’ each second which are about 0.5m in diameter, that appear all round the prim the script is in, last 10 seconds and drift slowly away. The ‘balls of light’ is the default texture that gets used if you don’t define a different one, we’ll save that for later too!

The particles are at the top, in a function called particleSystem() so they’re the first thing you see. It’s not always necessary to do this, but it helps us focus on what’s going on!


particleSystem()
{
	llParticleSystem([	PSYS_PART_START_SCALE, <0.5, 0.5, 0.0>,		//This sets the size (scale) of the particles to 0.5m 
						PSYS_PART_MAX_AGE, 10.0, 					//This gives us the lifetime of the particles
						PSYS_SRC_BURST_RATE, 1.0,					//There's a new burst every 1.0 seconds
						PSYS_SRC_BURST_SPEED_MIN, 0.01,				//The minimum speed of the particles (in m/s)
						PSYS_SRC_BURST_SPEED_MAX, 0.1,				//The maximum speed - so they move slowly
						PSYS_SRC_BURST_PART_COUNT, 10,				//How many particles to make
						PSYS_SRC_PATTERN, PSYS_SRC_PATTERN_EXPLODE	//The pattern we use, this is all round the prim.
					]);
}

//Teaching about particles script, written by Eloise Pasteur. This is a teaching resource and it freely available. If you paid for it, complain to the person you bought it from, and let me know.

default
{
	state_entry()
	{
		particleSystem();
	}
}

OK, paste that into a script and see how it goes! (You might want to make the prim rather smaller than usual so you can see the effects clearly).

Although it’s pretty scary you might notice some common things in the names of the constants (the blue words in capitals). They all start with PSYS – for particle system, and the next group of letters is either PART or SRC. PART refers to the particle part of the system, size, colour etc. of the particles, whilst SRC refers to the source part of the system, how often the particles appear, where they appear and so on.

So, PSYS_PART_START_SCALE is addressing the actual particles we see… and their starting size (scale). Hopefully the name makes more sense now. And yes, it does imply a PSYS_PART_END_SCALE variable so you can change the size of the particles over time, more on that later. You might also notice that the scale vector only has two values set to something other than 0. Particles are flat – BUT they’re what we call client side – so everyone looking at them, from whatever angle, seems them as flat on their screen.

Similarly PSYS_SRC_BURST_RATE is addressing the source prim, and telling it how often to fire off more particles – in fact it’s the time between bursts, just like you were recalling the function in a timer event each time.

Let’s play with these one row at a time, except for the last row and see what happens:

Try changing PSYS_PART_START_SCALE, <0.5, 0.5, 0.0>, to PSYS_PART_START_SCALE, <5.0, 5.0, 0.0>,

What happens? The particles get much bigger.

Go back to PSYS_PART_START_SCALE, <0.5, 0.5, 0.0>, and change PSYS_PART_MAX_AGE, 10.0, to PSYS_PART_MAX_AGE, 1.0,

What happens? The particles die much, much faster, so it look like there are few around, and they don’t spread as far out.

Go back to PSYS_PART_MAX_AGE, 10.0, and change PSYS_SRC_BURST_RATE, 1.0, to PSYS_SRC_BURST_RATE, 10.0,

What happens? The particles appear only every 10 seconds. There are fewer particles on the screen at a time, and they start in the middle and drift out, then as one group die the next appears in the middle.

Go back to PSYS_SRC_BURST_RATE, 1.0, and change PSYS_SRC_BURST_SPEED_MIN, 0.01, to PSYS_SRC_BURST_SPEED_MIN, 0.05,

What happens? The particles seem to move a bit faster. If you watch closely the highest speed is the same, but the lowest is much higher, and so’s the average which makes them look faster.

Go back to PSYS_SRC_BURST_SPEED_MIN, 0.01, and change PSYS_SRC_BURST_SPEED_MAX, 0.1, to PSYS_SRC_BURST_SPEED_MAX, 1.0,

What happens? Again the particles seem to move much faster. This time they get further away from the centre, and again the average speed has increased. The differenced between the minimum and maximum speed can be tricky to spot, but they’re important to making it look right.

Go back to PSYS_SRC_BURST_SPEED_MAX, 0.1, and change PSYS_SRC_BURST_PART_COUNT, 10, to PSYS_SRC_BURST_PART_COUNT, 100,

What happens? Loads more particles seem to fill the space around you!

This is why there is an element of artistry in particle systems that there doesn’t have to be in many other scripting situations. Simply changing one number can make some major differences to how the particles look. Imagine tweaking them all at once, what would it look like?

Feel free to experiment with the various parameters and make something that looks good to you.

Back to top

_______
I want to tweak the colour of the particles

So, you’re bored of the grey and white smoke default particles and want to try something a bit different then? Let’s add a line to the top of the particle system we’ve used above. (I’m only using the particle system call here, the whole script is here


llParticleSystem([		PSYS_PART_START_COLOR, <0.0, 0.0, 1.0>,	//This sets the colour of the particles to blue
						PSYS_PART_START_SCALE, <0.5, 0.5, 0.0>,		//This sets the size (scale) of the particles to 0.5m 
						PSYS_PART_MAX_AGE, 10.0, 					//This gives us the lifetime of the particles
						PSYS_SRC_BURST_RATE, 1.0,					//There's a new burst every 1.0 seconds
						PSYS_SRC_BURST_SPEED_MIN, 0.01,				//The minimum speed of the particles (in m/s)
						PSYS_SRC_BURST_SPEED_MAX, 0.1,				//The maximum speed - so they move slowly
						PSYS_SRC_BURST_PART_COUNT, 10,				//How many particles to make
						PSYS_SRC_PATTERN, PSYS_SRC_PATTERN_EXPLODE	//The pattern we use, this is all round the prim.
					]);

The line breaks down as follows: PSYS_PART_START_COLOR is the constant that tells the script to change the colour of the particle. The fact it’s START_COLOR does suggest there’s also a PSYS_PART_END_COLOR, but more of that later. The <0.0, 0.0, 1.0> defines a colour vector. The three numbers are the red, green and blue values of the colour. Unlike almost everyone else in the world lsl uses 0 – 1 rather than 0-255 for the values. So <0.0, 0.0, 1.0> is blue (0, 0, 255), whilst <0.0, 1.0, 0.0> is green (0, 255, 0). You can convert between the two systems by multiplying or dividing by 255.

You should also not that the colour you get is a bit like a multiply filter – the colours underneath are affected by the colour you apply. Making grey scale images gives you a more controllable effect, but you can get some amazing looks by applying a colour to a complex image. Try this in your particle system, and play with the colours and see how they work.

Back to top

_______
I want the particles more spread out

So you want your particles more spead out? Let’s look at the particle system call of the basic script again (the whole script is here):


llParticleSystem([		PSYS_PART_START_SCALE, <0.5, 0.5, 0.0>,		//This sets the size (scale) of the particles to 0.5m 
						PSYS_PART_MAX_AGE, 10.0, 					//This gives us the lifetime of the particles
						PSYS_SRC_BURST_RATE, 1.0,					//There's a new burst every 1.0 seconds
						PSYS_SRC_BURST_SPEED_MIN, 0.01,				//The minimum speed of the particles (in m/s)
						PSYS_SRC_BURST_SPEED_MAX, 0.1,				//The maximum speed - so they move slowly
						PSYS_SRC_BURST_PART_COUNT, 10,				//How many particles to make
						PSYS_SRC_PATTERN, PSYS_SRC_PATTERN_EXPLODE	//The pattern we use, this is all round the prim.
					]);

The basic script as we discussed here gives you a few ways to do that. You can adjust the speed (either) of the particles so they go further, their age (so they’ve got more time to get there) etc.

There is also another way of doing it. Adding the line PSYS_SRC_BURST_RADIUS, 5.0, into the particle call e.g.


llParticleSystem([		PSYS_PART_START_SCALE, <0.5, 0.5, 0.0>,		//This sets the size (scale) of the particles to 0.5m 
						PSYS_PART_MAX_AGE, 10.0, 					//This gives us the lifetime of the particles
						PSYS_SRC_BURST_RATE, 1.0,					//There's a new burst every 1.0 seconds
						PSYS_SRC_BURST_SPEED_MIN, 0.01,				//The minimum speed of the particles (in m/s)
						PSYS_SRC_BURST_SPEED_MAX, 0.1,				//The maximum speed - so they move slowly
						PSYS_SRC_BURST_PART_COUNT, 10,				//How many particles to make
						PSYS_SRC_BURST_RADIUS, 5.0,					//How far out the particles start.
						PSYS_SRC_PATTERN, PSYS_SRC_PATTERN_EXPLODE	//The pattern we use, this is all round the prim.
					]);

Try this in your script – notice how the particles explode from further out from the source? You can play with the range to make it further and closer… The burst radius doesn’t work with every pattern and with some flags, but it is often useful. If it DOESN’T work in a script you’re using check the patterns and flags.

Back to top

_______
I want to tweak the alpha (transparency) of the particles

So, you want to make your particles more see through? Amneding the basic particle script as below will help.


llParticleSystem([		PSYS_PART_START_ALPHA, 0.5,							//This affects the overall alpha of the particles (low is more transparent)
						PSYS_PART_START_SCALE, <0.5, 0.5, 0.0>,		//This sets the size (scale) of the particles to 0.5m 
						PSYS_PART_MAX_AGE, 10.0, 					//This gives us the lifetime of the particles
						PSYS_SRC_BURST_RATE, 1.0,					//There's a new burst every 1.0 seconds
						PSYS_SRC_BURST_SPEED_MIN, 0.01,				//The minimum speed of the particles (in m/s)
						PSYS_SRC_BURST_SPEED_MAX, 0.1,				//The maximum speed - so they move slowly
						PSYS_SRC_BURST_PART_COUNT, 10,				//How many particles to make
						PSYS_SRC_PATTERN, PSYS_SRC_PATTERN_EXPLODE	//The pattern we use, this is all round the prim.
					]);

The new top line, PSYS_PART_START_ALPHA, 0.5, gives us particles which are more see through. The range is 0.0 (totally see through (0% opaque) to 1.0 (100% opaque). A bit like colours this interacts with the alpha of the actual textures (which we will look at properly below. The basic particle shape for ALL particles is actually rectangular (or square). The particle default texture is round in appearance, because the rest of the shape is alphaed out. When you make these particles more transparent the already 0% opaque edges can’t get more transparent so they stay completely see through. If you have absolute changes like this the effects are easy to see and predict, if you have partially opaque parts of your base texture you can have more interesting and tricky interactions.

Oh, and yet again the START part of the name implies another one, PSYS_PART_END_ALPHA which we will see later.

Back to top

_______
I want to make the particles fall (snow, rain, showers etc.)

This section will actually look at making the particles accelerate away from the source. The things we see that accelerate in a simple to describe way includes anything falling under gravity, and although you can use this for other things we’ll start by looking at that.

Once again we’ll amend the basic particle script:


llParticleSystem([		PSYS_SRC_ACCEL, <0.0, 0.0, -10.0>,							//This makes the particles accelerate downwards, quite quickly
						PSYS_PART_START_SCALE, <0.5, 0.5, 0.0>,		//This sets the size (scale) of the particles to 0.5m 
						PSYS_PART_MAX_AGE, 10.0, 					//This gives us the lifetime of the particles
						PSYS_SRC_BURST_RATE, 1.0,					//There's a new burst every 1.0 seconds
						PSYS_SRC_BURST_SPEED_MIN, 0.01,				//The minimum speed of the particles (in m/s)
						PSYS_SRC_BURST_SPEED_MAX, 0.1,				//The maximum speed - so they move slowly
						PSYS_SRC_BURST_PART_COUNT, 10,				//How many particles to make
						PSYS_SRC_PATTERN, PSYS_SRC_PATTERN_EXPLODE	//The pattern we use, this is all round the prim.
					]);

The top line is the one we’ve changed again. This time we’re adding an acceleration (ACCEL) which is a property of the source, not the particles. You’ll notice that the acceleration is given as a vector, which you might expect if you remember your physics. In SL terms this is a global vector, so the first component will cause acceleration along the East (positive) – West (negative) axis, the second along the North (+) – South (-) axis and the third along Up (+) – Down(-). -10.0 gives us a strong acceleration downwards – in fact it’s pretty much acceleration due to gravity (which is 9.8m/s/s approximately). For some things that looks right, but for many it looks a little odd. Raindrops, and even more so snowflakes, fall quite slowly. Although they are being pulled by gravity, they’ve reached their relatively low terminal velocity already by the time we see them. Applying accelerations lower than <0.0, 0.0, -10.0>, such as <0.0, 0.0, -1.0> can often work well and give you the right effect.

There is one other problem with this system… people like using particles for exhaust/jet/spray systems on vehicles, but the vehicle keeps changing direction. The acceleration doesn’t! If you’re doing something like this you want to work out your particle acceleration vector with the prim aligned “normally” (no rotations) if possible. If you then multiply the acceleration by llGetRot() and call it whenever the vehicle changes direction you can get a perfectly good result. You can also, if things will work by other means use the DROP pattern to drop the particle where the prim currently is, and rely on the movement of the vehicle to leave it behind. This technique can work very nicely.

The top line for an llGetRot() call would look like this:

PSYS_SRC_ACCEL, <0.0, 0.0, -10.0>*llGetRot(),

Back to top

_______
I want the make the particles have a different texture

OK, we’ve played with the default texture so far. But you’ve probably seen poofers and other things that use different textures. We can do that by amending the basic particle script as follows:


llParticleSystem([		PSYS_SRC_TEXTURE, "texture name or key here",							//This particles look different.
						PSYS_PART_START_SCALE, <0.5, 0.5, 0.0>,		//This sets the size (scale) of the particles to 0.5m 
						PSYS_PART_MAX_AGE, 10.0, 					//This gives us the lifetime of the particles
						PSYS_SRC_BURST_RATE, 1.0,					//There's a new burst every 1.0 seconds
						PSYS_SRC_BURST_SPEED_MIN, 0.01,				//The minimum speed of the particles (in m/s)
						PSYS_SRC_BURST_SPEED_MAX, 0.1,				//The maximum speed - so they move slowly
						PSYS_SRC_BURST_PART_COUNT, 10,				//How many particles to make
						PSYS_SRC_PATTERN, PSYS_SRC_PATTERN_EXPLODE	//The pattern we use, this is all round the prim.
					]);

It’s worth playing with various textures in here and seeing what they look like and how they work. You can put in the key of the texture you want to use – the easy way to do that is get a full perms texture (or snapshot) right click it and choose “Copy Asset UUID” from the menu, then pasting it in to the code above (it does need the quote marks). Putting in the key lets you make sure that the script works because it doesn’t need the texture present. If you give the name of the texture, which you might have to for a texture you don’t have full permissions for, you must also put the texture into the same prim’s contents as the script. If you, or the next user, take the texture out and the particle system is reset the texture will revert to the default texture.

Although particles are all client side, if you make big textures they still have to be streamed out, and can slow clients down quite appreciably. Use your textures responsibly – if you’re particles are only going to be tiny, use a tiny texture, even if they’re huge use the smallest texture you can. It makes people more likely to look at the whole effect if it loads quickly and smoothly!

Back to top

_______
I want the make the particles in a different shape than this explosion thing…

Bored of explosions huh? They might be one of the most commonly used patterns for particles, but they’re NOT the only one.

Hopefully you’ve got some idea of what to change already – the PSYS_SRC_PATTERN, line at the bottom of the basic particle script is the place we’re looking. The values you can put in there are:

PSYS_SRC_PATTERN_ANGLE
PSYS_SRC_PATTERN_ANGLE_CONE
PSYS_SRC_PATTERN_ANGLE_CONE_EMPTY
PSYS_SRC_PATTERN_DROP
PSYS_SRC_PATTERN_EXPLODE

Let’s look at these one at a time.

If you simply change the line PSYS_SRC_PATTERN, PSYS_SRC_PATTERN_EXPLODE to PSYS_SRC_PATTERN, PSYS_SRC_PATTERN_ANGLE you might get different results to those you expect. You actually get a line of particles going straight up… That’s because the three angle patterns (PATTERN_ANGLE, PATTERN_ANGLE_CONE and PATTERN_ANGLE_CONE_EMPTY) can (and nearly always will) use the PSYS_SRC_ANGLE_BEGIN and PSYS_SRC_ANGLE_END values as well.

NOT assigning them leaves the values as 0.0, and so the particles go straight up.


llParticleSystem([		PSYS_PART_START_SCALE, <0.5, 0.5, 0.0>,		//This sets the size (scale) of the particles to 0.5m 
						PSYS_PART_MAX_AGE, 10.0, 					//This gives us the lifetime of the particles
						PSYS_SRC_BURST_RATE, 1.0,					//There's a new burst every 1.0 seconds
						PSYS_SRC_BURST_SPEED_MIN, 0.01,				//The minimum speed of the particles (in m/s)
						PSYS_SRC_BURST_SPEED_MAX, 0.1,				//The maximum speed - so they move slowly
						PSYS_SRC_BURST_PART_COUNT, 10,				//How many particles to make
						PSYS_SRC_PATTERN, PSYS_SRC_PATTERN_ANGLE,    //The pattern we're using - a plane with some parts not filled.
                        PSYS_SRC_ANGLE_BEGIN, PI_BY_TWO/2.0,
                        PSYS_SRC_ANGLE_END, PI_BY_TWO
                    ]);

Setting the particle system like this lets you see two things quickly. First, and most obviously what you can see if you orbit around the prim making the particles, the particles are all in a vertical plane. They’re actually in the YZ plane – so if you look at the prim from the North or South you see a line still, although some of the particles will come towards you and some away if you look closely. If you rotate the prim you can quickly see that this is a local vertical plane, as you spin the prim the plane the particles are in varies.

If you look from the (local) East or West you see a slightly odd shape of particles. There are two sections with no particles in them. NO particles go down at all. There is also an area on either side of straight up that has no particles in it. If your geometry with radians is up to speed you might quickly spot the pattern. If not, PI_BY_TWO is 90º, PI_BY_TWO/2.0 (or pi/4) is 45º. What you are seeing is an area between 45º either side of the vertical with no particles, and then particles out to 90º either side of the vertical, then no more particles. More more about radians read the wiki article on degrees.

This can let you do some fun things. If you want a horizontal line rather than a vertical line setting both PSYS_SRC_ANGLE_BEGIN and PSYS_SRC_ANGLE_AND to PI_BY_TWO will do that for you. A line going down… try PI in both. If you’re making something like a jetpack and you want an exhaust… you can use this with something like 2.1 for the two values (about 2PI/3) to get lines going out and down. 2.1 might be a bit shallow for you… using 2.8 for ANGLE_BEGIN and 2.9 for ANGLE_END looks good to me – but this is where the artistry comes into particles, play with the numbers for yourself.

The PSYS_SRC_PATTERN_ANGLE_CONE value is very similar to the PATTERN_ANGLE pattern. The only difference is that you see the arc from any direction – the particles go in a cone rather than being restricted to the local YZ plane.

The PSYS_SRC_PATTERN_ANGLE_CONE_EMPTY is the opposite of the the PATTERN_ANGLE_CONE. Wherever PATTERN_ANGLE_CONE draws the particles PATTERN_ANGLE_CONE_EMPTY will leave empty, and vice versa.

PSYS_SRC_PATTERN_DROP is the gentlest of the effects in some ways. It merely puts the particle stationary at the centre of the prim. This can let you make obscuring smoke and mist around you if that’s your thing very nicely. The wiki describes PATTERN_DROP as having no force on the particle. This is a little confusing – the particles have 0 initial speed, but if you include a PSYS_SRC_ACCEL line (see here) the particles will accelerate as you’d expect. Dropping a particle with this pattern can be a good way to make an exhaust or wake quickly. The particles will dropped at a distance apart that depends on the speed of the vehicle (and the parameters you choose) so it will look fairly naturally more spread out at high speed, closer at low speeds.

We’ve seen what PATTERN_EXPLODE does, it also lets us use all of the “burst” parameteres, like PSYS_SRC_BURST_RADIUS which has no effect on the other patterns.

Back to top

_______
I want the particles to follow someone/things

You can make particles follow people or objects in your field of view as well. This is one of a number of flags that can be set singly or together. We will look at combining flags below but here we are going to look at the TARGET_POS_MASK here – making the particles head towards a target.

The amendments to the basic particle script take up two lines for the basic changes – one to set the flag, one to set the target.


llParticleSystem([		PSYS_PART_FLAGS, PSYS_PART_TARGET_POS_MASK,			//This tells the system to follow a target key if given
						PSYS_SRC_TARGET_KEY, llGetKey(),					//This sets the key of the object or av for the particles to target.
						PSYS_PART_START_SCALE, <0.5, 0.5, 0.0>,		//This sets the size (scale) of the particles to 0.5m 
						PSYS_PART_MAX_AGE, 10.0, 					//This gives us the lifetime of the particles
						PSYS_SRC_BURST_RATE, 1.0,					//There's a new burst every 1.0 seconds
						PSYS_SRC_BURST_SPEED_MIN, 5.0,				//The minimum speed of the particles (in m/s)
						PSYS_SRC_BURST_SPEED_MAX, 10.0,				//The maximum speed - so they move slowly
						PSYS_SRC_BURST_PART_COUNT, 10,				//How many particles to make
						PSYS_SRC_PATTERN, PSYS_SRC_PATTERN_EXPLODE	//The pattern we use, this is all round the prim.
					]);

This system will produce quite fast moving particles that fly out and then return to their emitter. You need BOTH the lines – the PSYS_PART_FLAGS, PSYS_PART_TARGET_POS_MASK, line enables the following of a target. PSYS_SRC_TARGET_KEY, takes a key for the target of the particles. The example I’ve given uses the key of the emitter. Other common keys you can get quickly are llGetOwner(), and llGetCreator(). You can also use sensors, listens, touches etc. to get keys of other things, or find a key by some other means and hard code it in. I use this method for chains on a rising bridge I’ve built because it won’t get rerezzed often so it was easy to do.

NOTE: Once you’re more confident you can combine PSYS_PART_TARGET_POS_MASK with PSYS_PART_FOLLOW_VELOCITY_MASK to make the particles point towards the target as they move. The correct code would be PSYS_PART_FLAGS, PSYS_PART_TARGET_POS_MASK | PSYS_PART_FOLLOW_VELOCITY_MASK. This makes arrows and things work nicely.

Back to top
_______
I want the particles to blow in the wind

You can also make particles blow in the wind. Smoke for example follows the wind (although it also changes volume and transparency over time as it disperses, which is why we’ll deal with it below). One very direct application of this would be to make a particle flag that would stream in the wind, although flexi-prims lets us do this to some extent now as well, and particle wind socks can certainly be used, and are on some sailing vessels in SL.

Amending the basic particle script takes up one line for the basic change, you set the follow wind flag and sit back to watch the effect!


llParticleSystem([		PSYS_PART_FLAGS, PSYS_PART_WIND_MASK,			//This tells the system to follow the wind
						PSYS_PART_START_SCALE, <0.5, 0.5, 0.0>,		//This sets the size (scale) of the particles to 0.5m 
						PSYS_PART_MAX_AGE, 10.0, 					//This gives us the lifetime of the particles
						PSYS_SRC_BURST_RATE, 1.0,					//There's a new burst every 1.0 seconds
						PSYS_SRC_BURST_SPEED_MIN, 5.0,				//The minimum speed of the particles (in m/s)
						PSYS_SRC_BURST_SPEED_MAX, 10.0,				//The maximum speed - so they move slowly
						PSYS_SRC_BURST_PART_COUNT, 10,				//How many particles to make
						PSYS_SRC_PATTERN, PSYS_SRC_PATTERN_EXPLODE	//The pattern we use, this is all round the prim.
					]);

NOTE: You might find that you want to combine with with the PSYS_PART_FOLLOW_VELOCITY_MASK depending on the shape of your particles – it will make them turn to point in the wind if that is relevant for your texture.

Back to top
_______
I want the particles to change colour/alpha

The colour mask flag (PSYS_PART_INTERP_COLOR_MASK) slightly confusingly allows you to change both the colour AND/OR the alpha of the particles over their life time. The INTERP part is an abbreviation for Interpolate – the colours (sometimes with surprising results) and alpha (with more predictable results) change from the start values to the end values over the lifetime of the particle.

The first part of using this flag is simple, you use the PSYS_PART_FLAGS, PSYS_PART_INTERP_COLOR_MASK call in the basic script. This then lets you use both PSYS_PART_END_ALPHA and PSYS_PART_END_COLOR (or only one if you prefer) in your particle system. Let’s amend the basic particle system so the burst changes from a darker to a light colour, and fades to invisibility as it does this. We’ll amend the basic particle script as follows:


llParticleSystem([		PSYS_PART_FLAGS, PSYS_PART_INTERP_COLOR_MASK,			//This tells the system to change colour and/or alpha if start and end values are given.
						PSYS_PART_START_ALPHA, 1.0, 				//So it starts fully visible
						PSYS_PART_END_ALPHA, 0.0,					//So it fades to be totally transparent over time
						PSYS_PART_START_COLOR, <1.0, 1.0, 1.0>, //Starts it out normal colour (white)
						PSYS_PART_END_COLOR, <0.0, 0.0, 0.0>,		//End colour is black
						PSYS_PART_START_SCALE, <0.5, 0.5, 0.0>,		//This sets the size (scale) of the particles to 0.5m 
						PSYS_PART_MAX_AGE, 10.0, 					//This gives us the lifetime of the particles
						PSYS_SRC_BURST_RATE, 1.0,					//There's a new burst every 1.0 seconds
						PSYS_SRC_BURST_SPEED_MIN, 5.0,				//The minimum speed of the particles (in m/s)
						PSYS_SRC_BURST_SPEED_MAX, 10.0,				//The maximum speed - so they move slowly
						PSYS_SRC_BURST_PART_COUNT, 10,				//How many particles to make
						PSYS_SRC_PATTERN, PSYS_SRC_PATTERN_EXPLODE	//The pattern we use, this is all round the prim.
					]);

Give it a try and see… Play with the colour values too. If you change from red (1.0, 0.0, 0.0) to green (0.0, 1.0, 0.0) do you expect to go through a mucky yellow colour? There will be a point where your particles are at (0.5, 0.5, 0.0) which is a dark, mucky yellow. The interpolation IS predictable, the particle colouring (and alpha) will change smoothly from the start value in each field to the final value in each field. In the example I’ve given the red goes from 1.0 to 0.0 as green goes from 0.0 to 1.0. Half way there is a time when they are both 0.5. If you are used to playing with colour values you might expect that change, but if you are not used to that the changes can be somewhat unusual. Play and experiment with it. Remember that making things evenly darker or lighter (so all three RGB values are tending to 0.0 or 1.0 together) the results are predictable. The other effects are sometimes good, fun and pretty, so see what they look like! If they’re not, then tweak them gently, think of different ways you can realise your dream.

Back to top
_______
I want the particles to change size

You can also make your particles change size if you want, using the PSYS_PART_INTERP_SCALE_MASK. This lets you use the PSYS_PART_END_SCALE as well as the START_SCALE value. Why might you want to do this? Well smoke (which we’ll look at fully below) gets bigger as it leaves the chimney, but also things like bubbles for a wake seem to expand, explosions obviously billow out from a centre and so on.

Let’s amend the basic particle system so the particles get bigger. We’ll amend the basic particle script as follows:


llParticleSystem([		PSYS_PART_FLAGS, PSYS_PART_INTERP_SCALE_MASK,			//This tells the system to change colour and/or alpha if start and end values are given.
						PSYS_PART_START_SCALE, <0.5, 0.5, 0.0>,		//This sets the start size (scale) of the particles to 0.5m 
						PSYS_PART_END_SCALE, <5.0, 5.0, 0.0$gt;,	//This sets the end scale to 5m. You can go up to 10 X 10 as usual.
						PSYS_PART_MAX_AGE, 10.0, 					//This gives us the lifetime of the particles
						PSYS_SRC_BURST_RATE, 1.0,					//There's a new burst every 1.0 seconds
						PSYS_SRC_BURST_SPEED_MIN, 5.0,				//The minimum speed of the particles (in m/s)
						PSYS_SRC_BURST_SPEED_MAX, 10.0,				//The maximum speed - so they move slowly
						PSYS_SRC_BURST_PART_COUNT, 10,				//How many particles to make
						PSYS_SRC_PATTERN, PSYS_SRC_PATTERN_EXPLODE	//The pattern we use, this is all round the prim.
					]);

Back to top
_______
I want to change size, colour AND follow the wind (and rise too – let’s make some smoke!)

We’re going to look at some light smoke for this. Smoke follows the wind, and the “puffs” of smoke seem to get larger, fainter and change colour so we’re going to have to combine three flags for this. We’re also going to use a different texture, and because you’re going to copy this from the website I’ve referenced the texture by key.

I’ve incuded the whole script so you can just copy and paste it.

particleSystem()
{
    llParticleSystem([
        PSYS_PART_FLAGS,            PSYS_PART_INTERP_COLOR_MASK | PSYS_PART_INTERP_SCALE_MASK | PSYS_PART_WIND_MASK,
        PSYS_SRC_PATTERN,           PSYS_SRC_PATTERN_ANGLE,
        PSYS_PART_START_COLOR,      <0.6, 0.6, 0.6>,
        PSYS_PART_END_COLOR,        <0.8, 0.8, 0.8>,
        PSYS_PART_START_ALPHA,      1.0,
        PSYS_PART_END_ALPHA,        0.0,
        PSYS_PART_START_SCALE,      <0.5, 0.5, 0.0>,
        PSYS_PART_END_SCALE,        <1.5, 1.5, 0.0>,
        PSYS_PART_MAX_AGE,          2.0,
        PSYS_SRC_ACCEL,             <0.0, 0.0, -0.01>,
        PSYS_SRC_TEXTURE,           "d1df5743-efa9-8fab-0d2f-8c206931299b",
        PSYS_SRC_BURST_RATE,        0.04,
        PSYS_SRC_INNERANGLE,        1.0,
        PSYS_SRC_OUTERANGLE,        0.0,
        PSYS_SRC_BURST_PART_COUNT,  1,      
        PSYS_SRC_BURST_RADIUS,      1.0,
        PSYS_SRC_BURST_SPEED_MIN,   0.0,
        PSYS_SRC_BURST_SPEED_MAX,   0.1 
    ]);
}

//Teaching about particles script, written by Eloise Pasteur. This is a teaching resource and it freely available. If you paid for it, complain to the person you bought it from, and let me know. This script makes light smoke.

default
{
    state_entry()
    {
        particleSystem();
    }
}

If this doesn’t do what you want quite, tweak the numbers – gently! It does produce quite reasonable smoke from a chimney or similar. Read the last section as well, it will help.

NOTE: This works best in a small prim, or a heavily tortured one. Try a sphere dimpled to 0.5 and cut at 0.125 and 0.375 so it comes out of the vertex is my advice, and think about making the sphere 100% transparent.

Back to top
_______
I want to get rid of these pesky particles

Fed up with the particles invading your space?

You might already have found that simply deleting the script doesn’t actually stop the particles… although deleting the prim/object does.

Particles are one of a range of things that are set by script but become a property of the prim. That that means is taking the script away *doesn’t* stop them working. Sit target, sit text, touch text, hover text, loop sounds also fall into this category. There are some (like STATUS_PHANTOM) that are similar in some ways, but can also be accessed through the edit window and toggled that way. The only way to turn a particle system off without deleting the prim is to run an empty particle system llParticleSystem([]); This is useful for particle effects that can be triggered on and off by users as well.

Back to top
_______
Bringing it all together – making your particles really dance.

This doesn’t give you 100% coverage of everything particles can do. That’s still the job of the Particle System section of the wiki. What is has hopefully helped you do is see what most of the major commands do, as well as see how they’re used. If there are things that you really think ought to be put into this tutorial please contact me and I’ll add them in.

If you’re staring at this wondering how on earth to incorporate it into the particles you want to make I’m going to suggest a way you might be able to do that.

I tend to run down the list of calls in the wiki and when I come to one I know I’m going to use, write it in. Some, like PSYS_PART_START_SCALE and PSYS_PART_START_COLOR are almost there before I stop to think about them, but I think about the size and colour I’m after, at least approximately.

That process lets me check I’ve got all the effects I want/need and gives me something that’s close to the desired effect all being well. This process usually takes about 10 minutes.

Then I’ll go through and tweak the numbers to get it just right. This part, for a relatively simple script (I was making water for a shower) took me 3 HOURS so it can take a while. There are some tricks to this. Make sure you only change one number/vector at a time. If, for example, you change both the number of particles per burst AND the burst rate you are changing how many particles are drawn at once in two ways at the same time. Say you use that to make more particles, but you’ve gone too far… which one do you change, or do you change them both back a bit? If the colours aren’t right, tweak only one of the vectors if possible so you can see what the effect is and so forth.

Taking it gently like this means you can go back and undo a change if it’s the wrong change. It will also let you analyse how big a change you actually need – have you gone too far, is there further to go? Sadly, past that, it’s your artistic talent that comes to rule. Does it look better with more particles per burst or more bursts per second? It depends on what you’re doing… and that’s really your call.

Back to top


Trackbacks & Pingbacks

  1. Playing with Particles | A Kat and A Mouse pingbacked on 2 years, 5 months ago

Comments

  1. Eloise–
    Excellent start. Looks great! I’m just about to get into trying out some stuff with the particle engine. This will be a great help.

    I would like to suggest that you add section identifiers at the top of each section, so as you scroll down, you can quickly see what the section contains. Just title each section with the link information used at the top of the blog.

    Again, great stuff. I signed up with WordPress.com just so I could add this comment 🙂

    –Trevor Langdon

    | Reply Posted 10 years, 11 months ago
  2. * eloise says:

    Thank you Trevor. It’s a good comment and one I’ve taken the time to bring on board. I also plan to take some videos of the effects of the various scripts and embed them, last time I tried that my video capture tool gave me corrupted files, but they will be here sometime I promise!

    | Reply Posted 10 years, 10 months ago
  3. * nand Nerd says:

    Fantastic idea using embedded videos to explain particle effects. Sounds like a lot of work but then again, documenting particle effects is no easy job!

    Keep up the astounding work,

    nand.

    P.S. may eventually steal your idea for my particle interface documentation, if you have no objections.

    | Reply Posted 9 years, 11 months ago
  4. * dublklik says:

    I would sure like to work on particle scripts but I can not get even the most basic particle script to run in Second Life. All my other non-particle scripts run fine.
    I rez a prim in land I own, edit & open the content tab, give full permissions, paste your “10 grey-white ‘balls of light” script into a new script, save, get notice ‘save complete’ & ‘running’, close the edit. and, nothing appears from the rezzed cube! just to be sure, I try ‘left click’, . . . nothing. I have tried a dozen other basic & example particle scripts but have yet to see any particles. I am using Second Life viewer 2.6.0. I used to get good support in Second Life when there was ‘live help’. now , there are ‘tickets’ & ‘forums’ which are poor alternatives.

    | Reply Posted 6 years, 2 months ago
  5. * eloise says:

    Can you see particles from other people’s scripts? It could be that you have particles turned off in the advanced menu (Cntl-Alt-Shift-=) or a really low number (like 0) set in the Graphics preferences if you can’t see any.

    I don’t routinely use 2.6, you could try in a different viewer and see if that changes it. I think Imprudence and Phoenix both use different preferences files if you’ve done something like that. Both are working towards a viewer with all the 2.6 features too.

    | Reply Posted 6 years, 2 months ago
  6. * dublklik says:

    Eloise,
    Thank you for your prompt reply to my inquiry of yesterday. I had no idea what or where to look. I didn’t know if I needed a different viewer or if there was some programming problem or what. Your giving me some places to look really paid off!
    in Preferences: Graphics; Quality and speed, I saw that the slider was set all the way to left on ‘Low’. When I moved it right to ‘Mid’ all the particles appeared. I went back and checked in the ‘particle laboratory’ where I hadn’t seen any particles and they all appeared. Thanks again for your help. Your site here is the best I have found for learning about particles.

    | Reply Posted 6 years, 2 months ago


Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: