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