User Tools

Site Tools


gamedev:particleemitters

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
gamedev:particleemitters [2011/09/15 20:41] – created dragonlordgamedev:particleemitters [2019/05/24 23:43] (current) – ↷ Links adapted because of a move operation dragonlord
Line 1: Line 1:
-====== Particle Emitters ======+{{tag>particle graphic physics collision}} 
 +<WRAP youarehere> 
 +[[:start|Start Page]] >> [[:gamedev|Game Development with the Drag[en]gine]] >> **Particle Emitters** 
 +</WRAP> 
 Particle emitters allow to create particles in the game world influenced by physics. Physical behavior is not mandatory but the default behavior. Particle systems are split into two individual components to simplify the process of defining and using particles. Particle emitters are defined once and are then reused multiple times using instances. Emitters support both continuous and burst like emission of particles. For fine grained control over the properties of generated particles controllers are used. These work similar to controllers in [[gamedev:animators|animators]]. Furthermore emitters support collision emitters to simplify creating cascaded emitters like rain drops hitting the floor bursting into smaller drops upon impact. Emitters can also be set to self-destroy after the last particle has died. This allows to use particles in a deploy-and-forget manner. Particle emitters allow to create particles in the game world influenced by physics. Physical behavior is not mandatory but the default behavior. Particle systems are split into two individual components to simplify the process of defining and using particles. Particle emitters are defined once and are then reused multiple times using instances. Emitters support both continuous and burst like emission of particles. For fine grained control over the properties of generated particles controllers are used. These work similar to controllers in [[gamedev:animators|animators]]. Furthermore emitters support collision emitters to simplify creating cascaded emitters like rain drops hitting the floor bursting into smaller drops upon impact. Emitters can also be set to self-destroy after the last particle has died. This allows to use particles in a deploy-and-forget manner.
  
 ====== Emitters ====== ====== Emitters ======
-Emitters contain the definition of a single particle system. Emitters are non-resource objects hence they are not loaded from a file but build at run-time. This allows the user to use his own way of storing particle systems. An emitter should not be changed after it has been initialized and is in use by instances. Emitters can emit particles either continuously or in bursts. The default behavior is to emit particle continuously. In this mode the interval parameter is used to determine the time until the next particle is emitted. The number of particle emitted each time the interval elapses is defined using the particle count parameter. In burst mode particles are emitted once only. In burst mode the particle count parameter is also evaluated over the burst lifetime of the emitter. This lifetime defines the length of a burst. Using the progress curve of the particle parameter multiple emissions of particles can be defined along the burst lifetime. Thus it is possible to fine tune the emission behavior of particles in a burst if required. More information about this can be found in the particle count parameter section.+Emitters contain the definition of a single particle system. Emitters are non-resource objects hence they are not loaded from a file but build at run-time. This allows the user to use his own way of storing particle systems. An emitter should not be changed after it has been initialized and is in use by instances. Emitters can emit particles either continuously or in bursts. The default behavior is to emit particle continuously. In this mode the interval parameter is used to determine the time until the next particle is emitted. The number of particle emitted each time the interval elapses is defined using the particle count parameter. In burst mode particles are emitted once only. In burst mode the particle count parameter is also evaluated over the burst lifetime of the emitter. This lifetime defines the length of a burst. Using the progress curve of the particle parameter multiple emissions of particles can be defined along the burst lifetime. Thus it is possible to fine tune the emission behavior of particles in a burst if required. More information about this can be found in the particle count parameter section. The layer mask and group number are set to each instance the emitter is assigned to. This is required for cascaded emitters since the game code does not have access to the created instances. You can still though change the layer mask and group number in instances you have access to after you set an emitter.
  
 ^Name^Description^Type^Default^ ^Name^Description^Type^Default^
 |Emit Burst|Determines if particles are emitted continuously or in bursts|Boolean|False| |Emit Burst|Determines if particles are emitted continuously or in bursts|Boolean|False|
 |Burst Lifetime|The life time in seconds of the emitter if using burst mode|Float|1.0| |Burst Lifetime|The life time in seconds of the emitter if using burst mode|Float|1.0|
 +|Layer Mask|Collision mask.|LayerMask|(empty)|
 +|Group Number|Collision group number|Int|0|
 |Controllers|Controller definitions.|ParticleEmitterController[]| | |Controllers|Controller definitions.|ParticleEmitterController[]| |
 |Types|Particle type definitions.|ParticleEmitterType[]| | |Types|Particle type definitions.|ParticleEmitterType[]| |
