Sorry about the lack of a post last week, anyways, this week I will be talking about trail effects in Galactose.
|Trails are important!|
Originally the trail effect started as a quick modification of the "wake" effect from a game called "Poultry Pirates", which we wrote for a 3d games course. Poultry Pirates became the initial tech base for Galactose (then called Star Chronicles), and initially, I used a slightly modified wake effect for the trails. It wasn't great, but it was very quick to (ab)use the old effect for this purpose:
Those old trails were pretty buggy, and had a lot of visual artifacts and were generally pretty slow, however. Thus, they were revised...
|An allied ship's trail ~(March 10, 2012)|
The next iteration of trails looked a fair bit better, though you can still see quite a few visual artifacts here. In fact, it had additional artifacts when looking at it from behind the player's ship:
|The player ship's trail ~(March 10, 2012)|
The coloring is based on a cool strategy I implemented in a homework assignment for a computer graphics class, in order to make my particle system much cooler.
Basically, I use a 4th degree polynomial to decide the color at a given point along the trail. I use the position along the trail with some scaling and tweaking as the x term, and have 5 coefficents for each of the red, green, and blue components. For the effect seen on the dinner ships, the terms I use are
//a b c d e
0.00f, -0.00f, 0.03f, 0.16f, 0.00f, //red
0.00f, 0.01f, -0.03f, 0.03f, -0.00f, //green
0.00f, 0.02f, -0.13f, 0.15f, 0.13f //blue
The Individual particles of the trails are pretty simple to render. First, we decide their color with the coloring strategy above, then, per-pixel, we decide on the opacity based on how far the pixel is from the center of the particle. We could have done this last part with a texture lookup, but I've found that it also works pretty nicely to just use the distance formula and pick their opacity procedurally, which was a strategy I came to like after taking Procedural Shading.
Anyways, basically additive blending works, is that you make things "brighter" when you additively blend atop them. This has a number of useful properties, first of all, its great for "energy" type effects which want to make things "brighter", and secondly, since addition is communitive, the order that additive things are blended does not matter. Both of these properties are important for trails, if you break them you get things like this:
|A Trail Rendering Bug|
Anyways, the other part of our trail system is that we keep track of a series of points where the trail emitter has been recently, and use the geometry shader to interpolate a number of small quads between those points, which are then additively blended together to produce the trail visual.
Low End Graphics Cards
For different trail quality levels, I adjust the number of trail particles, so if you turn down the quality, you might start to see the individual particles more, and the gaps between them, which will tend to look something like the "Player ship's trail" image above.
But isn't this expensive to render, you ask?
Well, that actually depends. On decent discrete modern graphics cards, it runs pretty smoothly, but for something like a really old integrated Intel graphics card, it is kinda a problem, so we use a slightly different approach for our "ultra low graphics" mode.
|Ultra-low-quality Graphics mode|
|Ultra-Low-Quality Graphics Mode + no glow|
Glow and Polish
Almost surprisingly, this works across a fairly large range of trail sizes. In the above image, you can see a fairly recent change to trail rendering in Galactose, where we added a "glow" effect to them (along with many other effects in Galactose), which makes them look significantly cooler
|Glow (Left) and Without Glow (Right)|
Anyways, for the "glow" effect, we basically render to a lower-resolution off-screen buffer, then blur that a few times and then blend it back into the final image. We use an approach probably not all that different from the one described in GPU Gems 2. Instead of a glow texture, we render the effects which want a glow effect normally and then use that. We also use a somewhat different implementation since we're not as constrained by the shader language as they were back then.
|Concept Art from the Start Screen|
|More Concept Art|
|Probably my favorite trails|
Thanks for reading my long winded post about trails.
Also, since we are demoing our latest build tomorrow, be on the lookout for a new build soon. (sadly, it won't be a huge change in things, but it will have some improvements)