Help - Particle Engines

Started by
8 comments, last by Ex777 17 years, 9 months ago
Okay, well I have created a particle system interface that fits nicely into my scene node system in my engine, and has the standared optimizations such as batching, and so on. My problem is I need to have spark like emiters that emit lines, and figured I could modify my particle system to use 3d textured line lists, instead of point lists witch is what I'm currently using. I am wondering if this would be the correct way of going about this? Or if there a better way to acomplish the "line" effect in a particle engine?
Advertisement
Lines, both line-list and line-strip will be rendered at a single pixel thickness. You can texture these, but obviously you'll be a bit limited as to how much of the texture you can display.

Trying to create thicker lines isn't going to be simple - you'd need to do some sort of billboarding (point sprites can't non-uniformly scale afaik). At a guess you could do some sort of VShader based billboarding by packing extra per-vertex data and getting it to construct it accordingly (where it can perform trivial screen alignment).

If you were to pack an origin and direction vector into each vertex (two float3's) and then assigned an "ID" to each vertex so you could identify which of the 4 vertices it is - e.g. "top left", "top right"...

Transform the origin and (origin+direction) vectors into projection space and you can then extrude the 4 vertices accordingly. They should then be screen-aligned and follow your particle.

Downside is that it'll require you to pack more per-vertex data and send 4 vertices per particle and have a more complex shader... but I'd imagine it'd still be good enough for most uses [smile]

hth
Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

Bummer, I was really hoping I wasn't going to need to use textured quads for my particle system. All I want to do is create spark like emiters, like the ones from HL2 when you shoot metal object, or rain. Oh well, if this is the only way for me to do it I guess I'll get to work.
Well if you're happy with single-pixel lines then go for it. At the very least it might be worth trying before you invest time/effort into a more complex solution...

I can't remember what HL2's effect looked like.

Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

Yes, well here is what it looks like, I took the picture just right now, and I need to implement something along these lines:

http://img47.imageshack.us/img47/4605/hl2sparks5lq.jpg

Im, totaly lost on how this is done, so if you have any more wisdom that can be givin it would be greatly appretiated. Just as well, if valves hl2 does its sparks by using the textured quad (billboard) particle system, does anybody have a good one already built demonstrating this system? I would love to examine the way you whould accomplishe this, and try to implement the technique in my system. Thanks in advance.

[Edited by - Ex777 on June 25, 2006 10:52:33 PM]
Having looked at the image, I'd still be inclined to think it was some sort of quad-based particle. It might well have an alpha channel (to give each spark that slight glow) but doesn't appear to have a diffuse texture as such - just a solid orange/yellow colour. Then again, the glow could be independent of the particle system - the top of the car roof is also showing a slight glow, thus it could just as easily be regular post-processing...

Whether their method is the same as the extrusion I suggested before is difficult to tell - I'm sure there are several (and possibly better) ways to achieve the same result...

hth
Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

The glow is hl2's new HDR implemention, only on some maps though. Anyways, I'm pretty sure it is the Textured quad with a texture on it thats being radicly stretched in a direction then being positioned to look at the camera (a billboard), because I turned wireframe on and saw what looked to be a quad made up of 2 triangles-4 vertice. Recently I have become more interested in this technique and would like to get more information on it, but I cannot find any good tutorials, articles, or code, witch is really discouraging me. If you have any information on the subject at all, it would be greatly appretiated, if not I'll do my best to do it myself (if you could presesent some code\math on how the bill board affect is acheived). Thanks :)
It might be worth asking the folks over in Graphics Programming and Theory if they've got any clever mathemagical/graphical algorithm for this sort of thing.

My take would be something along the following lines:

Each particle requires 4 vertices (Only D3D10's pipeline can amplify), so the trick is packing the data up.

I'd go with defining the vertex something like:

struct ParticleVertex{    D3DXVECTOR2 texCoord;    D3DXVECTOR3 particleOrigin;    D3DXVECTOR3 sparkDirection;    float       particleSize;    float       sparkLength;};


Define texCoord such that you get a (0,0)-(0,1)-(1,0)-(1,1) type set up.

In the vertex shader you can transform particleOrigin to get a projection-space position, and you can use an inverse-transpose to transform particleDirection (same rules as transforming a normal vector).

You can now generate the output POSITION by taking the transformed particleOrigin and extruding it according to the texCoord offsets (you might want to change 0..1 to be -1..+1 though). Check the SDK's point-sprite documentation for details - this step is essentially a manual implementation of what they do [wink]

The trick is to extrude only in projection-space X,Y and just copy-through the transformed Z.

Use the particleSize field to control the extrusion in the previous step - possibly also factor in the depth (particleOrigin.z post-transform) so distant sparks get smaller.

At this point you'd have a square particle similar to what you'd get with PSprites.

The trick is now to extrude along the sparkDirection vector (once its correctly transformed of course). You could simply use the U/X texture coordinate as a scalar... that way the '0' end will stay where it is and the '1' end will get moved in the direction of the spark. Scale by sparkLength to alter this.


I'm pretty sure the above will work - because you're doing the amplification in projection space (which is effectively 2D for this purpose) theres no need for the normal awkward billboarding transforms. The difficulty will be getting the numbers to match up as you're not working in pixel-coordinates (unless you pass in the RT height/width and scale accordingly).

If you do try it, let me know - I'd be curious to know if this actually works [smile]

hth
Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

Billboards:

http://www.mvps.org/directx/articles/view_oriented_billboards.htm
Byron Atkinson-JonesXiotex Studioswww.xiotex.com
Thanks, bolth of you, I'll get to work right away, and reply if it works (or I need some help :) ).

This topic is closed to new replies.

Advertisement