Line 13: Line 19:
  
 ====== Instances ====== ====== Instances ======
-Particle emitters can only emit particles if placed in the world using instances. Instances have a position and orientation in the world and are allowed to move while emitting particles. Particles are emitted along the Z-axis of the instance coordinate frame at the instance position. Particles move independently from the instance once emitted. Particles are emitted as long as Emitter is not null and Enable Casting is True. If Emitter has Emit Burst set to true particles are burst-emitted only once. To start another burst of particles call the ResetBurst method. Particles emitted up to this point are kept and a new burst cycle started. The old burst cycled is stopped. If Remove After Last Particle Died is set to True the instance removes itself from the world if the last particle died. If Emitter has Emit Burst set to True the Burst Lifetime has to have elapsed too in addition to the last particle rule for the instance to be removed. This way you can defined a burst which has a gap in between where no particles exists without the instance incorrectly being removed. The Layer Mask and Group Number are used to define which objects the particles collide with.+Particle emitters can only emit particles if placed in the world using instances. Instances have a position and orientation in the world and are allowed to move while emitting particles. Particles are emitted along the Z-axis of the instance coordinate frame at the instance position. Particles move independently from the instance once emitted. Particles are emitted as long as Emitter is not null and **Enable Casting** is True. If Emitter has **Emit Burst** set to true particles are burst-emitted only once. To start another burst of particles call the **ResetBurst** method. Particles emitted up to this point are kept and a new burst cycle started. The old burst cycled is stopped. If **Remove After Last Particle Died** is set to True the instance removes itself from the world if the last particle died. If Emitter has **Emit Burst** set to True the **Burst Lifetime** has to have elapsed too in addition to the last particle rule for the instance to be removed. This way you can defined a burst which has a gap in between where no particles exists without the instance incorrectly being removed. The **Layer Mask** and **Group Number** are used to define which objects the particles collide with.
  
 ^Name^Description^Type^Default^ ^Name^Description^Type^Default^
Line 42: Line 48:
 Particles in types are drawn using billboards. A skin object has to be set which defines the texture to use for these billboards. The first texture in the skin object is used. The billboards are scaled using the size parameter. The Physics Size property is used only for physics and is not required to match the drawn size of the particle. In general the Physics Size is less than half the size of the real size and does not change. The color, transparency and emissivity of the billboard texture can be altered using the red, green, blue, transparency and emissivity parameter. The texture properties are multiplied with these parameter values. Particles in types are drawn using billboards. A skin object has to be set which defines the texture to use for these billboards. The first texture in the skin object is used. The billboards are scaled using the size parameter. The Physics Size property is used only for physics and is not required to match the drawn size of the particle. In general the Physics Size is less than half the size of the real size and does not change. The color, transparency and emissivity of the billboard texture can be altered using the red, green, blue, transparency and emissivity parameter. The texture properties are multiplied with these parameter values.
  
-Particles are emitted relative to the coordinate frame of the instance which produces them. They are emitted at the origin along the Z-Axis. The cast angle x and cast angle y parameter defines the deviation from this direction. In addition a model can be defined which then is used to emit particles from. The Cast From parameter defines where from the model particles are emitted from. If Vertex is chosen particles are emitted from the vertices of the model along the vertex normals. Vertices are picked randomly. Vertex normals are not the normals defined in the model but the surface normals. If Face is chosen particles are cast from the faces of the model along interpolated vertex normals. Faces are chosen randomly as well as the position inside the face area. Particles are thus emitted randomly all across the entire surface defined by all faces. If Volume is chosen particles are cast from inside the model volume. Their normal in this case is the same as without a model as no unique normal can be defined for a point inside the model volume. If a skin is defined for the model this can be used to alter particle properties depending on where on the mode it has been emitted.+Particles are emitted relative to the coordinate frame of the instance which produces them. They are emitted at the origin along the Z-Axis. The **cast angle x** and **cast angle y** parameter defines the deviation from this direction. In addition a model can be defined which then is used to emit particles from. The **Cast From** parameter defines where from the model particles are emitted from. If **Vertex** is chosen particles are emitted from the vertices of the model along the vertex normals. Vertices are picked randomly. Vertex normals are not the normals defined in the model but the surface normals. If **Face** is chosen particles are cast from the faces of the model along interpolated vertex normals. Faces are chosen randomly as well as the position inside the face area. Particles are thus emitted randomly all across the entire surface defined by all faces. If **Volume** is chosen particles are cast from inside the model volume. Their normal in this case is the same as without a model as no unique normal can be defined for a point inside the model volume. If a skin is defined for the model this can be used to alter particle properties depending on where on the mode it has been emitted.
  
