collision.rst 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. .. _doc_3d_particles_collision:
  2. 3D Particle collisions
  3. ----------------------
  4. .. figure:: img/particle_collision.webp
  5. :alt: Particle collisions
  6. Since GPU particles are processed entirely on the GPU, they don't have access to the game's physical
  7. world. If you need particles to collide with the environment, you have to set up particle collision nodes.
  8. There are four of them: :ref:`class_GPUParticlesCollisionBox3D`, :ref:`class_GPUParticlesCollisionSphere3D`,
  9. :ref:`class_GPUParticlesCollisionSDF3D`, and :ref:`class_GPUParticlesCollisionHeightField3D`.
  10. .. note::
  11. GPU Particle collision is not yet implemented for 2D particle systems.
  12. Common properties
  13. ~~~~~~~~~~~~~~~~~
  14. .. figure:: img/particle_collision_common.webp
  15. :alt: Common particle collision properties
  16. :align: right
  17. Common collision properties
  18. There are some properties that you can find on all collision nodes. They're located in the
  19. ``GPUParticlesCollision3D`` section in the inspector.
  20. The ``Cull Mask`` property controls which particle systems are affected by a collision node based
  21. on each system's :ref:`visibility layers <class_VisualInstance3D>`. A particle system collides with a
  22. collision node only if at least one of the system's visibility layers is enabled in the
  23. collider's cull mask.
  24. .. warning::
  25. There is a `known issue <https://github.com/godotengine/godot/issues/61014>`_ with
  26. GPU particle collision that prevent the cull mask from working properly in Godot 4.0. We will
  27. update the documentation as soon as it is fixed.
  28. Box collision
  29. ~~~~~~~~~~~~~
  30. .. figure:: img/particle_collision_box_entry.webp
  31. :alt: Particle collision box
  32. :align: right
  33. Box collision in the node list
  34. Box collision nodes are shaped like a solid, rectangular box. You control their size with the ``Extents``
  35. property. Box extents always measure half of the sides of its bounds, so a value of ``(X=1.0,Y=1.0,Z=1.0)``
  36. creates a box that is 2 meters wide on each side. Box collision nodes are useful for simulating floor
  37. and wall geometry that particles should collide against.
  38. To create a box collision node, add a new child node to your scene and select ``GPUParticlesCollisionBox3D``
  39. from the list of available nodes. You can animate the box position or attach it to a
  40. moving node for more dynamic effects.
  41. .. figure:: img/particle_collision_box.webp
  42. :alt: Box collision with particle systems
  43. Two particle systems collide with a box collision node
  44. Sphere collision
  45. ~~~~~~~~~~~~~~~~
  46. .. figure:: img/particle_collision_sphere_entry.webp
  47. :alt: Particle collision sphere
  48. :align: right
  49. Sphere collision in the node list
  50. Sphere collision nodes are shaped like a solid sphere. The ``Radius`` property controls the size of the sphere.
  51. While box collision nodes don't have to be perfect cubes, sphere collision nodes will always be
  52. spheres. If you want to set width independently from height, you have to change the ``Scale``
  53. property in the ``Node3D`` section.
  54. To create a sphere collision node, add a new child node to your scene and select ``GPUParticlesCollisionSphere3D``
  55. from the list of available nodes. You can animate the sphere's position or attach it to a
  56. moving node for more dynamic effects.
  57. .. figure:: img/particle_collision_sphere.webp
  58. :alt: Sphere collision with particle systems
  59. Two particle systems collide with a sphere collision node
  60. Height field collision
  61. ~~~~~~~~~~~~~~~~~~~~~~
  62. .. figure:: img/particle_collision_height.webp
  63. :alt: Particle collision height field
  64. :align: right
  65. Height field collision in the node list
  66. Height field particle collision is very useful for large outdoor areas that need to collide with particles.
  67. At runtime, the node creates a height field from all the meshes within its bounds that match its cull mask.
  68. Particles collide against the mesh that this height field represents. Since the height field generation is
  69. done dynamically, it can follow the player camera around and react to changes in the level. Different
  70. settings for the height field density offer a wide range of performance adjustments.
  71. To create a height field collision node, add a new child node to your scene and select ``GPUParticlesCollisionHeightField3D``
  72. from the list of available nodes.
  73. A height field collision node is shaped like a box. The ``Extents`` property controls its size. Extents
  74. always measure half of the sides of its bounds, so a value of ``(X=1.0,Y=1.0,Z=1.0)`` creates a box that
  75. is 2 meters wide on each side. Anything outside of the node's extents is ignored for height field creation.
  76. The ``Resolution`` property controls how detailed the height field is. A lower resolution performs faster
  77. at the cost of accuracy. If the height field resolution is too low, it may look like particles penetrate level geometry
  78. or get stuck in the air during collision events. They might also ignore some smaller meshes completely.
  79. .. figure:: img/particle_heightfield_res.webp
  80. :alt: Height field resolutions
  81. At low resolutions, height field collision misses some finer details (left)
  82. The ``Update Mode`` property controls when the height field is recreated from the meshes within its
  83. bounds. Set it to ``When Moved`` to make it refresh only when it moves. This performs well and is
  84. suited for static scenes that don't change very often. If you need particles to collide with dynamic objects
  85. that change position frequently, you can select ``Always`` to refresh every frame. This comes with a
  86. cost to performance and should only be used when necessary.
  87. .. note::
  88. It's important to remember that when ``Update Mode`` is set to ``When Moved``, it is the *height field node*
  89. whose movement triggers an update. The height field is not updated when one of the meshes inside it moves.
  90. The ``Follow Camera Enabled`` property makes the height field follow the current camera when enabled. It will
  91. update whenever the camera moves. This property can be used to make sure that there is always particle collision
  92. around the player while not wasting performance on regions that are out of sight or too far away.
  93. SDF collision
  94. ~~~~~~~~~~~~~
  95. .. figure:: img/particle_collision_sdf_entry.webp
  96. :alt: Particle collision SDF
  97. :align: right
  98. SDF collision in the node list
  99. SDF collision nodes create a `signed distance field <https://www.reddit.com/r/explainlikeimfive/comments/k2zbos/eli5_what_are_distance_fields_in_graphics>`_
  100. that particles can collide with. SDF collision is similar to height field collision in that it turns multiple
  101. meshes within its bounds into a single collision volume for particles. A major difference is that signed distance
  102. fields can represent holes, tunnels and overhangs, which is impossible to do with height fields alone. The
  103. performance overhead is larger compared to height fields, so they're best suited for small-to-medium-sized environments.
  104. To create an SDF collision node, add a new child node to your scene and select ``GPUParticlesCollisionSDF3D``
  105. from the list of available nodes. SDF collision nodes have to be baked in order to have any effect on particles
  106. in the level. To do that, click the ``Bake SDF`` button in the viewport toolbar
  107. while the SDF collision node is selected and choose a directory to store the baked data. Since SDF collision needs
  108. to be baked in the editor, it's static and cannot change at runtime.
  109. .. figure:: img/particle_collision_sdf.webp
  110. :alt: SDF particle collision
  111. SDF particle collision allows for very detailed 3-dimensional collision shapes
  112. An SDF collision node is shaped like a box. The ``Extents`` property controls its size. Extents
  113. always measure half of the sides of its bounds, so a value of ``(X=1.0,Y=1.0,Z=1.0)`` creates a box that
  114. is 2 meters wide on each side. Anything outside of the node's extents is ignored for collision.
  115. The ``Resolution`` property controls how detailed the distance field is. A lower resolution performs faster
  116. at the cost of accuracy. If the resolution is too low, it may look like particles penetrate level geometry
  117. or get stuck in the air during collision events. They might also ignore some smaller meshes completely.
  118. .. figure:: img/particle_collision_sdf_res.webp
  119. :alt: Resolution comparison
  120. The same area covered by a signed distance field at different resolutions: 16 (left) and 256 (right)
  121. The ``Thickness`` property gives the distance field, which is usually hollow on the inside, a thickness to
  122. prevent particles from penetrating at high speeds. If you find that some particles don't collide with the
  123. level geometry and instead shoot right through it, try setting this property to a higher value.
  124. The ``Bake Mask`` property controls which meshes will be considered when the SDF is baked. Only meshes that
  125. render on the active layers in the bake mask contribute to particle collision.