Jump to content
  • Advertisement
Sign in to follow this  
Geometrian

OpenGL Explosions

This topic is 3931 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!