Skip to main content

.xbm / .xbg — Materials & Meshes

Community-reported

Source: Discord, Far Cry 2 Multiplayer, modding channel, an extended live reverse-engineering exchange between Gabor (unreleased XBM↔XML/XBG↔XML converter, built over "years") and fdx4061 (author of an XBM editor and an XBG texture/material extractor) — the deepest byte-level documentation of this format found anywhere in the community. This section is not independently verified by disassembly; see intro for how RE-verified and community-reported claims are distinguished on this site.

.xbm (materials) and .xbg (meshes) are structurally the same file format under different extensions: "they are the same files in a way, just with a different extension... they have the same structure." An XBM parser can read into an XBG's material data by skipping the XBG-specific mesh content, and vice versa — the section-parsing logic is shared. (The community account names LTMD as that mesh content; it is in fact an embedded material, and appears in only three shipped meshes — see Chunk framing below.)

Container shape​

FourCC-style section tags, stored reversed in the byte stream: HSEM (= "MESH" reversed, the header/section marker), EDON (= "NODE"), DIKS/SULC (submesh/mesh-block data — SULC holds one block per mesh/submesh, each delimited by FFFF marker bytes). A classic reversed-FourCC chunk format.

Section-parsing algorithm (the actual working algorithm behind both Gabor's and fdx4061's independent tools): after the header, the file is a fixed, always-present sequence of sections in constant order; every section begins with a count of the elements it contains, and a count of 0 means skip immediately to the next section. Confirmed section order for XBM materials:

  1. maps (texture references)
  2. reflection (a single f32)
  3. tiling (2 f32s)
  4. colours/RGB (3 f32s — diffuse base colour)
  5. illumination/RGBA (4 f32s)

In practice only one of the colour-RGB or illumination-RGBA blocks is actually populated for a given material, even though the format always reserves space for both. A section reserved for road-texture- only data in FC2 is present but "always empty" outside that use, and is used more heavily in Avatar.

