Sign in to follow this  
Bangladesh

Billboarding

Recommended Posts

As part of my particle-engine I use quad-billboards and DrawPrimitive() TriangleStrips to draw my particles. But I have a problem: Calculating the positions of the vertices for each particle. The particle resides in world-space, how do I calculate the positions of the vertices for each particle _before_ I fill the vertexbuffer and draw them so they point towards the camera? Will D3DXVec3TransformCoord be helpful and does that transform 3D coordinates by a given matrix only?

Share this post


Link to post
Share on other sites
Sorry if this answer might shake you a little bit. And I'm not sure I really understand your needs.

I don't know how much experience you have, but updating the vertexbuffer each frame and transforming the vertices on the CPU would be way too slow for use in a big app running in real-time. But of course: It is do-able (at a frame-rate cost)!

First, the whole thing would be easier with point sprites then billboards. That is, if your hardware supports it. Then you would only need to save the current positions of the particles in the VertexBuffer. Those should be easy to transform and you may not need to if your particle resides in world space already.

With billboarding things become a little more complicated. You will need to transform by the inverse view matrix I think (correct me if I'm wrong). EDIT: Here it will become a problem having your particles defined in world space. You need to do the inverse view transform on the local space for each particle (this rotates the particle to face the camera) on its four vertices, and then do a translation to the correct position. Maybe not exactly correct, but something like that. I'm sure there are good tutorials on the details of billboarding.

Why do you use billboards? I'm just interested...

Another thing (Advanced): You should consider moving into the world of shaders if you haven't already done so. Shader programming is EASY nowadays when you have highlevel languages like HLSL. Particle systems without collision can easily be implemented in vertex shaders.
There are even beatiful systems out there performing statebased particle system simulations on the GPU (with collisions!!!), storing positions and velocities in textures. Look at the GPU Particles sample at http://download.developer.nvidia.com/developer/SDK/Individual_Samples/samples.html (might be a too complicated if you are new to this though)

Share this post


Link to post
Share on other sites
I'd don't know if this will help becaue I am not 100% sure about what you are trying to achieve but still.

Basically the way I achieved a billboarding effect was to modify the way my coordinates held my data.
I changed the position to hold my the positions as if every vertex was based around the origin, and the normal I use to hold the translation position.

Hmm not making much sense.

Basically when i took the shapes, I took each triangle (which in my case represented a single group of leaves I wanted to billboard) and moved the so that the centre of the triangle was at 0,0,0 and modified the each vertex position to its new position.

Then I stored the amount that I had to translate these triangles by to achieve this in each vertex normal.

Then using a vertex shader:

I multiplied the Normal by the WorldMatrix then put it back into .w=1 before adding the Position and multiplying by the ViewProjectionMatrix to get the return postion.

This basically turns the faces so that they always face the same direction relative to the camera, but not necessarily the same direction. Basically they face the same direction relative to the camera that they had when they were defined.

So if the shape was at a 45 degree angle it rotates to stay at that angle. So when creating you shape make sure all faces are facing the camera when initally drawn and they should stay that way.

Not sure if this made sense. My first attempt at explaining something.

As Fortia said you do not want to be modifying the vertex positions manually all the time. Huge overhead.

If you want more detail i could try and explain more clearly.

The example above I use to render a large number of far distant trees that are comprised of a tree defined in two planes for the basic shape and some billboard leave to create more fullness and reduce the snapping effect for when it changes from the distant model to the close model.

Check out some screen shots of my project www.geocities.com/simondhopkin to see an idea of what i mean. If it will help will give more detail. if its not what you want well no probs.


TransformCoord3d as far as I am aware takes a vector3 multiplies it by a a single matix that can be the result of scaling, translating, and rotating etc.. (i.e multiply these matrix together) and returns a vector3.

I might be getting confused with the one that returns a vector4 though.

The vector4 has a .w component, in a vector3 this component is assumed to be 1.

If its the function I believe, once the conrdinate is multiplied by the vector it is transformed back into .w=1.

[Edited by - Sarky on September 12, 2006 5:13:08 AM]

Share this post


Link to post
Share on other sites
Fortia, Sarky thanks for the help; I've managed to figure it out. I used the viewmatrix to get the right, up and view vectors and just worked from there when building the quad. It doesn't point the billboard exactly towards the camera, but in the direction of the inversed eye-direction though, but it's faster than calculating a new set of vectors. =)

Fortia; the reason of billboards is that i want to be able to construct them anyway I want in space and in any shape; so I can have them lying down on a mesh like bloodsplatter on the ground or flat against a wall, bunch up as electric currents or stretch them as sparks.
Pointsprites can't do that, can they? If they can, I've been barking up the wrong tree! =D

Share this post


Link to post
Share on other sites
Quote:
Original post by Bangladesh
the reason of billboards is that i want to be able to construct them anyway I want in space and in any shape; so I can have them lying down on a mesh like bloodsplatter on the ground or flat against a wall, bunch up as electric currents or stretch them as sparks.
Pointsprites can't do that, can they? If they can, I've been barking up the wrong tree! =D
Point Sprites are pretty good at what they're designed for but they're not very flexible. What you're describing is going to be beyond the scope of PSprites.

Point Sprites are dead, long live the Geometry Shader... [grin]

Jack

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this