Partikel-Shader
Partikel-Shader sind eine spezielle Art von Shader, die ausgeführt werden, bevor das Objekt gezeichnet wird. Sie werden für die Berechnung von Materialeigenschaften wie Farbe, Position und Rotation verwendet. Sie werden mit jedem regulären Material für CanvasItem oder Spatial gezeichnet, je nachdem, ob sie 2D oder 3D sind.
Particle shaders are unique because they are not used to draw the object itself;
they are used to calculate particle properties, which are then used by a
CanvasItem or Spatial
shader. They contain two processor functions: start() and process().
Im Gegensatz zu anderen Shader-Typen behalten Partikel-Shader die Daten, die im vorherigen Frame ausgegeben wurden. Daher können Partikel-Shader für komplexe Effekte verwendet werden, die sich über mehrere Frames erstrecken.
Bemerkung
Partikel-Shader sind nur bei GPU-basierten Nodes (GPUParticles2D und GPUParticles3D) verfügbar.
CPU-basierte Partikel-Nodes (CPUParticles2D und CPUParticles3D) werden auf der GPU gerendert (d.h. sie können benutzerdefinierte CanvasItem- oder Spatial-Shader verwenden), aber ihre Bewegung wird auf der CPU simuliert.
Render-Modi
Rendermodus |
Beschreibung |
|---|---|
keep_data |
Beim Neustart keine vorherigen Daten löschen. |
disable_force |
Attraktor-Kraft deaktivieren. |
disable_velocity |
Ignore |
collision_use_scale |
Skalierung der Partikelgröße für Kollisionen. |
Built-ins
Values marked as in are read-only. Values marked as out can optionally be written to and will
not necessarily contain sensible values. Values marked as inout provide a sensible default
value, and can optionally be written to. Samplers cannot be written to so they are not marked.
Globale Built-ins
Globale Built-ins sind überall verfügbar, einschließlich benutzerdefinierter Funktionen.
Built-in |
Beschreibung |
|---|---|
in float TIME |
Global time since the engine has started, in seconds. It repeats after every |
in float PI |
Eine |
in float TAU |
Eine |
in float E |
Eine |
Start- und Prozess-Built-ins
Auf diese Propertys kann sowohl von den start() als auch von den process()-Funktionen zugegriffen werden.
Funktion |
Beschreibung |
|---|---|
in float LIFETIME |
Partikel-Lebensdauer. |
in float DELTA |
Delta-Ausführungszeit. |
in uint NUMBER |
Eindeutige Nummer seit Emissionsbeginn. |
in uint INDEX |
Partikelindex (von Gesamtpartikeln). |
in mat4 EMISSION_TRANSFORM |
Emitter-Transformation (wird für nicht-lokale Systeme verwendet). |
in uint RANDOM_SEED |
Zufälliger Seed, der als Basis für random verwendet wird. |
inout bool ACTIVE |
|
inout vec4 COLOR |
Partikelfarbe, kann in die Vertexfunktion des Mesh geschrieben und darauf zugegriffen werden. |
inout vec3 VELOCITY |
Partikelgeschwindigkeit, kann geändert werden. |
inout mat4 TRANSFORM |
Partikeltransformation. |
inout vec4 CUSTOM |
Custom particle data. Accessible from shader of mesh as |
inout float MASS |
Partikelmasse, vorgesehen für die Verwendung mit Attraktoren. Entspricht standardmäßig |
in vec4 USERDATAX |
Vector that enables the integration of supplementary user-defined data into the particle process shader.
|
in uint FLAG_EMIT_POSITION |
A flag for using on the last argument of |
in uint FLAG_EMIT_ROT_SCALE |
A flag for using on the last argument of |
in uint FLAG_EMIT_VELOCITY |
A flag for using on the last argument of |
in uint FLAG_EMIT_COLOR |
A flag for using on the last argument of |
in uint FLAG_EMIT_CUSTOM |
A flag for using on the last argument of |
in vec3 EMITTER_VELOCITY |
Velocity of the Particles2D (3D) node. |
in float INTERPOLATE_TO_END |
Value of interp_to_end (3D) property of Particles node. |
in uint AMOUNT_RATIO |
Value of amount_ratio (3D) property of Particles node. |
Bemerkung
Um die COLOR Variable in einem StandardMaterial3D zu benutzen, setzen Sie vertex_color_use_as_albedo auf true. In einem ShaderMaterial greifen Sie mit der Variable COLOR darauf zu.
Start-Built-ins
Built-in |
Beschreibung |
|---|---|
in bool RESTART_POSITION |
|
in bool RESTART_ROT_SCALE |
|
in bool RESTART_VELOCITY |
|
in bool RESTART_COLOR |
|
in bool RESTART_CUSTOM |
|
Prozess-Built-ins
Built-in |
Beschreibung |
|---|---|
in bool RESTART |
|
in bool COLLIDED |
|
in vec3 COLLISION_NORMAL |
A normal of the last collision. If there is no collision detected it is equal to |
in float COLLISION_DEPTH |
Eine Länge der Normalen der letzten Kollision. Wenn keine Kollision festgestellt wird, ist sie gleich |
in vec3 ATTRACTOR_FORCE |
Eine kombinierte Kraft der Attraktoren im Moment auf dieses Teilchen. |
Prozess-Funktionen
emit_subparticle() is currently the only custom function supported by
particles shaders. It allows users to add a new particle with specified
parameters from a sub-emitter. The newly created particle will only use the
properties that match the flags parameter. For example, the
following code will emit a particle with a specified position, velocity, and
color, but unspecified rotation, scale, and custom value:
mat4 custom_transform = mat4(1.0);
custom_transform[3].xyz = vec3(10.5, 0.0, 4.0);
emit_subparticle(custom_transform, vec3(1.0, 0.5, 1.0), vec4(1.0, 0.0, 0.0, 1.0), vec4(1.0), FLAG_EMIT_POSITION | FLAG_EMIT_VELOCITY | FLAG_EMIT_COLOR);
Funktion |
Beschreibung |
|---|---|
bool emit_subparticle (mat4 xform, vec3 velocity, vec4 color, vec4 custom, uint flags) |
Sendet ein Partikel von einem Sub-Emitter aus. |