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

Particle explosions

Started by xegoth Aug 20, 2004 at 10:50 PM 17 replies 3.7k views
Original Post
xegoth
xegoth
I added particles to my engine, the only trouble is I have no clue how to direct my particles so they make good looking explosions. Can anyone point me in the direction of a DirectX tutorial that might help me out with that?
Telastyn
Telastyn
Does +velocity away from point not look good?

How about +velocity away from point followed by constant small -velocity?

[I've not tried with my own particle system, but that's what I've seen used]
wolfgangw
wolfgangw
The funny thing is:
From my experience what looks best is NOT creating a whole lot of particles and endlessly play with the parameters.

But instead: render 30+ frames of an explosion in 3D studio or whatever (in 3DS there's a fire effect which looks quite nice), use this animation as a texture for your particles, create just a few (like 10 per second) but make the particles really big. Optionally use additive blending.

I'd say that's the way most games do it. Even the movie industry often uses filmed explosions in CG stuff (the fire of the balrog in LOTR1). That's also the method nvidia has chosen for it's balrog like fire demo (and they explain it in great detail in gpu programming gems).

evolutional
evolutional
The last explosion I did with particles was pretty simple yet looked effective. I started by creating a host of particles of slightly different sizes at a given point. Each particle was given a life around a certain time (some would be longer, some smaller) and a velocity (again, added some randomness). As the particle aged, it shrunk and faded in colour (velocity stayed constant). What happened was a bright centre of particles that dispersed as expected, the fading and shrinking of the particles ensured that only the biggest ones lasted until the end.

You could expand this system by placing a pseudo shockwave effect, essentially a rapidly expanding sphere that travels faster than the explosion itself (and fades) and by adding secondary explosions - and debris. The debris could fly out at a random tragectory and is affected by gravity, it could even cause a mini explosion when it impacts something.
xegoth
xegoth
Thanks evolutional I'm going to give that a try, what was did the texture of your particles look like though?
evolutional
evolutional
This is one that I used. It's a TGA with RGBA (eg: Alpha channel).. It's fairly simple, I'll probably experiment with other textures when I have time, but I think the key is to having it rendered with several different scales and getting the colour blend right.

EDIT: For some reason the TGA wouldn't download from my GDNet+ space, so I put a BMP up.
pex22
pex22
@evalutional
it seems like your particle is different than the one i downloaded
here's the one i downloaded: http://www.microsqft.com/files/particle.png
can it be useful for explosions? fire? or its not a good particle?
i didn't made any particle effects (like explosions or fire) yet so i have no idea

thanks,
Amir.
pex.
Matt Halpin
Matt Halpin
If you're doing an explosion, you probably want to have fire and smoke. That means additive blending for the fire and alpha blending for the smoke. If you use pre-multiplied alpha textures you can render both blend modes in one go. Just sort the particles back-to-front and render them all in one batch. You'll probably want two images - one for the fire; one for the smoke. Pack these together into a single texture so they can be rendered in one batch. Also, if you can, use an animation for each one rather than a static image.

As for motion, try firing a few (5?) particles out and have them spawn other particles as they move. Randomise stuff like size, velocity; make them spin, etc.

HTH

Matt
evolutional
evolutional
My texture is a simple one I jammed together, you can use pretty much any texture you want - it's a good idea to experiment and try things out.

As Matt said, you definitely need Additive blending to get the correct effect, the colours blend together and brighten when several are over one another, giving the effect of a white hot core which dissipates into fire and smoke. I don't use smoke in many of mine, mainly because my stuff is mostly space based (and smoke doesn't seem to be a feature of space explosions). It is good if you give an explosion as a whole an 'energy' value, each time the explosion breaks into particles, split this energy between them and again, if the energy is above a certain threshold, make the particle explode slightly again, breaking up it's energy until it's exhausted. This way, as Matt pointed out, you'll get a nice cascade effect and several smaller explosions.

I think creating effects for games can be really good fun, the best thing you can do is try and implement a particle system you can control/manipulate and then play with the results. When I got my first plasma systems going, I spent literally hours just playing with it :)
xegoth
xegoth
Okay i think a big thing my explosions are missing is additive blending, heh anyone know how to turn that on? ;)
crystal
crystal
this r a nice ref may they help

1) The Ocean Spray In Your Face (old one for basic stuff)
PDF: http://www.darwin3d.com/gamedev/articles/col0798.pdf

2) Advanced Particle Systems by john van der burg
PDF :http://www.mysticgd.com/misc/AdvancedParticleSystems.pdf
HTML: http://www.gamasutra.com/features/20000623/vanderburg_pfv.htm

