尝试旋转我的粒子系统时遇到问题。首先,我不想旋转每个粒子来尝试增强效果,我想做的是旋转发射器位置。因此,例如,如果我在 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();
上面是我的几何着色器绘制函数的代码,一个粒子作为一个点进来并扩展为一个四边形,缩放然后计算世界位置。如果粒子系统位于原点,则旋转计算是错误的不是世界零吗?代码已被删减,因此无需回复此代码可能不起作用。