Texturing a replaced weapon
mods/vss-vintorez, which replaces the Dart Rifle, has been through this end to end. Every number on
this page is measured off it or off the retail set, and says which.
Replacing an existing weapon gets a donated mesh into the game wearing somebody else's materials. This page is the other half: taking that model's own texture set and getting it onto the weapon, without repainting whatever you borrowed the mesh from.
It is a smaller job than the mesh and it fails in fewer ways, but the ways it does fail are all silent. Nothing warns you that a material is shared, that an albedo is too dark to light, or that a specular floor is sitting under every texel on the gun.
The shader has no albedo slot
This is the fact the whole page hangs off. Weapon and Generic build colour out of two shared,
game-wide tiling detail maps blended by a per-model mask:
layer1 = DiffuseTexture1 * lerp(DiffuseColorBase, DiffuseColor1, mask.b * vertexColour.b)
layer2 = DiffuseTexture2 * DiffuseColor2
albedo = lerp(layer1, layer2, mask.g * vertexColour.g)
A weapon's own two .xbt are its damage-state masks, not its colour. So a donated colour map has
nowhere to go until you rewrite the .xbm to give it one. See
.xbm/.xbg for the full parameter set and where the formula was read
from.
The rewrite is four lines:
| Slot | Set to | Why |
|---|---|---|
DiffuseTexture1 | your albedo | layer 1 becomes the weapon's own texture instead of a tiling detail map |
DiffuseTiling1 | 1,1 | so it lands on the model's UVs instead of repeating |
MaskTexture1, MaskTextureBroken | your control map | both, or a degraded weapon falls back to the old mask |
DiffuseColorBase, DiffuseColor1 + Clean/Broken | equal to each other | so no weapon condition and no vertex channel can re-tint it |
Your control map then holds green at 0 so the second tiling layer never blends, and blue at 1
so the tint weight is full. With blue pinned, DiffuseColor1 stops being a lerp end and becomes a
plain per-material multiplier — which is the knob you set the weapon's overall level with.
The Clean/Broken pairs and the second mask are the degradation system: a weapon interpolates
between them as its condition falls, which is how a rifle gets visibly filthy. Setting each pair to
the same value and pointing MaskTexture1 and MaskTextureBroken at the same texture leaves
nothing to interpolate, so the weapon looks identical at every condition however much it is used.
It never affects the weapon mechanically — it still jams and still breaks, it just never looks it. Getting the look back needs a second control map, which needs a third texture path, which is not the obstacle it appears to be.
A weapon owns exactly two texture paths — its damage-state masks. That is enough for one albedo and one control map. It is not the ceiling it looks like, though; see below.
A weapon is not limited to the texture paths it owns
A texture at a path that exists in no shipped archive, in no hashlist, and in no world's depload
loads from patch.dat and renders.
The canary: a solid magenta 1024² texture staged at
graphics\weapons\special\dart_rifle\vss_test_d.xbt — an invented path — with the material's
DiffuseTexture1 pointed at it. The gun renders magenta.
What that means in practice:
- No hashlist entry is needed.
tools/JackAll/assets/fc2.hashlistis JackAll's hash→name dictionary for extraction;mod buildCRC32s the layer path directly, and the engine only ever asks for the hash. The one cost is thatarchive extract --namescannot resolve your new file's name afterwards, so it lands under_unknown\<hash>. Compute the hash yourself to find it: CRC32 of the path, lowercased, backslash-separated. deploaddoes not gate it. At least for a texture reached through a material that is itself indepload— which is the case that matters, since your material is one the replaced weapon owned.- So a weapon can have as many textures as it needs, a second control map for the degradation
look among them. A normal map is not one of them, for a different reason: the
Weaponshader samples none.
The canary borrowed its .xbt header from a UI icon, a texture with no _mip0 companion. A texture at
a new path needs no donor: jackall-cli xbt build <name>.dds with no header XML beside it
writes a fresh header that names no companion (.xbt). That is
backed by the engine's code, but a fresh header has not been tried in game yet. Either way you get a
single self-contained file; put the whole mip chain in it with texconv -m 0 rather than splitting
the pair by hand.
Step 1 — find a material you are allowed to own
The mesh moved to a new .xbg path. Its material and texture references did not. If you built
your model inside a donor's pack, your weapon is drawing through that donor's .xbm files — and the
donor is still in the game, drawing through the same ones. Rewriting them retextures both.
The VSS is the worked case. Its .xbg sits at the Dart Rifle's path and names seven materials, every
one of them the Dragunov's, because that is the pack the mesh was built in.
JackAll can make a material at a new path — xbm new, New material… on the Files tab, or
fc2model add-material straight into a pack — but a material at a path the game never listed has
not been tried in game. A texture at a new path loads (above);
a material may not. Until one is tried, take a material the replaced weapon owned. Your mod already
made it unused — you overwrote the mesh that was its only reader.
Build the reference index and ask:
jackall-cli mod restore --game "C:\Games\Far Cry 2"
jackall-cli xref build --game "C:\Games\Far Cry 2"
jackall-cli fc2model export graphics/weapons/special/dart_rifle/dart_rifle.xbg \
--game "C:\Games\Far Cry 2" -o dartrifle.fc2model
jackall-cli fc2model inspect dartrifle.fc2model
Restore first, so the index describes the vanilla install rather than your own patch. The role
column then reads owned or shared per file, and owned outside the model's own folder means
exactly one file uses it — see .fc2model. Without the index that
column is a directory-rule guess and marks a pooled material shared even when only this model uses
it.
On the Dart Rifle two came back owned:
material owned GRAPHICS\_MATERIALS\FBOIVIN2-M-2007050148031384.xbm DART_RIFLE_METAL
material owned GRAPHICS\_MATERIALS\FBOIVIN2-M-2007050162241150.xbm the wood/camo one
jackall-cli xref to <path> confirms it and shows something better: both are already listed in
world1_depload.dat and world2_depload.dat, sited against dart_rifle.xbg. A material at a path
you invented would not be, and that is the untested ground worth staying off.
If nothing comes back owned, there is no material to take, and a material at a new path is the
only route left — the untested one.
Step 2 — repoint the mesh, and append rather than overwrite
A pack carries the mesh as model/mesh.json, where materials is a plain list of paths and every
cluster holds a material_index into it. fc2model add-material appends a material to that list —
at the owned path or a new one, copied from any material — and fc2model assign-material --part FRAME moves one part's clusters onto it at every LOD; fc2model inspect --materials lists the
indices and the parts drawing with each.
Append your material and move only the body's clusters onto it. Do not overwrite the entry that is already there. The reason is specific and easy to miss:
FRAME_LOD0 cluster 4 mat 6 15,651 tris the gun body
ACCESSORY02 cluster 1 mat 6 1,628
CLIP cluster 0 mat 6 318
SLIDE cluster 0 mat 6 556
SCOPE_HI cluster 4 mat 6 144 <- the same material
SCOPE_HI draws through the body's material. It is the zoomed sight picture, calibrated to a camera
you cannot see, and it is the only thing on screen while
zoomed.
Overwrite the entry in place and you repaint 144 triangles of the scope along with the gun. Append,
and the scope keeps what it had.
Two other things that table shows:
- Only one material draws any of the model. The other six carry a single sub-millimetre triangle
each, because
cluster.zero-trianglesis a blocking rule and a transplant fills the clusters it cannot supply. So "the donor's seven materials" is not seven materials to reproduce — it is one. - The cluster index is not stable between LOD tiers.
FRAMEis cluster 4 at LOD0 and cluster 1 at LOD4. Select by material index, not by position.
Step 3 — convert the maps
Modern models ship metallic-roughness; older ones ship specular-glossiness. Neither is what the
engine reads. Roughness is the lossy direction — Blender has no SpecularPower and Dunia has no
roughness.
The conversion is a short numpy script run headless in Blender — a hundred-odd lines that read the source maps, box-filter them down, and write two PNGs.
The albedo needs a band, not a curve
A physically based albedo is far too dark for a shader with no metalness input. A raw PBR source can measure well under 0.10 luma and read as black plastic once lit.
The fix is to fit it into a band with a floor and a ceiling — 0.13 to 0.52, which is also what
tools/BlenderFC2 tells a modeler. Not a gamma lift: a gamma compresses the top, so it burns pale
areas to white under the game's sun while barely moving the darkest metal. And do it in float,
before compression — reaching a metal level from 0.05 needs about 8×, and DXT1 gives red five bits,
so multiplying through DiffuseColor1 afterwards bands it badly.
Anchor the fit on your own source's percentiles rather than hardcoding the curve. The VSS's source luma sat at 0.124–0.534 p1–p99 with a near-neutral 0.072 mean saturation — already inside the target band, so it needed almost no lift. Mapping the source's own p1–p99 onto the band is one rule that serves any source: it is nearly identity for a well-authored one and a large lift for a dark one.
Apply the scale to all three channels off a luma-derived factor, not to each channel independently, or a linear remap shifts hue.
Three smaller traps
- V orientation. Blender holds images bottom-up and a PNG stores rows top-down. Read through Blender and write through a hand-rolled PNG writer that flips, and the two cancel. Get it wrong and every texture is upside down, which no numeric gate can see — look for lettering in a render.
- Size. Retail ships nothing over 2048 and everything power-of-two, but a weapon sits well
under that ceiling: the Dart Rifle's pair is a 512² base with a 10-level chain plus a 1024²
single-level
_mip0, 1.33 MiB for four files, and the Dragunov's is 256²/512². Author at 2048 and ship at 1024 — a 1024²/2048² pair is four times the pixels for a gun that is barely a metre of screen space, and nothing in the game does that. Compared in game on the VSS, retail's tier reads as well as the guns Ubisoft shipped, so the larger tier's extra 4 MB buys nothing. - Ambient occlusion. glTF packs AO in the same map's red channel. A quarter of the VSS's AO sits at zero, which is what a bake leaves outside the UV islands, and multiplying that in bleeds black across island edges at low mips. Check the distribution before you use it.
Step 4 — get the level right
The number that decides whether the weapon reads correctly is what the shader hands the lighting:
effective albedo = DiffuseTexture1 mean x lerp(DiffuseColorBase, DiffuseColor1, mask.b)
Measured across the cases that exist:
| Weapon | DiffuseTexture1 | tint | effective |
|---|---|---|---|
| Dragunov, retail | metalbrushed_d tiled 5,5 | 0.208 | 0.092 |
| Sawed-off, retail | metalbrushed_d tiled 5,5 | 0.405 | 0.180 |
| VSS Vintorez, shipped | its own albedo | 0.640 | 0.213 |
Retail runs 0.09 to 0.18. Note what the retail rows are doing: their DiffuseTexture1 is a bright
generic detail map and DiffuseColor1 brings it down. Under this recipe the texture is the
weapon's own and the tint usually brings it up — but not always, and that is the trap.
The VSS shipped at 2.31× its Dragunov donor's level (0.092 → 0.213) and was confirmed in game. That ratio is the figure here validated by playing, so anchor on it: apply it to your donor's level rather than copying the VSS's absolute 0.213, which belongs to its own texture mean of 0.332 and a neutral tint of 0.64.
Leave the tint neutral unless the source needs correcting. The texture already carries the author's hue.
Set DiffuseColorBase equal to DiffuseColor1 rather than leaving base at white. With the two
equal the tint is a constant no mask channel and no vertex colour can move — which matters because
VertexColorEnabled is 1 on most weapon materials, and with a tint below 1 a white base makes
low-vertex-colour areas brighter rather than darker.
Step 5 — get the specular right
SpecularColorBase is what every texel gets where the mask asks for nothingThe render gates cannot see this. A VSS with a high SpecularColorBase looks correct in every
offline check and reads in game as one polished surface — stock, receiver and suppressor all
equally glossy.
Specular is a separate additive Blinn term, and the pair SpecularColorBase/SpecularColor1 has the
same shape as the diffuse pair, weighted by the control map's red:
specCol = lerp(SpecularColorBase, SpecularTexture1 * SpecularColor1, mask.r)
specular = specCol * pow(saturate(N.H), SpecularPower)
That is read out of the Weapon pixel shader, along with a cube-map term covered
below — see .xbm.
SpecularColorBase is what a texel gets when red is zero. Set it high and no mask can make anything
matte. Measured:
| VSS, glossy build | Dragunov, retail | VSS, 1.0.0 | |
|---|---|---|---|
SpecularColorBase | 0.600 | 0.043 | 0.043 |
SpecularColor1 | 2.000 | 2.000 | 2.000 |
SpecularPower | 8 | 30 | 30 |
| control red p5 / p25 | 0.137 / 0.298 | 0.020 / 0.051 | 0.024 / 0.043 |
| control red p75 / p95 | 0.745 / 0.773 | 0.710 / 0.969 | 0.816 / 0.839 |
| contrast, dullest to brightest | ~2:1 | ~14:1 | ~14:1 |
Two things to copy from that table.
A working weapon's specular control is bimodal. Over half the Dragunov's surface sits at 0.02–0.09 — effectively matte — and a quarter sits at 0.71–0.97. It is not a mid-grey map. The glossy VSS build's was a flat band sitting on a floor higher than the Dragunov's value over half its gun, which is exactly what "polished shoe" looks like.
SpecularPower is lobe width, and low is wide. Retail runs 2 to 20 with a mode of 8; the
Dragunov's 30 is tight enough to keep a highlight on the edge it belongs to. A wide lobe on a weapon
that is mostly tube spreads one highlight across the whole thing.
Shinier means a smaller highlight, not a brighter one. Asked for shinier wood on the VSS, the
player meant the spot, so the material went from 30 to 80 and then, asked again, to 150. The spot's
width at half brightness goes as roughly 1/√SpecularPower — about 12° at 30, 7.5° at 80, 5.5° at
150 — and its peak stays the same; a stronger peak is the control map's red. The normal
is interpolated across each triangle, so curves get a real spot; a flat face has none to shrink, and
a higher power only narrows the angles at which the whole face catches the sun.
Level the metal band, not the mean
Deriving red from a metallic-roughness source is gloss = 1 - roughness, gated down where the
surface is not metal. Two details decide whether it works:
- A low dielectric gate is what separates wood from steel inside one material. The VSS's metallic
map is very nearly binary — p25 of 0.000 and p50 of 0.996 — so a gate of
0.06puts the stock and grip in the same near-zero band the Dragunov puts most of its surface in. A gate of 0.35 leaves them a third as shiny as the steel, which reads as uniformly polished. - Fit the gamma to the metal texels alone. Levelling the mean to a donor's is the intuitive move and it is wrong: the Dragunov's mean is low because more of it is matte, not because its metal is dimmer. Levelling the VSS's mean to the Dragunov's 0.347 dimmed its metal to p95 0.627. Fitting the metal band to 0.80 instead puts both ends where they belong, and lets a weapon that happens to be 57% metal keep a mean higher than the donor's without that being wrong.
Metal is the cube map
The VSS 1.0.0 shipped without this term: the material it took, DART_RIFLE_METAL, is one of the 30
retail weapon materials that declare no ReflectionTexture. Since 1.1.0 it draws through the Dart
Rifle's other owned material, DART_RIFLE_PASTIC, which declares one.
A highlight makes a surface glossy, not metallic: it shows only where the sun's half-vector lines up, and the rest of the time the steel reads as paint. What retail uses for metal is a cube map added on top of it:
reflection = texCUBE(ReflectionTexture, R) * mask.r * saturate(lighting) * ReflectionPower * specCol
It is gated by the same red as the highlight, so a control map that already separates wood from steel
already says where it goes — a texel at red 0 reflects nothing. It is multiplied by specCol, so the
tiled SpecularTexture1 patterns it too, and by the lighting, so it does not glow in shadow.
72 of the 102 Weapon materials declare one, and the split by what the material is made of is sharp
(classed by name, all 102):
| materials | reflection | SpecularPower | tiled SpecularTexture1 | |
|---|---|---|---|---|
| metal | 56 | 44 at 0.2–1.0 | 3–30, median 12 | infra_bridges_metal_s, metalweapon02_s |
| plastic | 20 | 19 none or ≤ 0.1 | 2–30, median 10 | infra_bridges_metal_s, plasticbump_01_s |
| wood | 16 | 11 none or ≤ 0.1 | 3–16, median 5 | genericwood_02_s, all 16 |
The Desert Eagle is the far end, and the clearest view of how the look is built. Its control map's red is 1.0 over the whole gun, its albedo is dark, and the cube map carries the rest:
| Desert Eagle chrome | Dragunov metal | VSS, specular only | VSS as shipped | |
|---|---|---|---|---|
| control red over the metal | 1.00 | ~0.8 | ~0.8 | ~0.8 |
| effective albedo of the metal | 0.14 | 0.092 | 0.221 | 0.081 |
ReflectionTexture | genericcubemap02 | genericcubemap01 | none | genericcubemap01 |
ReflectionPower | 0.8 | 0.4 | — | 0.2 |
cube-map weight, mask.r × ReflectionPower × specCol | 0.72 | 0.27 | 0 | 0.14 |
SpecularPower | 15 | 30 | 30 | 150 |
Copying the Dragunov's specular triplet without the reflection that goes with it leaves the cube map out entirely (the third column). Taking the Dragunov's reflection too, at 0.4 over steel halved to 0.113, plays too light and too reflective. The VSS ships with the steel's albedo cut to 35% and the cube map at half the Dragunov's. The albedo is scaled by the control map's red — the channel that gates the cube map — so what a texel loses in diffuse tracks what it gains in reflection.
Relief is a specular pattern, not a normal map
The AR-16's stock looks pebbled — the tops of the bumps lit differently from the valleys. That is not
a normal map. The gun's plastic, M16_CAMOE_PLASTIC — the only material on it with a bump pattern —
tiles plasticbump_01_s 25×25 as its SpecularTexture1 at SpecularColor1 2.0, with
genericcubemap01 at 0.1. That texture is a dark field, mean 0.17, with the top of every bump
painted bright. Since both the highlight and the cube map are multiplied by specCol, the tops shine
wherever the stock is lit and the valleys stay dark.
No Weapon material declares NormalTexture1, and none of the shader's six permutations samples
one — the normal it lights with is the interpolated vertex normal. So relief on a weapon material is
either a tiled specular pattern like that one, or shading baked into the albedo and the control map.
A true normal map needs a Generic material. That template does sample one, weapon meshes already
carry tangents and binormals, and first-person items draw that way in retail — the cell-phone
detonator and the IED kit. What it costs is the worn look: Generic has no MaskTextureBroken and
no condition-driven colours. On wood, which the worn map leaves
unrusted anyway, that is only the darkening. Untested on a weapon body.
Step 6 — give it a degraded look
Once a third texture path is available the degradation system works as authored, and it is a small job. Measured on the Dragunov's own pair, a clean and a broken mask differ in one channel:
| red | green | blue | |
|---|---|---|---|
MaskTexture1 (clean) | 0.3474 | 0.0000 | 0.3474 |
MaskTextureBroken | 0.3269 | 0.3957 | 0.3472 |
Green is the weight on DiffuseTexture2, which on a weapon material is the game's own rust map —
dirtrust_03_d.xbt on both the Dragunov and the Dart Rifle. So the painted map says where rust
appears, not what it looks like, and green at 0 on the clean mask is exactly why a weapon following
the recipe above never grimes.
The whole change is:
- A second control map at a new path, identical to the clean one but with the painted rust in green. Retail spans the full range and averages about 0.40; paint coverage, not colour.
MaskTextureBrokenpointed at it instead of at the clean map.DiffuseColor1BrokenandDiffuseColorBaseBrokenmoved off the clean tint, so the weapon darkens as well as rusting. The worked example uses0.50, 0.47, 0.44against a clean0.64.- Leave
DiffuseColor2*alone. That is the rust layer's own colour and vanilla already brightens it from 0.31 to 1.54 as a weapon wears — flattening it is what kills the effect.
The mask shares the model's UVs, so paint it over the albedo as an underlay. On the worked example the wooden stock, handguard and grip are painted black: wood does not rust, and a rust map that covers them reads as obviously wrong.
To see it without firing 200 rounds, drop iClipsForSelfDestruct to 1 in a temporary layer — the
whole condition ramp then runs inside a single magazine. See
jamming and breaking.
Step 7 — ship it
Do the whole thing through a .fc2model pack. The Blender add-on edits it for you: the material's
values in its Far Cry 2 panel, its textures by painting them or picking another image for the
slot, and export marks what changed and recounts the mip chain of a resized texture. By hand, edit
materials/<name>.json and swap the texture PNGs inside the zip, then set origin_sha256 on each
entry you touched — that field's presence is exactly what marks an entry modified — and set levels
to the new chain length (11 for a 1024 image). Either way the applier does the rest:
jackall-cli fc2model extract edited.fc2model -o mylayer
jackall-cli mod build --game "C:\Games\Far Cry 2" --layer mylayer
It re-encodes each PNG in the codec the entry records, generates the mip chain, and splits it
itself — level 0 to the _mip0 companion, the rest to the base file. That removes the whole
xbt extract / xbt build step and its trap: a hand-made pair whose
header names the wrong companion, or splits the levels the wrong way
round.
The applier also refuses to write a shared entry that was edited, which is the gate that keeps
step 1 honest.
.xbm code lives in JackAllThe .xbm reader and writer are in JackAll.Tools, which is why the add-on carries no format code
of its own; the pack is the route to them. fc2fmt, the Python .xbm/.xbg library some
material-editing scripts import, is not in the repo — its code is in JackAll.
Then read it back out of the patch, not out of your layer:
jackall-cli archive extract "C:\Games\Far Cry 2\Data_Win32\patch.fat" --names --filter <weapon> -o check
Both textures should come back as a 512² base with 10 mips and a 1024² companion with one, in the same codec — the same four file sizes to the byte as the weapon you replaced.
What the offline gates cannot see
Render the weapon and compare it against the donor — that rule governs the mesh half and it applies here too. The view that matters is a lit one, rendered in EEVEE with the materials the file carries. It will catch an upside-down albedo, a body reading black, and a seam.
It will not catch the specular, and that is worth knowing precisely. The add-on's material preview
drives Blender's roughness from SpecularTexture1 and SpecularColor1; it models neither
SpecularColorBase nor the control map's red. Those are the two inputs that decide whether the gun
reads matte or polished, so a glossy build and a fixed one render essentially identically. Only the
game shows it.
One more, if your build takes its animation from a different weapon than its mesh path: the sight
render derives its eye from whichever aim bank the pack carries, and a pack collects banks by model
name. The VSS therefore renders its scope from the Dart Rifle's sp389 bank while the game plays
the Dragunov's spdra. The framing is wrong by however far those two eyes differ.
Known constraints, collected
- The
Weaponshader samples no albedo. Colour is two tiling maps blended by a mask until you rewrite the.xbm. - A weapon owns two texture paths, its damage-state masks — but it is not limited to them. A
texture at an invented path loads from
patch.datwith no hashlist and nodeploadentry. - A borrowed
.xbtheader must come from a texture with no_mip0companion, or it sends the engine looking for a sibling that is not yours.xbt buildwithout a header XML writes one that names none. - Green on the control map is the rust weight, and it is 0 on every clean mask. Pinning
MaskTextureBrokento the same map is what stops a weapon ever looking used. - A transplanted mesh keeps its donor's material table. Take a material the replaced weapon owned
instead, and check it with
xrefrather than the directory rule. - A material at a new path is untested in game. JackAll makes one; whether the engine loads a
material no
deploadlists is the open question. An owned material is the confirmed route. - Append the material and move clusters onto it.
SCOPE_HIshares the body's material and must keep it. - Fit the albedo into a band anchored on the source's own percentiles, in float, before compression.
- Match the effective albedo to your donor's level, not to another mod's absolute number.
SpecularColorBaseis what a texel gets where the mask's red is low, so a chrome weapon's 0.6 makes the whole surface glossy however the mask is painted. The Dragunov ships 0.043.- A working specular control is bimodal, and its metal band is what to level — not its mean.
SpecularPoweris lobe width and low is wide. A smaller highlight is what reads as shinier.- Metal reads as metal through
ReflectionTexture, a cube map gated by the same red as the highlight. 44 of 56 retail metal materials carry one at 0.2 or more; a highlight alone reads as paint. - The
Weaponshader samples no normal map. Relief is a tiledSpecularTexture1pattern; a true normal map needs aGenericmaterial, which has no worn look. - Set
DiffuseColorBaseequal toDiffuseColor1so no condition or vertex channel re-tints. - The
_mip0companion is twice the base, and the pack applier splits it for you. - Ship a weapon at 1024, a 512² base beside a 1024²
_mip0— the tier every retail weapon uses. origin_sha256is what marks a pack entry modified.- No offline gate models the specular path. That one needs the game.