Materials: two-layer blend weight from the shader code #269

Manually merged
github merged 2 commits from gh-pr/269/head into gh-pr/269/base 2026-11-26 20:23:08 +00:00
Owner

@⁠holdmysocks on GitHub · 2026-11-25 13:08 UTC · original
holdmysocks:six-2lyr-blend → master · +135 −23 · 2 files · 2 commits · merged 2026-11-25 13:55 UTC

Follow-up to PR 262. The two-layer materials' multilayer block now gives the layer weight the way the shaders compute it. Before, it named COLOR0.a, which was a guess from vertex statistics (and the reverse, 1 − COLOR0.a, on prop_2lyr_batch).

What the shader code says

The deferred pixel programs of standard_2lyr and prop_2lyr_batch were read in full. The pxm and decal-ground variants (standard_2lyr_pxm, _pxm_ground, _pxm_decal_ground; _ground shares the standard_2lyr program) have the same code; the pxm ones first run a pass that moves the mask's UV. The mesh programs were also read, to see which vertex stream feeds which pixel input.

  • Weight input: the pixel input COLOR1.x. The mesh programs load it from mesh stream 12, which is the exported _COLOR1, red byte. COLOR0.a reaches the pixel program too, but it multiplies the dirt overlay's alpha and is not the layer weight.
  • Formula (colour = lerp(base, layer2, w)):
    • h = dot(M, 59eb15c5), where M is the blend mask (slot 11, extra_data); use 1 - h when f208e5ee ≠ 0
    • t = saturate(c × (1 + h)), with c = _COLOR1.r
    • k = 1 / max(0.001, blendsoftness²)
    • s = saturate(t / max(0.01, t + k(1 − t)))
    • w = saturate(s × m + blendoffset)
    • w ×= lyr1diffusetex.a when d6de9e14 ≠ 0
  • m is blendintensity when a per-instance value b is 1. In general it is b if b + d969fac9 < 1, else min(blendintensity, 3b). That value is not exported, so the output assumes b = 1.

Output

  • layers[].weight is now 1 - w / w.
  • A new blend block holds the inputs, the steps, the material's own constants (params) and the formula with them filled in (resolved).
  • vertex_color1_channels is new. vertex_color_channels.a now says it scales the dirt.
  • The README is updated.
  • The mask's UV: f50070cc = 1 is TEXCOORD_0, 2 is TEXCOORD_1 (the mesh program packs mesh UV sets 0 and 1 into one pixel input).

Checked

  • 270 sampled map models, 1,350 two-layer materials. _COLOR1.r is the channel painted over the full range; _COLOR1.g is mostly constant.
  • 53 of those materials have a blendintensity other than 1 (0.1 to 0.91) or a blendoffset other than 0 (0.05 to 0.3).
  • New test two_layer_blend_from_constants; prop_two_layer_slots is updated.

Not compared with a rendered image. Not read: where the per-instance value comes from, and the normal and material-map blend (which uses max(0, w − _COLOR1.g)).

**@⁠holdmysocks** on GitHub · 2026-11-25 13:08 UTC · [original](https://github.com/holdmysocks/SixNG/pull/269) `holdmysocks:six-2lyr-blend` → `master` · +135 −23 · 2 files · 2 commits · merged 2026-11-25 13:55 UTC Follow-up to PR 262. The two-layer materials' `multilayer` block now gives the layer weight the way the shaders compute it. Before, it named COLOR0.a, which was a guess from vertex statistics (and the reverse, 1 − COLOR0.a, on `prop_2lyr_batch`). ## What the shader code says The deferred pixel programs of `standard_2lyr` and `prop_2lyr_batch` were read in full. The pxm and decal-ground variants (`standard_2lyr_pxm`, `_pxm_ground`, `_pxm_decal_ground`; `_ground` shares the `standard_2lyr` program) have the same code; the pxm ones first run a pass that moves the mask's UV. The mesh programs were also read, to see which vertex stream feeds which pixel input. - **Weight input:** the pixel input COLOR1.x. The mesh programs load it from mesh stream 12, which is the exported `_COLOR1`, red byte. COLOR0.a reaches the pixel program too, but it multiplies the dirt overlay's alpha and is not the layer weight. - **Formula** (`colour = lerp(base, layer2, w)`): - `h = dot(M, 59eb15c5)`, where M is the blend mask (slot 11, `extra_data`); use `1 - h` when `f208e5ee` ≠ 0 - `t = saturate(c × (1 + h))`, with `c = _COLOR1.r` - `k = 1 / max(0.001, blendsoftness²)` - `s = saturate(t / max(0.01, t + k(1 − t)))` - `w = saturate(s × m + blendoffset)` - `w ×= lyr1diffusetex.a` when `d6de9e14` ≠ 0 - **m** is `blendintensity` when a per-instance value b is 1. In general it is `b` if `b + d969fac9 < 1`, else `min(blendintensity, 3b)`. That value is not exported, so the output assumes b = 1. ## Output - `layers[].weight` is now `1 - w` / `w`. - A new `blend` block holds the inputs, the steps, the material's own constants (`params`) and the formula with them filled in (`resolved`). - `vertex_color1_channels` is new. `vertex_color_channels.a` now says it scales the dirt. - The README is updated. - The mask's UV: `f50070cc` = 1 is TEXCOORD_0, 2 is TEXCOORD_1 (the mesh program packs mesh UV sets 0 and 1 into one pixel input). ## Checked - 270 sampled map models, 1,350 two-layer materials. `_COLOR1.r` is the channel painted over the full range; `_COLOR1.g` is mostly constant. - 53 of those materials have a `blendintensity` other than 1 (0.1 to 0.91) or a `blendoffset` other than 0 (0.05 to 0.3). - New test `two_layer_blend_from_constants`; `prop_two_layer_slots` is updated. Not compared with a rendered image. Not read: where the per-instance value comes from, and the normal and material-map blend (which uses `max(0, w − _COLOR1.g)`).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 20:23:06 +00:00
github manually merged commit b6ec17cf74 into gh-pr/269/base 2026-11-26 20:23:08 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.