particle_systems_2d.rst 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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. Going forward there are no plans to add new features to CPUParticles2D, though
  27. pull requests to add features already in GPUParticles2D will be accepted. For
  28. that reason we recommend using GPUParticles2D unless you have an explicit reason
  29. not to.
  30. You can convert a CPUParticles2D node into a GPUParticles2D node by clicking on
  31. the node in the scene tree, selecting the 2D workspace, and selecting
  32. **CPUParticles2D > Convert to GPUParticles2D** in the toolbar.
  33. .. image:: img/particles_convert.webp
  34. It is also possible to convert a GPUParticles2D node to a CPUParticles2D node,
  35. however there may be issues if you use GPU-only features.
  36. The rest of this tutorial is going to use the GPUParticles2D node. First, add a GPUParticles2D
  37. node to your scene. After creating that node you will notice that only a white dot was created,
  38. and that there is a warning icon next to your GPUParticles2D node in the scene dock. This
  39. is because the node needs a ParticleProcessMaterial to function.
  40. ParticleProcessMaterial
  41. ~~~~~~~~~~~~~~~~~~~~~~~
  42. To add a process material to your particles node, go to ``Process Material`` in
  43. your inspector panel. Click on the box next to ``Material``, and from the dropdown
  44. menu select ``New ParticleProcessMaterial``.
  45. .. image:: img/particles_material.webp
  46. Your GPUParticles2D node should now be emitting
  47. white points downward.
  48. .. image:: img/particles1.png
  49. Texture
  50. ~~~~~~~
  51. A particle system can use a single texture or an animation *flipbook*. A
  52. flipbook is a texture that contains several frames of animation that can be
  53. played back, or chosen at random during emission. This is equivalent to a
  54. spritesheet for particles.
  55. The texture is set via the **Texture** property:
  56. .. image:: img/particles2.webp
  57. .. _doc_particle_systems_2d_using_flipbook:
  58. Using an animation flipbook
  59. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  60. Particle flipbooks are suited to reproduce complex effects such as smoke, fire,
  61. explosions. They can also be used to introduce random texture variation, by
  62. making every particle use a different texture. You can find existing particle
  63. flipbook images online, or pre-render them using external tools such as `Blender
  64. <https://www.blender.org/>`__ or `EmberGen <https://jangafx.com/software/embergen/>`__.
  65. .. figure:: img/particles_flipbook_result.webp
  66. :align: center
  67. :alt: Example of a particle system that uses a flipbook texture
  68. Example of a particle system that uses a flipbook texture
  69. Using an animation flipbook requires additional configuration compared to a
  70. single texture. For demonstration purposes, we'll use this texture with 5
  71. columns and 7 rows (right-click and choose **Save as…**):
  72. .. figure:: img/particles_flipbook_example.webp
  73. :align: center
  74. :width: 240
  75. :alt: Particle flipbook texture example
  76. Credit: `JoesAlotofthings <https://opengameart.org/content/alot-of-particles-indispersal-special-effect-alotofparticles30>`__
  77. (CC BY 4.0)
  78. To use an animation flipbook, you must create a new CanvasItemMaterial in the
  79. Material section of the GPUParticles2D (or CPUParticles2D) node:
  80. .. figure:: img/particles_flipbook_create_canvasitemmaterial.webp
  81. :align: center
  82. :alt: Creating a CanvasItemMaterial at the bottom of the particles node inspector
  83. Creating a CanvasItemMaterial at the bottom of the particles node inspector
  84. In this CanvasItemMaterial, enable **Particle Animation** and set **H Frames** and **V Frames**
  85. to the number of columns and rows present in your flipbook texture:
  86. .. figure:: img/particles_flipbook_configure_canvasitemmaterial.webp
  87. :align: center
  88. :alt: Configuring the CanvasItemMaterial for the example flipbook texture
  89. Configuring the CanvasItemMaterial for the example flipbook texture
  90. Once this is done, the :ref:`Animation section <doc_particle_systems_2d_animation>`
  91. in ParticleProcessMaterial (for GPUParticles2D) or in the CPUParticles2D inspector
  92. will be effective.
  93. .. tip::
  94. If your flipbook texture has a black background instead of a transparent
  95. background, you will also need to set the blend mode to **Add** instead of
  96. **Mix** for correct display. Alternatively, you can modify the texture to
  97. have a transparent background in an image editor. In `GIMP <https://gimp.org>`__,
  98. this can be done using the **Color > Color to Alpha** menu.
  99. Time parameters
  100. ---------------
  101. Lifetime
  102. ~~~~~~~~
  103. The time in seconds that every particle will stay alive. When lifetime
  104. ends, a new particle is created to replace it.
  105. Lifetime: 0.5
  106. .. image:: img/paranim14.gif
  107. Lifetime: 4.0
  108. .. image:: img/paranim15.gif
  109. One Shot
  110. ~~~~~~~~
  111. When enabled, a GPUParticles2D node will emit all of its particles once
  112. and then never again.
  113. Preprocess
  114. ~~~~~~~~~~
  115. Particle systems begin with zero particles emitted, then start emitting.
  116. This can be an inconvenience when loading a scene and systems like
  117. a torch, mist, etc. begin emitting the moment you enter. Preprocess is
  118. used to let the system process a given number of seconds before it is
  119. actually drawn the first time.
  120. Speed Scale
  121. ~~~~~~~~~~~
  122. The speed scale has a default value of ``1`` and is used to adjust the
  123. speed of a particle system. Lowering the value will make the particles
  124. slower while increasing the value will make the particles much faster.
  125. Explosiveness
  126. ~~~~~~~~~~~~~
  127. If lifetime is ``1`` and there are 10 particles, it means a particle
  128. will be emitted every 0.1 seconds. The explosiveness parameter changes
  129. this, and forces particles to be emitted all together. Ranges are:
  130. - 0: Emit particles at regular intervals (default value).
  131. - 1: Emit all particles simultaneously.
  132. Values in the middle are also allowed. This feature is useful for
  133. creating explosions or sudden bursts of particles:
  134. .. image:: img/paranim18.gif
  135. Randomness
  136. ~~~~~~~~~~
  137. All physics parameters can be randomized. Random values range from ``0`` to
  138. ``1``. The formula to randomize a parameter is:
  139. ::
  140. initial_value = param_value + param_value * randomness
  141. Fixed FPS
  142. ~~~~~~~~~
  143. This setting can be used to set the particle system to render at a fixed
  144. FPS. For instance, changing the value to ``2`` will make the particles render
  145. at 2 frames per second. Note this does not slow down the particle system itself.
  146. .. note::
  147. Godot 4.3 does not currently support physics interpolation for 2D particles.
  148. As a workaround, disable physics interpolation for the particles node by setting
  149. **Node > Physics Interpolation > Mode** at the bottom of the inspector.
  150. Fract Delta
  151. ~~~~~~~~~~~
  152. Setting Fract Delta to ``true`` results in fractional delta calculation,
  153. which has a smoother particles display effect.
  154. This increased smoothness stems from higher accuracy.
  155. The difference is more noticeable in systems with high randomness or fast-moving particles.
  156. It helps maintain the visual consistency of the particle system,
  157. making sure that each particle's motion aligns with its actual lifespan.
  158. Without it, particles might appear to jump or move more than they should in a single frame
  159. if they are emitted at a point within the frame.
  160. The greater accuracy has a performance tradeoff,
  161. particularly in systems with a higher amount of particles.
  162. Drawing parameters
  163. ------------------
  164. Visibility Rect
  165. ~~~~~~~~~~~~~~~
  166. 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.
  167. The rectangle's ``W`` and ``H`` properties respectively control its Width and its Height.
  168. The ``X`` and ``Y`` properties control the position of the upper-left
  169. corner of the rectangle, relative to the particle emitter.
  170. 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.
  171. 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.
  172. Local Coords
  173. ~~~~~~~~~~~~
  174. By default this option is on, and it means that the space that particles
  175. are emitted to is relative to the node. If the node is moved, all
  176. particles are moved with it:
  177. .. image:: img/paranim20.gif
  178. If disabled, particles will emit to global space, meaning that if the
  179. node is moved, already emitted particles are not affected:
  180. .. image:: img/paranim21.gif
  181. Draw Order
  182. ~~~~~~~~~~
  183. This controls the order in which individual particles are drawn. ``Index``
  184. means particles are drawn according to their emission order (default).
  185. ``Lifetime`` means they are drawn in order of remaining lifetime.
  186. Particle Process Material Settings
  187. ----------------------------------
  188. For information on the settings in the ParticleProcessMaterial see :ref:`this page<doc_particle_process_material_2d>`.