Viewer: wear and primer window widths with the game's float arithmetic #381

Manually merged
github merged 1 commit from gh-pr/381/head into gh-pr/381/base 2026-11-26 20:32:08 +00:00
Owner

@⁠holdmysocks on GitHub · 2026-11-26 17:10 UTC · original
holdmysocks:wear-window-widths → master · +19 −8 · 1 files · 1 commits · merged 2026-11-26 18:33 UTC

The viewer now computes the wear and primer window bytes with the game's float arithmetic, so its widths match the game's.

What the game does

  • When a wear preset loads, a precompute (rva 0x173f430) packs the window dwords from the preset bytes.
  • Each byte is read as byte * 0x3b808081 in f32 (helper 0x44b6d0), the float nearest 1/255.
  • Rust windows: width = trunc(255 * max(1e-4, end - start)).
  • Primer window and primer gradient window: the same, but with no floor. A negative width wraps through the low byte.
  • Starts and the primer cross byte are trunc(255 * f(byte)).

Because of the f32 rounding, many widths come out one less than end - start. Before, the viewer rounded the exact byte difference. For example, 27..43 gives 15 in the game and gave 16 in the viewer. On the rancher, 12 of the 31 presets it uses have at least one such window.

Change

  • part_wear: preset bytes go through the game's 1/255 float. Window starts, widths, the primer window, the cross byte and the gradient window are truncated as the game does them.
  • The test has a new one-less case (12..44 gives 31) and a case where the floats give the full difference (19..255 gives 236).

Check

  • Viewer tests pass.
  • Rancher render with the primer at full amount, set 1, against the previous render: 32 pixels change, in one small spot. Windows that differ by 1/255 barely move this vehicle's wear edges.
**@⁠holdmysocks** on GitHub · 2026-11-26 17:10 UTC · [original](https://github.com/holdmysocks/SixNG/pull/381) `holdmysocks:wear-window-widths` → `master` · +19 −8 · 1 files · 1 commits · merged 2026-11-26 18:33 UTC The viewer now computes the wear and primer window bytes with the game's float arithmetic, so its widths match the game's. ## What the game does - When a wear preset loads, a precompute (rva 0x173f430) packs the window dwords from the preset bytes. - Each byte is read as `byte * 0x3b808081` in f32 (helper 0x44b6d0), the float nearest 1/255. - Rust windows: width = `trunc(255 * max(1e-4, end - start))`. - Primer window and primer gradient window: the same, but with no floor. A negative width wraps through the low byte. - Starts and the primer cross byte are `trunc(255 * f(byte))`. Because of the f32 rounding, many widths come out one less than `end - start`. Before, the viewer rounded the exact byte difference. For example, 27..43 gives 15 in the game and gave 16 in the viewer. On the rancher, 12 of the 31 presets it uses have at least one such window. ## Change - `part_wear`: preset bytes go through the game's 1/255 float. Window starts, widths, the primer window, the cross byte and the gradient window are truncated as the game does them. - The test has a new one-less case (12..44 gives 31) and a case where the floats give the full difference (19..255 gives 236). ## Check - Viewer tests pass. - Rancher render with the primer at full amount, set 1, against the previous render: 32 pixels change, in one small spot. Windows that differ by 1/255 barely move this vehicle's wear edges.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 20:32:06 +00:00
github manually merged commit e0320542cc into gh-pr/381/base 2026-11-26 20:32:08 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.