Viewer: clear-coat loss and the edge bump on worn paint #405

Manually merged
github merged 6 commits from github-bot/gh-405 into gh-pr/405/base 2026-11-27 00:39:55 +00:00 AGit
Owner

@⁠holdmysocks on GitHub · 2026-11-26 19:54 UTC · original
holdmysocks:wear-coat-edge → master · +85 −3 · 2 files · 6 commits · merged 2026-11-26 21:17 UTC

Worn paint in the viewer now loses its clear coat and gets the game's edge bump. Builds on PR 401 (it includes that commit; merge 401 first).

What the game does (shader and packer, read from the code)

  • Clear-coat loss. Each wear layer takes weight × 10 × b/255 off the clear coat (shader at 03278 and 0332c). Here b is part record +56 byte 3 = trunc(25.5 × aa7d4fbd), a float of the age record (fe5d32e7 +0xf0). The rancher's age records use 0, 1 or 2, so the most worn areas lose their whole clear coat.
  • Edge term. The shader has two paths, picked by part flag bit 17. The packer (rva 0x37766a0) never sets that bit (bits 3–10 are the configuration byte, 5–12 the per-part table byte, 18–26 and 31 the age bools), so the game always takes the bump path:
    • It samples the wear mask again one screen footprint L along each UV axis.
    • It takes edge(sat(M_R + M_G + M_B)) at each point, with edge(x) = sat((x - start) / (end - start)).
    • It adds 0.01 × (edge there − edge here) / (L + 1e-4) × edgeIntensity to the tangent-space normal, only where the levels sum above 0.
  • Edge bytes. The edge record (487f0f4c, linked from the wear preset by 7f1fe0a2) is packed by rva 0x1a0d7a0 into part record +40: f16 of edgeIntensity, then trunc(255 × edgeStart) and trunc(255 × edgeEnd) in bytes 2 and 3.

Changes

  • part_wear packs the edge record's intensity, start and end, and the clear-coat loss byte into coat-row columns 69 to 72.
  • The shader:
    • New helpers wear_level_sum and wear_edge.
    • The bump: two extra textureSampleGrad samples, with the derivatives taken in uniform control flow, added in the part's tangent frame.
    • coat.x -= (W1 + W3) × 10 × b/255.

Tests

  • Viewer: part_wear and primer tests pass (2). A new case checks the edge bytes (0.275 / 0.05 / 0.8 → 70, 12, 204) and the clear-coat byte (2 → 51).
  • Render: rancher_hi with primer amount 1 and set 1 at 1700×1000, compared with the PR 401 render. 6.7 % of pixels change (mean 14.5), all on the body. The worn patches on the roof, bonnet and bed rails now show as matte rust and primer; before, the glossy clear coat covered them.

Approximations

  • The viewer reads the wear mask at UV0 × 5, not the game's UV1 at the per-part tiling.
  • The bump is added in the viewer's tangent frame from UV0.
  • A preset with no edge record in the export has no edge term. The game uses a default record there, whose values are not read.

Not drawn yet

The dust/bleach/scratch mask, and the per-vehicle amounts I[0x220]/I[0x224].

**@⁠holdmysocks** on GitHub · 2026-11-26 19:54 UTC · [original](https://github.com/holdmysocks/SixNG/pull/405) `holdmysocks:wear-coat-edge` → `master` · +85 −3 · 2 files · 6 commits · merged 2026-11-26 21:17 UTC Worn paint in the viewer now loses its clear coat and gets the game's edge bump. Builds on PR 401 (it includes that commit; merge 401 first). ## What the game does (shader and packer, read from the code) - **Clear-coat loss.** Each wear layer takes `weight × 10 × b/255` off the clear coat (shader at 03278 and 0332c). Here `b` is part record +56 byte 3 = `trunc(25.5 × aa7d4fbd)`, a float of the age record (`fe5d32e7` +0xf0). The rancher's age records use 0, 1 or 2, so the most worn areas lose their whole clear coat. - **Edge term.** The shader has two paths, picked by part flag bit 17. The packer (rva 0x37766a0) never sets that bit (bits 3–10 are the configuration byte, 5–12 the per-part table byte, 18–26 and 31 the age bools), so the game always takes the bump path: - It samples the wear mask again one screen footprint L along each UV axis. - It takes `edge(sat(M_R + M_G + M_B))` at each point, with `edge(x) = sat((x - start) / (end - start))`. - It adds `0.01 × (edge there − edge here) / (L + 1e-4) × edgeIntensity` to the tangent-space normal, only where the levels sum above 0. - **Edge bytes.** The edge record (`487f0f4c`, linked from the wear preset by `7f1fe0a2`) is packed by rva 0x1a0d7a0 into part record +40: f16 of edgeIntensity, then `trunc(255 × edgeStart)` and `trunc(255 × edgeEnd)` in bytes 2 and 3. ## Changes - `part_wear` packs the edge record's intensity, start and end, and the clear-coat loss byte into coat-row columns 69 to 72. - The shader: - New helpers `wear_level_sum` and `wear_edge`. - The bump: two extra `textureSampleGrad` samples, with the derivatives taken in uniform control flow, added in the part's tangent frame. - `coat.x -= (W1 + W3) × 10 × b/255`. ## Tests - Viewer: `part_wear` and `primer` tests pass (2). A new case checks the edge bytes (0.275 / 0.05 / 0.8 → 70, 12, 204) and the clear-coat byte (2 → 51). - Render: rancher_hi with primer amount 1 and set 1 at 1700×1000, compared with the PR 401 render. 6.7 % of pixels change (mean 14.5), all on the body. The worn patches on the roof, bonnet and bed rails now show as matte rust and primer; before, the glossy clear coat covered them. ## Approximations - The viewer reads the wear mask at UV0 × 5, not the game's UV1 at the per-part tiling. - The bump is added in the viewer's tangent frame from UV0. - A preset with no edge record in the export has no edge term. The game uses a default record there, whose values are not read. ## Not drawn yet The dust/bleach/scratch mask, and the per-vehicle amounts I[0x220]/I[0x224].
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 20:33:31 +00:00
# Conflicts:
#	crates/sixng-gui/src/model_view.rs
#	crates/sixng-gui/src/shader.wgsl
github-bot changed target branch from master to gh-pr/405/base 2026-11-27 00:39:52 +00:00
github manually merged commit e42b057290 into gh-pr/405/base 2026-11-27 00:39:55 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.