Weapons: metalness and roughness per sub-material #129

Manually merged
github merged 1 commit from gh-pr/129/head into gh-pr/129/base 2026-11-26 20:12:01 +00:00
Owner

@⁠holdmysocks on GitHub · 2026-11-24 06:09 UTC · original
holdmysocks:claude/weapon-surface → master · +70 −11 · 5 files · 1 commits · merged 2026-11-24 06:14 UTC

What this changes

  • Metalness and roughness per weapon sub-material. matlib::Library::surface(preset, sub) reads two library parameters whose names are not recovered: 0e555ef5 as metalness and 83472381 as roughness (the preset's value for the sub-material, else its base material's; without one, metalness falls back to the tile's tilemetallic, else 0, and roughness to 0.5). The index (version 5) stores them per preset (surfaces).
  • Export. A weapon model's COLOR_0 alpha carries the pair as the code the viewer already reads for vehicle parts (round(metalness x 3) x 50 + round(roughness x 49)); weapon_preset in the material extras lists sub_material_surface. The material's own factors stay the stand-in.
  • Viewer (wgpu). weapon materials set the per-vertex surface bit, so the code is used; the assembled-weapon path writes the same code, also for a chosen finish. Cached weapon exports are refreshed once.
  • README: one sentence.

Why these two parameters

Read from the data, not from the shader. Over the 21,051 sub-materials of the weapon library, grouped by base colour:

group 0e555ef5 present / median 83472381 median
gold 96 % / 1.0 0.15
steel greys 78 % / 0.85 0.40 to 0.45
wood browns 34 % / 0.85 0.75

Roughness separates the groups clearly. Metalness is mostly a matter of presence, which is why a missing value falls back to the tile and then to 0.

What was checked

  • Screenshots (--gpu radeon) of the pistol before and after, and with the gold finish: the grip turns matte and non-metallic, frame and slide stay metallic, gold reads as metal.
  • Index values for the pistol: frame 0.95 / 0.5, grip 0.0 / 0.8, barrel 0.84 / 0.33.
  • cargo test -p sixng-core: 151 passed (the matlib test covers the fallback chain). Release builds of CLI and viewer pass.

What is not done / not known

  • The two parameters are identified by how their values behave, not by name or by reading the shader; the fallbacks (0 and 0.5) are guesses for values the game takes from its defaults.
  • Metalness has only four steps in the code.
  • The Metal renderer is unchanged: weapons keep one stand-in surface there.
  • Other glTF viewers see the code as vertex alpha; the materials are opaque, so it is ignored, but the per-part surface is only used by SixNG's viewer.
**@⁠holdmysocks** on GitHub · 2026-11-24 06:09 UTC · [original](https://github.com/holdmysocks/SixNG/pull/129) `holdmysocks:claude/weapon-surface` → `master` · +70 −11 · 5 files · 1 commits · merged 2026-11-24 06:14 UTC ## What this changes - **Metalness and roughness per weapon sub-material.** `matlib::Library::surface(preset, sub)` reads two library parameters whose names are not recovered: `0e555ef5` as metalness and `83472381` as roughness (the preset's value for the sub-material, else its base material's; without one, metalness falls back to the tile's `tilemetallic`, else 0, and roughness to 0.5). The index (version 5) stores them per preset (`surfaces`). - **Export.** A weapon model's COLOR_0 alpha carries the pair as the code the viewer already reads for vehicle parts (round(metalness x 3) x 50 + round(roughness x 49)); `weapon_preset` in the material extras lists `sub_material_surface`. The material's own factors stay the stand-in. - **Viewer (wgpu).** `weapon` materials set the per-vertex surface bit, so the code is used; the assembled-weapon path writes the same code, also for a chosen finish. Cached weapon exports are refreshed once. - README: one sentence. ## Why these two parameters Read from the data, not from the shader. Over the 21,051 sub-materials of the weapon library, grouped by base colour: | group | `0e555ef5` present / median | `83472381` median | |---|---|---| | gold | 96 % / 1.0 | 0.15 | | steel greys | 78 % / 0.85 | 0.40 to 0.45 | | wood browns | 34 % / 0.85 | 0.75 | Roughness separates the groups clearly. Metalness is mostly a matter of presence, which is why a missing value falls back to the tile and then to 0. ## What was checked - Screenshots (`--gpu radeon`) of the pistol before and after, and with the gold finish: the grip turns matte and non-metallic, frame and slide stay metallic, gold reads as metal. - Index values for the pistol: frame 0.95 / 0.5, grip 0.0 / 0.8, barrel 0.84 / 0.33. - `cargo test -p sixng-core`: 151 passed (the matlib test covers the fallback chain). Release builds of CLI and viewer pass. ## What is not done / not known - The two parameters are identified by how their values behave, not by name or by reading the shader; the fallbacks (0 and 0.5) are guesses for values the game takes from its defaults. - Metalness has only four steps in the code. - The Metal renderer is unchanged: weapons keep one stand-in surface there. - Other glTF viewers see the code as vertex alpha; the materials are opaque, so it is ignored, but the per-part surface is only used by SixNG's viewer.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 20:11:59 +00:00
github manually merged commit 39a392741c into gh-pr/129/base 2026-11-26 20:12:01 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.