Field types: everything in these sections is f32, except the very last section, which is u32. This was a point of disagreement between the two authors: treating these values as clamped 0–255 RGB integers (as one early editor's UI did) silently loses functionality the engine's real values support — driving a texture's colour value far above normal makes it visibly glow, useful for tiling/glow effects, but only if the values aren't clamped to a byte range.

String padding: every string in these files is followed by a 1-byte zero-padding, consistently.

XBG-only alignment: the start of the actual 3D mesh data inside an XBG must be 16-byte aligned (offset divisible by 16), or the game breaks on load. Does not apply to XBM (material) files, which carry no 3D data — some converters apply the rule to XBM anyway without it mattering either way.

Chunk framing, read out of the engine's own loader​

Verified via reverse engineering

Read out of LoadGeomResource (0x097fd440) in the symbol-bearing FarCry2_server binary, and checked against all 3,133 shipped .xbg. A reader written from it walks every file with zero trailing bytes, and a writer reproduces all 3,133 byte for byte.

The community description above works in practice but treats the chunk header as 12 bytes with the payload immediately after it. The engine reads a 20-byte header, and the payload is addressed backwards from the end of the chunk:

+0x00 u32 tag, stored reversed — 'EDON' in the file is 'NODE' to the engine
+0x04 u32
+0x08 u32 chunk size, including this header
+0x0C u32 payload size
+0x10 u32 sub-chunk count

payload = chunkStart + chunkSize - payloadSize

For every chunk in every shipped file that resolves to chunkStart + 20 — except DNKS, which is the only chunk in the format with a sub-chunk (subChunkCount is 1 in all 3,133 files). Its sub-chunk is SULC, framed the same way, and DNKS's own payload sits after it:

DNKS
+0x00 20-byte header, subChunkCount = 1
+0x14 SULC sub-chunk — per skin descriptor: u32 cluster count, then that many
110-byte clusters (7 x u16 header, then 48 x int16 bone palette)
...
end - payloadSize: u32 descriptor count, then per descriptor:
52-byte meta, u32 name length, name, NUL

That backwards-addressed payload is why parsers written from the community description need a hand-tuned "preamble" constant to find the DNKS name table.

The 52-byte meta is a LOD metric, ten floats of bounds, the LOD tier and a reserved word:

+0x00 f32 LOD metric
+0x04 f32[3] bounding sphere centre
+0x10 f32 bounding sphere radius
+0x14 f32[3] AABB min, over this part's own vertices
+0x20 f32[3] AABB max
+0x2C i32 LOD tier, matching the name's _LOD<n> suffix
+0x30 u32 reserved

The box matches the part's vertices in 16,885 of 16,885 shipped parts, once the comparison allows one position-quantisation step — the bounds were fitted before the positions were quantised to int16. Both are in the part's own space, not model space, so the placement node is not applied. The sphere is a fitted one rather than the box's circumscribed sphere: its radius is the exact distance to the furthest vertex in 99.3% of parts, but its centre is the box centre in only 5.6%, so it comes from a minimal-enclosing-sphere fit. XOBB/HPSB carry the same pair for the whole model, in model space, and their sphere behaves the same way.

The community reads these ten as a bare min/max pair, which holds for 18 of 18,533 — that reading takes the sphere for the box.

Alignment padding is a descending byte counter, not zeros. Nine bytes of padding before the vertex or index section are written 09 08 07 06 05 04 03 02 01. A file padded with zeros still loads, but no longer matches the original byte for byte.

Chunk tags are not unique within a file — objects\lights\torch01.xbg carries two LTMD chunks. A parser that keys chunks by tag silently drops data.

The PC loader reads less than the format carries, and changes two values as it loads. This is CGeometryResource::Load, GOG 0x10351480, (RE-verified):

  • The header. It checks only the major version at +4 (42), the root chunk size at +0x14 and the child count at +0x1C. The hash at +0x08 is never read, and the HSEM magic is never checked.
  • Ignored chunks. CMTL and UTXU are skipped.
  • Primitives. At most 128 primitives per LOD are taken; the count is clamped.
  • Skinned meshes. A mesh with a bone palette entry is treated as skinned. The loader grows its XOBB box by 1 m on every side and doubles its copy of the sphere radius, once per load. The box is the mesh's own, not a copy.

Chunk census​

Every shipped .xbg is version 0x0006002A and carries these ten chunks exactly once: LTMR, EDON, DIKS, DNKS, SDOL, XOBB, HPSB, DOL\0, PMCP, PMCU. Three more appear conditionally:

ChunkEngine nameFilesContents
MB2OO2BM78u32 count, then that many 64-byte inverse-bind matrices, column-major
ADKIIKDA10IK data, 52 bytes per entry. Byte-identical in all ten, all destructible props
LTMDDMTL4 chunks in 3 filesan embedded material, loaded by CMaterialResource::LoadFromGLM

LTMD is therefore not "XBG-specific mesh content an XBM parser skips" as described above — it is a material inlined into the mesh instead of referenced by path, carrying names like Torch01_587110454_0.fakemat. LTMR (RMTL) is the ordinary path-reference material list, and it carries a trailing word after mesh version 41.3, which FC2 (42.6) has.

An inline LTMD has the same layout as an .xbm's; only its first string is filled in. The engine reads every LTMD payload as a string it discards, the material's name, the shader name, then the body below (CMaterialResource::LoadMaterial, 0x09802320 in the Linux server, RE-verified). A standalone .xbm leaves the first string empty. An embedded one puts the name the mesh's LTMR list references there, and its material name is the DNKS part the material applies to (BAT, WOODTORCH01, CLOTHTORCH01, RAG01). Measured on all four shipped chunks, each consuming its payload exactly; the three meshes carrying one resolve their textures only through this path.

DIKS is the part table, and it names each part's placement node​

DIKS (SKID) entries are 8 bytes, not 4, and they are not LOD switch distances. The chunk is a u32 count followed by one entry per DNKS part:

+0x00 u32 CRC32 of the full part name, "FRAME_LOD0" — the exact-case DNKS name
+0x04 u32 (placement node index, or 0xFFFF when none) << 16 | this entry's position

Measured across all 2,922 shipped meshes and 16,885 entries:

ClaimResult
word 0 hashes to a DNKS part name16,885 / 16,885
entry count equals part count2,922 / 2,922
low 16 bits equal the entry's own position16,885 / 16,885
every skinned part carries 0xFFFF1,645 / 1,645

So a mesh states each part's placement node outright, and nothing has to match part names against node names. Matching by name is not merely slower, it is wrong: 291 parts fold to a different node than DIKS names, because those meshes have a node whose own name ends in _LOD0 (ColonialChurchBellRinger_01_LOD0 sits beside the root ColonialChurchBellRinger_01, and stripping the suffix from the part name matches the root). Judged by which placement makes a model's LOD0 geometry fill its own XOBB bounds, DIKS beats name matching in 3 meshes and loses in none; urbanmedium00_gazebo02_part02_bk sits 65% outside its declared bounds under name matching and within 1% under DIKS.

0xFFFF does not mean "no such node exists" — it means no node transforms this part. Both skinned parts and rigid parts already modelled in model space carry it, including ones that do have a same-named node (urbanlarge01_cs_door has nodes s1 and s2 and marks both parts 0xFFFF).

A LOD's geometry is a plain concatenation​

SDOL holds one flat vertex block and one flat index block per LOD, and the submesh table says how they are divided. The division is completely regular, which is what makes an exporter possible:

  • A cluster's vertices are vertex_count of them starting at the running total for its own buffer, counted in submesh order.
  • Its indices are face_count * 3 of them starting at the running total for the whole LOD, also in submesh order, and address the buffer directly.
  • Buffers sit end to end in the vertex block, in buffer order.
  • Nothing is left over at the end of either block.

Measured across every shipped mesh: 29,296 of 29,296 clusters and 9,746 of 9,746 LODs, with no exceptions to any of the four. Two consequences for a reader:

Every vertex is referenced by a triangle — 29,296 of 29,296 clusters have no spare vertices, and no shipped mesh contains a degenerate triangle or a 0xFFFF strip-restart index. A reader that compacts a cluster's vertices down to the referenced set is therefore doing nothing but permuting them, which quietly makes a re-export differ from the original.

cluster.stride always equals its buffer's stride, so it is a duplicate, not an override.

Vertex flags​

A buffer's flags word becomes the vertex declaration in 0x1041d5e0 (GOG), which lays the elements out in this order (RE-verified):

FlagElementBytes
0x0001, else 0x0002position: float3, else four int1612, else 8
0x0004, else 0x0008texcoord 0: float2, else short28, else 4
0x0800, 0x1000, 0x2000texcoords 1 to 3, short2 — only under 0x0008 without 0x00044 each
0x0010four weights and four palette indices8
0x0040, 0x0080, 0x0100, 0x0200normal, colour, tangent, binormal4 each

0x0020, 0x0400 and every bit above 0x2000 add no element. Shipped meshes use only 0x0BCA, 0x0BDA and 0x008A.

EDON node record​

68 bytes, memcpy'd wholesale by the engine, then a length-prefixed NUL-terminated name:

+0x00 u32 CRC32 of the exact-case name — 0 on the root, and not read at runtime
+0x04 u32 first child, 0xFFFFFFFF when none — not read at runtime
+0x08 u32 next sibling, 0xFFFFFFFF when none — not read at runtime
+0x0C u32 parent, 0xFFFFFFFF on the root
+0x10 f32[4] local rotation, xyzw
+0x20 f32[3] local translation
+0x2C f32[3] local scale
+0x38 i32 skinIndex — -1, or an index into MB2O
+0x3C f32 1.0 in all 16,738 shipped nodes
+0x40 f32 the square of the model's HPSB sphere radius — see below
+0x44 u32 name length, then the name, then a NUL

CGeomResource::GenerateMatrices (0x097fc880) builds each node's world transform as parent_world x TRS(scale, rotation, translation), so the scale at +0x2C is live — 121 shipped nodes carry a non-unit value.

+0x40 is the same in every node of a file: the squared radius of the whole model's bounding sphere. It matches HPSB's radius squared to within a relative 3e-5 in every node of 3,124 of the 3,133 shipped files. Only 51 nodes match bit for bit, so a writer should compute r * r and accept the drift. The exceptions:

  • the three meshes that embed their material (bat, torch01, rag_animready), which hold 0x000000FF
  • six more that do not match, w2c4_breakpce_02 among them with 2.3e14

Whether the engine reads the value was not checked. JackAll carries it as it shipped, and BlenderFC2's export rewrites every node's value with the new radius squared whenever it refits the sphere.

The .xbm body, and writing one back​

Verified against the retail corpus

Measured over all 2,379 shipped .xbm files, and round-tripped byte-identically through JackAll's writer.

The community account that an .xbm and an .xbg are the same format is exactly right, and stronger than stated: an .xbm is an .xbg carrying an LTMD chunk and no geometry. All 2,379 shipped materials have the byte-identical chunk layout

LTMD EDON DIKS DNKS SDOL XOBB HPSB DOL\0 PMCP PMCU

so a mesh writer that treats LTMD as opaque already emits a correct .xbm container — 2,379 of 2,379 come back byte-identical with no material-specific code at all. Only the LTMD payload needs its own serialiser.

That payload is a run of counted sections:

cstring discarded by the engine; empty in every .xbm, so 5 zero bytes
cstring material name e.g. SAWEDOFF_SHOTGUN_METAL_CHROME
cstring shader name e.g. Weapon
u32 count, then count x (cstring path, cstring slot) textures — path first, then its slot
for width in 1, 2, 3, 4:
u32 count, then count x (cstring key, f32[width]) float properties, grouped by width
u32 count, then count x (cstring key, u32) integer properties
u32 count, then count x (cstring key, u8) boolean properties — count 0 in all 2,379

cstring is the same length-prefixed, NUL-terminated form the .xbg chunks use. The float sections are what split DiffuseTiling1 (a float2) from DiffuseColor1 (a float3) — a key's width is carried by which group it sits in, not by the key.

A section may repeat a key, so a reader that stores properties in a map loses data. FATHER_MALIYA_HAIRHELMET (worlds/worlds/graphics/_materials/fchappart-m-2008041057227927.xbm) lists OmniSpotLightingDisabled twice in its integer section, both times 1. It is the only material in the set that does, and it is enough to break a byte-exact round trip: keep the entries in file order alongside whatever map the reader exposes.

Shader and slot census​

ShaderMaterials
Generic1,626
Cloth265
Skin142
Weapon102
RealtreeTrunk51
Unlit49
Hair37
Vehicle34
Leaf25
Road18
BigLeaf12
Water7

These counts are corpus-wide across all 2,379 materials, and the distribution is not uniform by shader — NormalTexture1 does not appear on any Weapon material at all. Texture slots, by how many materials name them: DiffuseTexture1 1,964, SpecularTexture1 1,889, NormalTexture1 1,656, MaskTexture1 1,565, DiffuseTexture2 1,503, RimLightTexture 397, BloodTexture 393, FabricTexture 264, PrintTexture 239, ReflectionTexture 222, SkinTexture 142, NormalTexture2 135, MaskTextureBroken 102, BurntDiffuseTexture 51, MaskTexture0 34, SpecularID 25.

How the shader name and the parameters are resolved​

The shader name picks a descriptor from engine\providerdescriptors\descriptors.xml. It ships 21 of them, with RealTreeLeafPure an alias of Leaf and RealTreeLeafHybrid of BigLeaf. The material's keys are matched against what that descriptor declares. The rules, (RE-verified on GOG) (SetShaderName 0x1044EAE0, the material loader at 0x10357420):

  • Names are case-sensitive. Shader names and parameter names are both matched by plain, case-sensitive CRC32. A shader name that matches no descriptor falls back to Error.
  • Undeclared keys do nothing. A key the descriptor does not declare writes nothing to the shader. It is not reported either, so a misspelt parameter fails silently.
  • Widths are converted. A float written to a float2, float3 or float4 parameter fills every component. Written to an int it is truncated, and to a bool it becomes "not zero".
  • Water loads caustics. An exact Water or WaterRiver shader whose descriptor declares CausticsTexture also loads the 32 frames AnimatedCaustics_001.xbt to _032.xbt.

What retail stores against what the descriptor declares​

Measured over all 2,379 materials, the descriptor is not the whole list in either direction:

  • Never stored: a parameter marked hide="1", and every …TilingAndGroup… one. Those are composed from a tiling and a UVGroupMapChannel, which is what materials store instead. ignore="1" does not mean unused: DiffuseTiling1 carries it and 1,647 materials store it.
  • Stored but not declared: LogicalMaterialId on 2,350, VertexColorEnabled 2,159, AmbientOcclusion 1,813, Maskable 394, RainOccluder 209, TwoSided 81, AccessoryCategory 64, Unlit's scroll and frame keys (USpeed, VSpeed, AngularSpeed, AnimType, NbFrames) on all 49, and on every Vehicle the unsuffixed colours and tilings, whose descriptor declares only the Clean/Broken twins and the composed tilings. Where the engine reads these is not traced.
  • Stored narrower than declared: a float4 colour is three floats (11,556 entries), and some declared floats are integers (2,090), both covered by the width conversion above.
  • The unsuffixed colour equals its Clean twin in every Weapon and Vehicle material.

JackAll's material editor and xbm lint offer and check exactly this set: the descriptor without the never-stored parameters, plus the stored-but-undeclared keys for the shaders that carry them. No retail material draws a complaint from it.

The Weapon shader's parameter set​

The 102 Weapon materials add the weapon-degradation system on top of Generic's mask-and-two-layer structure. They are not a superset of Generic's slots: no Weapon material declares NormalTexture1, and the template has no permutation that samples one — see the Weapon pixel shader.

  • MaskTextureBroken and MaskTilingBroken — a second mask, alongside MaskTexture1.
  • A Clean/Broken triplet for every colour. DiffuseColor1, DiffuseColor1Clean, DiffuseColor1Broken, and the same for DiffuseColorBase, DiffuseColor2, SpecularColor1 and SpecularColorBase. The unsuffixed key is what the shader reads; the two suffixed ones are the ends the weapon's condition interpolates between. The shader declares the suffixed keys and never reads them, so the colours are interpolated before the draw — while the two masks are blended in the shader itself.
  • ReflectionTexture and ReflectionPower on 72 of the 102 — a cube map, genericcubemap01 on 51 of them. The sawed-off's black-metal material names graphics\_textures\cubemap\lens_cubemap.xbt at power 0.9.

The mask channels behave as Generic's do, and the pair is where the degradation lives. Measured on the Dragunov's two masks, they differ in exactly one channel:

redgreenblue
MaskTexture1 — clean0.34740.00000.3474
MaskTextureBroken — worn0.32690.39570.3472

Green is the layer-2 blend weight, and DiffuseTexture2 on a weapon material is a rust map — dirtrust_03_d.xbt on both the Dragunov and the Dart Rifle. So a weapon in good condition blends no second layer at all, and the rust arrives as its condition falls. Red and blue barely move; the broken mask is a rust map with the other two channels carried over.

MaskTiling1 is 1,1 on all three of the sawed-off's materials while DiffuseTiling1 runs 6 to 12, which is the shape to expect: the mask is per-model and in the model's own UVs, the detail maps tile over it.

The shading model, read out of the engine's own shaders​

Verified via reverse engineering

Disassembled from the shipped shader objects. Everything in this section is the engine's own code, not inference from the asset files.

Data_Win32/shadersobj.fat carries the compiled shaders under two trees:

TreeBuildNames
engine/shaders/obj/*.pso, .vsoDirect3D 9stripped
engine/shaders/obj10/*.pso, .vsoDirect3D 10 (DXBC)intact

The D3D9 tree is the one that looks like a dead end: the bytecode begins 78 bytes into a proprietary wrapper and carries no CTAB, so every constant is a bare register number. The obj10 tree is plain DXBC from byte 0 with its RDEF reflection chunk intact, which means constant-buffer names, field offsets, sampler names and the template name all survive. Any DXBC disassembler reads it directly:

fxc /nologo /dumpbin shadernumber_06480e00.pso

Filenames are permutation ids, not paths, so the practical way to find a template is to grep the tree for a constant name (DiffuseColorBase, MaskTexture1) and disassemble the hits.

The Generic pixel shader​

Generic covers about two thirds of the retail material set. Two diffuse layers and a mask, where the mask decides both how much of layer 2 shows and how far layer 1's tint travels:

uvD1 = uv0 * DiffuseTilingAndGroup1.xy + uv1 * DiffuseTilingAndGroup1.zw
uvD2 = uv0 * DiffuseTilingAndGroup2.xy + uv1 * DiffuseTilingAndGroup2.zw
uvM = uv0 * MaskTilingAndGroup1.xy + uv1 * MaskTilingAndGroup1.zw

d1 = tex2D(DiffuseTexture1, uvD1)
clip(d1.a - AlphaValues.x) // alpha test, layer 1's alpha only
mask = tex2D(MaskTexture1, uvM)

layer1 = d1.rgb * lerp(DiffuseColorBase, DiffuseColor1, mask.b * saturate(vertexColour.b))
layer2 = tex2D(DiffuseTexture2, uvD2).rgb * DiffuseColor2

albedo = lerp(layer1, layer2, mask.g * saturate(vertexColour.g))
alpha = d1.a

Neither weight is guessable from the asset files, and both are easy to get half-right:

  • Layer-1 tint weight is MaskTexture1.b × vertexColour.b. Reading the vertex channel alone paints the full DiffuseColor1 over the whole surface — on a material whose DiffuseColor1 is a strong colour that turns a weathered wall into a flat repaint.
  • Layer-2 blend weight is MaskTexture1.g × vertexColour.g.

A material naming no mask samples white, which is why an unmasked surface takes its tint at full strength. DiffuseColorBase is not dead data even though the vertex channel is 1.0 on roughly three quarters of retail vertices — the mask is what brings it in.

Sampler bindings are t0 MaskTexture1, t1 DiffuseTexture1, t2 DiffuseTexture2. The Generic constant buffer's 16-byte slots are [1] DiffuseColorBase, [2] DiffuseColor1, [3] DiffuseColor2, [7] DiffuseTilingAndGroup1, [8] DiffuseTilingAndGroup2, [11] MaskTilingAndGroup1.

The Weapon pixel shader​

Verified via reverse engineering

Disassembled from the six obj10 objects that bind MaskTextureBroken and a Weapon constant buffer: shadernumber_50018991, 20788cdb and 8acbc469 with a cube map, 099960bb, a065741b and c078e7d7 without. They differ in shadow and light type; the material maths is the same in all six.

mask = lerp(tex2D(MaskTextureBroken, uvM * MaskTilingBroken),
tex2D(MaskTexture1, uvM * MaskTiling1), _Reliability) * vertexColour.rgb

layer1 = tex2D(DiffuseTexture1, uv * DiffuseTiling1).rgb
* lerp(DiffuseColorBase, DiffuseColor1, mask.b)
albedo = lerp(layer1, tex2D(DiffuseTexture2, uvD2).rgb * DiffuseColor2, mask.g)
specCol = lerp(SpecularColorBase,
tex2D(SpecularTexture1, uv * SpecularTiling1).rgb * SpecularColor1, mask.r)

diffuse = ambient * vertexColour.a + saturate(N·L) * light * shadow
spec = pow(saturate(N·H), SpecularPower) * light * shadow
refl = texCUBE(ReflectionTexture, R).rgb * mask.r * saturate(spec + diffuse) * ReflectionPower

colour = albedo * diffuse + (spec + refl) * specCol

What that settles:

  • Red is the specular weight, and it is applied twice to the reflection — once directly and once inside specCol. A texel at red 0 gets SpecularColorBase and no reflection at all.
  • The reflection is multiplied by specCol, so SpecularTexture1 patterns the cube map as well as the highlight, and it is scaled by how lit the surface is, so it does not glow in shadow.
  • N is the interpolated vertex normal. None of the six samples a normal map, so a NormalTexture1 on a Weapon material has nothing to bind to. Weapon meshes do carry per-vertex tangents and binormals, and the Generic template does sample a normal map — including in permutations alongside specular, reflection and mask. First-person items already draw that way: the cell-phone detonator, the IED kit and the Ithaca's 12-gauge shell are Generic materials with normal maps. Retail normal maps are DXT5, read with X in alpha and Y in green.
  • _Reliability blends the two masks; the Clean/Broken colour pairs are declared and unread.
  • Vertex colour weights all three mask channels, and its alpha scales the ambient term only.

The Weapon constant buffer's 16-byte slots are [0] DiffuseColorBase, [1] DiffuseColor1, [2] DiffuseColor2, [3] DiffuseTiling1/DiffuseTiling2, [10] MaskTiling1/ MaskTilingBroken, [11] SpecularColorBase, [12] SpecularColor1, [13] SpecularTiling1 and SpecularPower, [18].x ReflectionPower, [19].y _Reliability.

The Cloth and Skin pixel shaders​

Verified via reverse engineering

Disassembled from the obj10 objects that name FabricTexture and SkinColor (for example shadernumber_1c5dcae1 and shadernumber_e837c335). Neither shader has an option-free permutation, so they are found by constant name rather than by CRC32("Cloth").

Character clothing and skin use their own templates rather than Generic. uvG(n) is the UV set that UVGroupMapChannel<n> names; unlike Generic, each texture's group is fixed by the shader.

Cloth
fabric = tex2D(FabricTexture, uvG(1) * FabricTiling)
mask = tex2D(MaskTexture1, uvG(0))
print = tex2D(PrintTexture, uvG(2) * PrintTiling)
blood = tex2D(BloodTexture, uvG(3) * BloodTiling)
layer1 = fabric.rgb * lerp(BaseColor1, BaseColor2, vertexColour.b)
albedo = lerp(layer1, print.rgb, mask.g * vertexColour.g) * lerp(1, blood.rgb, vertexColour.r)
alpha = fabric.a
spec = lerp(SpecularColorBase * mask.b, SpecularTexture1 * SpecularColor1, mask.r)

Skin
skin = tex2D(SkinTexture, uvG(1))
mask = tex2D(MaskTexture1, uvG(0))
blood = tex2D(BloodTexture, uvG(2) * BloodTiling)
albedo = skin.rgb * lerp(PalmColor, SkinColor, vertexColour.b) * lerp(1, blood.rgb, vertexColour.g)
spec = mask.g * (SpecularColorBase at SpecularPower + SpecularColor1 at PeekSpecularPower)

Unlike Generic, the tint pair is weighted by the vertex colour alone, not by the mask. Cloth's print texture is not tinted. BloodTexture is dirt on most retail clothing (c_cm_dirt_02_d), and a character kit swaps it for a beard on a face (see kit picks). Hair is Generic-shaped: DiffuseTexture1 × DiffuseColor1, with a highlight from SpecularTexture1 × SpecularColor1.

The Vehicle pixel shader​

Verified via reverse engineering

Disassembled from the obj10 objects that bind MaskTexture0 and a Vehicle constant buffer, for example shadernumber_64691a95, the normal-mapped permutation without a cube map.

A car's paintwork is one Vehicle material, for example DATSUN_BODY or ROVER_BODY_PAINT. It has no painted colour texture. The textures it combines:

  • MaskTexture0, a per-model mask in the model's own UVs, such as datsun_ext_m or rover_m.
  • DiffuseTexture1, a tiling neutral detail: grey.xbt or diffusevariation_d, at tiling 1 to 6.
  • MaskTexture1, the shared dirt02_m: a splash rising from the bottom edge.
  • DiffuseTexture2, the dirt layer: clay02_d on every car.
m0 = tex2D(MaskTexture0, uv0) * saturate(vertexColour.rgb) // untiled
m1 = tex2D(MaskTexture1, uv1) // untiled
dirty = saturate(saturate((m1.r + dirtBlendFactor - 1) * 4) + m0.g * dustBlendFactor * 3)

tint = lerp(lerp(BaseClean, BaseBroken, dirty), lerp(Color1Clean, Color1Broken, dirty), m0.b)
layer1 = tint * tex2D(DiffuseTexture1, uv * DiffuseTiling1)
layer2 = tex2D(DiffuseTexture2, uv * DiffuseTiling2) * lerp(BaseClean, Color2Broken, dirty)
albedo = lerp(layer1, layer2, dirty)

N = lerp(flat, tex2D(NormalTexture1, uv * NormalTiling1), m0.b)
specCol = lerp(SpecBase, tex2D(SpecularTexture1, uv * SpecularTiling1) * Spec1, m0.r * (1 - dirty))
colour = albedo * diffuse + pow(N·H, SpecularPower * 8) * light * specCol * (1 - 0.8 * dirty)

What that settles:

  • MaskTexture0's channels:
    • Red is how much the paint shines.
    • Green is where dust collects.
    • Blue weights DiffuseColor1 (paint) against DiffuseColorBase (base), and the normal map's strength.
  • Clean and Broken mean clean and dirty, blended per pixel by dirty, not damage. The paint table writes one colour to both halves of each pair (see Paint), so on a painted car the pair never differs.
  • dirtBlendFactor and dustBlendFactor come from the archetype's fDirtFactor and fDustFactor. Retail cars have dirt 0, which keeps the bottom splash off.
  • The second UV set runs along the car and up its height, from 0 at the sills. dirt02_m is sampled on it untiled, so its splash sits along the bottom of every car.
  • ColorOverride, Glass and GlassInterior are declared but unread by this object. The override is applied on the CPU.

Every car body material has this layout, whatever its tiling:

  • Datsun: datsun_ext_m
  • Rover: rover_m
  • Big truck: bigtruck_ext_m
  • Buggy: buggybody01_m
  • Jeep Wrangler: jeepwrangler_body_m
  • Jeep Liberty: jeepliberty_m
  • Quad: quad_dlc_m
  • Unimog: unimog_ext_m_multi and unimog_ext02_m_multi, one per paint material.

The Datsun's mesh splits the body into parts, each with its own island in datsun_ext_m:

  • the hood and trunk, a single body-material cluster each, intact and damaged;
  • each door, alongside the interior materials;
  • the chassis, holding the roof, fenders and a side view.

The two doors share the same UVs, and the side view serves both sides. The mask is therefore mirrored, and a patch painted on one side shows on the other.

Tiling and the "group" half​

Each …TilingAndGroup constant is float4(tilingU, tilingV, groupU, groupV). The .xy half scales UV set 0 and the .zw half scales UV set 1, so a texture bound to the second set carries its tiling in zw and zeroes in xy. The .xbm stores the two halves apart: DiffuseTiling1, DiffuseTiling2 and MaskTiling1 as float2, plus UVGroupMapChannel0..3 mapping a group index to a UV channel.

UVGroupMapChannel0 is 0 on every retail material and layer 1 always sits on group 0, so layer 1 always reads UV set 0. Which group the mask and layer 2 use is not recorded in the .xbm — only the group-to-channel table is — and correlating tiling values against the table does not recover it, so that mapping is open.

Tiling is a real number, not a formality: 1,227 of 2,235 retail materials tile at something other than 1, up to 20×.

The lighting around the albedo​

The same shader family shows what the engine does with the albedo once it has it. The terrain pixel shader (the mesh templates share the structure) computes:

sun = _LightColor * shadow // shadow: the baked self-shadow map
ambient = lerp(hemiGround, _SkyColor * hemiAO, N·up * 0.5 + 0.5)
colour = albedo * (ambient + saturate(N·L) * sun)
+ specularColour * sun * pow(saturate(N·H), shininess)

Three structural facts, each visible if a renderer gets it wrong:

  • The ambient is a directional hemisphere, not a scalar — a ground colour below, a sky colour above, blended on how far the normal points up.

  • Ambient and sun add before the albedo multiplies, so a fully lit surface runs brighter than its texture and a shadowed one keeps colour from the sky term.

  • Specular is a separate additive Blinn term. The .xbm carries its inputs as SpecularColorBase/SpecularColor1 — the same pair shape as the diffuse tints. On Weapon and Cloth the pair is lerped by the mask's red (see the Weapon pixel shader), which is why a high SpecularColorBase makes a surface glossy everywhere the mask asks for nothing.

    With SpecularPower; measured across the 2,208 retail materials, 2,129 carry a non-zero power — mostly 2–20 with a mode of 8, broad lobes — but weapons run tighter and higher than that band: the Dragunov ships 30. 466 author colours past 1 up to 2.0, and 1,743 name a SpecularTexture1 that scales the highlight per texel. A renderer without that map has to tame the authored colours or a highlight covers half the surface.

    A retail weapon's full triplet, for scale: Dragunov SpecularColorBase 0.043, SpecularColor1 2.0, SpecularPower 30 — a dim floor everywhere plus a tight, over-1 highlight where the mask allows one.

  • The baked terrain shadow scales the sun rather than replacing N·L — see .sdat.

Vertex layout, measured across the retail set​

Verified against the retail corpus

Measured over all 2,922 .xbg files in worlds.fat, and cross-checked against the vertex shader that consumes them.

  • Two UV sets. 2,905 of 2,922 meshes (99%) carry UV set 1 — bit 0x0800, part of the common 0x0BCA static layout. None carry a third. The second set is what the tiling "group" half reads.
  • UV decompression is the PMCU chunk. The vertex shader runs both texcoords through one _MeshDecompression.zw pair as raw * scale + translate, which is exactly PMCU's translate and scale. UVs stay in D3D space, where V=0 is the texture's top row.
  • Vertex colour is a mask, stored BGRA. The vertex shader emits it as colour.zyxw, i.e. it swizzles the buffer's BGRA into RGBA before the pixel shader sees it. Green and blue are the two blend weights above; every mesh in the set carries the attribute. It is real data, not padding: across 8,550,866 shipped LOD0 vertices, 45.3% carry a non-white RGB. A writer that emits white is asking for both weights at full strength, which is right for a weapon (the sawed-off and the AK-47 are white in RGB, varying only in alpha) and wrong as a general default.
  • Triangles wind clockwise around their authored normal — the D3D convention. Measured at 99–100% per file across characters, vehicles, props and buildings. Renderers that assume OpenGL's counter-clockwise default will treat every outward-facing triangle as back-facing, which silently breaks backface culling and any lighting that keys off facing.
  • Vertex-format flags seen in retail: 0x0BCA (static, 32-byte stride), 0x0BDA (skinned, 40-byte), 0x008A (16-byte).

Parts, damage states and wardrobes​

Verified against the retail corpus

The DNKS chunk names each drawable block, and that name — not its index — is the part's identity. Names carry a _LOD<n> suffix which is the LOD tier, and the same part appears once per tier.

A rigid part's vertices are stored around its own pivot, not in model space. What places it is an EDON node — and DIKS names which one, so this needs no name matching. Take that node's world matrix and transform the part by it. Skip this and every wheel, door and bumper piles up at the model origin. Roughly half of retail parts have a non-identity placement, so the error is obvious on vehicles and invisible on a single-part prop. Sibling parts frequently share one vertex buffer and place it differently, so placement has to be applied per part rather than per buffer.

A part DIKS gives no node sits in the root's space. That covers every skinned mesh — their vertices already sit in the skeleton root's bind space — and rigid parts already modelled in place. The root is at a character's waist, around z = +1.0, so using the wrong one sinks a character to the knees through the floor.

A file holds every state a part can be in, and the engine draws one. Roughly 1,162 parts across the set carry a STATE<n> tag: a vehicle body intact and wrecked, a door closed/ajar/open, a road sign whole and snapped. The lowest number is the intact, closed, unbroken one. The comparison has to be made per part, not per file — 616 part groups in the retail set have no state 1 at all, so a file-wide minimum deletes them.

Character files are wardrobes. characters/mercenaries/merc_kit.xbg holds 111 parts — every head, hat, shirt, vest, trouser, boot and ethnicity-specific arm and chest a mercenary can be built from, 77,193 triangles in total. A single NPC wears about a dozen of them, roughly 7,700 triangles. Which dozen is on the entity, not in the mesh — see hidMeshName.

Character/creature bone palettes​

Verified via reverse engineering

Read out of LoadGeomResource (0x097fd440) and CGeometryResource::ClientProcessRawData (0x097fb3f0), and measured across every cluster in the retail set.

The community tools do not cover this ("I don't know how bone palettes work... that's why I still can't create a character-type xbg" — fdx4061). The chain is:

cluster palette slot → EDON node → that node's skinIndex → MB2O inverse-bind matrix.

Each 110-byte cluster inside SULC ends with 48 int16 palette slots. A slot holds an index into the file's EDON node array, not a bone id from any external file. Every EDON node carries an i32 at +0x38: -1 when the node is not a skinning bone, otherwise its index into the MB2O array of inverse-bind matrices. Across the 78 skinned files those indices form a clean permutation of 0 … MB2O count − 1, and the MB2O count equals the file's skinned-node count in every one.

Every palette slot in the retail set resolves to a node whose skinIndex is not -1 — 3,953 of 3,953 non-empty palettes.

Padding rules, measured over all 32,170 clusters:

Count
Static cluster (fmtFlags & 0x0010 clear) — all 48 slots -128,217 / 28,217
Skinned cluster — at least one bone3,953 / 3,953
Skinned palette is a contiguous prefix of indices, then -1 padding3,953 / 3,953
Skinned palette repeats a bone index within the prefix3,841 / 3,953

The rule that a skinned palette must never contain -1 is wrong — every skinned palette in the game is -1-padded, and duplicate indices inside the prefix are normal. The engine's only use of the palette at load is the final loop of LoadGeomResource, which scans all 48 slots and sets a single "has any bone" flag if any slot is not -1. The constraint a writer must actually hold is narrower: every slot a vertex's BLENDINDICES refers to has to be non--1.

Animation binds by name, not by index: CGraphicComponent::BuildSkeleton (0x094ac0b0) walks the nodes into CSkeletonBuilder::BeginAddBone(nameId, matrix), where nameId is the CRC32 of the node's exact-case name. An .xbg node and a .skeleton bone are the same bone when those hashes match, which is why a replacement model must keep part and bone names byte-identical. See .mab for how a clip then addresses those bones by skeleton bone id.

A container can be authored, not just edited​

Verified against the retail corpus

XbgAuthorTests rebuilds each shipped mesh from its decoded content and requires the bytes back: 3,133 of 3,133 byte-identical.

Editing a container in place preserves whatever was not understood, which is why exporters do that — and why none of them can add a part or an LOD. Originating one instead requires knowing which fields carry information and which are bookkeeping. Almost all of them are bookkeeping:

FieldDerived from
every chunk size, payload size and sub-chunk countthe body written under it
every chunk's word0constant 1, on all ten mandatory chunks and on SULC
header_words[1], [2], [4]constant 0
header_words[3]the file size, less the 12 bytes that precede it
DOL\0the LOD count, then a constant 98
node nameId, first child, next sibling, skinIndexthe name, and node order
node +0x3Cconstant 1.0
DIKS entries and their orderone per part, in part order, keyed by the part's name
part reservedconstant 0
part LOD tierthe _LOD<n> suffix on the part's own name
cluster.stride, cluster.flagsthe buffer the cluster draws from
cluster.face_count, vertex_countthe geometry
VertexBuffer third wordthat buffer's own vertex count
VertexBuffer fourth word, submesh.index_offsetthe running layout
submesh trailing wordssee below

A submesh's three trailing words are [last vertex index, byte offset, 0] — the index is start + vertex_count - 1 within its buffer, and the offset is buffer.offset + start * stride, absolute in the LOD's whole vertex block rather than relative to the buffer.

The two readings differ only when a LOD has a second buffer, and just six LODs across 1_grassjungle_b.xbg and 1_grassjungle_c.xbg do. The relative reading matches 3,131 of 3,133 files, so those two meshes are the entire evidence that distinguishes them.

Two fields carry information nothing else supplies, so a writer has to keep them:

  • header_words[0], a per-file value that is not a CRC32 of the file name, the stem in any casing, or the body.
  • LTMR's trailing word, zero in 3,114 files and 1 to 3 on nineteen grass meshes. It equals the material count on 17 of those 19, which is a coincidence rather than a rule — it is zero on every other mesh, and those have materials too.

Everything else a writer needs — node transforms, part and model bounds, the quantisation scales, vertex format flags, bone palettes, material paths and LOD distances — is content rather than bookkeeping, and a decoded model holds it already.

Adding a part to a model that shipped without one​

Verified against the retail corpus

XbgAppendTests gives every shipped mesh a part it never had, writes it and reads it back: 3,133 of 3,133 take one, with every original part's vertices and triangles unchanged.

Because the table above is derived rather than stored, appending a part is mostly a matter of not disturbing what is already there:

  • Append, never insert. A DIKS entry stores its own position in its low 16 bits and every submesh names its part by index, so adding at the end leaves both alone. Inserting renumbers every part after the new one.
  • A part and its DIKS entry are one thing. The two lists must stay the same length — the writer refuses otherwise — so whatever adds a part adds its placement entry with it.
  • Borrow a vertex format rather than inventing one. A LOD's buffer has a fixed layout, and a new cluster has to fill every channel that layout declares. Taking the format from a part already in the LOD guarantees both that it is one the file carries and that the channels are fillable.
  • Reuse the existing buffer. 10,456 of 10,462 shipped LODs have exactly one, and every offset and count in it is re-derived on write anyway.

What no rule supplies is the part's LOD metric, whose semantics are undocumented; copying it from a part at the same tier is the only guidance the shipped set offers.

Two things sit outside the container and do not follow from adding a part. CGraphicComponent carries one entry per part keyed by a CRC32 of the exact-case name, and hidMeshName — empty on almost everything, which means draw the whole file — names which parts to draw. A part added to the mesh alone is expected to draw, but anything wanting its own placement or animation binding is an entity edit as well.

Authoring ceilings​

Verified against the retail corpus

Measured over all 3,133 shipped .xbg files: 32,170 clusters and 10,462 LODs.

Indices are u16 throughout, and a cluster stores its own counts in u16 as well, which puts three hard ceilings on anything written. Retail sits just under all three — the art pipeline was clearly built against them:

CeilingLimitHighest shipped
Triangles in one cluster (face_count * 3 is a u16)21,84521,351 — bargearmsbazard_multi
Vertices addressed by one LOD's buffer65,53556,961 — merc_kit LOD0
cluster.vertex_count65,53529,965 — bridge_end_multi

The triangle ceiling is the one a donated mesh hits first, and it is per cluster, not per part or per LOD — a part with three clusters can draw 65,535 triangles between them. The vertex ceiling is per buffer, and 10,456 of 10,462 LODs use exactly one buffer, so in practice it is per LOD.

No shipped cluster draws nothing. 0 of 32,170 have a zero face count, so a submesh left empty is a shape the engine is never asked to handle. A writer that cannot fill a cluster should give it a degenerate or sub-millimetre triangle rather than a zero count.

Seven clusters put every UV in one place, and none of them at the origin. Of the 32,170, seven map their whole part to a single point — urbanelectricpole02b at (128.0039, 128.0039), pubboardsquare03 at (-3.0001, -3.0001), jeepwrangler_taxi's DASHLIGHT at (0.048, 0.643). So flat mapping is a thing the art pipeline did on purpose, and flat mapping at (0, 0) is not: that is the shape a UV layer nobody unwrapped takes, and no shipped part has it.

Four material names of 7,496 are embedded rather than named. Three meshes — bat.xbg, torch01.xbg and rag_animready.xbg — carry their material in their own LTMD chunk instead of pointing at an .xbm file, and none of them is a weapon. See the .xbm body for why the two layouts cannot be read with one reader.

Import/export tooling​

The supported route is tools/BlenderFC2, which reads and writes .fc2model packs rather than the container itself — JackAll decodes and re-authors the .xbg, so the add-on carries no format code. What follows is the community landscape it grew up alongside.

Dunia-Engine-XBG-Blender-Importer (Quiet_Joker) is the current working answer to custom mesh import, as of v3.0. Originally built for Avatar: The Game, ported from a Blender 2.49b-era script lineage; FC2 support works "more or less" because "Avatar shares the same stuff as far cry 2." Confirmed working: static object import, character import (with some broken clothing/UV-tiling material loading), and a real export/injection workflow — import with "Separate Primitives" on, edit or replace geometry in Blender, select only the objects to write out, then export (the script writes whatever is currently selected). Confirmed broken in v3.0: weapon XBG import (reproduced on the AK-47 and a 1911), HKX (Havok collision mesh) export, and export reliability generally reported by at least one other user. FC2 .xbg files live in Data_Win32\worlds\worlds.fat, not the more obvious common archive. Treat as pre-alpha but actively developed.

A second, separate XBG-injection path was mentioned in passing but not verified or linked further: "the only way of importing xbgs back into the game for fc was to use the unreal engine tool made by id-daemon" — id-daemon is independently credited elsewhere for FCBConverter (see Getting Started).

A modder porting FC2 models into FC3 (Ganic, several models ported) hit the same wall from the opposite side: raw geometry porting works, but there's no clean .xbm (material) converter, and rebuilding an .xbg from scratch fails on material indices/bone weighting.

A cross-game skeleton-reading tool (SkeleTree, fdx4061) works across Avatar (2009), Far Cry 2, and Far Cry 3 — direct evidence these three titles share a compatible skeleton/rig format at the binary level, beyond the broader Dunia lineage.

.spk filenames are themselves hashes (e.g. 004492b8.spk), consistent with the hash-based naming established for FCB/archive content — see .spk.