particle_systems_2d.rst 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. .. _doc_particle_systems_2d:
  2. Particle systems (2D)
  3. =====================
  4. Intro
  5. -----
  6. A simple (but flexible enough for most uses) particle system is
  7. provided. Particle systems are used to simulate complex physical effects,
  8. such as sparks, fire, magic particles, smoke, mist, etc.
  9. The idea is that a "particle" is emitted at a fixed interval and with a
  10. fixed lifetime. During its lifetime, every particle will have the same
  11. base behavior. What makes each particle different from the rest and provides a more
  12. organic look is the "randomness" associated with each parameter. In
  13. essence, creating a particle system means setting base physics
  14. parameters and then adding randomness to them.
  15. Particle nodes
  16. ~~~~~~~~~~~~~~
  17. Godot provides two different nodes for 2D particles, :ref:`class_Particles2D` and
  18. :ref:`class_CPUParticles2D`.
  19. Particles2D is more advanced and uses the GPU to process particle effects, but that limits
  20. it to higher end graphics API, and in our case to the GLES3 renderer. For projects using
  21. the GLES2 backend, CPUParticles2D is a CPU-driven option with near feature parity with
  22. Particles2D, but lesser performance. While Particles2D is configured via a
  23. :ref:`class_ParticlesMaterial` (and optionally with a custom shader), the matching options
  24. are provided via node properties in CPUParticles2D (with the exception of the trail settings).
  25. You can convert a Particles2D node into a CPUParticles2D node by clicking on the node in the
  26. inspector, and selecting "Convert to CPUParticles2D" in the "Particles" menu of the toolbar.
  27. .. image:: img/particles_convert.png
  28. The rest of this tutorial is going to use the Particles2D node. First, add a Particles2D
  29. node to your scene. After creating that node you will notice that only a white dot was created,
  30. and that there is a warning icon next to your Particles2D node in the inspector. This
  31. is because the node needs a ParticlesMaterial to function.
  32. ParticlesMaterial
  33. ~~~~~~~~~~~~~~~~~
  34. To add a process material to your particles node, go to ``Process Material`` in
  35. your inspector panel. Click on the box next to ``Material``, and from the dropdown
  36. menu select ``New ParticlesMaterial``.
  37. .. image:: img/particles_material.png
  38. Your Particles2D node should now be emitting
  39. white points downward.
  40. .. image:: img/particles1.png
  41. Texture
  42. ~~~~~~~
  43. A particle system uses a single texture (in the future this might be
  44. extended to animated textures via spritesheet). The texture is set via
  45. the relevant texture property:
  46. .. image:: img/particles2.png
  47. Time parameters
  48. ---------------
  49. Lifetime
  50. ~~~~~~~~
  51. The time in seconds that every particle will stay alive. When lifetime
  52. ends, a new particle is created to replace it.
  53. Lifetime: 0.5
  54. .. image:: img/paranim14.gif
  55. Lifetime: 4.0
  56. .. image:: img/paranim15.gif
  57. One Shot
  58. ~~~~~~~~
  59. When enabled, a Particles2D node will emit all of its particles once
  60. and then never again.
  61. Preprocess
  62. ~~~~~~~~~~
  63. Particle systems begin with zero particles emitted, then start emitting.
  64. This can be an inconvenience when loading a scene and systems like
  65. a torch, mist, etc. begin emitting the moment you enter. Preprocess is
  66. used to let the system process a given number of seconds before it is
  67. actually drawn the first time.
  68. Speed Scale
  69. ~~~~~~~~~~~
  70. The speed scale has a default value of ``1`` and is used to adjust the
  71. speed of a particle system. Lowering the value will make the particles
  72. slower while increasing the value will make the particles much faster.
  73. Explosiveness
  74. ~~~~~~~~~~~~~
  75. If lifetime is ``1`` and there are 10 particles, it means a particle
  76. will be emitted every 0.1 seconds. The explosiveness parameter changes
  77. this, and forces particles to be emitted all together. Ranges are:
  78. - 0: Emit particles at regular intervals (default value).
  79. - 1: Emit all particles simultaneously.
  80. Values in the middle are also allowed. This feature is useful for
  81. creating explosions or sudden bursts of particles:
  82. .. image:: img/paranim18.gif
  83. Randomness
  84. ~~~~~~~~~~
  85. All physics parameters can be randomized. Random values range from ``0`` to
  86. ``1``. The formula to randomize a parameter is:
  87. ::
  88. initial_value = param_value + param_value * randomness
  89. Fixed FPS
  90. ~~~~~~~~~
  91. This setting can be used to set the particle system to render at a fixed
  92. FPS. For instance, changing the value to ``2`` will make the particles render
  93. at 2 frames per second. Note this does not slow down the particle system itself.
  94. Fract Delta
  95. ~~~~~~~~~~~
  96. This can be used to turn Fract Delta on or off.
  97. Drawing parameters
  98. ------------------
  99. Visibility Rect
  100. ~~~~~~~~~~~~~~~
  101. The visibility rectangle controls the visibility of the particles on screen. If this rectangle is outside of the viewport, the engine will not render the particles on screen.
  102. The rectangle's ``W`` and ``H`` properties respectively control its Width and its Height.
  103. The ``X`` and ``Y`` properties control the position of the upper-left
  104. corner of the rectangle, relative to the particle emitter.
  105. You can have Godot generate a Visibility Rect automatically using the toolbar above the 2d view. To do so, select the Particles2D node and Click ``Particles > Generate Visibility Rect``. Godot will simulate the Particles2D node emitting particles for a few seconds and set the rectangle to fit the surface the particles take.
  106. You can control the emit duration with the ``Generation Time (sec)`` option. The maximum value is 25 seconds. If you need more time for your particles to move around, you can temporarily change the ``preprocess`` duration on the Particles2D node.
  107. Local Coords
  108. ~~~~~~~~~~~~
  109. By default this option is on, and it means that the space that particles
  110. are emitted to is relative to the node. If the node is moved, all
  111. particles are moved with it:
  112. .. image:: img/paranim20.gif
  113. If disabled, particles will emit to global space, meaning that if the
  114. node is moved, already emitted particles are not affected:
  115. .. image:: img/paranim21.gif
  116. Draw Order
  117. ~~~~~~~~~~
  118. This controls the order in which individual particles are drawn. ``Index``
  119. means particles are drawn according to their emission order (default).
  120. ``Lifetime`` means they are drawn in order of remaining lifetime.
  121. ParticlesMaterial settings
  122. --------------------------
  123. Direction
  124. ~~~~~~~~~
  125. This is the base direction at which particles emit. The default is
  126. ``Vector3(1, 0, 0)`` which makes particles emit to the right. However,
  127. with the default gravity settings, particles will go straight down.
  128. .. image:: img/direction1.png
  129. For this property to be noticeable, you need an *initial velocity* greater
  130. than 0. Here, we set the initial velocity to 40. You'll notice that
  131. particles emit toward the right, then go down because of gravity.
  132. .. image:: img/direction2.png
  133. Spread
  134. ~~~~~~
  135. This parameter is the angle in degrees which will be randomly added in
  136. either direction to the base ``Direction``. A spread of ``180`` will emit
  137. in all directions (+/- 180). For spread to do anything the "Initial Velocity"
  138. parameter must be greater than 0.
  139. .. image:: img/paranim3.gif
  140. Flatness
  141. ~~~~~~~~
  142. This property is only useful for 3D particles.
  143. Gravity
  144. ~~~~~~~
  145. The gravity applied to every particle.
  146. .. image:: img/paranim7.gif
  147. Initial Velocity
  148. ~~~~~~~~~~~~~~~~
  149. Initial velocity is the speed at which particles will be emitted (in
  150. pixels/sec). Speed might later be modified by gravity or other
  151. accelerations (as described further below).
  152. .. image:: img/paranim4.gif
  153. Angular Velocity
  154. ~~~~~~~~~~~~~~~~
  155. Angular velocity is the initial angular velocity applied to particles.
  156. Spin Velocity
  157. ~~~~~~~~~~~~~
  158. Spin velocity is the speed at which particles turn around their center
  159. (in degrees/sec).
  160. .. image:: img/paranim5.gif
  161. Orbit Velocity
  162. ~~~~~~~~~~~~~~
  163. Orbit velocity is used to make particles turn around their center.
  164. .. image:: img/paranim6.gif
  165. Linear Acceleration
  166. ~~~~~~~~~~~~~~~~~~~
  167. The linear acceleration applied to each particle.
  168. Radial Acceleration
  169. ~~~~~~~~~~~~~~~~~~~
  170. If this acceleration is positive, particles are accelerated away from
  171. the center. If negative, they are absorbed towards it.
  172. .. image:: img/paranim8.gif
  173. Tangential Acceleration
  174. ~~~~~~~~~~~~~~~~~~~~~~~
  175. This acceleration will use the tangent vector to the center. Combining
  176. with radial acceleration can do nice effects.
  177. .. image:: img/paranim9.gif
  178. Damping
  179. ~~~~~~~
  180. Damping applies friction to the particles, forcing them to stop. It is
  181. especially useful for sparks or explosions, which usually begin with a
  182. high linear velocity and then stop as they fade.
  183. .. image:: img/paranim10.gif
  184. Angle
  185. ~~~~~
  186. Determines the initial angle of the particle (in degrees). This parameter
  187. is mostly useful randomized.
  188. .. image:: img/paranim11.gif
  189. Scale
  190. ~~~~~
  191. Determines the initial scale of the particles.
  192. .. image:: img/paranim12.gif
  193. Color
  194. ~~~~~
  195. Used to change the color of the particles being emitted.
  196. Hue variation
  197. ~~~~~~~~~~~~~
  198. The ``Variation`` value sets the initial hue variation applied to each
  199. particle. The ``Variation Random`` value controls the hue variation
  200. randomness ratio.
  201. Emission Shapes
  202. ---------------
  203. ParticlesMaterials allow you to set an Emission Mask, which dictates
  204. the area and direction in which particles are emitted.
  205. These can be generated from textures in your project.
  206. Ensure that a ParticlesMaterial is set, and the Particles2D node is selected.
  207. A "Particles" menu should appear in the Toolbar:
  208. .. image:: img/emission_shapes1.png
  209. Open it and select "Load Emission Mask":
  210. .. image:: img/emission_shapes2.png
  211. Then select which texture you want to use as your mask:
  212. .. image:: img/emission_shapes3.png
  213. A dialog box with several settings will appear.
  214. Emission Mask
  215. ~~~~~~~~~~~~~
  216. Three types of emission masks can be generated from a texture:
  217. - Solid Pixels: Particles will spawn from any area of the texture,
  218. excluding transparent areas.
  219. .. image:: img/emission_mask_solid.gif
  220. - Border Pixels: Particles will spawn from the outer edges of the texture.
  221. .. image:: img/emission_mask_border.gif
  222. - Directed Border Pixels: Similar to Border Pixels, but adds extra
  223. information to the mask to give particles the ability to emit away
  224. from the borders. Note that an ``Initial Velocity`` will need to
  225. be set in order to utilize this.
  226. .. image:: img/emission_mask_directed_border.gif
  227. Emission Colors
  228. ~~~~~~~~~~~~~~~
  229. ``Capture from Pixel`` will cause the particles to inherit the color of the mask at their spawn points.
  230. Once you click "OK", the mask will be generated and set to the ParticlesMaterial, under the ``Emission Shape`` section:
  231. .. image:: img/emission_shapes4.png
  232. All of the values within this section have been automatically generated by the
  233. "Load Emission Mask" menu, so they should generally be left alone.
  234. .. note:: An image should not be added to ``Point Texture`` or ``Color Texture`` directly.
  235. The "Load Emission Mask" menu should always be used instead.