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

What goes into a texture

Almost every texture in the three games is a DirectX DDS file: block-compressed, with its mip chain already in the file, so the loader copies bytes straight to the GPU. Names matter: a suffix tells the loaders what a map is for.

BF22142Heroes

DDS and the mip chain#

bri_jeep_willys.dds, the jeep's colour map: DXT1, 1024 x 512, five mip levels stored after the header, each half the size of the one before.
bri_jeep_willys.dds, the jeep's colour map: DXT1, 1024 x 512, five mip levels stored after the header, each half the size of the one before.

bf2-texture reads a DDS the way the two retail loaders see it (lib.rs module doc): dds.rs Dds::parse computes what D3DX reports (format, size, mip count, cube / volume), Dds::surface(face, level) slices one level, and decode.rs decode_rgba8 decodes it on the CPU. RendDX9's TextureManager (manager.rs) never decodes: it asks for the image info, then copies each level's bytes into the texture, after its own mip clamp and quality skip (a lower texture quality setting drops the top levels).

FormatBits per texelAlphaSeen in (these pages' examples)
DXT14none or 1 bitthe jeep's colour and wreck maps, the house, p_rocks_b.dds (normal), trunk_mt_de.dds (detail)
DXT384-bit explicitch_vehicleglass_b.dds (a vehicle glass normal map)
DXT58interpolated 8-bitsprite_mt_leaftree_03.dds (the leaf sprites)
A8R8G8B8, X8R8G8B8, R8G8B8, R5G6B5, A4R4G4B4, P88-32variesthe uncompressed formats of retail files, decoded and checked against D3DX
TGA (32-bit)328-bitHeroes hero item textures (composed into an atlas, below)

The decoders of the formats retail files use are verified against D3DX (decode.rs decode_rgba8 doc). 2142 and Heroes use the same formats as BF2; the enhanced texture pack's DX10 files (BC4 / BC5 / BC7) are beyond retail (dx10.rs).

Names the loaders act on#

Four conventions: a wreck geometry's second map (_w), an alpha-tested leaf sprite (DXT5, alpha shown over a checker), a bundled normal map (_b) and a detail map (_de).
Four conventions: a wreck geometry's second map (_w), an alpha-tested leaf sprite (DXT5, alpha shown over a checker), a bundled normal map (_b) and a detail map (_de).
  • _b.dds: for a bundled mesh, map 1 ending in _b.dds is the normal map; any other later map that is not a SpecularLUT marks a GI map (bf2-render bundledmesh.rs, BundledMeshStateManager::readState).
  • alpha: the material's alpha mode decides what alpha means: 1 blend, 2 test (cut out at a threshold); with the ColormapGloss technique the colour map's alpha is the gloss.
  • _de.dds: a detail map, tiled over a static mesh's base colour in its own UV set (TEXCOORD 1 + the detail index; bf2-mesh MeshFile::texcoords).
  • _w.dds: the jeep's wreck geometry (geometry 2) takes the colour map plus this second map (materials shows the slots).

Heroes: the hero atlas and the colour tables#

A hero's look is not stored in one texture. Every worn item adds a TGA that is painted into a 1024 x 1024 atlas at the rectangle of its item type; the item meshes' UVs point into that rectangle (bfh-client hero_mesh.rs compose_atlas).

The atlas rectangles of ItemSettings.con (skinnedMeshRenderer.setCustomTextureCoordOffsetAndScale): body and hands share the top half, legs, head, feet and the small items the bottom.
The atlas rectangles of ItemSettings.con (skinnedMeshRenderer.setCustomTextureCoordOffsetAndScale): body and hands share the top half, legs, head, feet and the small items the bottom.

Skin and hair items are drawn grey. Before they go into the atlas each texel is overlaid with the hero's colour from Colors.xml (9 skin tones, 5 hair colours): s < 128 ? 2cs / 255 : 255 - 2(255 - c)(255 - s) / 255 per channel, then blended by the texel's alpha (bfh-client hero_mesh.rs overlay, RendDX9.dll@bfh!0x1013c43f).

BRI_M_Head001_Head001.tga as shipped (grey) and overlaid with skin tones 1, 5 and 9; below, the two Colors.xml tables.
BRI_M_Head001_Head001.tga as shipped (grey) and overlaid with skin tones 1, 5 and 9; below, the two Colors.xml tables.

How it is tested#

  • Every shipped texture goes through the reader (crates/bf2-texture/tests/retail.rs); where the reference table exists, the image's info and its decoded top level are compared with what the game's own DirectX helper library gives.
  • Name resolution (resolution.rs): every material map of every mesh in the object archives and every atlas texture resolves through the file manager as the original's texture manager would.
  • Writing (crates/bf2-gltf/tests/d3dx_parity.rs, nvdxt_parity.rs): the port's DDS encoders against files written by the game's own helper library and by the 2005 editor's converter. Those reference files are small images made for the test.

All of the reading tests need an install and are skipped without one.

Where it is read#

Stepbf2-rs
file detection, image infobf2-texture info.rs detect, image_info
DDS levelsbf2-texture dds.rs Dds::parse, Dds::surface
CPU decode (thumbnails, Flash images, tools)bf2-texture decode.rs decode_rgba8, lib.rs decode_d3dx
TextureManager rules (paths, mip clamp)bf2-texture manager.rs
texture atlases (.tai)bf2-texture atlas.rs
hero atlas and tintsbfh-client hero_mesh.rs compose_atlas, overlay

The per-patch colour, detail and light maps of a terrain are on terrain; the animated sprite atlases of particles on effects.

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