Billboard WVP + rotation problem

Started by
1 comment, last by michaelruecker 10 years, 5 months ago

I have particles which are processed to a billboard in the geometry shader.

These particles emit from a source point. This source point is attached to a placement. One can position, rotate and scale this placement.

What I would like to have is, that if I rotate the placement (which rotates the emitter) the emission direction is also rotated. So i.e. if my particles follow the y-axsis and I rotate it by 90° it would then follow the x-axis. Sounds more complicated than it is. Check these images to imagine it:

particle_WVP1.jpgparticle_WVP2.jpg

Basicly I am getting the WVP matrix from that placement(emitter). So all I need to do is project my particle with that matrix.

Here is what I tried:



float3 g_positions[4] =
    {
        float3( fHalfBillboardSizeX, fHalfBillboardSizeY, 0 ),
        float3( -fHalfBillboardSizeX, fHalfBillboardSizeY, 0 ),
        float3( fHalfBillboardSizeX, -fHalfBillboardSizeY, 0 ),
        float3( -fHalfBillboardSizeX, -fHalfBillboardSizeY, 0 ),
    };


// for all 4 billboard edge points (g_positions[4] )  do:


float3 position =  g_positions[i];
float3 vInputPos = input[0].position; // that is the center point of the billboard. the actual particle position.
output.position = float4(vInputPos, 1.0);
output.position = mul(output.position, World);
output.position = mul(float4(position, 1.0f), (float4x4)ViewInv ) + output.position;
output.position = mul(output.position, View);
output.position = mul(output.position, Projection);

This does nearly work. It's just that my depth buffer seems to be broken with this. I see my particles through other objects for example. Any ideas why that is and how I could fix it?

Advertisement

To visualize this I made a simple test scene and a video:

This was done with the settings mentioned above. As you can see there are actually two problems:

1. The depth buffer problem

2. The billboards aren't rotated accordingly. The arrow should point to the right when I rotate the placement.

A friend of mine found the solution.

Apparently I corrupted the w value of the vector.

And the second problem is actually no problem.

Anyways thank you!

This topic is closed to new replies.

Advertisement