Work in progress

The content of this page was not yet updated for Godot 4.2 and may be outdated. If you know how to improve this page or you can confirm that it's up to date, feel free to open a pull request.

2D particle systems

イントロ

Particle systems are used to simulate complex physical effects, such as sparks, fire, magic particles, smoke, mist, etc.

その考えは、 "particle" が一定の間隔でそして一定の寿命で放出されるということです。 その寿命の間、すべての粒子は同じ基本的なふるまいを持ちます。 各パーティクルを他のパーティクルとは異なるものにし、より有機的に見えるのは、各パラメータに関連付けられた "randomness" です。基本的に、パーティクルシステムを作成することは、基本物理パラメーターを設定してから、それらにランダム性を追加することを意味します。

パーティクルノード

Godot provides two different nodes for 2D particles, GPUParticles2D and CPUParticles2D. GPUParticles2D is more advanced and uses the GPU to process particle effects. CPUParticles2D is a CPU-driven option with near-feature parity with GPUParticles2D, but lower performance when using large amounts of particles. On the other hand, CPUParticles2D may perform better on low-end systems or in GPU-bottlenecked situations.

While GPUParticles2D is configured via a ParticleProcessMaterial (and optionally with a custom shader), the matching options are provided via node properties in CPUParticles2D (with the exception of the trail settings).

You can convert a GPUParticles2D node into a CPUParticles2D node by clicking on the node in the inspector, selecting the 2D viewport, and selecting GPUParticles2D > Convert to CPUParticles2D in the viewport toolbar.

../../_images/particles_convert.webp

The rest of this tutorial is going to use the GPUParticles2D node. First, add a GPUParticles2D node to your scene. After creating that node you will notice that only a white dot was created, and that there is a warning icon next to your GPUParticles2D node in the scene dock. This is because the node needs a ParticleProcessMaterial to function.

ParticleProcessMaterial

To add a process material to your particles node, go to Process Material in your inspector panel. Click on the box next to Material, and from the dropdown menu select New ParticleProcessMaterial.

../../_images/particles_material.png

Your GPUParticles2D node should now be emitting white points downward.

../../_images/particles1.png

テクスチャ

A particle system can use a single texture or an animation flipbook. A flipbook is a texture that contains several frames of animation that can be played back, or chosen at random during emission. This is equivalent to a spritesheet for particles.

The texture is set via the Texture property:

../../_images/particles2.png

Using an animation flipbook

Particle flipbooks are suited to reproduce complex effects such as smoke, fire, explosions. They can also be used to introduce random texture variation, by making every particle use a different texture. You can find existing particle flipbook images online, or pre-render them using external tools such as Blender or EmberGen.

Example of a particle system that uses a flipbook texture

Example of a particle system that uses a flipbook texture

Using an animation flipbook requires additional configuration compared to a single texture. For demonstration purposes, we'll use this texture with 5 columns and 7 rows (right-click and choose Save as…):

Particle flipbook texture example

Credit: JoesAlotofthings (CC BY 4.0)

To use an animation flipbook, you must create a new CanvasItemMaterial in the Material section of the GPUParticles2D (or CPUParticles2D) node:

Creating a CanvasItemMaterial at the bottom of the particles node inspector

Creating a CanvasItemMaterial at the bottom of the particles node inspector

In this CanvasItemMaterial, enable Particle Animation and set H Frames and V Frames to the number of columns and rows present in your flipbook texture:

Configuring the CanvasItemMaterial for the example flipbook texture

Configuring the CanvasItemMaterial for the example flipbook texture

Once this is done, the Animation section in ParticleProcessMaterial (for GPUParticles2D) or in the CPUParticles2D inspector will be effective.

ちなみに

If your flipbook texture has a black background instead of a transparent background, you will also need to set the blend mode to Add instead of Mix for correct display. Alternatively, you can modify the texture to have a transparent background in an image editor. In GIMP, this can be done using the Color > Color to Alpha menu.

時間パラメーター

生存時間

すべてのパーティクルが生き続ける秒単位の時間。ライフタイムが終了すると、新しいパーティクルが作成されて置き換えられます。

Lifetime: 0.5

../../_images/paranim14.gif

Lifetime: 4.0

../../_images/paranim15.gif

単発

When enabled, a GPUParticles2D node will emit all of its particles once and then never again.

前処理