-Particles collide with objects using the Layer Mask and Group Number of the parent instance. The Collision Response parameter defines the reaction of particles to collisions. If Destroy is set particles are destroy upon collision. If Physical is chosen particles bounce of the surface they hit using physical simulation. The elasticity and roughness parameter governs this behavior. If Custom is chosen the game scripts are used to determine what to do. This works similar to the callback in [[gamedev:colliders|colliders]]. Additionally upon impact new child instances can be produced. This allows to create cascading particle effects. Care has to be taken to not produce loops or producing too many particles. An emitter can be specified using Collision Emitter. To avoid creating too many particles in the case of Physical for Collision Response the impulse of the impact is used to limit the cases where instances are produced. Only if the impulse of the impacting particle exceeds Emit Min Impulse an instance is created. This value should be kept large to produce only instances upon heavy impacts. Once created particle parameters can be transfered to the controllers of the created instance. This allows to influence the child particles using impact properties. You can set a controller index for the lifetime, mass, linear and angular velocity of the impacting particle. If the controller is set to a valid controller in the created child instance the given particle property is set as the controller value.+Particles collide with objects using the **Layer Mask** and **Group Number** of the parent instance. The **Collision Response** parameter defines the reaction of particles to collisions. If **Destroy** is set particles are destroy upon collision. If **Physical** is chosen particles bounce of the surface they hit using physical simulation. The **elasticity** and **roughness** parameter governs this behavior. If **Custom** is chosen the game scripts are used to determine what to do. This works similar to the callback in [[gamedev:colliders|colliders]]. Additionally upon impact new child instances can be produced. This allows to create cascading particle effects. Care has to be taken to not produce loops or producing too many particles. An emitter can be specified using **Collision Emitter**. To avoid creating too many particles in the case of **Physical** for **Collision Response** the impulse of the impact is used to limit the cases where instances are produced. Only if the impulse of the impacting particle exceeds Emit Min Impulse an instance is created. This value should be kept large to produce only instances upon heavy impacts. Once created particle parameters can be transfered to the controllers of the created instance. This allows to influence the child particles using impact properties. You can set a controller index for the lifetime, mass, linear and angular velocity of the impacting particle. If the controller is set to a valid controller in the created child instance the given particle property is set as the controller value
 + 
 +Trails can be added to all particles of a type using the **Trail Emitter** parameter. The set emitter should be a continuous emitting particle emitter. Upon emitting a particle an instance of this emitter is created and attached to the particle in reverse. Hence the orientation of the instance is opposite direction than the one the particle is traveling. As soon as the particle dies the trail instance is set to remove itself one the last particle died. You can set a controller index for the lifetime, mass, linear and angular velocity of the trail emitter. If the controller is set to a valid controller in the created child instance the given particle property is set as the controller value. Trail emitters and collision emitters can be used together if required. Here too make sure to not create too many particles. 
 + 
 +<WRAP center round info 90%> 
 +If the particle is moving at different velocities the density of the trail emitter varies. You can create a trail emitting the right amount of particles depending on the velocity using the **Trail Controllers**. Simply create a trail emitter with a single controller and set in the **Trail Controller** for **linear velocity** to the index of this controller (0 in this example). The value of the trail controller is now always set to the linear velocity of the particle it is attached to. Now use this controller on the **interval** parameter and you can control precisely the density of your trail or any other parameter as you see fit. The required interval can be easily calculated using overlap*(size/velocity). **Value** of the parameter acts as the overlap value which makes it easy to adjust the overall density. Calculate a bunch of values for different velocities inside the controller range and you have a basic curve keeping density equal. 
 +</WRAP> 
 + 
 +Types can have different simulation types. Using **particle** as **Simulation Type** simulates particles the default way. Using **ribbon** all generated particles are connected using a ribbon in the order they have been cast. Use [[gamedev:skinproperties|Skin Texture Properties]] to alter how the rendering is done. In general there is a strict separation between properties affecting rendering only and properties affecting also the physics part of particles. Later ones only are stored in the emitter types. Last simulation type is **beam** which renders a beam for each particle between the cast position and the final position which is the particle simulated over the entire lifetime. 
 + 
 +Using **Interval As Time** the usage of the **interval** parameter can be modified. By default the interval is used over time. Hence if the interval parameter for example resolves to 0.1 then a particle would be cast after 0.1 seconds. If **Interval As Time** is set to true though the usage changes to over distance instead of time. Hence with an interval value of 0.1 a particle would be cast after the emitter instance displaced by 0.1 meters from the last time a particle has been cast. This can be used for trail particles to have better control as well as for ribbons in connection with dynamically moving emitter instances.
  
 ^Name^Description^Type^Default^ ^Name^Description^Type^Default^
