Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

粒子系统(3D)

本教程的本节介绍了(3D) GPU 加速的粒子系统。这里讨论的大部分内容同样适用于 CPU 粒子。

前言

你可以使用粒子系统来模拟复杂的物理效果,如火焰、火花、烟雾、魔法效果等等。它们非常适用于创建动态而有机的行为,并为你的场景增加"生命"。

The idea is that a particle is emitted at a fixed interval and with a fixed lifetime. During its lifetime, every particle will have the same base behavior. What makes each particle different from the others and creates the organic look is the randomness that you can add to most of its parameters and behaviors.

在Godot中,你创建的每个粒子系统由两个主要部分组成:粒子和发射器。

Particles

粒子是粒子系统中可见的部分。当粒子系统处于活动状态时,它就是你在屏幕上看到的东西:微小的尘埃、火焰的火苗、魔法效果的发光球体。在一个单独的系统中,你可以拥有从几百个到成千上万个粒子。你可以随机设置粒子的大小、速度和运动方向,并在其生命周期内改变其颜色。当你想到一堆火时,可以将所有从中飞出的小火星视为独立的粒子。

Emitters

发射器产生粒子。发射器通常是不可见的,但它们可以有一个形状。该形状控制粒子的生成位置和方式,例如它们是否应该像尘土一样填满房间,还是像喷泉一样从一个点射出。回到火的例子,发射器就相当于火焰中心的炽热,产生了烟尘和火焰。

Node overview

在分组中的节点列表

在Godot中可用的所有三维粒子节点

在 Godot 中有两种类型的三维粒子系统:在 GPU 上进行处理的 GPUParticles3D,以及在 CPU 上进行处理的 CPUParticles3D

CPU particle systems are less flexible than their GPU counterpart, but they work on a wider range of hardware and provide better support for older devices and mobile phones. Because they are processed on the CPU, they are not as performant as GPU particle systems and can't render as many individual particles. In addition they currently do not have all the available options GPU particles have for control.

GPU粒子系统在GPU上运行,并且可以在现代硬件上渲染成十几万个粒子。你可以为其编写自定义粒子着色器,使其非常灵活。还可以通过使用吸引子节点和碰撞节点,使它们与环境进行交互。

有三种粒子吸引器节点:GPUParticlesAttractorBox3DGPUParticlesAttractorSphere3DGPUParticlesAttractorVectorField3D。吸引器节点对其作用范围内的所有粒子施加力,并根据该力的方向使它们靠近或远离。

有几种粒子碰撞节点。GPUParticlesCollisionBox3DGPUParticlesCollisionSphere3D 是较简单的节点。你可以使用它们来创建基本形状,如盒子、地板或墙壁,以便粒子与其碰撞。另外两个节点提供了更复杂的碰撞行为。当你希望室内场景与粒子发生碰撞,无需手动创建所有单独的盒子和球体碰撞器时,GPUParticlesCollisionSDF3D 非常有用。如果你希望粒子与大型室外场景发生碰撞,可以使用 GPUParticlesCollisionHeightField3D 节点。它会创建一个包含世界和其中对象的高度图,并将其用于大规模粒子碰撞。

基本用法

高级专题