explosions using OpenGL and textures...

dave05
Unregistered
 
Post: #1
Mine suck. seriously.

I'm using a single .PNG for my texture, basically a semi-transparent orange-yellow gradient ball with a thick roughened edge and a white outer-glow. its size is 64x64.

When an explosion is created, I create several "particles" at random rotations about a central explosion point, give the explosion a random rotation speed, and fade the explosion in and out as it expands (uniformly).

i expect that uniform expansion and uniform fade is part of my problem... but I really don't get the fundamentals of explosion creation. Should I be using 50-60 tiny particles rather than 5-6 big ones? Should my particles have multiple frames? (haha what a ghetto question) Any advice? I couldn't find anything too good on google, and I know I've seen some awesome looking explosions on this site...

I wish some of you would share your explosion secrets... pleeeeeeeeeeease?
Quote this message in a reply
Moderator
Posts: 529
Joined: 2003.03
Post: #2
If you want to make some canned explosion frames, you can try this monstrosity:

http://www.vikingdan.com/Programming/ParticleX/

"Yes, well, that's the sort of blinkered, Philistine pig-ignorance I've come to expect from you non-creative garbage."
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #3
First, uniform speed is a no no. It makes for very bland looking explosions. You want the particles to slow down as they go. What I've found works well is to give every particle a random direction and speed, then multiply that vector by (1 - d^-t)/ln(d) where d is the decay, and t is the time. The effect is that the speed will become 1/d what it was a second before, so keep the value close to 1. The product of the vector and the other factor is your distance from the start. Don't make every particle start at the same place, it will look to uniform.

Don't make the particle image a specific color. Just make it grayscale and color it using openGL. That way it can change color from a bright yellow to a dull red as time goes on. Don't use straight addition for the blending, it will lead to ugly clipping. Use glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ONE) as your blending function, this works like the "screen" mode in Photoshop.

More particles will make a more detailed looking explosion, but using fewer and larger particles will make a smoother and easier explosion.
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #4
I've done a bunch of work on my explosions ( see here: http://idevgames.com/forum/showthread.php?t=9354 ).

The first thing, and this may already be your situation, is to make an explosion testbed. E.g. you might already have a game with missiles and characters and whatnot, but then testing your explosions becomes tedious because you've got to load your level, and fire your missile, and so on.

Anyway, putting that aside, you've got to *look* at some real explosions, and at some really good looking ones in games done by professionals. I had thought "mine are fine, they're good enough" until I saw some shots of Yet-Another-WW2-Epic and realized mine totally sucked.

So, I guess to condense what's in an explosion, you've got these things:
a) A fiery core. You'd use particles with blending set to (GL_SRC_ALPHA, GL_ONE). These would not travel very far from the center, following the velocity dropoff Skorche mentioned.

b) Smoke. This would be normally blended, using GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA and would cover a larger radius than the fiery particles.

c) White-hot sparks. These -- in my game -- are linearly billboarded and represent a different type of particle system. They'd travel very fast, use additive blending like the fire.

d) Shrapnel. Treated like the white hot sparks, but use normal blending like the smoke.

The important part here is that you've got 4 particle systems, so you've got to do some trickery to get them to draw in the correct order. For me, I have some depth-sorting chicanery with my scene graph, but the drawing order is guaranteed to be Smoke, Shrapnel, Sparks, Flame.

Motion and velocity dropoff are super important, and basically, you'll just have to tweak it until it looks right. It took me a long time to make mine make me happy.

You also want your particles to be created at random distances from the center, so you have an *immeidate* appreance of volume.

My explosions have not too many particles. Off the top of my head, it's like 20 fire particles, 20 smoke particles, 10 spark particles, and 10 shrapnel.

Further, for the visual effect of super-saturated-lighting, I billboard a single almost entirely opaque flare image over the whole thing in a final pass, using additive blending, with depth-testing turned off ( if the centerpoint isn't occluded, which required ray-collision testing against your environment ) -- if it is occluded I turn depth testing back on. This looks particularly nice, since it looks a little like you're being blinded, and like it's causing the atmosphere itself to illuminate.

Finally, I add a lightsource and modulate it for the duration of the explosion, which adds some credibility since if it's so damn bright, things *should* be illuminated. For reasons of fixed-function pipeline lighting ( I don't use any shaders ) I project the lightsource position away from the ground along the normal for that point by some fairly large distance.
Quote this message in a reply
Member
Posts: 208
Joined: 2005.04
Post: #5
This is a great thread! Thanks for the info guys! Grin
Quote this message in a reply
Moderator
Posts: 522
Joined: 2002.04
Post: #6
I get stuck on making the textures. I can make some mediocore ones, like mreh:

