Tattoo bake: the 0x40 vertex-colour region cap #544

Manually merged
github merged 3 commits from github-bot/gh-544 into gh-pr/544/base 2026-11-28 05:54:37 +00:00 AGit
Owner

@⁠holdmysocks on GitHub · 2026-11-28 05:39 UTC · original
holdmysocks:claude/tattoo-region-vertex-385 → master · +106 −46 · 2 files · 3 commits · merged 2026-11-28 05:51 UTC

Part of #385: the vertex-colour region cap for decorations (flag 0x40). Follows #539.

A decoration record with a layer flagged 0x40, and none flagged 0x2, scales every layer by one vertex-colour channel. I traced which channel a layer reads through the game's exe:

  • Job builder (0x140231120). It makes one bake job per decoration record. For each PSO layer it writes a shader record of 0x130 bytes:
    • +0x50 = the layer's flags (PSO +0xd0, OR 0x40000000 when the layer has no decal);
    • +0x54 = the layer's mode (PSO +0xdc), copied unchanged.
  • Draw (0x1415298e0). It makes one pass per mode and writes the pass's mode to cbuffer +112. The whole layer buffer is uploaded once per job.
  • Mesh shader (MSNC_VS_BakeDecorations). It scans every layer of the record:
    • any layer with 0x2 → the mask test from #539;
    • otherwise any layer with 0x40 → z = vertex channel (cbuffer +112): 0-3 are _COLOR0 rgba, 4-7 are _COLOR1 rgba, 8 and up are 1.
    • The colour load uses a descriptor the shader builds itself (word3 0x11014fac): identity swizzle, 8-bit unorm for the colour stream's format.
  • Pixel shader. A layer's coverage starts at min(opacity, z), as in #539.

So the channel is the layer's own mode, and the rule is decided per record.

What changes:

  • peddeco::Region (Mask / Vertex) and Region::of replace the mask-only check. The mask wins when a record has both flags.
  • Corner carries both colour streams. A part without a stream reads 255 there, so it gets no cap.
  • region_cap takes the region and the layer's mode. The export builds one cap per (region, mode) it needs.
  • The export's record notes describe both rules. The bake rule version is bumped.

Result. The guardia's teal torso piece (outfits 17 and 37) is in a 0x40 record as a mode-2 layer. Mode 2 reads _COLOR0.b, which is 16 on every vertex of the male skin meshes. So the game draws it at about 6% (16/255), and the bake now matches. Before and after on outfit 17: only the teal piece changes (253 texels, all inside it); the outfit's other baked texture is byte-identical.

Reach: 27 of the 7,509 records have 0x40 without 0x2. The other two layers in the guardia record are mode 4 (_COLOR1.r, 255 on the skin), so they are unchanged.

Caveat: this uses the vertex colours stored in the mesh files. I found no code that rewrites them at runtime, but I can't rule it out.

Tests:

  • flags pick the record's cap (none, vertex, and mask over vertex);
  • a vertex cap interpolates the mode's channel, has no cap past channel 7, and fills gutters from covered neighbours;
  • the #539 mask tests, updated to the new signature.
**@⁠holdmysocks** on GitHub · 2026-11-28 05:39 UTC · [original](https://github.com/holdmysocks/SixNG/pull/544) `holdmysocks:claude/tattoo-region-vertex-385` → `master` · +106 −46 · 2 files · 3 commits · merged 2026-11-28 05:51 UTC Part of #385: the vertex-colour region cap for decorations (flag 0x40). Follows #539. A decoration record with a layer flagged 0x40, and none flagged 0x2, scales every layer by one vertex-colour channel. I traced which channel a layer reads through the game's exe: - **Job builder** (0x140231120). It makes one bake job per decoration record. For each PSO layer it writes a shader record of 0x130 bytes: - +0x50 = the layer's flags (PSO +0xd0, OR 0x40000000 when the layer has no decal); - +0x54 = the layer's mode (PSO +0xdc), copied unchanged. - **Draw** (0x1415298e0). It makes one pass per mode and writes the pass's mode to cbuffer +112. The whole layer buffer is uploaded once per job. - **Mesh shader** (`MSNC_VS_BakeDecorations`). It scans every layer of the record: - any layer with 0x2 → the mask test from #539; - otherwise any layer with 0x40 → z = vertex channel (cbuffer +112): 0-3 are `_COLOR0` rgba, 4-7 are `_COLOR1` rgba, 8 and up are 1. - The colour load uses a descriptor the shader builds itself (word3 0x11014fac): identity swizzle, 8-bit unorm for the colour stream's format. - **Pixel shader.** A layer's coverage starts at min(opacity, z), as in #539. So the channel is the layer's own mode, and the rule is decided per record. What changes: - `peddeco::Region` (`Mask` / `Vertex`) and `Region::of` replace the mask-only check. The mask wins when a record has both flags. - `Corner` carries both colour streams. A part without a stream reads 255 there, so it gets no cap. - `region_cap` takes the region and the layer's mode. The export builds one cap per (region, mode) it needs. - The export's record notes describe both rules. The bake rule version is bumped. **Result.** The guardia's teal torso piece (outfits 17 and 37) is in a 0x40 record as a mode-2 layer. Mode 2 reads `_COLOR0.b`, which is 16 on every vertex of the male skin meshes. So the game draws it at about 6% (16/255), and the bake now matches. Before and after on outfit 17: only the teal piece changes (253 texels, all inside it); the outfit's other baked texture is byte-identical. **Reach:** 27 of the 7,509 records have 0x40 without 0x2. The other two layers in the guardia record are mode 4 (`_COLOR1.r`, 255 on the skin), so they are unchanged. **Caveat:** this uses the vertex colours stored in the mesh files. I found no code that rewrites them at runtime, but I can't rule it out. **Tests:** - flags pick the record's cap (none, vertex, and mask over vertex); - a vertex cap interpolates the mode's channel, has no cap past channel 7, and fills gutters from covered neighbours; - the #539 mask tests, updated to the new signature.
A record with a layer flagged 0x2 has the bake mesh shader cap every
layer's coverage by the mesh's own coverage: z = 1 at a vertex whose four
mask texels lie on the mesh, else 0, interpolated over the triangles, and
coverage starts at min(opacity, z). The cap is built in the layout the
texture is baked in (TEXCOORD_1 on the upper body). Flag 0x40 (a vertex
colour channel as z) is left out.
A record with a layer flagged 0x40 (and none flagged 0x2) caps each
layer's coverage by the vertex colour channel its mode picks: 0-3 are
_COLOR0 rgba, 4-7 _COLOR1 rgba. Read from the game's job builder (shader
record +0x54 = PSO layer mode), its draw (mode to cbuffer +112) and the
bake mesh shader. Bake rule 12.
# Conflicts:
#	crates/sixng-core/src/export.rs
#	crates/sixng-core/src/peddeco.rs
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 05:43:38 +00:00
github-bot changed target branch from master to gh-pr/544/base 2026-11-28 05:54:35 +00:00
github manually merged commit e91797fd31 into gh-pr/544/base 2026-11-28 05:54:37 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.