Day 158: Creating Particle Effects Part 1

Particles are the "special effects" of Second Life. They make fun and interesting displays, and can give life to the most mundane objects. The best part is: they are surprisingly easy to create!
I tend to think of particles as little thingies that shoot out of an object. You can control how the thingies look (can either be a colored circle/ellipse, or a texture). You can also control the direction that the thingies travel in (in an exploding pattern, towards the owner, to another object, or in a cone).
Here is the official Second Life definition of particles (frankly, I like thingies better :P):
"Two-dimensional sprites (graphic images that always face the viewer). Second Life's particle system allows a wide variety of particles, enabling residents to create burning fires, glistening waterfalls, vapor trails on jet fighters, tracers on bullets, the occasional macabre spurt of blood, floating hearts of affection, billowing smoke, rainbows, and much more."
If you want to see what particles can do, there is no better place than the Particle Laboratory. Not only is it a fun place to visit, you get a chance to really see how to tweak particle effects.
**Update: Jopsy Pendragon just put up some new sample particle scripts in the Particle Laboratory:
"Targeting particles, 4 free/copy/mod/trans samples for setting up emitter and target pairs. 2 for linked emitter & target prims, 2 for emitter and prim in seperate objects.
There are also the "Basic Particle Effect" samples in the middle of the lab that are free/copy/mod/transfer and show common effects like fire, smoke, steam, fountain, bling, jet flames, ripples, glows and a handful of others."
If you have not to the Particle Laboratory, go take a look!
The most popular form of particles is probably the "bling" effect. Yep, "bling" is nothing more than little white particles with very short lives. You may also have seen things like dense smoke (not fog or clouds, thats something else), fireworks, lighting effects, and sprays of water (like a shower). Even groups of insects or schools of fishes are usually made with particles.
Particles are created using a script placed inside a prim. That prim can be rezzed on the ground, or worn as an attachment (like a bracelet or necklace). The particle scripts are relatively simple to change. You would be amazed at what you can do by tweaking a few settings inside the script! Trust me, Im not a programmer. So if I can do this, you can too :)
BTW, particles are displayed locally. That means each avatar's computer displays the particle effects locally. What you actually see will be slightly different than what other avatars in the area see. The good thing is that this causes minimal lag and server load. Despite popular belief, the "bling" effect itself doesnt cause that much load...AO does! So feel free to bling away, but take off that Sexy Walk :P
I tend to think of particles in 2 major groups: those that are colored shapes, and those based on textures. This tutorial will show you how to make particle effects with colored shapes. I will create a later tutorial using textures.
You will need the free Particle Scripts folder from Sirena Hair & Fashion to complete this tutorial. Click on Search, select the Places tab, and enter "sirena" as the keyword. The SLURL is West Sunset (160,50,22).
1. Candle
A Candle (specifically the candle flame) is perfect for demonstrating particle effects. It is easy to make, and can be placed on the ground or held.
The Candle portion of the tutorial is based on an old candle flame particle script and tutorial by Oz Spade. I made a slight change to the script to make it easier to build (changed the pattern to PSYS_SRC_PATTERN_ANGLE_CONE_EMPTY).
Rez a Cylinder on the ground. Go to the General tab, and change the Name to "Candle".
Enter the following dimensions:
Size X: 0.030
Size Y: 0.030
Size Z: 0.300
Go to the Texture tab. Click on the square above "Texture". This will open the Pick:Texture window. Click on the Blank button and the Select button.
So make sure the "Candle" Prim is selected in Edit more, and you can see the Red/Green/Blue movement arrows. Press and hold the Shift key, then click on the Blue arrow and pull it up. This will make a copy of the "Candle" Prim.
Go to the General tab of the copy and change the name to "Wick".
Enter the following dimensions:
Size X: 0.010
Size Y: 0.010
Size Z: 0.030
Go to the Texture tab. Click on the square above "Color". This will open the Color Picker. Click on the grey square on the bottom row. Click Select.
Now move the "Wick" down into the "Candle" until it sinks just slightly into the "Candle".
We are going to link the "Wick" to the "Candle". We want the "Candle" to be the Root prim.
Right-click on the "Wick" and select Edit. Then press Shift and click on the "Candle" to select it as well (its important that you select "Candle" last). To link the prims, click on Tools at the top of your screen, and select Link. The "Candle" should be outlined in yellow, the "Wick" should be outlined in blue.
Next, we are going to put the particle script into the "Wick". Click on the "Edit linked parts" checkbox in the Edit window. Click on the "Wick" so that only the "Wick" is selected. Select the Contents tab. Look for the "Particle Script - Candle Flame" script from the Particle Scripts folder you got from Sirena Hair & Fashion. Drag and drop the "Particle Script - Candle Flame" script from your Inventory into the Contents tab of the "Wick".
If all goes well, the candle should be lit :)
Next, we are going to add a script so our avatar will hold this candle. This script runs a built-in SL animation that causes your avatar's arm to hold an object.
Right-click on the Candle and select Edit. Click on the "Edit linked parts" checkbox in the Edit window. Click on the "Candle" so that only the "Candle" is selected. Select the Contents tab. Look for the "Hold Object Script" script from the Particle Scripts folder you got from Sirena Hair & Fashion. Drag and drop the "Hold Object Script" script from your Inventory into the Contents tab of the "Candle".
Right-click on the Candle and select Take.
Right-click on "Candle" in your Inventory, select "Attach To >", and click on "Right Hand".
The Candle will initially attach with the wrong orientation. You need to rotation the Candle.
Go ahead and Edit the Candle while it is in your hand and enter these values:
Rotation (degrees) Y: 70.00
Next, drag the Red/Green/Blue arrows until the Candle fits well on your hand.
That's it! You just made a particle candle, complete with avatar animation :)
Remember to Right-click on the Candle and select Detach to save the settings youve made. Now you can just select "Wear" to hold the Candle.
2. Lightstick
You may be wondering how the particle script actually works. 
We are going to turn the Candle into a Lightstick (one of those annoying multi-color lightsticks you see at raves and parties :P). This will give us a chance to talk about how some of the settings work inside the particle script.
First, lets make a copy of the Candle and change its shape into a Lightstick.
Right-click on the Candle in your Inventory, and select Copy. Right-click on Candle again, and select Paste to make a copy of the Candle. You should now have 2 Candle objects in your Inventory.
Right-click on one of the Candle objects, and select Rename. Change the Name to "Lightstick".
Right-click on "Lightstick" in your Inventory and select Wear.
Right-click on the "Lightstick" in your hand and select Edit. Click on the "Edit linked parts" checkbox in the Edit window. Click on the "Wick" so that only the "Wick" is selected.
Change the Building Block Type to "Sphere". Enter the following settings:
Size X: 0.050
Size Y: 0.050
Size Z: 0.050
Go to the Texture tab. Change the Transparency to 50.
Select the Content tab of the "Wick". Double-click on the "Particle Script - Candle Flame" script to open the Script Editing window.
Change the following settings in the script:
integer pattern = PSYS_SRC_PATTERN_EXPLODE;
float age = 1.0;
float maxSpeed = 0.5;
float minSpeed = 0.1;
float startAlpha = 1;
float endAlpha = 1;
vector startColor = <0,1,1>;
vector endColor = <1,0,1>;
vector startSize = <0.1,0.1,0.0>;
vector endSize = <0.1,0.1,0.0>;
vector push = <0,0,0>;
float rate = 0.1;
float radius = 0.01;
integer count = 10;
Click the Save button and close the script editing window.
You should now have a really annoying Lightstick, perfect for causing a mess at any SL party. Please use it sparingly, or your friends may shoot you :P
If you want to dance with the Lightstick, you should Delete the "Hold Object Script" from the body of the Lightstick (or uncheck "Running" box in the script). You would then hold the Lightstick at your side and can dance normally.
If you feel brave, go ahead and add a second particle emitter with different colors on the other end of the Lightstick. More is better, right? ;P
3. What Just Happened?
Lets talk about how the particle script work.
Most particle effects are created by changing settings inside the particle script. Thankfully, there is very little programming involved. There are a large number of settings you can tweak to make particles do what you want.
Here is the main reference for all the settings within the particle script. Its not entirely written in English. But it is a good reference.
You can "see" these settings in action at the Particle Laboratory. Theres even a small sandbox there, so you can tweak your particle script right there. If you are wondering what a setting looks like, go check out the specific display at the Particle Labortaory!
The best way to learn about particles is to play with it. Change one setting at a time and see what happens. Dont worry, the worst things that could happen are either nothing coming out, or causing a giant lightshow that annoys your neighbors :)
Alternatively, most freebie items that have particle effects also give you Mod permission to the scripts. So take a look at the settings to learn how some effects are done.
Lets talk about a few of these settings we just changed above:
integer pattern = PSYS_SRC_PATTERN_EXPLODE;
"pattern" controls how the particles are sent out.
The Candle used the PSYS_SRC_PATTERN_ANGLE_CONE_EMPTY pattern, because we wanted the particles to go in a narrow pattern upward. The outerAngle and innerAngle settings control the size and direction of the "Angle Cone".
The Lightstick used the PSYS_SRC_PATTERN_EXPLODE pattern. This is your basic explosion: particles going in all directions.
One more common pattern is the PSYS_SRC_PATTERN_DROP pattern. In this case, the particles fall down, like water or anything affected by gravity.
float age = 1.0;
All particles are temporary objects that have a short life. "age" controls the lifetime of each particle in seconds. When a particle reaches its "age", it will disappear.
float maxSpeed = 0.5;
float minSpeed = 0.1;
The "maxSpeed" and "minSpeed" determine a range of speeds at which particles will shoot out from the center. If these numbers are very different, each particle will move at different speeds, giving a somewhat random appearance.
float startAlpha = 1;
float endAlpha = 1;
The "startAlpha" and "endAlpha" control the transparency of a particle when it is created to the end if its "age" (when it disappears). An Alpha of 1 is completely opaque. An Alpha of 0 is completely transparent. So startAlpha = 1 and endAlpha = 0 means the particle will gradually become more transparent until it disappears.
vector startColor = <0,1,1>;
vector endColor = <1,0,1>;
The "startColor" and "endColor" determines how the color of the particle will change from when it is created to the end of its age (when it disappears). The color will only change if the "interpColor" setting is set to TRUE.
The colors are represented by 3 numbers, one each for Red, Green, and Blue. Unfortunately, the values are a little different than the ones you see in the SL Color Picker window. In this case, 0 is complete absence of that color (0 in the Color Picker). A 1 is a full amount of that color (255 in the Color Picker). You can enter decimal values. A 0.5 is equal to 128 in the Color Picker.
So <0,1,0> is all green. <0,1,1> is all green and all blue, mixed together to make cyan (kinda aquamarine). <1,0,1> is all red and all blue, mixed together to make magenta (kinda pink).
So startColor = <0,1,1> and endColor = <1,0,1> means the particle will change from cyan to blue-ish to magenta. Just the kinda change you need in a Lightstick :)
vector startSize = <0.1,0.1,0.0>;
vector endSize = <0.1,0.1,0.0>;
The "startSize" and "endSize" controls the size of the particle from creation to the end of its "age". The size will only change if the "interpSize" setting is set to TRUE.
There are 3 numbers for each setting, corresponding to X, Y, and Z sizes. It the 2 sets of numbers are different, the particle will grow or shrink accordingly.
vector push = <0,0,0>;
The "push" makes the particle accelerate in a given direction. There are 3 numbers, corresponding to X, Y, and Z.
float rate = 0.1;
The "rate" is the time between each burst of particles, in seconds. So a rate of 1 would be 1 burst every second. A burst of 0.01 would be 100 bursts of particles per second.
integer count = 10;
The "count" is the number of particles that will be sent out per burst of particles.
float radius = 0.01;
The "radius" controls the distance from the emitter where the particles will be created. So a "radius" of 1.0 would create all particles 1M from the center of the particle emitting prim, creating a sphere of particles that move outward (or whatever direction you specify).
4. How Do I Stop These Particles?
Theres currently an SL bug with particles. Once you put a particle script into a prim, that prim will not stop sending out particles. Even if you delete the script. The only way to stop the particles is to delete the prim.
There is another way: You can drop the "Cancel Particles" script from the Particle Scripts folder into the prim. This will stop the particles without having to delete the prim. This is good for when you are playing around with particles.
I hope this gives you a good overview of what particles are, what they can do, and how you can change the settings. To learn more about particle effects, play with them!
In Part 2 of this tutorial series, we will create some watery particle effects.
20567-071006-122811-91
© 2007 All Rights Reserved.


