Advertisement Jump to content
  • Advertisement
Sign in to follow this  
  • entries
  • comments
  • views

Cut, Copy & Paste

Sign in to follow this  


Yesterday I made several improvements to the flame particle system. It was an interesting problem. I wanted randomness, but not too much. Also I didn't want to do collision on them to avoid the runtime cost, so I wanted to flame particles to stay within their trigger box ( or nearly so ).

What I did was to start the flames at a random location within the box, but effectively converted to a cylinder. I chose a random location in [-1,-1,-1]..[1,1,1], then added 1.0 to y, then normalized the resulting vector. This makes the distribution round instead of square, and concentrates more particles near the origin than at the edges. Then I scaled the x & z by the trigger box width & depth, then just took the abs of the original y value * the box height, to get the final position.

Next I changed the per-particle code to add a random displacement to its velocity every frame, apply the velocity to the position, then look to see of the particle has left the box. If so, I mark it for death, and then stop updating its velocity and fade it out over 300 msecs. I also do a fade as the particles reach the top of the box, multiplying the two fade factors together and using this as the particle alpha.

In the pixel shader, I additionally fade based on the fog factor, so the flames look correct in the distance.

Once I had it working well, I put some more flames in the various levels, and it really helps the look & immersion factor, when I added a sound source and light flicker to the effect. Of course, this was a pain to track 3 separate objects - the trigger, sound, and light in the editor, so I decided to partly automate it.

I made the engine look for facets on the trigger box for sound info as well as for light parameters, and put some useful defaults in for the flame case ( like the light will flicker by default, etc. ). So, now all the designer must do is create the trigger and give it 4-5 facets to get the effect. I also added a volume facet to a sound source, which was inexplicably not handled before.

This made it easier, but was still overly complicated, so at the level designer's request, I put in Cut, Copy & Paste into the level editor. It doesn't work for static world triangles, but only for editor objects, like meshes, triggers, entities, sound, lights, etc.

Took a while to get it all sorted out, compiling and working, but now I'm glad I did it - it will be a huge time saver, and much more generally useful than making separate macro butters for 'torch', etc., which was my previous idea.

Here is a shot of the crypt level with several torches visible. Note how the torch at the middle top of the shot is almost faded out in the fog.

Sign in to follow this  


Recommended Comments

Guest Anonymous Poster


"I chose a random location in [-1,1,1]..[1,1,1]"

Are some "-" missing?
Currently it is only a line.
Do you mean [-1,-1,-1]..[1,1,1]?

Share this comment

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!