流れる粒子

これは、ParticleBlinkScriptノードで達成できることのやや複雑な例です。その結果、パーティクルがオブジェクトの周りを流れます。

パーティクルカーネルを流れる次の例の結果の効果

ParticleBlinkScriptノードからジオメトリにアクセスできないため、式をtranslaterotateそしてscaleにアクセスするParticleBlinkScriptノードのノブtranslaterotateそしてscaleからの値Cylinderジオメトリノード。のradius式を使用してリンクすることもできます。

次のカーネルのノードグラフの例

このカーネルの基本原理は、空間内のすべての点で粒子の流れの方向を与えるベクトル場を生成することです。各粒子の速度ベクトルは、流れの方向を指すように変更されます。

ヒント:  オブジェクトの回避は、この例を使用する方法の1つにすぎません。さまざまなフローフィールド関数を使用することで、さまざまな効果を実現できます。

これは、これを実装するカーネルの関連部分です。のfieldAt関数は、空間内のポイントでの流れの方向を返し、 処理する関数は、各粒子の速度ベクトルを、その位置でフローベクトルに沿って指すようにリダイレクトします。

float3 fieldAt( float3 pos )

{

return pos; // A field which just points away from the origin

}

void process()

{

float3 p = p_position();

float3 v = p_velocity();

float3 field = fieldAt( p );

field.normalize();

p_velocity() = field*v.length();

}

次のサンプルカーネルは、仮想シリンダーの周りに粒子を流す関数を実装しています。

kernel ParticleCylinderFlowKernel : ImageComputationKernel<ePixelWise>

{

Image<eReadWrite> p_position;

Image<eReadWrite> p_velocity;

Image<eReadWrite> p_orientation;

param:

float3 _origin; // Origin of the cylinder

float3 _axis; // Axis of the cylinder

float _radius; // Radius of the cylinder

float3 _flow; // Direction of flow

float _strength; // The strength of the interaction with the flow

float _falloff; // The speed at which the force falls off with distance from the surface

local:

float3 _normalizedAxis;

void define() {

defineParam(_origin, "pa_origin", float3(0.0f, 0.0f, 0.0f));

defineParam(_axis, "pa_axis", float3(0.0f, 1.0f, 0.0f));

defineParam(_flow, "pa_flow", float3(0.0f, 0.0f, -1.0f));

defineParam(_radius, "pa_radius", 1.0f);

defineParam(_strength, "pa_strength", 1.0f);

defineParam(_falloff, "pa_falloff", 1.0f);

}

void init() {

_normalizedAxis = normalize(_axis);

}

float3 mix(float3 a, float3 b, float t ) {

return a+t*(b-a);

}

void process() {

float3 p = p_position()-_origin;

float l = length(p);

if ( l != 0.0f ) {

float3 axis = _axis/l;

p -= _origin+_normalizedAxis*dot(p, _normalizedAxis);

float r = length(p);

float3 normal = p;

float3 d = cross(normal, _flow);

float3 tangent = cross(d, normal);

float fall;

if ( r >= _radius )

fall = exp(-_ falloff *(r-_radius));

else

fall = 1.0f;

float3 force = tangent*_strength;

force = mix( _flow, force, fall );

l = length(force);

if ( l != 0.0f ) {

force = force / l;

浮くspeed = length(p_velocity());

p_velocity()= speed * force;

p_orientation()= float4(0.0、force.x、force.y、force.z);

}

}

}

};

ヒント:  このカーネルを試すには多くの方法があります。流体シミュレーションを使用して煙をシミュレートするための流れ場を生成してみてください。