1

パーティクル システムを回転させようとすると問題が発生します。まず、各パーティクルを回転させて効果を高めようとしているのではなく、エミッターの位置を回転させようとしています。たとえば、エミッタの位置が 0,0,0 で、x 軸と z 軸の両方で -5 と 5 のパーティクルを放出すると、ワールド軸に沿った正方形の形でパーティクルが放出されます。私がしたいのは、これを回転させて、まったく同じように放射するが、エミッターポイントを中心に回転させることです。

 // Each particle point is converted to a quad (two triangles)
[maxvertexcount(4)]  
void mainGSDraw
(
point VS_VertIn                  inParticle[1], // One particle in, as a point
inout TriangleStream<GS_VertOut> outStrip       // Triangle stream output, a quad containing two triangles
)
{
// Camera-space offsets for the four corners of the quad from the particle centre
// Will be scaled depending on distance of the particle
const float3 Corners[4] =
{
    float3(-1,  1, 0),
    float3( 1,  1, 0),
    float3(-1, -1, 0),
    float3( 1, -1, 0),
};

// Texture coordinates for the four corners of the generated quad
const float2 UVs[4] = 
{ 
    float2(0,1), 
    float2(1,1),
    float2(0,0),
    float2(1,0),
};

const float3x3 RotY = 
{ 

    cos(rotationAngle),0,sin(rotationAngle), 
    0,1,0,
    -sin(rotationAngle),0,cos(rotationAngle)
};
GS_VertOut outVert; // Used to build output vertices

// Output the four corner vertices of a quad centred on the particle position
[unroll]
for (int i = 0; i < 4; ++i)
{
    // Use the corners defined above and the inverse camera matrix to calculate each world
    // space corner of the quad

    float3 corner = Corners[i] * inParticle[0].Scale;   // scale first
    float3 worldPosition;


worldPosition = mul(inParticle[0].Position + mul( corner, (float3x3)InvViewMatrix), RotY) ;   // face the camera
    // Transform to 2D position and output along with an appropriate UV
    outVert.ViewportPosition = mul( float4(worldPosition, 1.0f), ViewProjMatrix );
    outVert.TexCoord = UVs[i];
    outStrip.Append( outVert );
}
outStrip.RestartStrip();

上記は私のジオメトリ シェーダー描画関数のコードです。ポイントとしてのパーティクルが入り、クワッドに展開され、スケーリングされ、ワー​​ルド位置が計算されます。パーティクルシステムが原点にある場合、回転計算は間違っています。システムを希望どおりに回転させますが、移動するとすぐに原点を中心に回転するため、エミッタの原点を中心にこの回転を行う方法が問題ですワールドゼロじゃない?コードは削除されているため、このコードが機能しない可能性があるという返信は必要ありません。

4

1 に答える 1

1

エミッタの原点からのパーティクルの移動に回転を掛けてから、ワールドの原点からのエミッタの移動を追加します。

于 2012-05-04T12:29:55.543 に答える