Particleシェーダー

Particleシェーダーはオブジェクトが描画される前に実行される特別なタイプのシェーダーです。これらは、色、位置、回転などのマテリアルのプロパティを計算するために使用されます。これらは2Dか3Dかに応じて、CanvasItemまたはSpatialの通常のマテリアルを使用して描画されます。

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().

他のシェーダータイプとは異なり、Particleシェーダーは前のフレームに出力されたデータを保持します。したがってParticleシェーダーは複数のフレームにわたって実行される複雑なエフェクトに使用できます。

注釈

ParticleシェーダはGPUベースのパーティクル ノード (GPUParticles2D および GPUParticles3D) でのみ使用できます。

CPUベースのパーティクルノード (CPUParticles2D および CPUParticles3D) は、GPU上で レンダリング されます (つまりカスタムCanvasItemまたはSpatialシェーダーを使用できる) が、その動きは CPU 上で シミュレート されます。

レンダリングモード

レンダリングモード

説明

keep_data

再起動時に以前のデータをクリアしない。

disable_force

アトラクターの力を無効にします。

disable_velocity

Ignore VELOCITY value.

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 3,600 seconds (which can be changed with the rollover setting). It's affected by time_scale but not by pausing. If you need a TIME variable that is not affected by time scale, add your own global shader uniform and update it each frame.

in float PI

PI 円周率の定数 (3.141592)。円の円周とその直径の比率、および半回転のラジアン量。

in float TAU

定数 TAU` は円周率の2倍 (6.283185)。 PI * 2 と、1回転のラジアン量に相当します。

in float E

An E constant (2.718281). Euler's number and a base of the natural logarithm.

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

パーティクルがアクティブな場合は true 。更新中に false に設定できます。

inout vec4 COLOR

パーティクルの色。書き込むことができ、メッシュのシェーダーからアクセスされます。

inout vec3 VELOCITY

パーティクルの速度。更新中に変更できます。

inout mat4 TRANSFORM

パーティクルのトランスフォーム。

inout vec4 CUSTOM

Custom particle data. Accessible from shader of mesh as INSTANCE_CUSTOM.

inout float MASS

パーティクルの質量。アトラクターの処理で使用されることを意図しています。デフォルトは 1.0

in vec4 USERDATAX

Vector that enables the integration of supplementary user-defined data into the particle process shader. USERDATAX are six built-ins identified by number, X can be numbers between 1 and 6, for example USERDATA3.

in uint FLAG_EMIT_POSITION

A flag for using on the last argument of emit_subparticle() function to assign a position to a new particle's transform.

in uint FLAG_EMIT_ROT_SCALE

A flag for using on the last argument of emit_subparticle() function to assign the rotation and scale to a new particle's transform.

in uint FLAG_EMIT_VELOCITY

A flag for using on the last argument of emit_subparticle() function to assign a velocity to a new particle.

in uint FLAG_EMIT_COLOR

A flag for using on the last argument of emit_subparticle() function to assign a color to a new particle.

in uint FLAG_EMIT_CUSTOM

A flag for using on the last argument of emit_subparticle() function to assign a custom data vector to a new particle.

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.

注釈

StandardMaterial3D で COLOR 変数を使用するには、 vertex_color_use_as_albedotrue に設定します。 ShaderMaterial では COLOR 変数を使用してアクセスします。

start()のビルトイン

ビルトイン

説明

in bool RESTART_POSITION

true のとき、パーティクルが再起動された、またはカスタムの位置が設定されずに放出された (つまりこのパーティクルが FLAG_EMIT_POSITION フラグなしで emit_subparticle() によって作成された)。

in bool RESTART_ROT_SCALE

true のとき、パーティクルが再起動された、またはカスタムの回転とスケールが設定されずに放出された (つまりこのパーティクルが FLAG_EMIT_ROT_SCALE フラグなしで emit_subparticle() によって作成された)。

in bool RESTART_VELOCITY

true のとき、パーティクルが再起動された、またはカスタムの速度が設定されずに放出された (つまりこのパーティクルが FLAG_EMIT_VELOCITY フラグなしで emit_subparticle() によって作成された)。

in bool RESTART_COLOR

true のとき、パーティクルが再起動された、またはカスタムの色が設定されずに放出された (つまりこのパーティクルが FLAG_EMIT_COLOR フラグなしで emit_subparticle() によって作成された)。

in bool RESTART_CUSTOM

true``のとき、パーティクルが再起動された、またはカスタムのプロパティが設定されずに放出された (つまりこのパーティクルが ``FLAG_EMIT_CUSTOM フラグなしで emit_subparticle() によって作成された)。

process()のビルトイン

ビルトイン

説明

in bool RESTART

現在のプロセスフレームがパーティクルの初回であるときは true

in bool COLLIDED

パーティクルがパーティクルコライダーと衝突した時は true

in vec3 COLLISION_NORMAL

A normal of the last collision. If there is no collision detected it is equal to (0.0, 0.0, 0.0).

in float COLLISION_DEPTH

最後の衝突時の法線の長さ。衝突が検出されていない場合 0.0 になります。

in vec3 ATTRACTOR_FORCE

パーティクルに対するその時点でのアトラクターの合成された力。

process()で使える関数

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)

サブエミッターからパーティクルを放出します。