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...
Шейдеры частиц (particle)
Шейдеры частиц - это особый тип шейдеров, которые запускаются до отрисовки объекта. Они используются для вычисления свойств материала, таких как цвет, положение и вращение. Они рисуются вместе с любым обычным материалом для CanvasItem или Spatial, в зависимости от того, являются ли они 2D или 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()
.
В отличие от других типов шейдеров, шейдеры частиц сохраняют данные, которые были выведены на предыдущем кадре. Поэтому шейдеры частиц можно использовать для сложных эффектов, которые происходят в течение нескольких кадров.
Примечание
Шейдеры частиц доступны только для узлов частиц на базе GPU (GPUParticles2D и GPUParticles3D).
Узлы частиц на базе CPU (CPUParticles2D и CPUParticles3D) отрисовываются на GPU (что означает, что они могут использовать пользовательские шейдеры CanvasItem или Spatial), но их движение симулируется на CPU.
Режимы визуализации
Режим рендеринга |
Описание |
---|---|
kеep_data |
Не удаляет предыдущие данные при перезапуске. |
disаble_force |
Disable attractor force. |
disаble_velocity |
Ignore |
collision_use_scale |
Масштабирует размер частицы для столкновений. |
Встроенные функции
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.
Глобальные встроенные функции
Глобальные встроенные модули доступны везде, включая пользовательские функции.
Встроенный |
Описание |
---|---|
in float TIME |
Global time since the engine has started, in seconds. It repeats after every |
in float PI |
A |
in float TAU |
Константа |
in float E |
An |
Встроенные Start и Process
Доступ к этим свойствам можно получить как из функций start()
, так и из process()
.
Функция |
Описание |
---|---|
in float LIFETIME |
Время жизни частицы. |
in float DELTA |
Дельта времени процесса. |
in uint NUMBER |
Уникальный номер с момента начала эмиссии. |
in uint INDEX |
Индекс частиц (от общего количества частиц). |
in mat4 EMISSION_TRANSFORM |
Преобразование эмиттера (используется для нелокальных систем). |
in uint RANDOM_SEED |
Случайное начальное число используемое в качестве основы для случайного числа. |
inout bool ACTIVE |
|
inout vec4 COLOR |
Цвет частицы можно записать и получить к нему доступ в вершинной функции сетки. |
inout vec3 VELOCITY |
Скорость частиц, может быть изменена. |
inout mat4 TRANSFORM |
Преобразование частиц. |
inout vec4 CUSTOM |
Custom particle data. Accessible from shader of mesh as |
inout float MASS |
Масса частицы, предназначенная для использования с аттракторами. По умолчанию равна |
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. |
Примечание
Чтобы использовать переменную COLOR
в StandardMaterial3D, установите vertex_color_use_as_albedo
в true
. В ShaderMaterial доступ к ней осуществляется с помощью переменной COLOR
.
Встроенные константы функции Start
Встроенный |
Описание |
---|---|
in bool RESTART_POSITION |
|
in bool RESTART_ROT_SCALE |
|
in bool RESTART_VELOCITY |
|
in bool RESTART_COLOR |
|
in bool RESTART_CUSTOM |
|
Встроенные константы функции Process
Встроенный |
Описание |
---|---|
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 |
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);
Функция |
Описание |
---|---|
bool emit_subparticle (mat4 xform, vec3 velocity, vec4 color, vec4 custom, uint flags) |
Emits a particle from a sub-emitter. |