Viewer: wear layers with the colour-range samples and vertex colours; the primer layer behind a switch #305

Manually merged
github merged 5 commits from gh-pr/305/head into gh-pr/305/base 2026-11-26 20:26:05 +00:00
Owner

@⁠holdmysocks on GitHub · 2026-11-25 19:08 UTC · original
holdmysocks:primer-layer → master · +209 −14 · 8 files · 5 commits · merged 2026-11-25 19:43 UTC

Stacked on #301; merge that first. After it merges, this PR's diff contains only the changes below.

What

Two commits:

  1. The primer wear layer (layer B), behind a switch that is off by default. For each part id, the primer terms from its wear preset go into the coat row of the part ramp image (columns 25 to 33):

    • scale per mask channel: v0 × primer intensity × activation;
    • the cross byte (8ed71149);
    • the primerStart / primerEnd window;
    • the wear-mask switch (eff390bd);
    • the library's primer roughness and metalness (primerPalette, the middle of its low and high values).

    The shader draws layer B where the first layer is not. The switch is a "primer layer" checkbox, or --primer on the command line. As in the game, both layers are packed only when v0 > 0.1.

  2. The colour-range samples and the vertex colours, for both layers.

    • Decoded the sample builder (rva 0xc7b660). At load, each colour range record (3539c333) gets 50 samples, seeded by sample index + record name. Each value is lo + rand × (hi − lo):

      sample field low → high bytes
      scale R, G, B minRed..maxBlue (+0x0c..+0x11)
      bias 9d9ec6c9, fb2b7f54, f0fb4e0e → 19006c48, c5801a83, 77d2db40 (+0x12..+0x17)
      gamma 954382a0, 7e3dffd5, aa03fd91 → 87f89264, c82d2173, 483f35b8 (+0x18..+0x1d)
      tiling minTile → maxTile (f16)
      +0x44 306b7568 → e9e6aa6b

      The offsets come from f16 9ded6508 / 5310cf44. As the code reads, a negative offset leaves 0, even though the data mostly stores −0.1.

    • Both layers now use the middle of their range's samples:

      • first layer: link 02a27216;
      • primer: link 879774bd.
    • The level per channel is sat(v_c × (scale × mask + bias))^((1/gamma)²), as in the shader. Columns 34 to 45 hold the bias and gamma values.

    • v_c is the vertex colour: GLB _COLOR0 rgb, which is the shader's vA/vB/vC. On the paint parts it is a sparse per-vertex wear mask (mostly 0).

    • For the primer, the first channel is sat(vA − (vB + vC) × cross).

    • Fix: the primer's own mask is material parameter 640111c6. The shader's texture 19 is material slot 20, in the same way as its texture 10 is slot 11 (b9f4bdac). It is not 7bace7bd.

Checked

  • cargo test -p sixng-gui: 36 pass. part_wear_from_the_configuration now also covers the range middles, bias, gamma and the no-range fallback.
  • Rancher renders (configurations 10, 0 and 2, primer off and on). Note that the paint colour varies between viewer launches, so pixel diffs between runs are noisy.
    • Off: the first layer now shows along the edges and panels that the vertex colours mark (configuration 10), instead of the evenly windowed mask. Without the vertex colours, the decoded bias covered whole panels.
    • On: the truck bed no longer turns fully grey. Instead the primer blends about 20 % grey over most painted panels on configuration 0, evenly. This is still too much, so the switch stays off.

Not decoded / not done

  • The per-vehicle amounts I[0x220] (layer A) and I[0x224] (layer B) are taken as 1. They are the likely reason the primer is too even and too strong.
  • Each part's actual sample pick depends on a per-vehicle seed (inst+0x1c, not traced). The viewer uses the middle of the 50 samples.
  • Which range link feeds which layer (+0x38 = 02a27216 → first layer) is by link order, high confidence.
  • The masks use UV0 × 5. The game uses UV1 × the global multiplier I[0x3bc] × the range's tiling, plus the offsets. The tiling is decoded but not used.
  • The primer colour is a stand-in grey (palette gradient not decoded). Its roughness and metalness are mid values. The material flag MF 0x100 is not read.
