BF2.US bf2-rsdeveloper wiki Parity Discord bf2.us
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.

BF22142Heroes

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:

Effects_server.zip impacts/explosions/e_exp_medium/e_exp_medium.tweak (retail, excerpt)
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 2
e_exp_medium: the template tree the effect bundle starts (bf2_editor --template e_exp_medium) e_exp_medium EffectBundle timeToLive CRD_NONE/1/0/0 S_e_exp_medium_Start Sound soundFilename 5 wav files minDistance 15 em_exp_medium_Fire SpriteParticleSystem textureName anim_Fire_01 particleType Additive emitFrequency 22 emitTime 0.11 timeToLive 1 atlas 4 fram em_exp_medium_fireBoom SpriteParticleSystem textureName glow2 particleType Additive emitFrequency 22 emitTime 0.1 timeToLive 1 em_exp_medium_glow SpriteParticleSystem textureName halo particleType Additive emitFrequency 11 emitTime 0.1 timeToLive 0.8 em_exp_medium_glowring SpriteParticleSystem textureName GlowRing particleType Additive emitFrequency 22 emitTime 0.1 timeToLive 0.6 em_exp_medium_MP_LongSparks MeshParticleSystem geometry mp_spark2 emitFrequency 111 emitTime 0.2 timeToLive 1.6 em_exp_medium_MP_ExpFlash MeshParticleSystem geometry mp_expforce emitFrequency 55 emitTime 0.1 timeToLive 0.6 em_exp_medium_MP_ShortSparks MeshParticleSystem geometry mp_spark2 emitFrequency 55 emitTime 0.2 timeToLive 2 anim_Fire_01.dds: DXT5 128x128 left: the atlas, frame 1 framed; right: frame 1 em_exp_medium_Fire: animationFrameCount 4, CountX 2 frame size 0.5 x 0.5 of the texture animationSpeed 5 frames/s, playOnce 0 particleType Additive, maxSize ? colour = template class; second line: the properties the renderer reads first (bf2-effects psys/template.rs), from the .tweak lines the editor keeps
The template tree of e_exp_medium as the editor loads it: the bundle, its start sound, four sprite systems and three mesh particle systems with the properties the renderer reads first; right: the fire's sprite atlas (anim_Fire_01.dds, 2 x 2 frames) and one frame of it.

The template kinds#

Script typeWhat it emitsSimulated byRetail
EffectBundlenothing itself: starts and stops its children, speed / altitude / engine modifiers, camera shakebf2-effects bundle.rsBF2.exe EffectBundle (C!0x006424b0)
SpriteParticleSystemcamera-facing quads (sorted, additive or point sprites)bf2-effects psys/sprite.rsRendDX9.dll!0x1017fb00, update 0x10180ba0
MeshParticleSystemsmall meshes (mp_spark2, debris)psys/mesh.rs0x101849f0
TrailSystemribbons behind a moving pointpsys/trail.rs0x1017b7d0
ParticleSystemEmitterspawns other systemspsys/emitter.rs0x101823e0
NonScreenAlignedParticleSystemquads with their own orientation (shock rings)psys/nsa.rs0x1017d600
Emitter, Particlephysics debris objectsthe game objectsC!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#

BF22142Heroes 1.126
effect filesObjects/Effects in the Objects_server/client.zip pairthe same layoutObjects/Effects_server.zip (1,224 entries, 582 .tweak) and Effects_client.zip (243 entries: textures, particle meshes)
templatesthe six kinds abovethe 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)
rendererRendDX9.dll particle codeRendDX9.dll@2142 addresses, same behaviour per kindthe 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#

Stepbf2-rs
templates and propertiesbf2-objects (the CON system), bf2-effects props.rs / props_table.rs, psys/template.rs
simulationbf2-effects psys/*
drawbf2-render particles.rs (sprites), meshparticles.rs, trails.rs, nsa.rs
the picturebf2_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.

Source: docs/dev/assets/effects.md · built from bf2-rs e3b4f05 · part of the Battlefield 2 / 2142 / Heroes reimplementation. Not affiliated with EA or DICE.