particle_systems_2d.rst 11 KB

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