190 likes | 359 Views
Department of ELECTRONIC AND INFORMATION ENGINEERING. 3. Particle Effects by Dr Daniel Lun. EIE360 Integrated Project. Lecture 3 Particle Effects. References: [1] Gregory Junker, Pro OGRE 3D Programming, Apress, 2006
E N D
Department of ELECTRONIC AND INFORMATION ENGINEERING 3. Particle Effects by Dr Daniel Lun EIE360 Integrated Project Lecture 3 Particle Effects References: [1] Gregory Junker, Pro OGRE 3D Programming, Apress, 2006 [2] Ogre Tutorials – Ogre Wiki http://www.ogre3d.org/wiki/index.php/Ogre_Tutorials [3] http://code.google.com/p/gmogre3d/wiki/ParticleScripts [4] Microsoft MSDN, C++ reference 1
Department of ELECTRONIC AND INFORMATION ENGINEERING 3. Particle Effects by Dr Daniel Lun Architecture of the Interactive Virtual Aquarium System Computer A USB port Your program Kinect Sensor Device Network Computer B 3D Graphics System Your program 3D Graphics 2
Department of ELECTRONIC AND INFORMATION ENGINEERING 3. Particle Effects by Dr Daniel Lun 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 3
Department of ELECTRONIC AND INFORMATION ENGINEERING 3. Particle Effects by Dr Daniel Lun 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 A Typical Template emitter Point { angle 180 colour 1 0.9 0 0.9 colour_range_start 1 0.9 0 0.9 colour_range_end 1 0.2 0 0.9 direction 0 1 0 emission_rate 2000 position 0 0 0 velocity 300 velocity_min 300 velocity_max 300 time_to_live 2.5 time_to_live_min 2.5 time_to_live_max 2.5 duration 2 duration_min 2 duration_max 2 repeat_delay 5 repeat_delay_min 5 repeat_delay_max 5 } affector LinearForce { force_vector 0 -200 0 } affector ColourFader { red -0.4 green -0.4 blue -0.1 alpha -0.5 } } particle_system EIE360/Explosion { quota 1000 material Examples/FlarePointSprite particle_width 50 particle_height 50 cull_each false renderer billboard sorted false local_space true iteration_interval 0 nonvisible_update_timeout 0 billboard_type oriented_common billboard_origin center billboard_rotation_type texcoord common_direction 0 1 0 common_up_vector 0 1 0 point_rendering false accurate_facing false 5
Department of ELECTRONIC AND INFORMATION ENGINEERING 3. Particle Effects by Dr Daniel Lun 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 • 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 6
Department of ELECTRONIC AND INFORMATION ENGINEERING 3. Particle Effects by Dr Daniel Lun 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]): With sorting, the smoke obscures the fire Without sorting, we see the fire 7
Department of ELECTRONIC AND INFORMATION ENGINEERING 3. Particle Effects by Dr Daniel Lun Template: Basic example billboard_type oriented_common billboard_origin center billboard_rotation_type texcoord common_direction 0 1 0 common_up_vector 0 1 0 point_rendering false accurate_facing false particle_system EIE360/Explosion { quota 1000 material Examples/FlarePointSprite particle_width 50 particle_height 50 cull_each false renderer billboard sorted false local_space true iteration_interval 0 nonvisible_update_timeout 0 Many flare light points of large size 8
Department of ELECTRONIC AND INFORMATION ENGINEERING 3. Particle Effects by Dr Daniel Lun 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 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 Template: Emitters example emitter Point { angle 180 colour 1 0.9 0 0.9 colour_range_start 1 0.9 0 0.9 colour_range_end 1 0.2 0 0.9 direction 0 1 0 emission_rate 2000 position 0 0 0 velocity 300 velocity_min 300 velocity_max 300 time_to_live 2.5 time_to_live_min 2.5 time_to_live_max 2.5 duration 2 duration_min 2 duration_max 2 repeat_delay 5 repeat_delay_min 5 repeat_delay_max 5 } flare light points emitted in all directions 11
Department of ELECTRONIC AND INFORMATION ENGINEERING 3. Particle Effects by Dr Daniel Lun 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 0 -200 0 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 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) affector ColourFader { red -0.5 green -0.5 blue -0.5 alpha -0.5 } 13
Department of ELECTRONIC AND INFORMATION ENGINEERING 3. Particle Effects by Dr Daniel Lun Template: Affectors example affector LinearForce { force_vector 0 -200 0 } 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 14
Department of ELECTRONIC AND INFORMATION ENGINEERING 3. Particle Effects by Dr Daniel Lun Template: Affectors example affectorDeflectorPlane { plane_point 0 300 0 plane_normal 0 -1 0 bounce 0 } 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
Department of ELECTRONIC AND INFORMATION ENGINEERING 3. Particle Effects by Dr Daniel Lun 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 Can be downloaded from http://www.ogre3d.org 16
Department of ELECTRONIC AND INFORMATION ENGINEERING 3. Particle Effects by Dr Daniel Lun Introducing Particle Systems to the Aquarium • 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 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 17
Department of ELECTRONIC AND INFORMATION ENGINEERING 3. Particle Effects by Dr Daniel Lun An example … 18