Part 1 of 3
I’m actually taking a break from the project this week to work on some other things, but there are a few completed features I want to cover. Let’s start with the particle engine.
I wrote a particle engine about eight years ago, as part of my day job. It was good for its time, but since then I’ve come up with a lot of ways that it could have been done better.
I’m using the term “particles” here very broadly to refer to any small objects that are created in groups and have no physical presence. They don’t collide with stuff, they can’t be picked up or manipulated. They are visual only. Some examples of particle effects from other games include: Fire, smoke, fireworks, billowing fog, puffs of dust when you take a step, splashes of water droplets, things blowing in the wind, rain, snow, blowing sand, muzzle-flashes, airborne blood spatters, magic missiles and other spell effects.
I don’t need all of those effects, but any system I build needs to be at least flexible enough to produce them.
Particles come from particle emitters, and particle emitters are created using a long list of settings. The settings are things like:
- Texture – What texture to apply to all of the particles that this emitter will create. If I need more than one texture (say, if I wanted to make a shower of gold coins and rubies) then I’ll need to use multiple emitters. I could alter this so that an emitter could use multiple textures from a list, or maybe cut up and use selected sections of a texture. But for now this is good enough.
- Blending style – Note how fire or muzzle flashes seem to emit light of their own, while smoke and dirt to not. This is controlled by how I set the blend properties at render time. “Bright” particles (and other special effect) are usually created so that they lighten the pixels already on-screen, which is what makes them glow.
- Emitter lifespan – How long should this emitter last? A burst of fireworks releases all of its particles at once, after which the emitter is useless and can be discarded, while a plume of smoke is expected to keep churning out smoke as long as it’s in the scene.
- Emission count & emission interval – How often should particles be released, and how many should appear when they do? Sparks from a loose wire might release a bunch of particles at once, but wait for several seconds between busts. A fire creates flames at a steady rate, and creates them one at a time.
- Fade in & out – We need a way to control how long it takes for particles to appear and vanish. Fog and smoke should fade in and out very slowly. A burst of fireworks appears instantly, but fades out slowly. The aura of a blinking light should come and go instantly.
- Rotation – Something blowing in the wind should tumble through the air, while raindrops should remain pointed the same direction.
- Size – Some particles effects will be larger than others.
- Cubic volume – The volume of the emitter is a cubic area. New particles will appear at a random point inside of the volume. If you want all of the particles to come from a single point, you make this volume zero size. If you want to make the churning spray at the base of a waterfall, you’d make the volume roughly the size of the area where the falling water is striking the still water.
- Color – What color to tint the particles. I make all of the particle textures white and use this property to color them as needed. With any luck, I’ll be able to re-use textures and effects.
- Other – I’ve got a few other properties for special cases: Should particles be pulled down by gravity? Should they be affected by wind? Should they leave an imprint of the z buffer?
|First steps: Here I’ve got an emitter (the blue wireframe box) creating particles. (The blue rectangles.) These particles appear, persist for a second, then vanish.|
The upshot is that one set of properties will create one kind of particle effect, but a different set of numbers will yield an entirely different effect. Rather than have them hard-coded, I stick these settings into text files where I can edit them while the program is running. Here is an example, the effect I use for flower petals blowing in the wind:
<cvars> <particle_texture> particle_flower.png </particle_texture> <particle_acceleration> [ 0, 0, 0.0 ] </particle_acceleration> <particle_blend> 0 </particle_blend> <particle_emitter_lifespan> 0 </particle_emitter_lifespan> <particle_emit_count> 1 </particle_emit_count> <particle_emit_interval> 400 </particle_emit_interval> <particle_fade_in> 5 </particle_fade_in> <particle_fade_out> 500 </particle_fade_out> <particle_interpolate> 0 </particle_interpolate> <particle_lifespan> 3000 </particle_lifespan> <particle_origin> [ 0, 0, -0.25 ] </particle_origin> <particle_panel_type> 3 </particle_panel_type> <particle_rotation> [ 0, 0, 0 ] </particle_rotation> <particle_size_min> [ 0.07, 0.07, 0.07 ] </particle_size_min> <particle_size_max> [ 0.17, 0.17, 0.17 ] </particle_size_max> <particle_speed_min> [ 2, -1, 0.05 ] </particle_speed_min> <particle_speed_max> [ 3, 1, 0.25 ] </particle_speed_max> <particle_spin> [ 20, 40, 0 ] </particle_spin> <particle_volume_min> [ -2, -2, 1.0 ] </particle_volume_min> <particle_volume_max> [ 2, 2, 1.1 ] </particle_volume_max> <particle_wind> 0 </particle_wind> <particle_gravity> 0 <particle_z_buffer> 0 </particle_z_buffer> </particle_gravity></cvars>
|Now I can feed an emitter a list of colors. When it creates a particle, it selects randomly from the available colors. It’s now using a texture map (of a circle) and making them slowly spin through the air.|
Thanks again to glConsole, which is the gift that keeps on giving. I was able to use its environment variable system to load these particle properties, basically for free.
The next step is to populate the world with emitters. I make a system to examine the local climate and time of day and pick an appropriate emitter. Swamp? Swirling ground fog. Desert? Blowing sand. Field of flowers? Blowing flower petals. Evening in an open area? Fireflies.
|I set the particles to all move and spin at the same speed, which produces this ever-spooling ribbon effect. Cute.|
Other parts of the program can initiate one-off effects. When the avatar takes a step, it looks at the color of the terrain under its foot and creates a puff of particles. This looks great on sand or dirt, but kind of lame on grass. But you get the idea. It’s just one more thing making the world seem more like a living thing and less like a static scene.
Next time I’ll talk about those clouds you’re seeing in the screenshots.
Part 1 of 3
Lost Laughs in Leisure Suit Larry
Why was this classic adventure game so funny in the 80's, and why did it stop being funny?
Spec Ops: The Line
A videogame that judges its audience, criticizes its genre, and hates its premise. How did this thing get made?
DM of the Rings
Both a celebration and an evisceration of tabletop roleplaying games, by twisting the Lord of the Rings films into a D&D game.
Final Fantasy X
A game about the ghost of an underwater football player who travels through time to save the world from a tick that controls kaiju satan. Really.
Dear Hollywood: Do a Mash Reboot
Since we're rebooting everything, MASH will probably come up eventually. Here are some casting suggestions.