Particle shaders

Particle shaders are a special type of vertex 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 only available in the GLES3 backend. If you need particles in GLES2, use CPUParticles.

Render modes

Render mode 描述
keep_data 不要在重启时清除以前的数据。
disable_force 禁用吸引力。(目前在3.1版本中未实现)
disable_velocity Ignore VELOCITY value.

Built-ins

Values marked as “in” are read-only. Values marked as “out” are for optional writing and will not necessarily contain sensible values. Values marked as “inout” provide a sensible default value, and can optionally be written to. Samplers are not subjects of writing and they are not marked.

Global built-ins

Global built-ins are available everywhere, including custom functions.

内建的 描述
in float TIME 全球时间,以秒为单位。

Vertex built-ins

为了在空间材质中使用“颜色”变量,将“使用_顶点_作为_反照率”设置为“真”值。在空间材质中,使用“颜色”变量访问它。

内建的 描述
inout vec4 COLOR Particle color, can be written to and accessed in mesh’s vertex function.
inout vec3 VELOCITY 粒子速度,可以修改。
out float MASS Particle mass, use for attractors (not implemented in 3.1).
inout bool ACTIVE true when Particle is active, can be set to false.
in bool RESTART true when particle must restart (lifetime cycled).
inout vec4 CUSTOM 自定义粒子数据。可从网格着色器作为**实例化_自定义**访问。
inout mat4 TRANSFORM 粒子变换。
in float LIFETIME 粒子寿命。
in float DELTA 达美处理时间。
in uint NUMBER 排放开始后的唯一编号。
in int INDEX 颗粒指数(来自总颗粒)。
in mat4 EMISSION_TRANSFORM 发射器变换(用于非本地系统)。
in uint RANDOM_SEED 随机种子被用作随机的基础。