BF2.US bf2-rsdeveloper wiki Parity Discord bf2.us
On this page

Effects: bundles, particle systems and decals

BF22142Heroes

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.

An effect, from its event to the sprites an event a shot, an impact, an armor state, an engine starting: a bit in a bundle's start mask the effect bundle (the game) starts its children unless too far; one instance per child, each with its own clock scale particle systems (the renderer) sprite, mesh, trail, non-screen-aligned: each a pool with a template emission by frequency, cut when the pool is three quarters full; paused when 60 frames undrawn the particle's step 100 ticks a second: drag by the square of the speed, gravity, graphs over its life the draw sorted sprites, additive sprites, trails; decals in rings BF2.exe!0x00642f40 (bundle start), 0x00643140 (events); RendDX9.dll!0x10180ba0 (update), 0x10180790 (emission), 0x1017f520 (step)
An effect, from the event that starts it to the sprites on screen.

The files and the template properties are on effects in the assets area; this page is the runtime.

The kinds#

Script typeWhere it livesWhat it is
EffectBundlethe 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, GroundEffectBundlethe gamedust behind a wheel, under a rotor, under a hull: bundles driven by a vehicle's contact and speed
SpriteParticleSystemthe renderercamera-facing sprites: smoke, fire, sparks
NonScreenAlignedParticleSystemthe renderersprites with their own orientation: a ring on the ground, a splash
MeshParticleSystemthe renderersmall meshes: shell casings, splinters
TrailSystemthe renderera ribbon behind a moving point: a missile's smoke, a tracer
ParticleSystemEmitterthe renderera system that emits systems
Emitter, Particlethe gamephysical debris: objects with a physics node that bounce
Decalthe renderera bullet hole, a scorch mark
LightSourcethe gamea 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 its lodDistance (500 by default). On its first start it creates one particle system instance per child and scales each one's clock by a sample of randomAgeFactor, so two explosions of one template do not run in step. Children are flagged for first or third person.
  • Events (0x00643140): the template's startOnEffects and stopOnEffects are 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:

text
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 emission

So 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 emitFrequency times 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)#

text
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 += drag

airResistance 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):

EffectsSpritesMesh particlesTrailsView distance factor
low3003003000.5
medium5005005000.75
high10007006001

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#

PartState
template propertiesverified on every shipped script: 253,870 property lines on 3,830 effect templates
sprite simulationverified, the same bits: 22,749 dump lines over 10 scenarios
mesh particles, trails, non-screen-aligned systems, emitter systemsverified (24,625 and 26,899 lines for the last two)
the game's Emitter and Particle objectsverified in process: 141,169 lines
trail draw, additive spritesverified against the renderer's code
decal containers and the clipperverified
the effect bundle's runtime, light sources' own updatedraft: read from the listing, not run against the original
decals on a hit object's own meshthe container supports it; the client does not call it yet
2142
Battlefield 2142 and Heroes

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#

WhatWhere
particle systems, templates, the generatorcrates/bf2-effects (psys::sprite, psys::mesh, psys::nsa)
drawing, decals, the clippercrates/bf2-render (decals.rs, decalclip)
the client's use of effectscrates/bf2-client (fx)
the oraclecrates/bf2-effects/oracle/

Notes: notes/subsystems/effects.md, notes/subsystems/renderer.md ("Decals", "Particles", "Trails").

Source: 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.