Skip to main content
GameDev.net gamedev.net
🔒 Locked

Explosions

Started by Geometrian Nov 2, 2007 at 4:31 PM 12 replies 16.6k views
Original Post
Geometrian
Geometrian
Hi, everyone, I'm trying to make explosions for a game I'm writing. The explosion should not take up too much processor time; I'm doing real-time rendering. The explosions will be non-nuclear and both airborne and land-based. I can handle the particles of the exploding object, but I need to know how I should go about drawing the actual fireball. For example, should I do something fancy with OpenGL, or should I draw something with explosion textures? It is possible that the explosions could be different each time, but a predetermined explosion animation would be fine too. Thanks, G
[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]
LackOfGrace
LackOfGrace
at the end of this video




a pretty easy way of making accually pretty good looking explosions
they will be really cheap to render also
Geometrian
Geometrian
Really cool! Those explosions would certainly be acceptable. Where did the explosion come from? I want the same animation!
[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]
demonkoryu
demonkoryu
You can either render an explosion animation and do some pixel shader magic to make it look volumetric or you can layer several slices of a 3D-rendered explosion animation and blend them in whatever way you like (blurring + additive blending for example). Both methods are pretty cheap.

As to where to get explosion animations... stock footage and effect DVD's for real explosions and you can also render your own in 3D Studio, which has the additional benefit of having full control over the output(alpha + depth information etc.).

Then you can also use a particle system for unique explosions and style, but it takes a lot of tweaking to make them look realistic. Depends on the look and feel of your game if you want to do this.

Maybe post some screen shots for us to see what you're aiming at.
JTippetts
JTippetts
In the book, Texturing and Modeling: A Procedural Approach, Ken Perlin wrote a section describing a raymarching algorithm for rendering volumetric density functions, and one of the example techniques demonstrated constructing an explosion. He took a spherical shaped density function, where the density was 1 at the center and dropped off to 0 at the radius of the sphere, and distorted the function by applying simple noise-based turbulence to the domain. By animating the turbulence function over time you get a changing billow pattern. By scaling the sphere you can create the effect of the explosion expanding outward.

You could construct a simplified version of the raymarcher (code is given, and the concept is really very simple) to collect densities and colorize the field depending on density; then, by animating the density function of the initial sphere to tend toward 0 over time, you can simulate the explosion dissipating and fading away. By mapping the output density to an appropriate color function that includes black at very low densities, fading into dusky oranges, reds, yellows, and finally white (for very hot, intense explosions) you can generate a fairly decent explosion. Then animate the parameters for turbulence, density and radius over time, rendering into a colormap at each step, to generate the frames of your explosion. You can generate multiple explosions for the various layers to avoid the appearance of repetition. When shading effects are applied to the explosion, you get a turbulent, billowy cloud very much like an explosion.


As an alternative to doing a billboarded explosion of this nature, you could construct a run-time version of the raymarcher and build your explosions on the fly by using this same technique. Might be tricky, as volumetric raymarching is computationally expensive and multiple explosions, unless sampled in a very small value (and thus sacrificing detail) could bring your game to it's knees.

Or you could model an explosion using simple particles. Different components of the explosion would use different particle material settings. The smoke layer would use lots of black particles blended with the scene. The fireball would include particles with low-power reds and oranges additively blended onto the scene. If the low-power color of these reds and oranges includes a non-negative blue component, then as more particles are added, the color will tend toward the white, for high-intensities. In my (somewhat limited) experience, these particle-based explosions tend to be trickier, harder to produce realistic explosions, and may require a lot of heavy experimentation to get good results. However, they can be constructed to be fairly efficient in real-time and allow the generation of randomized, procedural explosions, thus avoiding repetition.
Geometrian
Geometrian
I like the raymarcher idea. There's already going to be particles in the form of fragments of the exploding object. There's probably only going to be one explosion at a time. Where can I get the source? Or can you give me a small sample program?
[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]
JTippetts
JTippetts
I've been fiddling around a little bit, and achieved some pretty nice results for creating the explosion sprite images as used in the youtube video that somebody linked earlier. For example:



