Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
Shader di particelle
Particle shaders are a special type of shader that runs before the object is drawn. They are used for calculating material properties such as color, position, and rotation. They can be drawn with any regular material for CanvasItem or Spatial, depending on whether they are 2D or 3D.
Gli shader di particelle sono unici perché non sono utilizzati per disegnare l'oggetto stesso, ma per calcolare le proprietà delle particelle, che sono poi utilizzate da uno shader CanvasItem o Spatial. Contengono due funzioni di elaborazione: start() e process().
A differenza degli altri tipi di shader, gli shader di particelle mantengono i dati prodotti nel frame precedente. Pertanto, essi si possono utilizzare per effetti complessi che avvengono su più frame.
Nota
Gli shader di particelle sono disponibili solo con nodi di particelle basati sulla GPU (GPUParticles2D e GPUParticles3D).
I nodi di particelle basati sulla CPU (CPUParticles2D e CPUParticles3D) sono renderizzati sulla GPU (il che significa che possono utilizzare shader CanvasItem o Spatial personalizzati), ma il loro movimento è simulato sulla CPU.
Modalità di rendering
Modalità di rendering |
Descrizione |
|---|---|
keep_data |
Non cancellare i dati precedenti al riavvio. |
disable_force |
Disabilita la forza di attrattori. |
disable_velocity |
Ignora il valore di |
collision_use_scale |
Adatta le dimensioni delle particelle per le collisioni. |
Variabili integrate
I valori marcati come in sono di sola lettura. I valori marcati come out sono scrivibili facoltativamente e non contengono necessariamente valori sensati. I valori marcati come inout forniscono un valore predefinito sensato e sono scrivibili facoltativamente. I campionatori non sono scrivibili, quindi non sono marcati.
Variabili integrate globali
Le variabili integrate globali sono disponibili ovunque, comprese le funzioni personalizzate.
Integrato |
Descrizione |
|---|---|
in float TIME |
Global time since the engine has started, in seconds. It repeats after every |
in float PI |
Una costante |
in float TAU |
Una costante |
in float E |
Una costante |
Variabili integrate di inizio ed elaborazione
È possibile accedere a queste proprietà dalle funzioni start() e process().
Funzione |
Descrizione |
|---|---|
in float LIFETIME |
Tempo di vita delle particelle. |
in float DELTA |
Tempo delta di elaborazione. |
in uint NUMBER |
Numero univoco dall'inizio dell'emissione. |
in uint INDEX |
Indice della particella (sul numero totale di particelle). |
in mat4 EMISSION_TRANSFORM |
Trasformazione dell'emettitore (utilizzata per i sistemi non locali). |
in uint RANDOM_SEED |
Seed casuale utilizzato come base per la casualità. |
inout bool ACTIVE |
|
inout vec4 COLOR |
Particle color, can be written to and accessed in the mesh's vertex function. |
inout vec3 VELOCITY |
La velocità della particella, può essere modificata. |
inout mat4 TRANSFORM |
Trasformazione della particella. |
inout vec4 CUSTOM |
Custom particle data. Accessible from the mesh's shader as |
inout float MASS |
Particle mass, intended to be used with attractors. |
in vec4 USERDATAX |
Vettore che consente l'integrazione di dati supplementari definiti dall'utente nello shader di processo di particelle. |
in uint FLAG_EMIT_POSITION |
A flag for the last argument of the |
in uint FLAG_EMIT_ROT_SCALE |
A flag for the last argument of the |
in uint FLAG_EMIT_VELOCITY |
A flag for the last argument of the |
in uint FLAG_EMIT_COLOR |
A flag for the last argument of the |
in uint FLAG_EMIT_CUSTOM |
A flag for the last argument of the |
in vec3 EMITTER_VELOCITY |
Velocità del nodo Particles2D (3D). |
in float INTERPOLATE_TO_END |
Value of the interp_to_end (3D) property of the Particles node. |
in uint AMOUNT_RATIO |
Value of the amount_ratio (3D) property of the Particles node. |
Nota
Per utilizzare la variabile COLOR in uno StandardMaterial3D, impostare vertex_color_use_as_albedo su true. In uno ShaderMaterial, accedervi tramite variabile COLOR.
Variabili integrate di inizio
Integrato |
Descrizione |
|---|---|
in bool RESTART_POSITION |
|
in bool RESTART_ROT_SCALE |
|
in bool RESTART_VELOCITY |
|
in bool RESTART_COLOR |
|
in bool RESTART_CUSTOM |
|
Variabili integrate di elaborazione
Integrato |
Descrizione |
|---|---|
in bool RESTART |
|
in bool COLLIDED |
|
in vec3 COLLISION_NORMAL |
Una normale dell'ultima collisione. Se non viene rilevata alcuna collisione, è uguale a |
in float COLLISION_DEPTH |
A length of the normal of the last collision. If there is no collision detected it is equal to |
in vec3 ATTRACTOR_FORCE |
Una forza combinata degli attrattori che agiscono in quel momento su quella particella. |
Funzioni di elaborazione
emit_subparticle() is currently the only custom function supported by
particle 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);
Funzione |
Descrizione |
|---|---|
bool emit_subparticle (mat4 xform, vec3 velocity, vec4 color, vec4 custom, uint flags) |
Emette una particella da un sotto-emettitore. |