Skip to content

Commit a662fff

Browse files
committed
Created 3D particle documentation
1 parent e61ad46 commit a662fff

File tree

91 files changed

+1866
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+1866
-0
lines changed

tutorials/3d/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Rendering
2222
lights_and_shadows
2323
using_decals
2424
physical_light_and_camera_units
25+
particles/index
2526
high_dynamic_range
2627
global_illumination/index
2728
environment_and_post_processing

tutorials/3d/particles/attractors.rst

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
.. _doc_3d_particles_attractors:
2+
3+
3D Particle attractors
4+
----------------------
5+
6+
.. figure:: img/particle_attractor.webp
7+
:alt: Particle attractors
8+
9+
Particle attractors are nodes that apply a force to all particles within their reach. They pull
10+
particles closer or push them away based on the direction of that force. There are three types
11+
of attractors: :ref:`class_GPUParticlesAttractorBox3D`, :ref:`class_GPUParticlesAttractorSphere3D`,
12+
and :ref:`class_GPUParticlesAttractorVectorField3D`. You can instantiate them at runtime and
13+
change their properties from gameplay code; you can even animate and combine them for complex
14+
attraction effects.
15+
16+
.. note::
17+
Particle attractors are not yet implemented for 2D particle systems.
18+
19+
The first thing you have to do if you want to use attractors is enable the ``Attractor Interaction``
20+
property on the ParticleProcessMaterial. Do this for every particle system that needs to react to attractors.
21+
Like most properties in Godot, you can also change this at runtime.
22+
23+
Common properties
24+
~~~~~~~~~~~~~~~~~
25+
26+
.. figure:: img/particle_attractor_common.png
27+
:alt: Common particle attractor properties
28+
:align: right
29+
30+
Common attractor properties
31+
32+
There are some properties that you can find on all attractors. They're located in the
33+
``GPUParticlesAttractor3D`` section in the inspector.
34+
35+
``Strength`` controls how strong the attractor force is. A positive value pulls particles
36+
closer to the attractor's center, while a negative value pushes them away.
37+
38+
``Attenuation`` controls the strength falloff within the attractor's influence region. Every
39+
particle attractor has a boundary. Its strength is weakest at the border of this boundary
40+
and strongest at its center. Particles outside of the boundary are not affected by the attractor
41+
at all. The attenuation curve controls how the strength weakens over that distance. A straight
42+
line means that the strength is proportional to the distance: if a particle is halfway
43+
between the boundary and the center, the attractor strength will be half of what it is
44+
at the center. Different curve shapes change how fast particles accelerate towards the
45+
attractor.
46+
47+
.. figure:: img/particle_attractor_curve.png
48+
:alt: Different attractor attenuation curves
49+
50+
Strength increase variations: constantly over the distance to the attractor (left), fast
51+
at the boundary border and slowly at the center (middle), slowly at the boundary and
52+
fast at the center (right).
53+
54+
The ``Directionality`` property changes the direction towards which particles are pulled.
55+
At a value of ``0.0``, there is no directionality, which means that particles are pulled towards
56+
the attractor's center. At ``1.0``, the attractor is fully directional, which means particles
57+
will be pulled along the attractor's local ``-Z``-axis. You can change the global direction
58+
by rotating the attractor. If ``Strength`` is negative, particles are instead pulled along
59+
the ``+Z``-axis.
60+
61+
.. figure:: img/particle_attractor_direction.webp
62+
:alt: Different attractor directionality values
63+
64+
No directionality (left) vs. full directionality (right). Notice how the particles move along
65+
the attractor's local Z-axis.
66+
67+
The ``Cull Mask`` property controls which particle systems are affected by an attractor based
68+
on each system's :ref:`visibility layers <class_VisualInstance3D>`. A particle system is only
69+
affected by an attractor if at least one of the system's visibility layers is enabled in the
70+
attractor's cull mask.
71+
72+
.. warning::
73+
There is a `known issue <https://github.com/godotengine/godot/issues/61014>`_ with
74+
GPU particle attractors that prevent the cull mask from working properly in Godot 4.0. We will
75+
update the documentation as soon as it is fixed.
76+
77+
Box attractors
78+
~~~~~~~~~~~~~~
79+
80+
.. figure:: img/particle_attractor_box.png
81+
:alt: Particle attractor box
82+
:align: right
83+
84+
Box attractor in the node list
85+
86+
Box attractors have a box-shaped influence region. You control their size with the ``Extents``
87+
property. Box extents always measure half of the sides of its bounds, so a value of
88+
``(X=1.0,Y=1.0,Z=1.0)`` creates a box with an influence region that is 2 meters wide on each side.
89+
90+
To create a box attractor, add a new child node to your scene and select ``GPUParticlesAttractorBox3D``
91+
from the list of available nodes. You can animate the box position or attach it to a
92+
moving node for more dynamic effects.
93+
94+
.. figure:: img/particle_attractor_box.webp
95+
:alt: Box attractor parts particle field
96+
97+
A box attractor with a negative strength value parts a particle field as it moves through it.
98+
99+
Sphere attractors
100+
~~~~~~~~~~~~~~~~~
101+
102+
.. figure:: img/particle_attractor_sphere.png
103+
:alt: Particle attractor sphere
104+
:align: right
105+
106+
Sphere attractor in the node list
107+
108+
Sphere attractors have a spherical influence region. You control their size with the ``Radius``
109+
property. While box attractors don't have to be perfect cubes, sphere attractors will always be
110+
spheres: You can't set width independently from height. If you want to use a sphere attractor for
111+
elongated shapes, you have to change its ``Scale`` in the attractor's ``Node3D`` section.
112+
113+
To create a sphere attractor, add a new child node to your scene and select ``GPUParticlesAttractorSphere3D``
114+
from the list of available nodes. You can animate the sphere position or attach it to a
115+
moving node for more dynamic effects.
116+
117+
.. figure:: img/particle_attractor_sphere.webp
118+
:alt: Sphere attractor parts particle field
119+
120+
A sphere attractor with a negative strength value parts a particle field as it moves through it.
121+
122+
Vector field attractors
123+
~~~~~~~~~~~~~~~~~~~~~~~
124+
125+
.. figure:: img/particle_attractor_vector.png
126+
:alt: Particle attractor vector field
127+
:align: right
128+
129+
Vector field attractor in the node list
130+
131+
A vector field is a 3D area that contains vectors positioned on a grid. The grid density controls
132+
how many vectors there are and how far they're spread apart. Each vector in a vector field points
133+
in a specific direction. This can be completely random or aligned in a way that forms distinct
134+
patterns and paths.
135+
136+
When particles interact with a vector field, their movement direction changes to match the nearest vector
137+
in the field. As a particle moves closer to the next vector in the field, it changes
138+
direction to match that vector's direction. The particle's speed depends on the vector's length.
139+
140+
Like box attractors, vector field attractors have a box-shaped influence region. You control their size with the ``Extents``
141+
property, where a value of ``(X=1.0,Y=1.0,Z=1.0)`` creates a box with an influence region that is
142+
2 meters wide on each side. The ``Texture`` property takes a :ref:`3D texture <class_Texture3D>`
143+
where every pixel represents a vector with the pixel's color interpreted as the vector's direction and size.
144+
145+
.. note::
146+
When a texture is used as a vector field, there are two types of conversion you need to be aware of:
147+
148+
1. The texture coordinates map to the attractor bounds. The image below shows which part of the texture
149+
corresponds to which part of the vector field volume. For example, the bottom half of the texture
150+
affects the top half of the vector field attractor because ``+Y`` points down in the texture UV space,
151+
but up in Godot's world space.
152+
2. The pixel color values map to direction vectors in space. The image below provides an overview. Since
153+
particles can move in two directions along each axis, the lower half of the color range represents
154+
negative direction values while the upper half represents positive direction values. So a yellow pixel
155+
``(R=1,G=1,B=0)`` maps to the vector ``(X=1,Y=1,Z=-1)`` while a neutral gray ``(R=0.5,G=0.5,B=0.5)``
156+
results in no movement at all.
157+
158+
.. figure:: img/particle_attractor_vector_mapping.png
159+
:alt: Mapping from texture to vector field
160+
161+
To create a vector field attractor, add a new child node to your scene and select ``GPUParticlesAttractorVectorField3D``
162+
from the list of available nodes. You can animate the attractor's position or attach it to a
163+
moving node for more dynamic effects.
164+
165+
.. figure:: img/particle_attractor_vector.webp
166+
:alt: Vector field attractor in a field of particles
167+
168+
Two particle systems are affected by the same vector field attractor. :download:`Click here to download the 3D texture <img/particle_vector_field_16x16x16.bmp>`.

tutorials/3d/particles/collision.rst

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

0 commit comments

Comments
 (0)