The way I created this:

First, I setup a color gradient that ranges from RGB(0,0,0) to RGB(1,1,1), passing through points where the color is red, orange and yellow. Then I constructed a spherical function with a radius of 1.0 that returns a value of 1.0 at the center and 0 beyond the radius. Then I set up a turbulence modifier attached to the spherical function, with 3 separate Perlin noise modules.

The way the turbulence works is, imagine you are iterating the 2x2x2 cube from (-1,-1,-1) to (1,1,1), and outputing the spherical noise function. If you could envision the output, you would see a 'fuzzy' sphere, smoothly gradient from center outward. By adding a little noise to the input coordinates passed to the sphere function you get a turbulent shape that still maps from 1.0 to 0.0, but the noise added to the input domain distorts the shape from a perfect sphere to a more fluid 'explody' type shape.

Now, I iterated a 'slice' of the distorted sphere right through center, rendering this 2D slice onto a plane. The output value of the input coords is used as an interpolant to lookup the color from the color scale, so that values of 0 (outside the sphere) are black with an alpha of 0, progressing through red, orange, yellow and finally to white at 1.0. The looked-up color was written to a color buffer and the final result saved to an image file. I opened the file in Gimp, copied the whole thing, scaled the copy down, and pasted it a couple times on top of the original to see what it might look like when used as demonstrated in the youtube video linked earlier. The results were pretty neat, all things considered.

I rendered only a single frame, but by animating the various parameters used to generate the sphere and perturb, and by scaling the output of the function downward over time, you can get a roiling effect with the flame 'cooling' toward black and increasing in transparency as it tends toward the 0 end of the color scale. Couple that with some scaling to increase the expansion of the gas cloud, and you could get some pretty neat results.

I implemented all of this using my own custom tools, but if you would like to see the code I used, let me know.
Geometrian
Geometrian
I'd love that. I think I see how that works, but that is just beautiful.
[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]
Geometrian
Geometrian
Looks really cool, BTW, and it runs really quickly (1 sec. to render 10 frames and save on my computer), so I think this could work real-time.
[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]
JTippetts
JTippetts
Quote:
Original post by Geometrian
Looks really cool, BTW, and it runs really quickly (1 sec. to render 10 frames and save on my computer), so I think this could work real-time.


It could certainly be tweaked to run faster as well. Right now it uses 3 separate octaved noise modules to supply the turbulence, and the modules are using 3 dimensional noise. You could probably use 1 turbulence function for all three coordinate axes, trim it to 2D noise and lower the octave count, possibly degrade the interpolation to cubic or even linear, etc... Also, as written, the code works by default on 128x128 frame sizes, so that could certainly be scaled down for a pretty significant speed boost, if you want to sacrifice quality. The explosion frames in that youtube video all fit onto a 256x256 texture, so this is certainly a valid option.

It would probably be workable to generate some finite set (maybe 10 or so) sets of frames, then just select them randomly when constructing an explosion.
Geometrian
Geometrian
I thought of that last, too, but the textures alone are about 23MB. I would scale them down, as you suggested. Somehow, saving 10 explosions seems like the wrong way to do it. Also, that's a lot of textures. Especially as long as there's no more than about three going on at the time, it will be fast enough. Now I have to figure out Lua, which means installing it, or get someone else to translate a it to Python.
[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]
JTippetts
JTippetts
You can use the Gimp to put multiple explosion frames on a single texture atlas. That is probably the best way to do it. If you make the frames 64x64, or half the size that they are right now, you can squeeze 16 of them onto a 256x256 texture. If you create perhaps 10 different animations (though that might be overkill), then you can randomly select from them when you are building explosions. Having varieties would help eliminate the sense of repetition, since the shapes and smoke patterns would be different. Even having 3 variations would probably be sufficient.

The code could easily be tweaked to build the frames into a texture atlas for you.
Geometrian
Geometrian
I've got several explosions going now, made by rendering various frames. I haven't attempted to make it real-time, though that is a logical next step.
[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.