11 Lecture 3 Particle Effects References: [1] Gregory Junker, Pro OGRE 3D Programming, Apress, 2006 [2] Ogre Tutorials – Ogre Wiki [3] [4]Microsoft MSDN, C++ reference EIE360 Integrated Project Department of ELECTRONIC AND INFORMATION ENGINEERING 3. Particle Effects by Dr Daniel Lun
22 Architecture of the Interactive Virtual Aquarium System Department of ELECTRONIC AND INFORMATION ENGINEERING 3. Particle Effects by Dr Daniel Lun USB port 3D Graphics System 3D Graphics Your program Your program Network Computer A Computer B Kinect Sensor Device
33 Particle Effects in OGRE Particle systems are the foundation of most visual special effects in a 3D application They refer to the kind of computer graphics techniques to simulate certain fuzzy phenomena They are otherwise very hard to reproduce with conventional rendering techniques These fuzzy phenomena include bubbles, fire, smoke, explosion, snow, … Fireball Bubbles Department of ELECTRONIC AND INFORMATION ENGINEERING 3. Particle Effects by Dr Daniel Lun
4 Particle System Templates Particle systems are typically script based to enable fast prototyping and iteration Users only need to change the data in a script file in order to change the behavior of a particle system Templates are used to standardize the script files Can be reused to create multiple particle systems that are similar Some major items in a template Basic – the basic setup information of the particle system Emitters – define how the particles are emitted Affectors – define the particles’ path and lifetime once emitted 4 Department of ELECTRONIC AND INFORMATION ENGINEERING 3. Particle Effects by Dr Daniel Lun
5 A Typical Template particle_system EIE360/Explosion { quota1000 material Examples/FlarePointSprite particle_width50 particle_height50 cull_eachfalse rendererbillboard sortedfalse local_spacetrue iteration_interval0 nonvisible_update_timeout 0 billboard_type oriented_common billboard_origincenter billboard_rotation_type texcoord common_direction0 1 0 common_up_vector0 1 0 point_renderingfalse accurate_facingfalse 5 emitter Point { angle180 colour colour_range_start colour_range_end direction0 1 0 emission_rate2000 position0 0 0 velocity300 velocity_min300 velocity_max300 time_to_live2.5 time_to_live_min2.5 time_to_live_max2.5 duration2 duration_min2 duration_max2 repeat_delay5 repeat_delay_min5 repeat_delay_max5 } affector LinearForce { force_vector } affector ColourFader { red-0.4 green-0.4 blue-0.1 alpha-0.5 } Department of ELECTRONIC AND INFORMATION ENGINEERING 3. Particle Effects by Dr Daniel Lun
6 Template: Basics quota Particle systems cannot emit particles without bound Need to specify a quota Will stop emitting particles when quota has been used up 6 material Need to define how each particle is composed E.g., an explosion can be composed by many flare light points of different colors The definition of materials is stored in a script file Many material examples script files can be found in media/materials/scripts flare Department of ELECTRONIC AND INFORMATION ENGINEERING 3. Particle Effects by Dr Daniel Lun
7 Template: Basic (cont) sorted Ogre can sort particles based on their distance from the camera Require heavy computation hence disable by default May be useful in some situation such as (excerpt from [1]): 7 Without sorting, we see the fire With sorting, the smoke obscures the fire Department of ELECTRONIC AND INFORMATION ENGINEERING 3. Particle Effects by Dr Daniel Lun
8 Template: Basic example 8 particle_system EIE360/Explosion { quota1000 material Examples/FlarePointSprite particle_width50 particle_height50 cull_eachfalse rendererbillboard sortedfalse local_spacetrue iteration_interval0 nonvisible_update_timeout 0 billboard_typeoriented_common billboard_origincenter billboard_rotation_type texcoord common_direction0 1 0 common_up_vector0 1 0 point_renderingfalse accurate_facingfalse Many flare light points of large size Department of ELECTRONIC AND INFORMATION ENGINEERING 3. Particle Effects by Dr Daniel Lun
9 Template: Emitters In the context of particle systems, an emitter is an object that emits particle. A few emitters can be found in Ogre point emitters box emitters cylinder emitters ellipsoid emitters hollow ellipsoid emitters emit from the shell of an ellipsoidal volume ring emitters emit from the edges of a planar ring The rate, velocity, and direction in which particles are emitted are completely configurable 9 Department of ELECTRONIC AND INFORMATION ENGINEERING 3. Particle Effects by Dr Daniel Lun
10 Template: Emitters (cont) angle and direction Particles are usually emitted in a “cone” around the direction of the emitter The size of the cone is defined by “angle” If “angle” = 0, emit particle in a straight line If “angle” = 180, emit in all directions If “angle” = 90, emit in a hemisphere around the direction vector The direction is defined by “direction” “direction” = 0 1 0, means parallel to the y-axis 10 Department of ELECTRONIC AND INFORMATION ENGINEERING 3. Particle Effects by Dr Daniel Lun
11 Template: Emitters example 11 emitter Point { angle180 colour colour_range_start colour_range_end direction0 1 0 emission_rate2000 position0 0 0 velocity300 velocity_min300 velocity_max300 time_to_live 2.5 time_to_live_min 2.5 time_to_live_max 2.5 duration2 duration_min2 duration_max2 repeat_delay5 repeat_delay_min 5 repeat_delay_max 5 } flare light points emitted in all directions Department of ELECTRONIC AND INFORMATION ENGINEERING 3. Particle Effects by Dr Daniel Lun
12 Template: Affectors Affectors affect the particles’ path and lifetime once they are emitted into the game world Can impose “gravity”, “wind” on particles Can define particles that will change color after emission LinearForce Apply a force to the particles The particles will drift following the direction of the force after emission E.g. force_vector defines a force vector that forces the particles falling onto the ground after emission 12 Department of ELECTRONIC AND INFORMATION ENGINEERING 3. Particle Effects by Dr Daniel Lun
13 Template: Affectors (cont) ColorFader Modify a particle’s color while it exists The color definition is in terms of “component change per second” E.g. The following code will fade the color by 0.5 each second (the max and min value are 1 and 0, resp) 13 affector ColourFader { red -0.5 green -0.5 blue -0.5 alpha -0.5 } Department of ELECTRONIC AND INFORMATION ENGINEERING 3. Particle Effects by Dr Daniel Lun
14 Template: Affectors example 14 affector LinearForce { force_vector } affector ColourFader { red-0.4 green-0.4 blue-0.1 alpha-0.5 } All flare light points will fall onto the ground Color will change and disappear at the end Department of ELECTRONIC AND INFORMATION ENGINEERING 3. Particle Effects by Dr Daniel Lun
Template: Affectors example 15 Department of ELECTRONIC AND INFORMATION ENGINEERING 3. Particle Effects by Dr Daniel Lun affector DeflectorPlane { plane_point plane_normal bounce0 } Define an invisible plane at point (0, 300, 0) with normal equal to -1 (0, 300, 0) X Normal = -1 Means all particles will go thru the plane without bouncing back
16 Particle Editor For fast prototyping of particle systems, an application ParticleEditor is provided by the Ogre community Allow real time visualization of the particle effect with changes in parameters 16 Can be downloaded from Department of ELECTRONIC AND INFORMATION ENGINEERING 3. Particle Effects by Dr Daniel Lun
17 Introducing Particle Systems to the Aquarium 17 Department of ELECTRONIC AND INFORMATION ENGINEERING 3. Particle Effects by Dr Daniel Lun Ogre::ParticleSystem *bubblesParticle = mSceneMgr->createParticleSystem(“Bubbles”, “EIE360/Bubbles”); mBubblesNode = mSceneMgr->getRootSceneNode()-> createChildSceneNode("BubblesNode"); //Node name mBubblesNode->attachObject(bubblesParticle); mBubblesNode->setPosition(Ogre:: Vector3(0, -20, -50)); //Position of the bubbles Assume the following variable is defined: Then create a ParticleSystem with the particle effect Bubbles defined in EIE360/Bubbles Create a scene node and attach the ParticleSystem to it SceneNode * mBubblesNode
An example … 18 Department of ELECTRONIC AND INFORMATION ENGINEERING 3. Particle Effects by Dr Daniel Lun