On this page
What goes into an effect
An explosion, a muzzle flash or the smoke over a chimney is an EffectBundle: a template
with child templates that each emit something - sprite particles, small meshes, trails, sounds, lights. The
properties live in a .tweak written by the 2005 editor; the textures are sprite atlases whose frames
the particles step through.
The .tweak#
Objects/Effects/impacts/explosions/e_exp_medium/ holds a two-line .con that creates the bundle and includes the .tweak. The tweak lists the children (addTemplate), then creates each one with every property the editor knows. The lines that matter most:
ObjectTemplate.activeSafe EffectBundle e_exp_medium
ObjectTemplate.addTemplate S_e_exp_medium_Start
ObjectTemplate.addTemplate em_exp_medium_Fire
ObjectTemplate.setPosition 0/0.1/0
ObjectTemplate.timeToLive CRD_NONE/1/0/0
ObjectTemplate.cameraShake 1
ObjectTemplate.create SpriteParticleSystem em_exp_medium_Fire
ObjectTemplate.emitterType Box
ObjectTemplate.emitFrequency 22
ObjectTemplate.emitTime 0.11
ObjectTemplate.timeToLive 1
ObjectTemplate.sizeGraph 0/0/7/-1
ObjectTemplate.particleType Additive
ObjectTemplate.textureName objects\effects\textures\animated\anim_Fire_01
ObjectTemplate.animationEnable 1
ObjectTemplate.animationSpeed 5
ObjectTemplate.animationFrameCount 4
ObjectTemplate.animationFrameCountX 2The template kinds#
| Script type | What it emits | Simulated by | Retail |
|---|---|---|---|
EffectBundle | nothing itself: starts and stops its children, speed / altitude / engine modifiers, camera shake | bf2-effects bundle.rs | BF2.exe EffectBundle (C!0x006424b0) |
SpriteParticleSystem | camera-facing quads (sorted, additive or point sprites) | bf2-effects psys/sprite.rs | RendDX9.dll!0x1017fb00, update 0x10180ba0 |
MeshParticleSystem | small meshes (mp_spark2, debris) | psys/mesh.rs | 0x101849f0 |
TrailSystem | ribbons behind a moving point | psys/trail.rs | 0x1017b7d0 |
ParticleSystemEmitter | spawns other systems | psys/emitter.rs | 0x101823e0 |
NonScreenAlignedParticleSystem | quads with their own orientation (shock rings) | psys/nsa.rs | 0x1017d600 |
Emitter, Particle | physics debris objects | the game objects | C!0x00647d20 |
Every particle property line is forwarded to a field of the renderer's template (the full map: notes/subsystems/effects.md section 2.2, checked on 253,870 property lines of 3,830 retail templates). Graphs such as sizeGraph 0/0/7/-1 are four coefficients over the particle's normalised age (graph.rs); distributions such as CRD_UNIFORM/0.5/0/1 are random ranges (dist.rs). The sprite, mesh, trail, NSA and emitter simulations reproduce the retail arithmetic in the client's single x87 precision, verified bit for bit against the retail code run natively (sprites: 22,749 dump lines over 10 scenarios, 0 differences).
Sprite atlases#
A sprite system has one texture. With animationEnable 1 the texture is an atlas of animationFrameCount frames, animationFrameCountX across; each particle steps through them at animationSpeed frames per second (with animationPlayOnce the speed becomes frame count / time to live), optionally from a random start frame. The frame size is 1 / animationFrameCountX of the texture unless setAnimationFrameWidthRelative / HeightRelative set it (the animationFrameCountX setter recomputes both; RendDX9.dll!0x10177160 re-applies the atlas coordinates). The fire above is a 128 x 128 DXT5 texture with four 64 x 64 frames.
Per game#
| BF2 | 2142 | Heroes 1.126 | |
|---|---|---|---|
| effect files | Objects/Effects in the Objects_server/client.zip pair | the same layout | Objects/Effects_server.zip (1,224 entries, 582 .tweak) and Effects_client.zip (243 entries: textures, particle meshes) |
| templates | the six kinds above | the same, plus noRotationFromParent (the owner's position without its rotation, psys/mod.rs owner_position_world) and the heat shimmer shader type (SpriteSystem::init_2142, RendDX9.dll@2142!0x1013f6a0) | 2142's template set (the product runs the 2142 engine generation) |
| renderer | RendDX9.dll particle code | RendDX9.dll@2142 addresses, same behaviour per kind | the same kinds |
How it is tested#
- Every effect template property of the shipped scripts goes through the port's model (
crates/bf2-effects/tests/retail_scripts.rs): each script in the archives and loose under the mods is read, and a property the model does not know fails. - The particle code against the original's (
oracle.rs): the original renderer's own sprite, mesh and trail systems are run and the port must match bit for bit (effects and particles). - Heroes' trail templates in a process of their own; Battlefield 2's bundle functions run again in a 2142 process.
This page cites addresses of the reader, not of the particle code; those the format tests hold by reading every shipped file.
Where it is read and drawn#
| Step | bf2-rs |
|---|---|
| templates and properties | bf2-objects (the CON system), bf2-effects props.rs / props_table.rs, psys/template.rs |
| simulation | bf2-effects psys/* |
| draw | bf2-render particles.rs (sprites), meshparticles.rs, trails.rs, nsa.rs |
| the picture | bf2_editor --template e_exp_medium (bf2-editor), the atlas through bf2-texture examples/texture_mips.rs |
The particles are drawn in the transparency block, stage 11 of the render pipeline; the template tree of a whole vehicle, effects included, is on objects.
How these templates run (the bundle's events, the particle's step, the pools): effects and particles.
docs/dev/assets/effects.md · built from bf2-rs e3b4f05 · part of the Battlefield 2 / 2142 / Heroes reimplementation. Not affiliated with EA or DICE.