User Tools

Site Tools


LAB8: Particle Systems

In this lab we will be checking out particle systems, This lab will be roughly based on the “The Ogre 3D Startup Sequence” from the book “Ogre 3D 1.7 - Beginner's Guide” by Felix Kerger, Chapter 10.


Discussion thread for this lab is here: Lab 8 Discussion Thread


You will have to create the folder ParticleSystems where your application can see it. and add the folder into your resource file like you have done in previous labs.

You can use your own project or start fresh with the base application code


  1. Add the following code your MyApplication::createScene function Here we are creating a particle system from the given examples that come with the ogre sdk, and attaching it to our Sinbad model.
    You should see a “fireish” thingamajing emitting from the head of Sinbad.
    // Create a particle system
    Ogre::ParticleSystem* partSystem = _sceneManager->createParticleSystem("smoke", "Examples/Smoke");
    // Attach the particle system to Sinbad
  2. Creating our own particle emitter Now we will create our own particle system.
    Particle systems are created in *.particle files so create a file MyParticleSystem.particle in your ParticleSystems folder.
  3. Adding particle code Now we must add some code to it. This will create a particle system that can be acces via its name in the application. You can see more about particle script configuration at The Ogre Particle System reference.
    particle_system MySmoke1 {
    	// Make the particles use the "Examples/Smoke" material, and be 10x10 units large.
    	material			Examples/Smoke
    	particle_width		10
    	particle_height		10
    	// Make the emitter limit the emitter to have at maximum 500 particles active.
    	// And set the particle type as point, which always faces the camera.  
    	quota			500
    	billboard_type		point
    	// Make the emitters origin a point.
    	emitter Point {
    		// Make the emitter emit 3 particles per second. 
    		emission_rate		3
    		// Emitt the particles in the given direction, at a velocity of 20 units per second.
    		direction		1 0 0 
    		velocity		20
  4. Now add additional properties to the Emitter, Now lets make the particle emitter shoot the particles in a random fashion, and destroy them after 10 seconds alive. Additionally we will colour them red.
    // This will be the range of angle variation the particles will be fired at.
    angle			30
    // Destroy the particle after 10 seconds.
    time_to_live		10
    // Colour the particles red with a fully opaque alpha value.
    colour			1 0 0 1
  5. Now we will add some Additional variation Lets make the time to live random, and give them colour a certain range. We do that by changing the time_to_live and colour attributes in the emitter block. Also change the emission rate to 30 increasing the rate of which the particles spawn.
    // Destroy the particle after 1 to 4 seconds.
    time_to_live_min	1
    time_to_live_max	10
    // Colour the particles linearly interpolated from red to blue.
    colour_range_start	1 0 0
    colour_range_end	0 0 1
  6. Additional attributes, Now remove all the additional lines added in the previous steps from the particle emitter leaving only the emission_rate, direction and velocity. And we will now modify the behaviour of the emitter, giving it a emission duration and restart delay. Lets make it emit particles for 1 second and then stop for one second before starting again.
    // Emit particles for 1 second at a time with a 1 second interval.
    duration 		1
    repeat_delay		1
  7. Adding affectors Now we will explore particle system affectors: Remove the attributes added in the last step. leaving again, only the emission rate, velocity and direction. And set the time_to_live 10. See: Affector Reference.
    1. Scaling affector: Add the following line to the particle_system block, this will scale the particles by the given value per second :
      affector Scaler {
      	rate 	10
    2. Colour fading affector Colour affector will add the given values to the particle colour. To use it replace the scalar affector with:
      // This affector will add the following values to the colour of the particles each second.þ
      affector ColourFader {
      	red 	 0.0
      	green 	-0.25
      	blue	-0.25

      Color fader has some additional functionality, like changing the color in two stages.

      // This affector will add the following values to the colour of the particles each second. 
      // Notice the suffix of the ColorFader(2), that is important.
      affector ColourFader2 {
      	// Notice the suffix here also, red(1) this indicates the color change per second for state 1
      	red1 	0.0
      	green1 	-1
      	blue1	-1
      	// Set the second state when the particle has 2 second left to live.
      	state_change 2
      	// And here is has the suffix 2, which in turn sets the change per second for state 2
      	red2	0	
      	green2	+1
      	blue2	+1
      	// This is all works for the alpha channel to of course.
      	alpha2  -1
    3. And finally we have the ColorInterpelator. It works similarly to the ColorFader2 but with 1..6 number of states. It is used quite differently though. You provide the time on scale from 0-1 time# scale , and colours are given in the form colour# r g b a. Lets create a jolly little stream:
      // ColourInterpolators can have up to 6 colour intervals indexed 0 to 5. 
      affector ColourInterpolator {
      	time0 0
      	colour0 1 0 0 0
      	time1 0.195
      	colour1 1 1 0 1
      	time2 0.39
      	colour2 0 1 1 1
      	time3 0.585
      	colour3 0 0 1 1
      	time4 0.78
      	colour4 1 0 1 1
      	time5 1
      	colour5 0 1 0 0

      Note: You have to define the default colour as colour 1 0 0 0 in the point_emitter block to eliminate the stuttering when the particles spawn. Just remember to remove that for the next step.

  8. Direction Randomiser We can make the particles change direction at random:
    // This will make the particles fly around like they have no tomorrow.
    affector DirectionRandomiser {
    	// This indicates the magnitude of the random choices the particle makes.
    	randomness 	1000
    	// Scope governs the chance that a given particle takes a random direction change scale from 0..1 ~ 0-100%
    	scope 		1
    	// Here you can indicate if the particle should randomize its velocity or not. <true|false>
    	keep_velocity true

    This could be useful for a pile of fireworks catching fire?, or a swarm of mosquitoes.

  9. Deflector Planes Deflector planes can make the particles change direction when they hit the deflector plane, the plane is provided in point normal form.
    // Deflector planes bounce the particles of the given plane.
    affector DeflectorPlane {
    	//The point of the plane, note: the plane is infinite
    	plane_point 	10 0 0
    	// The normal vector of the plane, the direction of the particles will be mirror around this normal.
    	plane_normal 	-0.7 0.7 0
    	// The amount of velocity the particles retain after the collision.
    	bounce 		1.0
    // You can provide more than one plane.
    affector DeflectorPlane {
    	plane_point 	10 15 0
    	plane_normal 	-0.7 -0.7 0
    	bounce 		1.0
  10. Different emitters We can make the spawn point of the particles different, some of them have different parameters see: Emitters
    1. Point
    2. Box
    3. Cylinder
    4. Ellipsoid
    5. Hollow Ellipsoid
    6. Ring
  11. Get your hands dirty. Now create a particle system using the things you have learned. Don't just randomly assign everything to a particle effect, make something :) A fountain, bleeding wound, did Sinbad eat tacos for dinner, hint, anybody?, where will you be when #”/& strikes? What I want to see is at least: Any Emitter, a DeflectorPlane, any Color Changer, and a LinearForce affector:
    A very simple fountain:


Das Bonus von GEDE!

  1. Using particle effects for something swell. Add a glowing particle effect to Sinbads sword. Particle effects are often used for all sorts of special effects :) and More. You can use the same command as attaching the sword to the handle bone, just as well to attach a particle generator. Hint: If Sinbad was holding a broom stick, the length of the broom would be the positive Z axis, and the y axis goes up into his arm.
    // Attach a sword to Sinbads right hand. 
    // Create the sword entity.
    Ogre::Entity* sword = _sceneManager->createEntity("Sword.mesh");
    // Attach the sword to Sinbads right hand.
    _SinbadEnt->attachObjectToBone("Handle.R", sword);
    // Clasp Sinbads hands around the hilt of the sword.
  2. Celebrate Sinbads amazing sword effect. If you followed the last point then Sinbad is surely a happy seadog, and a happy fellow deserves a show! Create some fireworks using the particle system Ogre provides. Hint: Check out the Emitter emitters. I'll provide you with some skeleton code.
    // Use this as a base for your fireworks :)
    particle_system Fireworks {
    	// Make the particles use the "Examples/Flare" material, and be 1x1 units large.
    	material 		Examples/Flare
    	particle_width 		1
    	particle_height		1
    	// Make the emitter limit the emitter to have at maximum 2000 particles active.
    	// And set the particle type as point, which always faces the camera.  
    	quota			2000
    	billboard_type		point
    	// The maximum amount of emitter emitters
    	emit_emitter_quota 	10
    	// Make the emitters origin a Point.
    	emitter Point {
    		// tell the particles to emitt the "bomb emitter" described below
    		emit_emitter 		bomb
    		// Fire one firework per second
    		emission_rate		1
    		// Make the particles go up. 
    		direction 		0 1 0
    		velocity 		70
    		time_to_live 		2
    	// The emitter emitted by the particles above
    	emitter Point {
    		// Name the emitter to match the name in the emit_emitter block
    		name 			bomb
    		// Configure the explosion.
    		emission_rate 		200
    		velocity 		30
    		// How long should the firework emit
    		duration_min            0.1
    		duration_max		0.2
    		// This is used to make sure the particles in the emitter emitter dont fire while the particle is in mid flight.
            repeat_delay_min        1
            repeat_delay_max        1.9
            time_to_live_min	0.3
            time_to_live_max	0.4
    	// Add some pseudo gravity.
    	affector LinearForce {
    		force_vector 0 -50 0

    Note: Affectors affect both the emitter and the emitter emitter :)

  3. Lastly If you come up with a use for the particle system and think that it deserves an additional bonus point or half, then I might be generous :)
    Hint: You could use the cylindrical effect from Lab 3 for interesting particle system effects :)

When You Are Finished

Upload your commented source files into Lab8 in MySchool (zip them up if more than one). The lab projects will not be graded, but their completion counts towards your participation grade.

/var/www/ailab/WWW/wiki/data/pages/public/t-gede-15-1/lab8.txt · Last modified: 2015/03/12 11:03 by marino