   Quake 2 railgun effect
The problem seemed trivial initially, but upon closer inspection this is a pretty costly effect (especially since I want to have at least a dozen or so of these on the screen at a time). The gun discharges, propelling a pellet at high velocity. The pellet leaves behind a vortex, which twists particles around its trajectory (let's, for simplicity's sake, assume this trajectory is a straight line), which can have any 3D orientation. After the initial bang is over, the particles take some small amount of time to start losing coherence of formation and are then torn apart by gravity and other forces like wind as they fade out.In other words the problem becomes a quite simple case of rotate-a-point-around-an-arbitrary-axis. Which turns out to be a costly endeavor if you have 10x500 of these particles in sight at any given time. Doing the rotation on the GPU makes me shudder as this would either involve a matrix operation (a matrix, which would need to be calculated beforehand per particle per update anyway) or a number of state pushes and pops along with an even greater number of translates and rotates. Both cases seem bad for me.What would be the most cost-effective way to do this effect? (It might easily be the lateness of time that I can't think of anything useful myself. Or the fact that I might just as well be simply stupid.)   
  How did Quake 2 do it? I was under the impression that Quake 2's source code had been released...   ;  Trying this in the Quake 2 demo it seems to just add particles along the trail, with an initial velocity and fade and nothing else. What version are you using?Your image looks a bit different, but is probably the same idea. 5000 particles shouldn't be too much of a problem. How do you create and draw them?   ;Quote:Original post by irreversibleDoing the rotation on the GPU makes me shudder as this would either involve a matrix operation...Matrix multiplications on the GPU are *cheap*. Really, really cheap (at least when compared to matrix multiplications on the CPU).Don't forget that the GPU's vertex pipeline is designed specifically to do exactly that, multiply vertices by matrices. A few thousand particles simulated on the GPU should noticeably affect the frame-rate.   ;Quote:Original post by swiftcoderA few thousand particles simulated on the GPU should not noticeably affect the frame-rate.FIFY :-)But I think Erik is right. From memory, and the quick check I did on YouTube, I don't think the helix actually rotates, it just slowly expands and fades out from start to finish which probably gives the impression that it's rotating. The effect is over so quickly, it's kind of hard to tell though.Also, it looks like there's been a couple of different railgun designs... I don't remember myself, but I can see two distinct versions on YouTube (the one you've got, and one that's clearly more particle-y). It's been a while since I played Quake 2, I can't remember what the default effect is?   ;  Just to clear up some confusion.. the screenshot the op posted is not from the original Quake2. It's from an engine mod that was made after the source code was released. Looks like it's the mod "Quake 2 Evolved".The source to both Q2 and Q2Evolved is freely available, so probably worth checking those out.   ;Quote:Original post by ZenixJust to clear up some confusion.. the screenshot the op posted is not from the original Quake2. It's from an engine mod that was made after the source code was released. Looks like it's the mod "Quake 2 Evolved".Ah, that explains it! I haven't played Quake 2 in a while, so I couldn't remember...   ;Quote:Original post by ZenixJust to clear up some confusion.. the screenshot the op posted is not from the original Quake2. It's from an engine mod that was made after the source code was released. Looks like it's the mod "Quake 2 Evolved".I didn't think the rail gun effects looked that good in the original Quake 2 either (although it was still cool).I can't remember if the original used particles or just a helix made up of line segments. I think it was particles but they were fairly blocky, pixelated quads, although i would think you can just draw a bunch of segments to form a helix rather than use particles. It seems like overkill since the effect happens so fast that you won't notice the particles being affected by forces like wind.   ;  nice effect, I might use that :)to do what they have theredraw the center as you would+ the spiral is just a collection of quads all joined up orbiting the centers axis;  Well this is classic - naturally I didn't even think of checking out Q2's source code :D.Anyhow, gathering from comments in this thread, I understand the most rational method would be tracking the particles around the trajectory using hardware transforms.So, expanding this to the idea that in the end I want to have slightly curved ("homing") trajectories, the pseudocode would become something like this:option 1)pushset up modelview matrix along the trajectory on the CPU and update the GPUset up the local space transform matrix for each particle (based on its position around the trajectory curve) on the CPUmultiplydrawpoprinse and repeatoption 2)pre-compute the angular offset of the particle around the trajectorypushset up modelview matrix along the trajectory on the CPU and update the GPUuse 3D api's translation and rotation procedures to position the particle around the trajectorydrawpoprinse and repeatAfter a few visual fidelity tests, however, it seems my initial estimates that I can get away with 500 particles seem to be slightly optimistic. 1000-2000 particles would be a much better guess (which would pump the desired average of on-screen particles to 10-20k).   