PDA

View Full Version : Particle trails with OpenGL


mars
2003.12.11, 12:08 AM
Hi all,

does anyone have some working code, or a link to a tutorial, for how to put together linked particle trails?

The particles side of thing is easy. What I want to do now is have stretched particles joined to other particles, seamlessly. I can do the particles and lists of them, but I'm not sure how to go about creating joined stretched particles.

Any ideas?

thanks.

FCCovett
2003.12.11, 12:25 AM
With quadstrips that face the camera (billboarding) or not, I would guess.

BobimusPrime
2003.12.11, 01:14 AM
By particle trail do you mean a 3D path that has width? Like, would it have a source (the particle's current location) and a path back to where the particle was before?

If the program you are working on is in 2D this shouldn't be too hard to do. You would probably want to use a quad strip for this and I can go into more detail if you'd like.

If the program you are working on is in 3D with perspective it becomes a little bit more complicated. The billboarding calculations for the individual line segments end up not connecting to each other and you need to do some averaging. If this is what you are trying to do I can put together an explanation for you. I had to figure it out when writing my uDevGame entry for this year :).

Robert

DoG
2003.12.11, 05:44 PM
Originally posted by BobimusPrime
...If the program you are working on is in 3D with perspective it becomes a little bit more complicated. The billboarding calculations for the individual line segments end up not connecting to each other and you need to do some averaging. If this is what you are trying to do I can put together an explanation for you. I had to figure it out when writing my uDevGame entry for this year :).

Robert

What averaging? All billboards look in the same direction, they are co-planar with the screen.

I am not quite getting what this joined-particle trail is supposed to be. Do you want to connect the particles to form a line, basically? Can anyone explain?

monteboyd
2003.12.11, 06:22 PM
How about a screenshot of it in an existing game to help us understand the effect?

mars
2003.12.11, 06:49 PM
Sorry, I should have been a bit clearer.

here is a picture, from this morning's news, of Brian Greenstone's new game Nanosaur 2.

Nanosaur 2 contrails (http://www.pangeasoft.net/nano2/files/screenshots/nano2.jpg)

The effect I'm looking for is similar to those white contrails that are emitting from the wing tips of the Pterodactyl.

Oh, and this is for a 2D game, using OGL.

Thanks for your help.

deekpyro
2003.12.11, 07:13 PM
I'm thinking about doing something similar in 3D, I REALLY like how trails were done in Homeworld 2 and recreating a similar effect could be an interesting experience, thanks!

great example:

http://homeworld2.sierra.com/img/gallery/large/screen_3.jpg

-Derek

deekpyro
2003.12.11, 07:21 PM
also see:

http://homeworld2.sierra.com/img/gallery/large/screen_8.jpg

monteboyd
2003.12.11, 07:43 PM
The board trails in Slope Rider:
http://www.isp.net.au/~monteboyd/images/sr_shot5.jpg

is a quad strip which simply places the front most vertices at the center of the board, then each side-by-side vertex set going back are updated to what the ones in front of them were in the previous frame. Does that make any sense?

BobimusPrime
2003.12.11, 07:57 PM
mars:
I was in a weird mood so I wrote out a tutorial with pictures that explains how to draw the particle trails. Hopefully it doesn't make things even more confusing :).

http://www.bobbosoft.com/2dpath.html


deekpyro:
Doing the trails in 3D is a quite a bit more complicated but I can write out an explanation for you if you want.

Hope this helps!

Robert

Bachus
2003.12.11, 08:31 PM
Man have I been waiting for this thread. I've been trying to figure this very question out for the past few days.

arekkusu
2003.12.11, 08:44 PM
mars: Once you start coding this, if you follow the outline BobimusPrime gave (which I think is an accurate way to do what you want in 2D), you will find that most of your CPU time is going into sqrt();

To get around that, approximate the sqrt, which can be done with the PPC's frsqrte instruction and the Newton-Rhapson method. Replace:

float factor = dx*dx+dy*dy;
float normal = 1.0f/sqrt(factor);

with:

float factor = dx*dx+dy*dy;
float normal = __frsqrte(factor);
normal *= (1.5f - (0.5f*factor * normal * normal));

You'll need to #include <ppc_intrinsics.h> and compile with -force_cpusubtype_ALL to get it to work.

This premature optimization tip brought to you by many hours of creating basic GL primitives that don't suck.

FCCovett
2003.12.11, 08:51 PM
Originally posted by DoG
What averaging? All billboards look in the same direction, they are co-planar with the screen.

Nope. Billboards "face" the camera, but they are not coplanar with the screen; the quads may cross the screen plane.

The thing is that you would rotate the quads around each one's center (the pathline of the ship, for instance) so that the quads face the camera, sort of.

Now, if you want to do something similar to Homeworld, the quads don't need to be aligned to the screen; you just get two points on the tail of the ship and connect them to the last quad of the trail generated on the previous frame. It's like footprints in the sand, when you give a new step, you fade out the first footstep, and so on.

Fenris
2003.12.11, 09:11 PM
Wow, this thread is kickass! Two of the questions I wanted to figure out answered in the same thread! Bobimus, that tutorial really helped me - will it still be there in a week, or do you have to take it down eventually? (Would you like to turn it into a tutorial for iDevGames, by the way?)

Also, arekkusu, thanks for giving me a slot-in solution for my sqrts! :D

NCarter
2003.12.11, 09:32 PM
Originally posted by FCCovett
Nope. Billboards "face" the camera, but they are not coplanar with the screen; the quads may cross the screen plane.

Nope. Billboards should be coplanar with the screen. If you point them directly at the camera they'll look distorted as they approach the edge of the screen. This is what you'd expect from a one-point perspective - objects which are aligned with the viewing plane look flat, objects which are not look skewed.

Trust me, I've tried it both ways! ;)

FCCovett
2003.12.11, 11:03 PM
Originally posted by NCarter
If you point them directly at the camera they'll look distorted as they approach the edge of the screen.

In the proper sense, billboards are parallel to the screen. But in the context of contrails, we started using the term "billboarding" loosely just to help illustrate the case, and you've just made me regret doing so.

No hard feelings though. ;)

