The Science of Video Game Explosions

As gamers we often take a lot for granted. Every year we are provided with vast new worlds for us to explore, filled to bursting with adventuring potential. Yet they’re never perfect. There’s always a quest that doesn’t quite work properly, or a texture that looks blurry or out of place, and when we stumble across such bugs or glitches, it’s inevitably annoying. After all, a book never crashes, suddenly slamming shut on your fingers, and actors in films don’t randomly fall halfway through the floor and start flapping around like a flag in a hurricane. Why do we have to put up with this nonsense?

Truth be told, we’re now so used to these grand spectacles it’s quite easy to get lost in the small things, and forget just how difficult it is to actually make a game. They are art created with maths, the most complex paint-by-numbers books in existence. To better understand the challenges involved, we’re going to explore the workings of one of gaming’s more frequent occurrences – the common or garden explosion – and see just what sort of technology is required to make something go “boom”.

To do this, I’ve enlisted the help of a couple of developers who know a thing or two about virtually blowing stuff up. Cliff Harris is the founder of Positech games, the one-man developer army behind Gratuitous Space Battles and the upcoming Gratuitous Tank Battles, both of which feature more explosions than the entire Michael Bay back-catalogue. Cliff also created an explosion generator program available for free download online, which gives us an insight into the early days of combustion rendering.

I’ve enlisted the help of a couple of developers who know a thing or two about virtually blowing stuff up.

In the beginning, there was the Sprite. Alongside being a carbonated drink and a sort-of fairy, a sprite is also a 2D image that has been used in gaming since the early days of computer graphics. Sprites can be easily integrated into larger scenes and were originally a method of blending animated characters and objects with a pre-rendered background. They’re also the foundation of gaming’s earliest explosions, which took the form of a sequence of sprite-based images to form an animation. “That is what the explosion generator is providing, for quite older-fashioned games, or ones with a constant frame rate,” Cliff says. “You can't do that if you want a lot of variety, big explosions, and the ability to control time.”

Nowadays, rendering explosions even in two dimensions is a far more complicated affair. The foundation of any modern explosion is the engine’s particle system. This is generally controlled by an emitter, which acts as both the source of the particles and dictates their direction of travel. “My last two games do particle-based explosions, where you have maybe five or six different layers of particle all being combined together, some using different blend effects to others,” Cliff explains. “The thing that makes the Gratuitous Tank Battles ones look nice is that they actually model heat, so particles change from white hot through yellows and reds to flames and then smoke over time.”

When the particle system is ready, the next stage is to find a template explosion as a base for the in-game render. What makes explosions a particularly tough rendering challenge is that they occur extremely quickly and yet have enormous variations in terms of size, shape, colour brightness etc within that tiny sliver of time. “It's quite amazing how much stuff you need to make it look right,” Cliff says. You need those white hot molten bits, the yellowish sparks, the flames, both bright and cloudy, you need debris, and you need various types of smoke and maybe some smoke plumes.”

And this is just for two-dimensional explosions. When making the transition to three-dimensional rendering, a whole range of new problems need to be solved. Not least of these is ensuring the effect looks right regardless of where the player witnesses it from. Oddly enough, part of the solution lies in using two-dimensional sprites. Caleb Essex, a visual effects artist at Crytek, points out that sprites always face the camera, which helps to negate the problem of which angle the player approaches from. “The effects artist can set the size, speed, scale, lifetime, rotation, brightness, and other parameters of these sprites to create the desired effect.”

It's quite amazing how much stuff you need to make it look right.

Sprites alone won’t make for a convincing explosion, especially not in a 3D environment. Lighting also plays an important role in making them look realistic, both within the explosion itself and how it lights the environment around it. Crytek use three different lighting techniques to accommodate this. “The first technique is to make the textures emissive, which makes the texture very bright in dark lighting conditions,” Caleb explains. “The second technique is to allow the effect to cast light and illuminate objects around the explosion. This can be used to illuminate other sub effects of the particle such as a fireball illuminating the smoke it creates. The final technique is setting the effect to receive light and shadows from itself and the environment.” The combined effect of these lighting tricks is that the explosion both affects and responds to the light level of the environment it is in.

Illumination isn’t the only way an explosion affects its surroundings. Without the appropriate concussive forces applied to it, the effect is only half-finished. At this point, we move away from graphics rendering and into some heavy physics programming. To make the detonation convincing, nearby objects must respond to it in accordance with their weight, density etc. Will the object be knocked over or thrown around? Will it be destroyed entirely? “When creating the effect we have the ability to add impulse forces such as wind or gravity,” Caleb states. “These forces are tied in directly to the engines physics system and interact with the environment accordingly. If an object that has physics enabled comes in contact with this force it will behave in a realistic manner.”

A fairly recent but enormously useful addition to in-game physics is a feature known as soft-body dynamics. This enables developers to accurately simulate structures that are non-rigid, or can become non-rigid. This can be used for anything from ensuring Batman’s cape ripples realistically to making a box crumple when it is stood on by the player. It can also simulate how heftier objects are deformed by particularly powerful or nearby explosions, such as the shipping container in Crysis 2 below. This allows for some nice middle-ground for an explosion’s effect on in-game objects, rather than it either obliterating them or chucking them around.

You may have noticed another area we haven’t covered yet, and that’s the noise of the explosion. Audio is a huge part of the overall effect, and frankly the methods behind creating the appropriate sounds are worthy of their own article. But the basic formula is: sample plus mixing equals awesome explosion. The wonderful thing about sound engineering is that the sample can be taken from a wide variety of sources, be it a bona-fide explosion, a bottle filled with dry ice, or even white noise mixed in Audacity. Regardless of the source, plentiful bass is crucial in the final mix, so you feel the effect in your gut as well as hearing the sound in your ears.

For audio, the basic formula is: sample plus mixing equals awesome explosion.

There’s one last consideration for any virtual anarchist hell-bent on simulated destruction. As we have explored, explosions are both graphically and physically intense. More often than not they’re also triggered by the player, meaning it’s possible to have a fair few going off at once. Hence it’s vital to ensure that the hardware playing it can actually handle the bombardment, and doesn’t become the victim of a far more real, far less fun explosion. Interestingly, different developers have different ways of getting around the performance issue.

For Gratuitous Space Battles, the solution is a little forward thinking and a lot of hard graft. “It actually utilizes the gaps between frames when not much is happening to predict what particle effects might be needed next and load them into memory so they are primed ready to go when needed,” Cliff says. “Plus every line of code in the explosion system has been endlessly measured and optimised to make it run as fast as possible.”

Geometry Wars - some unconventional explosions.

Meanwhile, Caleb describes how Crytek uses organisation to get around any performance woes. First, they specify and catalogue every possible explosion combination that can happen in the game, whether it’s throwing a grenade onto tarmac or firing a rocket into sand. Then, when the player triggers an explosion, the game looks up those weapon/surface libraries. “This way only the required effect is loaded and played instead of all of them being loaded, effectively mitigating CPU load.”

Mix all the above ingredients together, leave to cook in your renderer for, oh, preferably as little time as possible, serve with a rocket launcher and lashings of drama and voila, you have a perfectly formed explosion. All that work, all that preparation, for an in-game effect that lasts only a few seconds – a bit like scoffing a piece of Christmas cake.

Rick Lane is the lead explosives correspondent for a variety of game magazines and websites (honest). You can follow his trail of destruction via Twitter.


Source : feeds[dot]ign[dot]com

0 comments:

Post a Comment