**@⁠holdmysocks** on GitHub · 2026-11-25 19:08 UTC · [original](https://github.com/holdmysocks/SixNG/pull/305) `holdmysocks:primer-layer` → `master` · +209 −14 · 8 files · 5 commits · merged 2026-11-25 19:43 UTC Stacked on #301; merge that first. After it merges, this PR's diff contains only the changes below. ## What Two commits: 1. **The primer wear layer (layer B), behind a switch that is off by default.** For each part id, the primer terms from its wear preset go into the coat row of the part ramp image (columns 25 to 33): - scale per mask channel: v0 × primer intensity × activation; - the cross byte (8ed71149); - the `primerStart` / `primerEnd` window; - the wear-mask switch (eff390bd); - the library's primer roughness and metalness (`primerPalette`, the middle of its low and high values). The shader draws layer B where the first layer is not. The switch is a "primer layer" checkbox, or `--primer` on the command line. As in the game, both layers are packed only when v0 > 0.1. 2. **The colour-range samples and the vertex colours, for both layers.** - Decoded the sample builder (rva 0xc7b660). At load, each colour range record (`3539c333`) gets 50 samples, seeded by sample index + record name. Each value is `lo + rand × (hi − lo)`: | sample field | low → high bytes | |---|---| | scale R, G, B | `minRed`..`maxBlue` (+0x0c..+0x11) | | bias | 9d9ec6c9, fb2b7f54, f0fb4e0e → 19006c48, c5801a83, 77d2db40 (+0x12..+0x17) | | gamma | 954382a0, 7e3dffd5, aa03fd91 → 87f89264, c82d2173, 483f35b8 (+0x18..+0x1d) | | tiling | `minTile` → `maxTile` (f16) | | +0x44 | 306b7568 → e9e6aa6b | The offsets come from f16 9ded6508 / 5310cf44. As the code reads, a negative offset leaves 0, even though the data mostly stores −0.1. - Both layers now use the middle of their range's samples: - first layer: link 02a27216; - primer: link 879774bd. - The level per channel is `sat(v_c × (scale × mask + bias))^((1/gamma)²)`, as in the shader. Columns 34 to 45 hold the bias and gamma values. - `v_c` is the vertex colour: GLB `_COLOR0` rgb, which is the shader's vA/vB/vC. On the paint parts it is a sparse per-vertex wear mask (mostly 0). - For the primer, the first channel is `sat(vA − (vB + vC) × cross)`. - **Fix:** the primer's own mask is material parameter `640111c6`. The shader's texture 19 is material slot 20, in the same way as its texture 10 is slot 11 (`b9f4bdac`). It is not `7bace7bd`. ## Checked - `cargo test -p sixng-gui`: 36 pass. `part_wear_from_the_configuration` now also covers the range middles, bias, gamma and the no-range fallback. - Rancher renders (configurations 10, 0 and 2, primer off and on). Note that the paint colour varies between viewer launches, so pixel diffs between runs are noisy. - Off: the first layer now shows along the edges and panels that the vertex colours mark (configuration 10), instead of the evenly windowed mask. Without the vertex colours, the decoded bias covered whole panels. - On: the truck bed no longer turns fully grey. Instead the primer blends about 20 % grey over most painted panels on configuration 0, evenly. This is still too much, so the switch stays off. ## Not decoded / not done - The per-vehicle amounts I[0x220] (layer A) and I[0x224] (layer B) are taken as 1. They are the likely reason the primer is too even and too strong. - Each part's actual sample pick depends on a per-vehicle seed (inst+0x1c, not traced). The viewer uses the middle of the 50 samples. - Which range link feeds which layer (+0x38 = 02a27216 → first layer) is by link order, high confidence. - The masks use UV0 × 5. The game uses UV1 × the global multiplier I[0x3bc] × the range's tiling, plus the offsets. The tiling is decoded but not used. - The primer colour is a stand-in grey (palette gradient not decoded). Its roughness and metalness are mid values. The material flag MF 0x100 is not read.
Packs each part's primer terms from its wear preset (primer intensities and activations per mask channel, the cross byte, primerStart/primerEnd window, the wear-mask switch) and the library's primer roughness and metalness into the part ramp image, binds the primer mask texture (7bace7bd), and draws layer B where the first layer is not. Both layers only above v0 0.1. Off by default (checkbox 'primer layer', --primer): the per-part colour-range samples and the per-vehicle amount are not decoded and taken as 1.
Decoded the colour range sample builder (rva 0xc7b660, 50 samples per 3539c333 record at load): scale, bias and gamma per mask channel are random lerps of byte pairs (minRed..maxBlue, 9d9ec6c9..77d2db40, 954382a0..483f35b8), tiling lerps minTile..maxTile. Both wear layers now use the middle of their range's samples for scale, bias and gamma, multiply by the vertex colours (_COLOR0 rgb, the shader's vA/vB/vC), and the primer reads its own mask 640111c6 (shader texture 19 is material slot 20, not 7bace7bd).
# Conflicts:
#	crates/sixng-gui/src/model_view.rs
#	crates/sixng-gui/src/shader.wgsl
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 20:26:03 +00:00
github manually merged commit e9613d1925 into gh-pr/305/base 2026-11-26 20:26:05 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.