パーティクルシステムは、パーティクルの放出がゼロから始まり、放出を開始します。これは、シーンを読み込むときに不便になる場合があり、トーチ、ミストなどのシステムは、入力した瞬間に放出を開始します。プリプロセスは、システムが実際に最初に描画される前に指定された秒数を処理するために使用されます。

スピードスケール

速度スケールのデフォルト値は 1 で、パーティクルシステムの速度を調整するために使用されます。値を小さくすると粒子が遅くなり、値を大きくすると粒子が非常に速くなります。

爆発性

ライフタイムが 1 で、パーティクルが10個ある場合、0.1秒ごとにパーティクルが放出されることを意味します。explosiveness パラメーターはこれを変更し、パーティクルをすべて一緒に放出させます。範囲は次のとおりです。

  • 0: 一定の間隔でパーティクルを放出します(既定値)。

  • 1: すべてのパーティクルを同時に放出します。

中間の値も使用できます。この機能は、パーティクルの爆発や突然のバーストを作成する場合に便利です。

../../_images/paranim18.gif

ランダム性

すべての物理パラメーターをランダム化できます。ランダム値の範囲は 0 から 1 です。パラメーターをランダム化する数式は次のとおりです:

initial_value = param_value + param_value * randomness

Fixed FPS

この設定を使用して、固定FPSでレンダリングするようにパーティクルシステムを設定できます。たとえば、値を 2 に変更すると、パーティクルは毎秒2フレームでレンダリングされます。これにより、パーティクルシステム自体の速度が低下することはありません。

Fract Delta

これを使用して、Fract Deltaをオンまたはオフにできます。

描画パラメーター

可視領域矩形(Visibility Rect)

可視領域を設定する四角形は、画面上のパーティクルの可視性を制御します。この四角形がビューポートの外側にある場合、エンジンはパーティクルを画面にレンダリングしません。

長方形の W および H プロパティは、それぞれ幅と高さを制御します。X および Y プロパティは、パーティクルエミッタを基準とした長方形の左上隅の位置を制御します。

You can have Godot generate a Visibility Rect automatically using the toolbar above the 2d view. To do so, select the GPUParticles2D node and Click Particles > Generate Visibility Rect. Godot will simulate the Particles2D node emitting particles for a few seconds and set the rectangle to fit the surface the particles take.

Generation Time (sec) オプションを使用して、放出時間を制御できます。最大値は25秒です。パーティクルが移動する時間が長くなる場合は、Particles2Dノードの preprocess の継続時間を一時的に変更できます。

Local Coords

デフォルトでは、このオプションはオンになっており、パーティクルが放出される空間がノードに対して相対的であることを意味します。ノードを移動すると、すべてのパーティクルも一緒に移動します:

../../_images/paranim20.gif

無効にすると、パーティクルはグローバルな空間に放出され、ノードを移動しても、既に放出されたパーティクルは影響を受けません。

../../_images/paranim21.gif

Draw Order

これにより、個々のパーティクルが描画される順序がコントロールされます。Index は、パーティクルが放出順序に従って描画される事を意味します(デフォルト)。Lifetime は、残っている寿命の順に描画されることを意味します。

ParticleProcessMaterial settings

Direction

This is the base direction at which particles emit. The default is Vector3(1, 0, 0) which makes particles emit to the right. However, with the default gravity settings, particles will go straight down.

../../_images/direction1.png

For this property to be noticeable, you need an initial velocity greater than 0. Here, we set the initial velocity to 40. You'll notice that particles emit toward the right, then go down because of gravity.

../../_images/direction2.png

広がり

このパラメーターは、基本的な 放出方向 に対していずれかの方向にランダムに加算される角度(度単位)です。180 のスプレッドでは、すべての方向(+/- 180度)で放出されます。スプレッドが作用するためには、"Initial Velocity"パラメータが0より大きくなければなりません。

../../_images/paranim3.gif

Flatness

This property is only useful for 3D particles.

重力

すべてのパーティクルに適用される重力。

../../_images/paranim7.gif

初期速度

初期速度は、パーティクルが放出される速度(ピクセル/秒)です。速度は、後で重力または他の加速度によって変更される可能性があります(後で詳しく説明します)。

../../_images/paranim4.gif

Angular Velocity

角速度は、パーティクルに適用される初期角速度です。

Spin Velocity

回転速度は、パーティクルが中心軸で回転する速度(度/秒)です。

../../_images/paranim5.gif

オービット速度