Line 51: Line 67:
 |Model Skin|Skin for the model to use. Allows to alter emission parameters depending on where a particle is emitted.|Skin|null| |Model Skin|Skin for the model to use. Allows to alter emission parameters depending on where a particle is emitted.|Skin|null|
 |Cast From|Determines from what element of the Model (if set) particles are emitted from.|{Vertex, Face, Volume}|Vertex| |Cast From|Determines from what element of the Model (if set) particles are emitted from.|{Vertex, Face, Volume}|Vertex|
 +|Simulation Type|How to simulate the particle emitter. Also defines how it is rendered.|{Particle, Ribbon, Beam}|Particle|
 +|Interval As Distance|Determines if the interval parameter is used over time (seconds) or over distance (meters).|boolean|False|
 +|Trail Emitter|Emitter to use as the trail for particles.|ParticleEmitter|null|
 +|Trail Controllers|Defines which controller (if any) in the trail emitter instance is set with particle parameters.|Int[]|-1|
 |Physics Size|Size in meters of the particle sphere used during physics.|Float|0.1| |Physics Size|Size in meters of the particle sphere used during physics.|Float|0.1|
 |Collision Response|Determines how particles react to collisions.|{Destroy, Physical, Custom}|Physical| |Collision Response|Determines how particles react to collisions.|{Destroy, Physical, Custom}|Physical|
Line 70: Line 90:
 EmitValue = ParamValue + ParamSpread * 0.5 * random() EmitValue = ParamValue + ParamSpread * 0.5 * random()
 RenderValue = EmitValue * CurveProgress( particle.lifetime )</code> RenderValue = EmitValue * CurveProgress( particle.lifetime )</code>
-This looks complex but is quite simple. Upon emitting a particle a random value between (Value - Spread/2)-(Value + Spread/2) is chosen whereas the value for Value and Spread are either the static values or sampled from CurveValue or CurveSpread depending if they have curve points and if ControllerValue or ControllerSpread points to a valid controller. During each update step this EmitValue is then multiplied by progress curve sampled over the particle lifetime. If there are no curve points in Curve Progress then 1 is used as the multiplication factor. Using controllers thus the user can influence the Value and Spread of individual particle parameters. See the listing of particle parameters for more information.+This looks complex but is quite simple. Upon emitting a particle a random value between (**Value** **Spread**/2)-(**Value** **Spread**/2) is chosen whereas the value for **Value** and **Spread** are either the static values or sampled from **CurveValue** or **CurveSpread** depending if they have curve points and if **ControllerValue** or **ControllerSpread** points to a valid controller. During each update step this **EmitValue** is then multiplied by **Curve Progress** sampled over the particle lifetime. If there are no curve points in **Curve Progress** then 1 is used as the multiplication factor. Using controllers thus the user can influence the **Value** and **Spread** of individual particle parameters. See the listing of particle parameters for more information
 + 
 +Curves are 2 dimensions bezier curves hence each point composes of 3 Vector2 values (point, left handle, right handle). Points are required to be sorted which the **CurveBezier** class takes care of.
  
 ^Name^Description^Type^Default^ ^Name^Description^Type^Default^
Line 140: Line 162:
 Defines the emit direction for particles creating instances upon impact. If set to 0 the created instance is oriented along the normal of the impact surface. If set to 1 the created instance is oriented along the repel direction as calculated using roughness. Defines the emit direction for particles creating instances upon impact. If set to 0 the created instance is oriented along the normal of the impact surface. If set to 1 the created instance is oriented along the repel direction as calculated using roughness.
  
-====== Links ====== +====== Examples ====== 
-  * [[gamedev:main|Game Development Informations]] +{{ youtube>6rdYWmf1yZc?600x450 |Particle Beams Example Video}}
-  * [[:start|Main page]]+
gamedev/particleemitters.1316119295.txt.gz · Last modified: 2011/09/15 20:41 by dragonlord