On this page
Effects: bundles, particle systems and decals
An explosion on screen is a small tree of objects: an effect bundle in the game with a sound, a light and several particle systems in the renderer, each a pool of sprites stepped a hundred times a second by rules a template spells out. Nothing of it touches the game's state: the dedicated server registers the same templates and creates none of the objects. Yet the port holds the particle simulation to the original bit for bit, because that is the only way to compare pictures.
The files and the template properties are on effects in the assets area; this page is the runtime.
The kinds#
| Script type | Where it lives | What it is |
|---|---|---|
EffectBundle | the game (BF2.exe!0x00643640 template, 0x006424b0 object) | a bundle of children that it starts and stops: particle systems, a sound, a light, emitters |
WheelEffectBundle, AirDraftEffectBundle, GroundEffectBundle | the game | dust behind a wheel, under a rotor, under a hull: bundles driven by a vehicle's contact and speed |
SpriteParticleSystem | the renderer | camera-facing sprites: smoke, fire, sparks |
NonScreenAlignedParticleSystem | the renderer | sprites with their own orientation: a ring on the ground, a splash |
MeshParticleSystem | the renderer | small meshes: shell casings, splinters |
TrailSystem | the renderer | a ribbon behind a moving point: a missile's smoke, a tracer |
ParticleSystemEmitter | the renderer | a system that emits systems |
Emitter, Particle | the game | physical debris: objects with a physics node that bounce |
Decal | the renderer | a bullet hole, a scorch mark |
LightSource | the game | a point or spot light (shadows and lighting) |
The effect bundle#
A bundle belongs to something: a weapon's muzzle, a projectile, a vehicle's engine, or nothing (an impact).
- Start (
0x00642f40): a bundle with a time to live does not start at all when the camera is farther than itslodDistance(500 by default). On its first start it creates one particle system instance per child and scales each one's clock by a sample ofrandomAgeFactor, so two explosions of one template do not run in step. Children are flagged for first or third person. - Events (
0x00643140): the template'sstartOnEffectsandstopOnEffectsare bit masks over event ids: fire, reload, an engine starting, a state of the armor. An effect that follows a state is therefore data: something raises an event, a bundle listens. - Update (
0x00643400): the time to live counts down; a free bundle that runs out destroys itself. A bundle with a water range starts and stops by the depth of the water where it is: the same template makes a splash in water and nothing on land. - Stop (
0x00642bc0): the systems stop emitting; the particles already out live out their lives.
A sprite particle system#
The simulation is the renderer's (RendDX9.dll!0x10180ba0), and it does not run at the game's 30 ticks or at the frame rate. Each update:
x = dt + remainder; n = trunc(x x 100); remainder = x - n x 0.01; time += n x 0.01
every particle is stepped n ticks of 0.01 s; the dead are removed
then emissionSo particles move in hundredths of a second whatever the frame rate, and a slow frame makes many ticks, not one long one: smoke looks the same at 30 and at 144 frames a second.
Emission (0x10180790)#
- The frequency is the template's
emitFrequencytimes two scale factors the bundle sets (by distance and by the effects quality), never below 0.05 of it. - A system pauses when it was not drawn for 60 renderer frames: smoke behind you costs nothing.
- When the sprite pool is more than three quarters full, a looping system's frequency is cut by its priority: to 0.4, 0.55 or 0.7. Under a heavy barrage the less important effects thin out first.
- While
last emit + interval <= time: one more particle, if the system is below its own capacity (time to live x frequency + 10). The new particle is born at the emitter's position interpolated between the last frame and this one, and aged by the ticks since its slot: a fast missile leaves an even trail, not a clump per frame.
One tick of one particle (0x1017f520)#
relative = velocity - wind x windAffectionFactor
drag = -relative x |relative| x airResistance x tick (by the square of the speed)
drag.y += gravity x tick
position += (velocity + drag / 2) x tick
velocity += dragairResistance and gravity are each scaled by a graph over the particle's life (as are size, colour, alpha and rotation): a smoke puff can start heavy and end buoyant. With collisionEnable a particle bounces off a plane: the ground under the emitter as it was when the particle was born, kept in a history of ten planes sampled three times a second.
Birth (0x101801c0)#
Each new particle draws, in a fixed order: a start frame of its animation, its lifetime, then signed values for size (reused for speed), intensity, rotation, rotation speed, the position in the emitter's shape (a sphere, a ring, a box), and three angles for its direction.
One generator for all of it#
Every particle system shares one random generator (0x1009f860: the engine's pair of multiplications modulo 2^31 - 1, started at 0x759dc150 and never reseeded). The effects quality, the order in which systems update and every emission decide where each system stands in the stream. That is why a picture comparison of an explosion only works when the port makes the same draws in the same global order: the port's particle code is held to 22,749 dumped lines of the original's over ten scenarios with no difference, at the client's 24-bit precision. At 53 bits the same scenarios differ almost everywhere.
Quality#
The effects option picks a row of pool sizes (0x100d3e50):
| Effects | Sprites | Mesh particles | Trails | View distance factor |
|---|---|---|---|---|
| low | 300 | 300 | 300 | 0.5 |
| medium | 500 | 500 | 500 | 0.75 |
| high | 1000 | 700 | 600 | 1 |
A system whose template names a higher qualityLevel than the option allows never starts. Decals exist only above the lowest setting.
Decals#
A bullet hole is a decal in a ring: 64 for the world, 32 for each object that carries decals; a new one in a full ring drops the oldest (0x101ae980). A decal lives 20 seconds and fades out over the last 15 percent; it ages twice as fast while its container is not visible. Its geometry is either a simple quad or the surface under it, clipped: heightmap cells for the ground, the hit collision mesh for an object (0x101ae450). The port's clipper equals the original's on 8,436 decals.
Debris with physics#
An Emitter in the game spawns Particle objects with a physics node: they fall, bounce and come to rest like any small body (physics). They are objects of the game, not sprites of the renderer.
What the port has#
| Part | State |
|---|---|
| template properties | verified on every shipped script: 253,870 property lines on 3,830 effect templates |
| sprite simulation | verified, the same bits: 22,749 dump lines over 10 scenarios |
| mesh particles, trails, non-screen-aligned systems, emitter systems | verified (24,625 and 26,899 lines for the last two) |
the game's Emitter and Particle objects | verified in process: 141,169 lines |
| trail draw, additive sprites | verified against the renderer's code |
| decal containers and the clipper | verified |
| the effect bundle's runtime, light sources' own update | draft: read from the listing, not run against the original |
| decals on a hit object's own mesh | the container supports it; the client does not call it yet |
The same systems. 2142's levels bring their own effect templates and post-production settings; Heroes adds outline and glow passes for its abilities, which are render passes and not particle systems (abilities).
How it is tested#
- The original's particle code computes the expected values (
crates/bf2-effects/tests/oracle.rs): the renderer's own sprite, mesh, trail and non-sprite systems are constructed, started and updated in the original, and the port's emission, spawn and particle step must match bit for bit, templates included. - The client's effect bundles (
crates/bf2-client/src/fx/mod.rs, 31 tests): which sounds an effect starts and whose velocity they take, the view-distance setter, Heroes' order of speed inheritance. - A shipped vehicle's damage effects (
crates/bf2-client/tests/it_bf2/armor_effects.rs): the effect map of one jeep's armor lines and what starts and clears through damage, destruction and wreck. Skipped without an install.
The effect bundle's runtime and the light sources' own update are a draft read from the listing, as the table above says: no test runs them against the original.
In the code#
| What | Where |
|---|---|
| particle systems, templates, the generator | crates/bf2-effects (psys::sprite, psys::mesh, psys::nsa) |
| drawing, decals, the clipper | crates/bf2-render (decals.rs, decalclip) |
| the client's use of effects | crates/bf2-client (fx) |
| the oracle | crates/bf2-effects/oracle/ |
Notes: notes/subsystems/effects.md, notes/subsystems/renderer.md ("Decals", "Particles", "Trails").
docs/dev/engine/effects-and-particles.md · built from bf2-rs e3b4f05 · part of the Battlefield 2 / 2142 / Heroes reimplementation. Not affiliated with EA or DICE.