尝试旋转粒子系统时遇到问题。首先,我不是试图旋转每个粒子来尝试增强效果,我想要做的是旋转发射器位置。所以例如如果我的发射器位置在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();
} 上面是我的几何着色器绘制函数的代码,一个粒子作为一个点进入并扩展为四边形,缩放,然后计算世界位置。旋转计算是错误的,如果粒子系统位于原点,它会完全按照我想要的方式旋转系统,但是一旦我移动它,它就围绕原点旋转,所以我的问题是如何围绕发射器的原点旋转不是世界零?代码已被删除,因此无需回复此代码可能无效。
答案 0 :(得分:1)
您可以通过旋转将粒子从发射器原点转换为多个,然后从世界原点添加发射器的平移。