Viewer: the game's dust and scratch mask on vehicle paint #410

Manually merged
github merged 9 commits from github-bot/gh-410 into gh-pr/410/base 2026-11-27 00:40:07 +00:00 AGit
Owner

@⁠holdmysocks on GitHub · 2026-11-26 20:50 UTC · original
holdmysocks:wear-dust → master · +137 −2 · 7 files · 9 commits · merged 2026-11-26 22:01 UTC

The viewer now draws the roughness and clear-coat effects of the game's dust and scratch mask on vehicle paint. Builds on PR 405, which builds on PR 401; merge those first.

What the game does (shader block 04f08–05260 and the packer, read from the code)

  • The mask is the material's dusttexture (parameter fb03ae36, shader texture 21 = material slot 22). Its red and blue are sparse scratch masks; its green is mostly high (dust).
  • Coordinates and contrast. The game samples it at UV1 × (part record +92 byte 3 × 50 / 255) plus a per-vehicle offset. The packer writes that byte as trunc(5.1 × lerp(minTiling, maxTiling, per-vehicle pick)). A per-vehicle contrast is applied: sat(I[0x30] × (1 − I[0x2c] × (1 − tex))).
  • The three mask values:
    • r = tex.r × +92 b1 (redScratch curve)
    • b = tex.b × +92 b2 (blueScratch curve)
    • dust = sat((+4 b0 × vertex G + +4 b1)/255 × tex.g)
  • k1 (clear-coat loss). k1 = sat(bit18·r + bit21·b + bit0·dust) × 10 × +60 b0/255, then coat = sat(coat − k1 × Wbase × +56 b0/255). The selector of the dust term is bit 0 (wear on), not bit 24, as the lift shows (mask constant 1 at 05018).
  • k3 (added roughness). k3 = sat(bit20·r + bit23·b + bit26·dust), then rough = sat(rough + k3 × (+56 b0 × Wbase + b1 × W3 + b2 × W1)/255).
  • Where the bytes come from. The age record's curves and floats (sunBleach, baseBleach, the +0x44 / +0x6c / +0xc8 / +0xdc groups, red / blue scratch, 91b26647, cf9f9929, b5abe9f2, 193c7eb1, 2c04933e). The flag bits are its bools +0xbc..+0xc4.

Changes

  • dusttexture is bound as material binding 8. Flag bit 4 says it is present; without it the wear mask is bound in its place.
  • part_wear packs the 16 bytes the shader reads, with the game's curve and byte arithmetic, into coat-row columns 73 to 88.
  • The shader adds k3's roughness after the layer blend and takes k1's clear coat off the base paint.

Tests

  • Viewer: part_wear, primer and shaders_validate pass (3). A new case checks the 16 bytes: tiling 6.5 × 5.1 → 33; red scratch curve 0.4 → 102 and signed 178; base gain 255; flag bits 18 and 26.
  • Render: rancher_hi with primer amount 1 and set 1 at 1700×1000, compared with the PR 405 render. 13.1 % of pixels change, but only 3.5 % by more than 8 levels (mean 7.0). The body paint, bed floor, rails and spare wheel are slightly rougher and duller; the chrome bumper keeps its shine.

Approximations and not done

  • The per-vehicle contrast and offset (I[0x2c], I[0x30], I[0x4c], I[0x50]) are runtime state: no static source was found. The viewer uses 1, 1, 0, 0. The tiling multiplier I[0x3bc] is 1, and the tiling pick is the middle of the range.
  • The viewer samples at UV0, not UV1.
  • Not drawn yet:
    • the HSV colour step: darkening and lightening by the detail texture's green, and bleaching toward white by the signed sum r, b, gA. It needs surface record +28 bytes, which the packer fills from a colour-space computation not traced yet.
    • the third G-buffer value (k2).
