Materials: two-layer blend weight from the shader code #269
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/holdmysocks--SixNG!269
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/269/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@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 UTCFollow-up to PR 262. The two-layer materials'
multilayerblock 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, onprop_2lyr_batch).What the shader code says
The deferred pixel programs of
standard_2lyrandprop_2lyr_batchwere read in full. The pxm and decal-ground variants (standard_2lyr_pxm,_pxm_ground,_pxm_decal_ground;_groundshares thestandard_2lyrprogram) 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._COLOR1, red byte. COLOR0.a reaches the pixel program too, but it multiplies the dirt overlay's alpha and is not the layer weight.colour = lerp(base, layer2, w)):h = dot(M, 59eb15c5), where M is the blend mask (slot 11,extra_data); use1 - hwhenf208e5ee≠ 0t = saturate(c × (1 + h)), withc = _COLOR1.rk = 1 / max(0.001, blendsoftness²)s = saturate(t / max(0.01, t + k(1 − t)))w = saturate(s × m + blendoffset)w ×= lyr1diffusetex.awhend6de9e14≠ 0blendintensitywhen a per-instance value b is 1. In general it isbifb + d969fac9 < 1, elsemin(blendintensity, 3b). That value is not exported, so the output assumes b = 1.Output
layers[].weightis now1 - w/w.blendblock holds the inputs, the steps, the material's own constants (params) and the formula with them filled in (resolved).vertex_color1_channelsis new.vertex_color_channels.anow says it scales the dirt.f50070cc= 1 is TEXCOORD_0, 2 is TEXCOORD_1 (the mesh program packs mesh UV sets 0 and 1 into one pixel input).Checked
_COLOR1.ris the channel painted over the full range;_COLOR1.gis mostly constant.blendintensityother than 1 (0.1 to 0.91) or ablendoffsetother than 0 (0.05 to 0.3).two_layer_blend_from_constants;prop_two_layer_slotsis 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)).