Viewer: the first wear layer's tint blend (W2) and 4th wear channel #401

Manually merged
github merged 4 commits from github-bot/gh-401 into gh-pr/401/base 2026-11-26 20:45:51 +00:00 AGit
Owner

@⁠holdmysocks on GitHub · 2026-11-26 19:16 UTC · original
holdmysocks:wear-tint-blend → master · +160 −13 · 4 files · 4 commits · merged 2026-11-26 20:40 UTC

The viewer now draws two more parts of the game's paint shader for the first wear layer: the tint-to-palette blend (W2) and the 4th wear channel (D4). Builds on PR 381 (it includes that commit; merge 381 first).

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

  • W2. The first wear layer's colour is lerp(tint, palette colour, W2). The tint is the colour of the colour record that the surface names for its second layer (5cffe5e0, the record's colour, packed sRGB to linear by rva 0x37766a0 into surface record +16). Per channel R, G, B, W2 puts a window on the same levels as the layer's weight. A fourth window covers D4. Each window is sat((x - start) / width × 255 / divisor). The R, G and B terms are summed and saturated, then max-ed with the D4 term.
  • W2 bytes. The packer builds the window bytes (part record +80/+84) per channel. It first computes the activation a = sat((v0 - s) / max(1e-4, e - s)) from preset bytes +0x46..+0x4b and +0x51/52. The start is then a × f(start) and the width a × f(end) - a × f(start) (one fused multiply-subtract, no floor). Both are ×255 and truncated to the low byte, so a negative width wraps round. The divisors are the raw preset bytes +0x4c/4d/4e/53 (part record +88).
  • D4. The 4th channel is f16(v0 × f(+0x21)) × lyr0diffusetex.b, with no level or gamma. Its window (+0x22/+0x23, part record +64 bytes 2 and 3) adds to the layer's weight. A second window feeds W2.
  • Palette column. The shader reads the first wear layer's palette column from lyr0diffusetex.r. Only the base paint's column comes from .g. The viewer used .g for both.

Changes

  • Export (vehcolour, export): adds wear_tint per look, the sRGB colour of each part id's second layer, 6 hex digits per part id, with a note. EXPORT_VERSION goes to 30 and FORMAT to 25, so the viewer re-exports older vehicles.
  • Viewer:
    • part_wear packs the W2 windows, the divisors, the D4 scale and the D4 window with the game's arithmetic.
    • The coat row has new columns 50 to 68: the W2 windows, the D4 values, the linear tint and a flag for whether the part has a tint and row.
    • The shader adds D4 to the first layer's weight, computes W2, blends the tint to the palette colour by it, and reads the layer's palette column from red.
  • If the second layer's colour record has no palette row, W2 is 0, so the tint shows. In that case the game writes an override pattern to +80 and leaves +84 unwritten; that path is not copied.

Tests

  • Core: vehcolour tests pass (9), including a new check of the wear_tint table.
  • Viewer: part_wear and primer tests pass (2). They include new cases for W2: activation 0.8 giving window 40/81, a reversed window wrapping round to 216, and the divisor byte. They also cover the D4 scale (102) and window (25/51), worked out in f32.
  • Render: rancher_hi with primer amount 1 and set 1 at 1700×1000, compared with the PR 381 render. 1.2 % of pixels change, mean change 3.1, all in the wear patches (rear wheel arch rust, bed and tailgate edges, cab roof).

Not drawn yet

The edge/bump term (+40), the clear-coat loss (+56 b3), the dust/bleach/scratch mask, and the per-vehicle amounts I[0x220]/I[0x224].

**@⁠holdmysocks** on GitHub · 2026-11-26 19:16 UTC · [original](https://github.com/holdmysocks/SixNG/pull/401) `holdmysocks:wear-tint-blend` → `master` · +160 −13 · 4 files · 4 commits · merged 2026-11-26 20:40 UTC The viewer now draws two more parts of the game's paint shader for the first wear layer: the tint-to-palette blend (W2) and the 4th wear channel (D4). Builds on PR 381 (it includes that commit; merge 381 first). ## What the game does (read from the shader and the packer) - **W2.** The first wear layer's colour is `lerp(tint, palette colour, W2)`. The tint is the colour of the colour record that the surface names for its second layer (`5cffe5e0`, the record's `colour`, packed sRGB to linear by rva 0x37766a0 into surface record +16). Per channel R, G, B, W2 puts a window on the same levels as the layer's weight. A fourth window covers D4. Each window is `sat((x - start) / width × 255 / divisor)`. The R, G and B terms are summed and saturated, then max-ed with the D4 term. - **W2 bytes.** The packer builds the window bytes (part record +80/+84) per channel. It first computes the activation `a = sat((v0 - s) / max(1e-4, e - s))` from preset bytes +0x46..+0x4b and +0x51/52. The start is then `a × f(start)` and the width `a × f(end) - a × f(start)` (one fused multiply-subtract, no floor). Both are ×255 and truncated to the low byte, so a negative width wraps round. The divisors are the raw preset bytes +0x4c/4d/4e/53 (part record +88). - **D4.** The 4th channel is `f16(v0 × f(+0x21)) × lyr0diffusetex.b`, with no level or gamma. Its window (+0x22/+0x23, part record +64 bytes 2 and 3) adds to the layer's weight. A second window feeds W2. - **Palette column.** The shader reads the first wear layer's palette column from `lyr0diffusetex.r`. Only the base paint's column comes from `.g`. The viewer used `.g` for both. ## Changes - Export (`vehcolour`, `export`): adds `wear_tint` per look, the sRGB colour of each part id's second layer, 6 hex digits per part id, with a note. EXPORT_VERSION goes to 30 and FORMAT to 25, so the viewer re-exports older vehicles. - Viewer: - `part_wear` packs the W2 windows, the divisors, the D4 scale and the D4 window with the game's arithmetic. - The coat row has new columns 50 to 68: the W2 windows, the D4 values, the linear tint and a flag for whether the part has a tint and row. - The shader adds D4 to the first layer's weight, computes W2, blends the tint to the palette colour by it, and reads the layer's palette column from red. - If the second layer's colour record has no palette row, W2 is 0, so the tint shows. In that case the game writes an override pattern to +80 and leaves +84 unwritten; that path is not copied. ## Tests - Core: `vehcolour` tests pass (9), including a new check of the `wear_tint` table. - Viewer: `part_wear` and `primer` tests pass (2). They include new cases for W2: activation 0.8 giving window 40/81, a reversed window wrapping round to 216, and the divisor byte. They also cover the D4 scale (102) and window (25/51), worked out in f32. - Render: rancher_hi with primer amount 1 and set 1 at 1700×1000, compared with the PR 381 render. 1.2 % of pixels change, mean change 3.1, all in the wear patches (rear wheel arch rust, bed and tailgate edges, cab roof). ## Not drawn yet The edge/bump term (+40), the clear-coat loss (+56 b3), 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:26 +00:00
github-bot changed target branch from master to gh-pr/401/base 2026-11-26 20:45:48 +00:00
github manually merged commit 963d96ee93 into gh-pr/401/base 2026-11-26 20:45:51 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.