**@⁠holdmysocks** on GitHub · 2026-11-26 20:50 UTC · [original](https://github.com/holdmysocks/SixNG/pull/410) `holdmysocks:wear-dust` → `master` · +137 −2 · 7 files · 9 commits · merged 2026-11-26 22:01 UTC The viewer now draws the roughness and clear-coat effects of the game's dust and scratch mask on vehicle paint. Builds on PR 405, which builds on PR 401; merge those first. ## What the game does (shader block 04f08–05260 and the packer, read from the code) - The mask is the material's `dusttexture` (parameter `fb03ae36`, shader texture 21 = material slot 22). Its red and blue are sparse scratch masks; its green is mostly high (dust). - **Coordinates and contrast.** The game samples it at UV1 × (part record +92 byte 3 × 50 / 255) plus a per-vehicle offset. The packer writes that byte as trunc(5.1 × lerp(minTiling, maxTiling, per-vehicle pick)). A per-vehicle contrast is applied: `sat(I[0x30] × (1 − I[0x2c] × (1 − tex)))`. - **The three mask values:** - r = tex.r × +92 b1 (redScratch curve) - b = tex.b × +92 b2 (blueScratch curve) - dust = sat((+4 b0 × vertex G + +4 b1)/255 × tex.g) - **k1 (clear-coat loss).** `k1 = sat(bit18·r + bit21·b + bit0·dust) × 10 × +60 b0/255`, then `coat = sat(coat − k1 × Wbase × +56 b0/255)`. The selector of the dust term is bit 0 (wear on), not bit 24, as the lift shows (mask constant 1 at 05018). - **k3 (added roughness).** `k3 = sat(bit20·r + bit23·b + bit26·dust)`, then `rough = sat(rough + k3 × (+56 b0 × Wbase + b1 × W3 + b2 × W1)/255)`. - **Where the bytes come from.** The age record's curves and floats (sunBleach, baseBleach, the +0x44 / +0x6c / +0xc8 / +0xdc groups, red / blue scratch, 91b26647, cf9f9929, b5abe9f2, 193c7eb1, 2c04933e). The flag bits are its bools +0xbc..+0xc4. ## Changes - `dusttexture` is bound as material binding 8. Flag bit 4 says it is present; without it the wear mask is bound in its place. - `part_wear` packs the 16 bytes the shader reads, with the game's curve and byte arithmetic, into coat-row columns 73 to 88. - The shader adds k3's roughness after the layer blend and takes k1's clear coat off the base paint. ## Tests - Viewer: `part_wear`, `primer` and `shaders_validate` pass (3). A new case checks the 16 bytes: tiling 6.5 × 5.1 → 33; red scratch curve 0.4 → 102 and signed 178; base gain 255; flag bits 18 and 26. - Render: rancher_hi with primer amount 1 and set 1 at 1700×1000, compared with the PR 405 render. 13.1 % of pixels change, but only 3.5 % by more than 8 levels (mean 7.0). The body paint, bed floor, rails and spare wheel are slightly rougher and duller; the chrome bumper keeps its shine. ## Approximations and not done - The per-vehicle contrast and offset (I[0x2c], I[0x30], I[0x4c], I[0x50]) are runtime state: no static source was found. The viewer uses 1, 1, 0, 0. The tiling multiplier I[0x3bc] is 1, and the tiling pick is the middle of the range. - The viewer samples at UV0, not UV1. - Not drawn yet: - the HSV colour step: darkening and lightening by the detail texture's green, and bleaching toward white by the signed sum r, b, gA. It needs surface record +28 bytes, which the packer fills from a colour-space computation not traced yet. - the third G-buffer value (k2).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 20:51:18 +00:00
# Conflicts:
#	crates/sixng-gui/src/model_view.rs
#	crates/sixng-gui/src/shader.wgsl
# Conflicts:
#	crates/sixng-gui/src/model_view.rs
#	crates/sixng-gui/src/shader.wgsl
github-bot changed target branch from master to gh-pr/410/base 2026-11-27 00:40:06 +00:00
github manually merged commit b660791dc2 into gh-pr/410/base 2026-11-27 00:40:07 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.