Jump to content
  • Advertisement
Sign in to follow this  

XNA Constrained Billboard Particles

This topic is 2803 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm using the particles sample from create.msdn.com/en-US/education/catalog/sample/particle_3d which by default, has all the particles look straight at the camera. I'm trying to modify it to use constrained billboard particles.

I took the code for the XNA CreateConstrainedBillboard method and rewrote it in HLSL. This is what I have in the shader now, but its not working right. What did I do wrong?

float4x4 billboardRotation = CreateConstrainedBillboard(output.Position, CameraPosition, float3(0, 1, 0));

output.Position.xy += mul(input.Corner, rotation) * size * ViewportScale;
output.Position = mul(output.Position, billboardRotation);
output.Position = mul(mul(output.Position, View), Projection);

This is the CreateConstrainedBillboard code in HLSL

float4x4 CreateConstrainedBillboard(float3 objectPosition, float3 cameraPosition, float3 rotateAxis)
float3 forwardVector = float3(0, 0, -1);
float3 rightVector = float3(1, 0, 0);
float3 result1 = objectPosition - cameraPosition;
float num = length(result1);

if (num < 0.0099999)
result1 = forwardVector;
result1 = mul(result1, 1.0f / num);

float3 vector2 = rotateAxis;
float result2 = dot(rotateAxis, result1);
float3 result3;
float3 result4;

if (abs(result2) > 0.998254656791687)

if(abs((rotateAxis.x * forwardVector.x + rotateAxis.y * forwardVector.y + rotateAxis.z * forwardVector.z)) > 0.998254656791687)
result3 = rightVector;
result3 = forwardVector;

result4 = normalize(cross(rotateAxis, result3));
result3 = normalize(cross(result4, rotateAxis));
result4 = normalize(cross(rotateAxis, result1));
result3 = normalize(cross(result4, vector2));

float4x4 outputValue = float4x4(
float4(result4, 0),
float4(vector2, 0),
float4(result3, 0),
float4(objectPosition, 1)

return outputValue;

And since I can't really describe in words what the particles are doing, I recorded it: http://dl.dropbox.co...e/particles.mkv. The particles are created in a square area and are supposed to fall straight down with no movement on the XZ axis.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!