3) Particle Chamber( nice source code) <<=== best one
ZIP:http://www.gamedev.net/reference/articles/article1043.asp
evolutional
evolutional
There's a column on Drunken Hyena that talks about additive blending.

The most simple way in DirectX is (from the tutorial above):

g_d3d_device->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_ONE);g_d3d_device->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_ONE);g_d3d_device->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);


Experiment by playing around with your blend factors to see what effects it produces.
xegoth
xegoth
What are my options as far as tweaking blending? Setting texture states is one of the things I haven't learned fully yet. Right now I get some blending but stacks of particles turn a bright yellow, I'd like it to go all the way to white where there are the most sprites. Is there any way to tweak this? I couldn't really figure out how to change how it blended. Here's all my render states

 	m_pD3DDevice->SetRenderState(D3DRS_LIGHTING, FALSE);    m_pD3DDevice->SetRenderState( D3DRS_ZWRITEENABLE, FALSE );    m_pD3DDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );	m_pD3DDevice->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_ONE);	m_pD3DDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_ONE);	//	// Set up the render states for using point sprites...	//    m_pD3DDevice->SetRenderState( D3DRS_POINTSPRITEENABLE, TRUE );    // Turn on point sprites    m_pD3DDevice->SetRenderState( D3DRS_POINTSCALEENABLE,  TRUE );    // Allow sprites to be scaled with distance    m_pD3DDevice->SetRenderState( D3DRS_POINTSIZE,     FtoDW(1.0) );  // Float value that specifies the size to use for point size computation in cases where point size is not specified for each vertex.    m_pD3DDevice->SetRenderState( D3DRS_POINTSIZE_MIN, FtoDW(1.0f) ); // Float value that specifies the minimum size of point primitives. Point primitives are clamped to this size during rendering.     m_pD3DDevice->SetRenderState( D3DRS_POINTSCALE_A,  FtoDW(0.0f) ); // Default 1.0    m_pD3DDevice->SetRenderState( D3DRS_POINTSCALE_B,  FtoDW(0.0f) ); // Default 0.0    m_pD3DDevice->SetRenderState( D3DRS_POINTSCALE_C,  FtoDW(1.0f) ); // Default 0.0


Here's a screenshot of my explosion how it is now:
Click here


I want it to get more white the closer it is to the center instead of just turning light yellow and staying there. Anything I can tweak?
dx elliot
dx elliot
it sounds like you're settings blue to 0, change it to something low and they'll all eventually add in color and clamp to the max of 255 each.
dx elliot
dx elliot
by the way, you don't add colors for smoke, that'll just increase the brightness and make it look like steam. You set the source to source alpha (texture and/or diffuse), destination to one, and the operation to reverse subtraction to darken what's already in the background.
xegoth
xegoth
Yes I am setting blue to zero. I bet that'll fix it. Thanks.

By the way, what should I do with particles after the initial burst? If I let them keep moving at the current speed they get way too spread out. I'm thinking maybe after a short period of time divide the velocity of all the particles by something, I noticed real explosions stop expanding outwards after a second or so and just shift and fade from there.
dx elliot
dx elliot
they turn the acceleration to a negative amount, which changes the velocity, which changes the speed to slow down. Obviously they have the initial velocity to some high number, so the acceleration is never positive...

you also give your particles some vector direction, don't try and change the actual vector on each particle and then (worst) renormalize them, that'll slow the game down. To have it change direction to kind of drop to the floor, subtract the y by gravity - which increases by another acceleration. So as the particles slow down from the point they explode, they'll slowdown and drop like some kind of firework.

you should also have them fade of course: (currage/maxage)*255 on each particle. If they all have the same max age, then before the loop, set a variable like "t" to the reciprocal of max age (1.0f / maxage) and multiply everything instead of dividing. I'm used to doing that, whether or not I gain a single frame per second.
xegoth
xegoth
Ah, so what you're saying is I should add an acceleration value to my particles (negative). Does the deceleration remain constant?
dx elliot
dx elliot
I just realized how many spelling and grammar mistakes I made from typing too fast, oh well. You should add to the gravity velocity by the constant acceleration... then set a max velocity cap. Then add the position by the velocity each frame. I like to subtract a positive gravity strength, some like to add a negative strength, it's up to you. You could even accelerate the acceleration if you wanted to. It may not be true physics, but it's good enough.

Topic Locked

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

Sign in to reply to this topic.