Hey Everyone!
Sorry about the lack of a post last week, anyways, this week I will be talking about trail effects in Galactose.
|
Trails are important! |
Overall, Trails are one of the effects that most expresses the visual style in Galactose. We use trails for projectiles and behind ships. They are also something that has gone through a large number of revisions. This week I'll take you through their history and explain a bit about their implementation.
Some History
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:
|
Humble beginnings... |
As a side note, I always thought the orange shot effect looked pretty cool. Anyways, this was the state of the trail effects on January 28, 2011. It should be noted that this is long before many game systems such as .obj file loading were implemented.
Improvements
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) |
But, here, you can see the genesis of how we implement our trails. Basically, we abuse additive blending and the geometry shader.
Coloring
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
Trail Particles
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.
Additive Blending
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 |
Clearly, this is not what you want to do. (In this case, iirc, it was actually that it wasn't applying blending)
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 |
Normally, you probably wouldn't notice the distortions visible above, it took me a few minutes to find the right direction to view it from; Anyways, for ultra-low-graphics mode, we "cheat" for distant trails, and render the trail with 3 polygons - two at a cross-section to give the length of the trail, and two cross-sectional slices which help hide the effect from the front and the back (you can see those cross-sectional slices as the two "bumps" in the above image). Overall, this actually comes pretty close visually to the most important cues about trails, but it creates trails that are very "rigid" and which can't express trajectory at all, instead, they stiffly point right behind the "emitter", in a straight line.
|
Ultra-Low-Quality Graphics Mode + no glow |
Its perhaps easier to see whats going on with the broccoli bombers and the glow effect turned off. Notice the cross shaped sections above. The reason you can notice the trails on these ships is because the cross sectional slice is occluded by the back of the broccoli ship, and with the glow off, its also much easier to see. Anyways, if you don't look too closely, it looks like a very similar effect to the "nice" trails, but at a much lower rendering cost.
Glow and Polish
|
Large Trails |
With a few more months of tweaking and minor improvements trails began to look event better.
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.
Future Work
|
Concept Art from the Start Screen |
|
More Concept Art |
There are always things to improve. What I'd like to improve the most is to make the trails look less smooth and more chunky, like you see on the background of the start screen. I haven't quite figured out how to do this yet, but I think it would really take the visual polish to the next level.
Conclusions
|
Probably my favorite trails |
I still think the trails on the enemy ships are probably my favorite trails, I really like the "fiery" impression they give off.
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)