How to make a ship's trail - best approach ?

Hi !
I’m currently wondering how to make a ship’s trail in space ? Like [this one] ( or this one

First, how to know where to attach the trail to a ship ? Is it a meta data in the model ? I don’t think it would be a good way if it was a job assigned to the developer. Would I have to use something like “Bones” to identify the anchor points ?

Second, is it better to do it the particles way, or volumes (using something like this ?)

Third, if particles way is better, is it efficient enough with CPU particles or on GPU (Is this possible with monogame?) ?

I must precise I plan to display hundreds (maybe thousands?) of ships at the same time. To do so I also planned to use some sort of LOD system for particles in an UE4’s way (currently working on this tool as particles will be there for other things than trails anyway)

Thanks for your advices :slightly_smiling:

Ok. No one has any idea, so I will do it my own way. :slightly_smiling:

If there are many types of ships, the way I would do it is, I’d have a Ship class with the anchor points and create a simple tool that allows to load a texture and select the points (and direction) and save it (in json or something) to a file with the texture and anchor points and have a custom content processor handle initialization from the json file.

If you just want straight trails volumes are easiest I think. Particles offer more flexibility. MG.Extended has a particle engine for 2D, but it can easily be expanded to 3D (in fact, the version on CodePlex is in 3D). It’s a CPU particle engine which is easier than GPU and will probably be performant enough.

You could make a special type of mesh subobject that is positioned where you want the trails to start (typically around the central rear of the ship). You could use particles, but you would need a lot to have the appearance of a solid trail. To have a solid trail I would have a small dynamic vertex buffer that gets updated each frame with the ship’s position. Remove the last pair of vertices from the buffer, shift all other vertices back so the second last pair of vertices are now at the end, and move each pair of vertices towards each other (makes the trail narrow towards the end). Add a pair of new vertices at the front of the buffer at the position of the special subobject, plus and minus a specified amount which gives the trail its initial width. Now this dynamic vertex buffer can be drawn as a triangle strip.

I hope that made sense.

1 Like

Thanks :slightly_smiling:
In the meantime I managed to have my particles system done (I need some particles to support deferred lighting which was a big part of the requirements), just need to know how/where to attach it to the ships.
I want flexible trails like in this video:

(better view afrom 3:40 to 4:xx)
So i think they use particles.

@jjagg I think i’ll do it with the help of a custom processor

@KonajuGames I think it is done like this in Homeworld. I was thinking about something like this at first, and using some translation on the texture to give the impression on being pushed from the trusters. But it is too much rigid.

Another problem concerns particles, motherships can have a nice trail as they move slower than small ships. These ones need an emitter with a lot more particles, which in the end will kill the framerate. If i set the number of particles too low this will generate discontinuated trails.
In conclusion the number of particles is related to speed. I’ll have to implement the two methods for each case.

To add to this:

Maybe you don’t have to orientate the vertices/mesh on the CPU side, just spawn 2 at the same position but with -1, 1 as texture coordinates. Then in the vertex shader translate them so they are positioned on top of each other in the ViewSpace (aka the one being translated -y and the other +y in VS). Plus maybe rotate given the direction.

That way they will always face the camera like billboards and I think the implementation is super easy.

I think dynamic vertex buffer would be easier to handle if I implement a LOD system for this type of particles: farther ships should use less triangles but these triangles should be stretched to compensate. But resizing the buffer is a little slow :confused: maybe cache an array for each LOD.

But the whole thing is pretty cheap, no?

These geometry trails have really few polys and the shading is practically free (only texture read)

You have minimal overdraw (unlike with particles) and the trails are always connected, no matter how fast the ship is moving (no gaps).

Actually I got so hyped I think I will implement trails in my car game now haha, I’ll report back!

EDIT: Ok implemented a basic version, phew that went a lot faster than expected haha

Edit2: Some normal adjustation for curves.

Edit3: Now with some fadeout

I wrote a tutorial with MonoGame code here

Nice :slightly_smiling:
I will give this method a try, but only after testing trails with my particles engine as it can be very fast (at least on my rig and my netbook which are tweaked for gaming and coding, about 30000 particles with lighting support which wont be needed for spaceships trails).

WOW Excellent. I’m about to start a new game a tank battle type game, and this gave me the idea to add tracks to the back of them… :slight_smile: got to go over now and read how to do it… Cool!

EDIT, I’ve had a quick look through, but i learn much better by seeing code in action, then then place break points and step through - is there anyway you could knock up a small “game” with a vehicle that the user can then move around with the cursor keys and make it available for download? I’ve never done anything with effects etc and not sure where to put the files as they don’t look like c# classes to me. (e.g. the HLSL code at the end)

EDIT 2: after reading it through several times, It looks like this won’t work for a topdown driving game - am I wrong?

I’ll need it for a topdown view later myself, I let you know when I’m done with that