[Image: explosion-test.jpg]
or... mreh:
[Image: explosion-finished.jpg]
Anyone have an example of a *good* one or a tip on making it?

-Jon
Quote this message in a reply
Member
Posts: 320
Joined: 2003.06
Post: #7
Wow, and I thought I'd got a bit carried away with the explosions in Chopper. Explosions have got to be THE most rewarding, enjoyable coding thing to waste countless hours on.

Chopper, iSight Screensavers, DuckDuckDuck: http://majicjungle.com
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #8
aarku Wrote:I get stuck on making the textures. I can make some mediocore ones, like mreh:

[Image: explosion-test.jpg]
or... mreh:
[Image: explosion-finished.jpg]
Anyone have an example of a *good* one or a tip on making it?

-Jon

Those are really good, Aarku. Mine are simple, low res, and crapulent. They're all in one 512x512 texture so I can switch particle really easily just by switching texture coordinates.

[Image: Particles.png]
Quote this message in a reply
neverever
Unregistered
 
Post: #9
Theres a scientific word for this topic..... ah now I remember, fluid dynamics. U might also want to try combustion, that is if u havent already.

Sorry I lost my bookmarks, but here are some that i refound, they arent as good looking as TPX's, but they are shaped based on physics.

http://www.gvu.gatech.edu/animation/explode/city.html
http://www.gvu.gatech.edu/animation/Pape...000:AE.pdf

http://www.gvu.gatech.edu/animation/expl...e-cvid.mov
Quote this message in a reply
dave05
Unregistered
 
Post: #10
neverever, i think downloading that pdf with colons in the file name broke my computer.

On macs, colons represent directories, do they not? The file (virus?) disappeared into my computer once downloaded.
Quote this message in a reply
Member
Posts: 567
Joined: 2004.07
Post: #11
no, that was on classic. however, if you name a folder something like "blah/bla", it shows up in n ls as "blah:blah". However, it shuldn't hurt your computer... o.0

It's not magic, it's Ruby.
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #12
Those fluid dynamics based explosions are astonishing, but I don't think any of us can realistically pull off explosions of that degree of physical realism -- in real time -- with the CPU power we have today. Perhaps in 10 years, but not today.
Quote this message in a reply
neverever
Unregistered
 
Post: #13
Errr.... sorry dave Blink

TPX, ur right, but did u see the way the explosion refracted the light?! It was so cool! Neways thats the reason everyone likes particle based systems......they are fast.

I read the article again, the math used requires time to be measured in microseconds, while they could measure in nanoseconds, they still had to slow it down. They used a grid system of voxels to define the resolution of the explosion---so we could theoretically do more blocky versions in real time....
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #14
That's pretty damn clever, actually. I didn't read the article, but I assume they generated their volumes by treating the voxels as NURBS? Because their volumes were mighty smooth and flowing.

I have to partially retract my earlier statement about real time performance. I've seen some mighty hairy physically correct particle systems done in real time on the GPU. Clever stuff.
Quote this message in a reply
Moderator
Posts: 916
Joined: 2002.10
Post: #15
David Rosen did a wonderful fluid dynamic based explosion demo awhile back. It was fast and real time. Believe me, this is NOT beyond the realms of reality here.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  [SOLVED]OpenGL edges of textures mk12 2 4,477 Sep 2, 2010 08:07 PM
Last Post: mk12
  OpenGL Image Textures mikey 52 25,123 Jun 30, 2009 10:42 AM
Last Post: AnotherJake
  Dealing with inverted textures in OpenGL johncmurphy 7 7,120 Jun 15, 2009 08:11 AM
Last Post: Skorche
  Using textures OpenGL switches to software renderer bruno 2 3,603 Oct 12, 2008 03:06 AM
Last Post: bruno
  Loading and using textures with alpha in OpenGL with Cocoa corporatenewt 4 6,413 Dec 8, 2007 02:06 PM
Last Post: Malarkey