18 comments:
Hi, Natalia! You inspired me to try my hand at doing some clothing design of my own. I created a cap-sleeve, sweetheart-neckline navy blue dress, after your Little Black Dress. But something went wrong...
I blogged about it here: http://jennifer-dunne.livejournal.com/186299.html
Any idea what caused the white background to show up? Do I have the wrong targa settings or something?
I'd appreciate any pointers to help. :-)
Heyla! Thanks for this! I've been wanting to mess with particles.
*runs to the store to grab the particle script*
I'm right behind you, Alison!
I've been wanting to dip my toes into the water with this for some time, but wasn't sure how to get started. Thanks, Natalia!
I use to wear your T-shirt continuosly.
But For such special event I though it was better to do not scare the audience. Better only think about the present while the ceremony. I am sure you understand me. hehehe.
Thanks again.
Tr.
Jennifer, this is definitely a problem with the Alpha Channel.
Try this: Make a copy of the PSD file. Delete all the Alpha Channels (in the Channels palette), leaving just the Red/Green/Blue/RGB channel.
Go to the Layer palette. Select just the shape of your Top (Ctrl-click on the picture of the shape in your Layer palette). Make sure that only the shape of your Top is selected, and nothing else.
Go to the Channel palette. Click on the rectangular button with a white circle ("Save selection as channel"). You should see a new channel appear called "Alpha 1". You should see the shape of your Top in white, and the background in black.
Next, click Save As..., select Targa (.TGA). Select 32 bits/pixel and do not check "Compress (RLE)".
Now go to SL, select Upload, and check the preview (Female Upper Body). Hopefully, this will fix the problem.
Alison, I hope this helps! Have fun with particles :)
Alyse, they are surprisingly easy to do. I just wish there was a library of particle settings somewhere... (like for water, fog, fire, etc.)
Trouble, I was just joking about the T-shirt :) Heehee You looked very nice on Sun!
Hi,
Just a note about stopping particles. If you use ''llParticleSystem([])'' when changing state (e.g. in responding to the object being touched) then this kills the particles.
Ashley, lol there was a problem with that working a year ago. It *should* stop the particles, but it did not before. I wonder if they have fixed it since...
hi i would really, really love it if you could copy and paste the script the one you can get at Sirena Hair & Fashion because i can't seem to get there... any way that would really help :) because its so hard to learn about particles and sort of stabbing in the dark.. if that makes sense...
Emmy, be sure you Right-click on the box and select Buy (for L$0). There are objects in the box as well (not just scripts). Lol and Im not sure I can get the script to look right on the blog anyways ;P
um... well.. the thing is that I've got an account on Teen Second Life so i can't go to the Main Adult Second Life and the people i'm with made this server island so i'm completely cut off from Main Teen Second Life as well... it would be really good if you could :) ... i don't care what the script looks like... Please?... if you don't want to put it up on here could you send it to me? :) i've fixed my blog account thing so you can :)
Emmy, I found a new copy of Oz Spade's script here: http://schome.open.ac.uk/wikiworks/index.php/Particle_generator_script :) Hope that helps!
thank you, thank you :) http://i118.photobucket.com/albums/o109/emmyjenny90/other/SecondLifeScreenSnapz001.gif
does it look good :) i've added a blue bit to the bottom :) i'm so happy :) thank you :) ill share this with all my friends and stuff :)
Emmy, congratulations (esp the blue part on the bottom :D). Thats so cool! Heehee and thanks for the view into TSL (lol Ive never seen it ;P)
I just have to comment and thank you for all of your wonderful tutorials. I started out transferring my RL t-shirt designs over to SL, but soon found I wanted to learn how to create more complex clothing, and things like bling effects. Now whenever I want to learn something new, your blog is the first place I go to for reference - as well as being a wonderful starting point for explorations of the SL world! Thank you. :)
Sapphire, heehee thank you so much :) Thats the cool part about SL (all the cool things you can do :D) Have fun with your projects :)
The LSL line of code to stop particles is
llParticleSystem([]);
which sets the particle system with no settings, which turns it off.
The fact that the particles don't stop when you take the script out is not a bug. The particle system is a setting on the object which the scripts just change. :)
Just thought I'd let you know ^_^
Nik.
Nik, lol there used to be some bug like a year ago when that wouldnt work. Im glad they fixed it! (It used to be really hard to turn particles off :P)
Post a Comment