軌道速度は、パーティクルを発生点の周で回転させるために使用されます。

../../_images/paranim6.gif

Linear Acceleration

各パーティクルに適用される線形加速度。

Radial Acceleration

この加速度が正の場合、パーティクルは中心から遠ざかります。負の場合は、中心に吸収されます。

../../_images/paranim8.gif

Tangential Acceleration

この加速度は、中心への接線ベクトルを使用します。radial accelerationと組み合わせることで、素敵な効果が得られます。

../../_images/paranim9.gif

Damping

ダンピングはパーティクルに摩擦を加え、パーティクルを強制的に停止させます。通常、速い初速(velocity)で始まり、フェードすると停止する火花または爆発に特に役立ちます。

../../_images/paranim10.gif

角度

パーティクルの初期角度(度単位)を決定します。このパラメーターは、主にランダム化に役立ちます。

../../_images/paranim11.gif

スケール

パーティクルの初期スケールを決定します。

../../_images/paranim12.gif

放出されるパーティクルの色を変更するために使用します。

Hue Variation

Variationの値は、各パーティクルに適用される初期の色相変化を設定します。 Variation Random の値は、色相変動のランダム性の比率を制御します。

アニメーション

注釈

Particle flipbook animation is only effective if the CanvasItemMaterial used on the GPUParticles2D or CPUParticles2D node has been configured accordingly.

To set up the particle flipbook for linear playback, set the Speed Min and Speed Max values to 1:

Setting up particle animation for playback during the particle's lifetime

Setting up particle animation for playback during the particle's lifetime

By default, looping is disabled. If the particle is done playing before its lifetime ends, the particle will keep using the flipbook's last frame (which may be fully transparent depending on how the flipbook texture is designed). If looping is enabled, the animation will loop back to the first frame and resume playing.

Depending on how many images your sprite sheet contains and for how long your particle is alive, the animation might not look smooth. The relationship between particle lifetime, animation speed, and number of images in the sprite sheet is this:

注釈

At an animation speed of 1.0, the animation will reach the last image in the sequence just as the particle's lifetime ends.

\[Animation\ FPS = \frac{Number\ of\ images}{Lifetime}\]

If you wish the particle flipbook to be used as a source of random particle textures for every particle, keep the speed values at 0 and set Offset Max to 1 instead:

Setting up particle animation for random offset on emission

Setting up particle animation for random offset on emission

Note that the GPUParticles2D node's Fixed FPS also affects animation playback. For smooth animation playback, it's recommended to set it to 0 so that the particle is simulated on every rendered frame. If this is not an option for your use case, set Fixed FPS to be equal to the effective framerate used by the flipbook animation (see above for the formula).

Emission Shapes

ParticleProcessMaterials allow you to set an Emission Mask, which dictates the area and direction in which particles are emitted. These can be generated from textures in your project.

Ensure that a ParticleProcessMaterial is set, and the GPUParticles2D node is selected. A "Particles" menu should appear in the Toolbar:

../../_images/emission_shapes1.png

それを開き、"Load Emission Mask" を選択します:

../../_images/emission_shapes2.png

次に、マスクとして使用するテクスチャを選択します。

../../_images/emission_shapes3.png

いくつかの設定を含むダイアログボックスが表示されます。

放出マスク

テクスチャからは3種類の放出マスクを生成できます:

  • Solid Pixels: テクスチャの透過部分を除くすべての領域から、パーティクルが発生。

../../_images/emission_mask_solid.gif
  • Border Pixels: パーティクルはテクスチャの縁から発生。

../../_images/emission_mask_border.gif
  • Directed Border Pixels: Border Pixelsと同じで、さらに方向の情報をマスクに加えることで、パーティクルは縁から遠ざかるように発生。これを使用するにはInitial Velocity(初速)をセットする必要があります。

../../_images/emission_mask_directed_border.gif

放出色

`` Capture from Pixel`` は、パーティクルがマスクの発生ポイントから色を継承するようにします。

Once you click "OK", the mask will be generated and set to the ParticleProcessMaterial, under the Emission Shape section:

../../_images/emission_shapes4.png

このセクション内のすべての値は、「Load Emission Mask」メニューによって自動的に生成されているため、通常はそのままにしておく必要があります。

注釈

画像を Point Texture または Color Texture に直接追加しないでください。代わりに、常に「Load Emission Mask」メニューを使用する必要があります。