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

What goes into a material

There is no separate material file. Each mesh LOD stores its own list of materials, one per draw call: which shader technique, which textures in which slots, how alpha is used, and which range of the vertex and index buffers it covers.

BF22142Heroes

What a material holds#

FieldExample (the jeep, geometry 1, material 0)Who reads it
alpha mode0 opaque (1 blend, 2 test)the draw: blending, alpha test, the view-sorted index copies below
effect fileBundledMesh.fxnobody: every retail loader skips it and picks the shader by mesh kind
techniqueColormapGlossthe shader permutation (below)
mapsobjects/vehicles/bri_jeep_willys/textures/bri_jeep_willys.ddsthe texture slots, in order
vertex start / count, index start / countthe batch's slice of the buffersDrawIndexedPrimitive

The fields and their order are bf2-mesh template.rs Material; an alpha-blend batch's indices are stored eight times, pre-sorted for eight view directions (MeshFile::sorted_index_copies; the bundled draw picks the copy for the camera's yaw).

Every material of the three examples with its decoded maps. The house: one Base map. The jeep: ColormapGloss body, an alpha-blended glass batch, the wreck with its _w map. The hero item: SoldierItem.fx without maps, because the hero atlas is bound instead.
Every material of the three examples with its decoded maps. The house: one Base map. The jeep: ColormapGloss body, an alpha-blended glass batch, the wreck with its _w map. The hero item: SoldierItem.fx without maps, because the hero atlas is bound instead.

The CON lines behind it#

The material list comes from the exporter, not from CON. CON names the geometry and how the object uses it:

Objects/Vehicles_server.zip bri_jeep_willys/bri_jeep_willys.con (retail, first lines)
GeometryTemplate.create BundledMesh bri_jeep_willys
CollisionManager.createTemplate bri_jeep_willys
ObjectTemplate.create PlayerControlObject bri_jeep_willys
ObjectTemplate.collisionMesh bri_jeep_willys
ObjectTemplate.mapMaterial 0 Metal 4500
ObjectTemplate.mapMaterial 1 glassHeadLights 4500
ObjectTemplate.geometry bri_jeep_willys

mapMaterial maps the collision mesh's face materials to game materials (hit effects, penetration, sounds); it is not the render material. The render side's tweakables are GeometryTemplate.* lines in the tweak (LOD distances, maxTextureRepeat, compressVertexData; see the house on meshes).

How the renderer picks the pipeline#

  1. Mesh kind picks the shader family: static meshes RaShaderSTM, bundled RaShaderBM, skinned RaShaderSM (bf2-render staticmesh.rs, bundledmesh.rs, skinned.rs); the .fx name in the file is ignored.
  2. Technique words set state flags: the bundled reader lower-cases the technique and looks for animated (UV animation), envmap, colormapgloss, alpha_test, alpha_one, cockpit, nohemilight; the maps add a normal map (_b.dds in map 1) or a GI map (bf2-render bundledmesh.rs module doc, BmFlags).
  3. Permutation bits: the flags become a bit set over the family's literal table (Heroes has its own, literals_in), and permutation_for finds the generated shader permutation whose literals give the same bits (staticmesh.rs / bundledmesh.rs permutation_bits, permutation_for).
  4. Fallback: no match logs Couldn't find shader bits: <bits> looked up name: <name> and draws with the default shader, a flat colour (staticmesh.rs default_shader, the retail findShader miss branch).

Static meshes add the lightmap and the detail / dirt / crack layers as literals of the same table; each layer reads its own TEXCOORD set (bf2-mesh MeshFile::texcoords). Skinned hero items use SoldierItem.fx with the composed hero atlas (textures).

The passes these pipelines run in (shadows, the opaque and the sorted transparent queue, post effects) are on the render pipeline page.

How it is tested#

  • The material scripts of every mod run through the port's reader (crates/bf2-physics/tests/retail_materials.rs).
  • Render materials: every shipped mesh's materials are read with the mesh (meshes); the shader permutation tables are held against the original's order and literal table (crates/bf2-render/tests/basics.rs).
  • The shipped shaders all parse, translate and validate (crates/bf2-shaders/tests/retail.rs).

This page cites no address, so no test names one: what is proven is that every shipped file is read, not that a material looks as in the original.

In the code#

WhatWhere
a mesh's materials and texture coordinate setscrates/bf2-mesh
the shaders and their translationcrates/bf2-shaders
choosing and running the pipelinescrates/bf2-render
the physics materials (friction, damage modifiers, effects of a pair), which are another thing with the same namecrates/bf2-physics/src/material.rs (damage and armor)
Source: docs/dev/assets/material.md · built from bf2-rs e3b4f05 · part of the Battlefield 2 / 2142 / Heroes reimplementation. Not affiliated with EA or DICE.