Materials: read constant values from their buffer at their byte offset #163

Manually merged
github merged 2 commits from gh-pr/163/head into gh-pr/163/base 2026-11-26 20:14:36 +00:00
Owner

@⁠holdmysocks on GitHub · 2026-11-24 14:38 UTC · original
holdmysocks:claude/material-constants → master · +119 −51 · 4 files · 2 commits · merged 2026-11-24 15:14 UTC

Problem

The values SixNG printed for a material's constants (in model.json under drawable.shaders[].constants, in materials.json under parameters, and in the four-layer multilayer.params) were wrong for nearly every constant. The reader took a descriptor's offset as a float index into the constant block itself, with 8 bits. Found while checking a shader reading against real ground materials.

Layout, as read from the data

  • A constant's descriptor is components << 22 | byte offset << 8 | buffer: 1 to 4 floats, a 14-bit byte offset, and which constant buffer (0x03; 0x07 on materials with a second one).
  • The constant block (shader record +0x08) starts with one pointer per buffer, in rising order of the buffer byte. Each points at that buffer's data inside the block: at +8 with one buffer, at +16 with two.
  • The offsets and component counts agree with the shader archive's own tables (sixng shader-bindings): for example the four-layer ground's second buffer has 4344d2cc (float4) at 0 and 1c1acf8c (float) at 640 in both.

Checked on the game data

  • About 13,000 materials sampled from three archives: one buffer (10,184) or two (2,915, buffers 0x03 and 0x07), every buffer pointer present, and every constant lies inside its buffer.
  • A four-layer ground material: all 86 constants read (28 before, from wrong places; the 58 of the second buffer were null). The values are plausible where the shader's use is known: UV scale (128, 128) with offset 0, the per-layer UV selector (1, 1, 1, 1), selector scalars 0 or 1.
  • A head: 38 of 38.
  • cargo test -p sixng-core: 171 passed (new tests for the reader and the four-layer split).

Changed

  • drawable.rs: the reader; ShaderConst gains buffer and count, and offset is now the byte offset.
  • materials.json: a scalar is one number, a vector its own 2 to 4 components (records without a count keep four).
  • Four-layer multilayer.params: float4 constants are split per layer (as the shader code uses them), the two UV transforms and the scalars are listed with the material, and the old per-layer notes are removed: they described values read from the wrong offsets.
  • README: exports made before today should be re-exported for parameter values.

Not done

  • Integer and boolean constants are printed as floats: the descriptor does not carry the type (the shader archive's tables do, but they are not joined here).
  • The 71 sampled materials whose block lies after the texture array are read with a looser end bound; not looked at one by one.
  • What most constants mean is still not decoded.
  • Touches the same README table as #161 in another row; the two do not overlap.
**@⁠holdmysocks** on GitHub · 2026-11-24 14:38 UTC · [original](https://github.com/holdmysocks/SixNG/pull/163) `holdmysocks:claude/material-constants` → `master` · +119 −51 · 4 files · 2 commits · merged 2026-11-24 15:14 UTC ## Problem The values SixNG printed for a material's constants (in `model.json` under `drawable.shaders[].constants`, in `materials.json` under `parameters`, and in the four-layer `multilayer.params`) were wrong for nearly every constant. The reader took a descriptor's offset as a float index into the constant block itself, with 8 bits. Found while checking a shader reading against real ground materials. ## Layout, as read from the data - A constant's descriptor is `components << 22 | byte offset << 8 | buffer`: 1 to 4 floats, a 14-bit byte offset, and which constant buffer (0x03; 0x07 on materials with a second one). - The constant block (shader record +0x08) starts with one pointer per buffer, in rising order of the buffer byte. Each points at that buffer's data inside the block: at +8 with one buffer, at +16 with two. - The offsets and component counts agree with the shader archive's own tables (`sixng shader-bindings`): for example the four-layer ground's second buffer has `4344d2cc` (float4) at 0 and `1c1acf8c` (float) at 640 in both. ## Checked on the game data - About 13,000 materials sampled from three archives: one buffer (10,184) or two (2,915, buffers 0x03 and 0x07), every buffer pointer present, and every constant lies inside its buffer. - A four-layer ground material: all 86 constants read (28 before, from wrong places; the 58 of the second buffer were null). The values are plausible where the shader's use is known: UV scale `(128, 128)` with offset 0, the per-layer UV selector `(1, 1, 1, 1)`, selector scalars 0 or 1. - A head: 38 of 38. - `cargo test -p sixng-core`: 171 passed (new tests for the reader and the four-layer split). ## Changed - `drawable.rs`: the reader; `ShaderConst` gains `buffer` and `count`, and `offset` is now the byte offset. - `materials.json`: a scalar is one number, a vector its own 2 to 4 components (records without a count keep four). - Four-layer `multilayer.params`: float4 constants are split per layer (as the shader code uses them), the two UV transforms and the scalars are listed with the material, and the old per-layer notes are removed: they described values read from the wrong offsets. - README: exports made before today should be re-exported for parameter values. ## Not done - Integer and boolean constants are printed as floats: the descriptor does not carry the type (the shader archive's tables do, but they are not joined here). - The 71 sampled materials whose block lies after the texture array are read with a looser end bound; not looked at one by one. - What most constants mean is still not decoded. - Touches the same README table as #161 in another row; the two do not overlap.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 20:14:34 +00:00
github manually merged commit 03a916f4bf into gh-pr/163/base 2026-11-26 20:14:36 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.