Up to date
This page is up to date for Godot 4.2
.
If you still find outdated information, please open an issue.
Shaders Particle¶
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 are drawn with any regular material for CanvasItem or Spatial, depending on whether they are 2D or 3D.
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()
.
Unlike other shader types, particle shaders keep the data that was output the previous frame. Therefore, particle shaders can be used for complex effects that take place over multiple frames.
Nota
Particle shaders are only available with GPU-based particle nodes (GPUParticles2D and GPUParticles3D).
CPU-based particle nodes (CPUParticles2D and CPUParticles3D) are rendered on the GPU (which means they can use custom CanvasItem or Spatial shaders), but their motion is simulated on the CPU.
Modos de renderizado¶
Modo de renderizado |
Descripción |
---|---|
keep_data |
No borre los datos anteriores sobre el reinicio. |
disable_force |
Disable attractor force. |
disable_velocity |
Ignora el valor de VELOCIDAD. |
collision_use_scale |
Escala el tamaño de las partículas para colisiones. |
Funciones propias¶
Los valores marcados como "in" son de sólo lectura. Los valores marcados como "out" son de escritura opcional y no necesariamente contendrán valores sensibles. Los valores marcados como "inout" proporcionan un valor por defecto sensato y pueden escribirse opcionalmente. Los valores marcados como "in" no son objeto de escritura y no están marcados.
Funciones incorporadas globales¶
Las internas globales están disponibles en todas partes, incluyendo las funciones personalizadas.
Integrado |
Descripción |
---|---|
en real TIME |
Tiempo global, en segundos. |
in float PI |
A |
in float TAU |
A |
in float E |
A |
Start and Process built-ins¶
These properties can be accessed from both the start()
and process()
functions.
Función |
Descripción |
---|---|
in real LIFETIME |
La vida de las partículas. |
in real DELTA |
Tiempo de proceso Delta. |
in uint NUMBER |
Un número único desde el comienzo de la emisión. |
in uint INDEX |
Índice de partículas (de partículas totales). |
in mat4 EMISSION_TRANSFORM |
Transformación del emisor (utilizado para sistemas no locales). |
in uint RANDOM_SEED |
Semillas al azar usadas como base para el azar. |
inout booleano ACTIVE |
|
inout vec4 COLOR |
El color de las partículas, se puede escribir y acceder a la función de vértice de la malla. |
inout vec3 VELOCITY |
La velocidad de las partículas, puede ser modificada. |
inout mat4 TRANSFORM |
Transformación de partícula. |
inout vec4 CUSTOM |
Datos de partículas personalizadas. Accesible desde el shader de malla como INSTANCE_CUSTOM. |
inout float MASS |
Particle mass, intended to be used with attractors. Equals |
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 Particles node. |
in float INTERPOLATE_TO_END |
Value of |
in uint AMOUNT_RATIO |
Value of |
Nota
In order to use the COLOR
variable in a StandardMaterial3D, set vertex_color_use_as_albedo
to true
. In a ShaderMaterial, access it with the COLOR
variable.
Start built-ins¶
Integrado |
Descripción |
---|---|
in bool RESTART_POSITION |
|
in bool RESTART_ROT_SCALE |
|
in bool RESTART_VELOCITY |
|
in bool RESTART_COLOR |
|
in bool RESTART_CUSTOM |
|
Process built-ins¶
Integrado |
Descripción |
---|---|
in booleano 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 |
A length of normal of the last collision. If there is no collision detected it is equal to |
in vec3 ATTRACTOR_FORCE |
A combined force of the attractors at the moment on that particle. |
Process functions¶
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);
Función |
Descripción |
---|---|
bool emit_subparticle (mat4 xform, vec3 velocity, vec4 color, vec4 custom, uint flags) |
Emits a particle from a sub-emitter. |