kelvin
2003.12.11, 11:42 PM
Originally posted by arekkusu
mars: Once you start coding this, if you follow the outline BobimusPrime gave (which I think is an accurate way to do what you want in 2D), you will find that most of your CPU time is going into sqrt();

To get around that, approximate the sqrt, which can be done with the PPC's frsqrte instruction and the Newton-Rhapson method. Replace:

float factor = dx*dx+dy*dy;
float normal = 1.0f/sqrt(factor);

with:

float factor = dx*dx+dy*dy;
float normal = __frsqrte(factor);
normal *= (1.5f - (0.5f*factor * normal * normal));

You'll need to #include <ppc_intrinsics.h> and compile with -force_cpusubtype_ALL to get it to work.

This premature optimization tip brought to you by many hours of creating basic GL primitives that don't suck.

um... why not glEnable(GL_NORMALIZE);? Unless you're using these normals for something other than passing to GL...

arekkusu
2003.12.12, 12:08 AM
We're creating geometry, not lighting normals.

BobimusPrime
2003.12.12, 02:29 AM
I put together a tutorial type thing for if the path is in 3D. Something I didn't mention in the tutorial is that back face culling should be turned off. If the path switches directions you will end up seeing the back of some of the quads so having it turned off will solve this problem.

http://www.bobbosoft.com/3dpath.html

Fenris:
I could turn these into a tutorial for idevgames if it seems like it would be useful. I probably won't want to leave the tutorials on my site in the form they are in for too long as i sort of just tossed them in there :).

Hope this helps!

Robert

deekpyro
2003.12.12, 11:02 AM
Originally posted by BobimusPrime
I put together a tutorial type thing for if the path is in 3D. Something I didn't mention in the tutorial is that back face culling should be turned off. If the path switches directions you will end up seeing the back of some of the quads so having it turned off will solve this problem.

http://www.bobbosoft.com/3dpath.html

Fenris:
I could turn these into a tutorial for idevgames if it seems like it would be useful. I probably won't want to leave the tutorials on my site in the form they are in for too long as i sort of just tossed them in there :).

Hope this helps!

Robert

Thanks so much man, this weekend I'll really dig into it and see what I can do. Much appreciation for any help!

Derek