Skip to content

Commit 0af7028

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

File tree

91 files changed

+1558
-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

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

Comments
 (0)