Viewer: the paint shader's HSV colour step (albedo multiply / screen, sun bleach) #413

Manually merged
github merged 11 commits from github-bot/gh-413 into gh-pr/413/base 2026-11-27 02:09:59 +00:00 AGit
Owner

@⁠holdmysocks on GitHub · 2026-11-26 21:37 UTC · original
holdmysocks:wear-colour-step → master · +135 −6 · 4 files · 11 commits · merged 2026-11-27 02:01 UTC

The viewer now draws the paint shader's colour step: darkening, lightening and sun bleaching in HSV, with each surface's own amounts. Builds on PR 410 (it includes that branch; merge 410 first).

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

  • Where the bytes come from. The shader reads bytes 1, 2, 3 of surface record +28. The packer (rva 0x37766a0) copies 8 bytes into surface record +24..+31 from the run-time object of a 307f162c record (object +0x28):

    • For the first layer's record, from the surface's 2cc72f7c link.
    • For the second layer's record, from its 174770cc link.
    • These are the same records that hold the layers' metalness and roughness.
  • The fields. Besides metalness and roughness low and high, a 307f162c record has three floats. Their name hashes match:

    • sunBleachScreen (d3d2bcd6)
    • albedoMultiply (4b19d0cb)
    • albedoScreen (de1ccc51)

    These match the shader's use of bytes 1, 2, 3: a bleach screen, a multiply and a screen. Most records hold 0.75, 0.135 and 0.135.

  • The step (shader 05160 to 0540c):

    • gr = (1 - paletteWeight) * (2 * (lyr0diffusetex.g - 0.5) + detail).
    • paletteWeight is the share of the colour taken from palette rows: W1·W2 + the primer + the base when it reads a row.
    • Below 0: V *= 1 - |gr|·mul and S = 1 - (1 - |gr|·mul)(1 - S).
    • Above 0: V = 1 - (1 - V)(1 - gr·scr) and S *= 1 - gr·scr.
    • Then, from the dust mask's signed bleach driver sgn: q = sgn · (per-layer dust gains · weights) · bleach, V = 1 - (1 - q)(1 - V) and S *= 1 - q.
    • The amounts are weighted by layer: the first wear layer uses the second layer's record, and the base and primer use the first layer's.

Changes

  • Export (vehcolour, export):
    • Adds surface_tone per look: 12 hex digits per part id (bleach, multiply and screen of the first layer, then of the second, ×255 rounded), with a note.
    • EXPORT_VERSION goes to 31 and FORMAT to 26, so the viewer re-exports older vehicles.
  • Viewer:
    • Coat-row columns 89 to 94 hold those bytes. Column 95 says whether the part's own colour is a palette row.
    • The dust block also computes the bleach driver.
    • After the layers are blended, the shader converts to HSV, applies the multiply, screen and bleach, and converts back.

Tests

  • Core: vehcolour tests pass (9). They include new checks of tone_table and of the per-layer lookup.
  • Viewer: part_wear and coat tests pass.
  • Render: rancher_hi with primer amount 1 and set 1 at 1700×1000, compared with the PR 410 render.
    • 3.9 % of pixels change, mean change 11.6.
    • Almost all of the change is the bed liner (a colour of its own, not a palette row). It is slightly lighter where the detail texture's green is high, and bleached where the dust mask is.
    • The palette-painted body barely changes.

Not done

  • The detail term added to the green's offset is not added (0 here).
  • The byte scale (×255 rounded) is inferred: the code that fills the object's +0x28 was not found. Byte 0 of +28 is not read by this step.
  • The primer's palette share is taken as 1.
**@⁠holdmysocks** on GitHub · 2026-11-26 21:37 UTC · [original](https://github.com/holdmysocks/SixNG/pull/413) `holdmysocks:wear-colour-step` → `master` · +135 −6 · 4 files · 11 commits · merged 2026-11-27 02:01 UTC The viewer now draws the paint shader's colour step: darkening, lightening and sun bleaching in HSV, with each surface's own amounts. Builds on PR 410 (it includes that branch; merge 410 first). ## What the game does (read from the shader, the packer and the library) - **Where the bytes come from.** The shader reads bytes 1, 2, 3 of surface record +28. The packer (rva 0x37766a0) copies 8 bytes into surface record +24..+31 from the run-time object of a `307f162c` record (object +0x28): - For the first layer's record, from the surface's `2cc72f7c` link. - For the second layer's record, from its `174770cc` link. - These are the same records that hold the layers' metalness and roughness. - **The fields.** Besides metalness and roughness low and high, a `307f162c` record has three floats. Their name hashes match: - `sunBleachScreen` (d3d2bcd6) - `albedoMultiply` (4b19d0cb) - `albedoScreen` (de1ccc51) These match the shader's use of bytes 1, 2, 3: a bleach screen, a multiply and a screen. Most records hold 0.75, 0.135 and 0.135. - **The step** (shader 05160 to 0540c): - `gr = (1 - paletteWeight) * (2 * (lyr0diffusetex.g - 0.5) + detail)`. - `paletteWeight` is the share of the colour taken from palette rows: W1·W2 + the primer + the base when it reads a row. - Below 0: `V *= 1 - |gr|·mul` and `S = 1 - (1 - |gr|·mul)(1 - S)`. - Above 0: `V = 1 - (1 - V)(1 - gr·scr)` and `S *= 1 - gr·scr`. - Then, from the dust mask's signed bleach driver `sgn`: `q = sgn · (per-layer dust gains · weights) · bleach`, `V = 1 - (1 - q)(1 - V)` and `S *= 1 - q`. - The amounts are weighted by layer: the first wear layer uses the second layer's record, and the base and primer use the first layer's. ## Changes - Export (`vehcolour`, `export`): - Adds `surface_tone` per look: 12 hex digits per part id (bleach, multiply and screen of the first layer, then of the second, ×255 rounded), with a note. - EXPORT_VERSION goes to 31 and FORMAT to 26, so the viewer re-exports older vehicles. - Viewer: - Coat-row columns 89 to 94 hold those bytes. Column 95 says whether the part's own colour is a palette row. - The dust block also computes the bleach driver. - After the layers are blended, the shader converts to HSV, applies the multiply, screen and bleach, and converts back. ## Tests - Core: `vehcolour` tests pass (9). They include new checks of `tone_table` and of the per-layer lookup. - Viewer: `part_wear` and `coat` tests pass. - Render: rancher_hi with primer amount 1 and set 1 at 1700×1000, compared with the PR 410 render. - 3.9 % of pixels change, mean change 11.6. - Almost all of the change is the bed liner (a colour of its own, not a palette row). It is slightly lighter where the detail texture's green is high, and bleached where the dust mask is. - The palette-painted body barely changes. ## Not done - The `detail` term added to the green's offset is not added (0 here). - The byte scale (×255 rounded) is inferred: the code that fills the object's +0x28 was not found. Byte 0 of +28 is not read by this step. - The primer's palette share is taken as 1.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 00:39:21 +00:00
github-bot changed target branch from master to gh-pr/413/base 2026-11-27 02:09:58 +00:00
github manually merged commit 1cf3f6cd64 into gh-pr/413/base 2026-11-27 02:09:59 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.