# XNA Constrained Billboard Particles

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

## 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; else 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; else result3 = forwardVector; result4 = normalize(cross(rotateAxis, result3)); result3 = normalize(cross(result4, rotateAxis)); } else { 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.

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633726
• Total Posts
3013571
×