Hair and fur: game strand generation, clumping and fibre lighting (checkpoint) #304

Manually merged
github merged 75 commits from gh-pr/304/head into gh-pr/304/base 2026-11-26 20:26:00 +00:00
Owner

@⁠holdmysocks on GitHub · 2026-11-25 18:50 UTC · original
holdmysocks:claude/people-hair-lighting → master · +2466 −108 · 15 files · 75 commits · merged 2026-11-25 20:20 UTC

Checkpoint for the hair and fur work (SIX-155). The hair is closer to the game, but it does not match yet. Follow-up PRs will carry the rest.

What changes

Strand generation (sixng-core, groom)

  • Strands grow the way the game's generation program does.
  • Strands are split into two groups:
    • scattered strands, spread by each root triangle's density;
    • clumped strands, grown around hashed clump centre lines and pulled toward them by the asset's stored pull profile.
  • Pieces with clump type 1 grow one strand per thread around a guide strand: it starts at the guide's root, offset by the clump radius in the root triangle's UV frame, and is pulled back toward the guide's curve. This makes long hair fuller and smoother.
  • Each clumped strand keeps one offset frame in its root triangle's plane, so the crown no longer has a frizzy halo.
  • The two clump axis scales are read from the asset.
  • The strand style records are read. The style pass and its strength formula are a research option, off by default. Its per-point strength is set while posing at run time, so the viewer cannot reproduce it.

Hair lighting (viewer)

  • Fibre lighting uses the game's four lighting tables, light sum and parameter and colour ramps along the strand.
  • A camera depth pre-pass adds:
    • strand openness on the hair ambient;
    • screen-space ambient occlusion modelled on the game's horizon pass;
    • reflection occlusion by roughness.
  • Sun shadow map (research option, SIXNG_SHADOWS):
    • strands are drawn into the map;
    • a 13-tap filter, which reaches 3× as far on strands;
    • the shadow ribbons turn each accumulation frame.
  • The hair ambient is the viewer's diffuse ambient taken around the strand tangent, matching the game's final gather, which uses a plain cosine lobe around the tangent (root to tip, not flipped), so the shaded side of hanging hair is darker.
  • The position across a strand's tube comes from per-pixel noise that changes every frame, as in the game's hair resolve; the accumulated frames average it, which removes fine dark lines from the hair.
  • Lash pieces are picked by their own name tag.

Merge with master

  • The hair tables and the research shadow map move to frame bindings 15–21, after the sky (6–11) and the cascaded shadows (12–14).
  • The research map's items are renamed sun_map…, so the cascades keep their names.
  • Its shadow and occlusion terms sit alongside master's sun transmittance, environment normal and sheen.
  • The mesh shaders now read 17 sampled textures in the fragment stage. The device asks for what the adapter supports, up to 32, instead of wgpu's default of 16.

Verified

  • The sixng-core and sixng-gui tests pass in release (296 + 44).
  • The merged viewer renders a character with hair from four views (front, side, back-lit, top), with shadows on. The shader validates, and hair, sky and shadows look as they did before the merge.
  • Cat fur still looks right with the clump changes (its pieces use clump types 0 and 3).

Not done / not verified

  • The 3D map was not opened after the merge; it shares the shader and the raised texture limit.
  • No side-by-side check against the game frames after the merge.
**@⁠holdmysocks** on GitHub · 2026-11-25 18:50 UTC · [original](https://github.com/holdmysocks/SixNG/pull/304) `holdmysocks:claude/people-hair-lighting` → `master` · +2466 −108 · 15 files · 75 commits · merged 2026-11-25 20:20 UTC Checkpoint for the hair and fur work (SIX-155). The hair is closer to the game, but it does not match yet. Follow-up PRs will carry the rest. ## What changes **Strand generation (sixng-core, groom)** - Strands grow the way the game's generation program does. - Strands are split into two groups: - scattered strands, spread by each root triangle's density; - clumped strands, grown around hashed clump centre lines and pulled toward them by the asset's stored pull profile. - Pieces with clump type 1 grow one strand per thread around a guide strand: it starts at the guide's root, offset by the clump radius in the root triangle's UV frame, and is pulled back toward the guide's curve. This makes long hair fuller and smoother. - Each clumped strand keeps one offset frame in its root triangle's plane, so the crown no longer has a frizzy halo. - The two clump axis scales are read from the asset. - The strand style records are read. The style pass and its strength formula are a research option, off by default. Its per-point strength is set while posing at run time, so the viewer cannot reproduce it. **Hair lighting (viewer)** - Fibre lighting uses the game's four lighting tables, light sum and parameter and colour ramps along the strand. - A camera depth pre-pass adds: - strand openness on the hair ambient; - screen-space ambient occlusion modelled on the game's horizon pass; - reflection occlusion by roughness. - Sun shadow map (research option, `SIXNG_SHADOWS`): - strands are drawn into the map; - a 13-tap filter, which reaches 3× as far on strands; - the shadow ribbons turn each accumulation frame. - The hair ambient is the viewer's diffuse ambient taken around the strand tangent, matching the game's final gather, which uses a plain cosine lobe around the tangent (root to tip, not flipped), so the shaded side of hanging hair is darker. - The position across a strand's tube comes from per-pixel noise that changes every frame, as in the game's hair resolve; the accumulated frames average it, which removes fine dark lines from the hair. - Lash pieces are picked by their own name tag. **Merge with master** - The hair tables and the research shadow map move to frame bindings 15–21, after the sky (6–11) and the cascaded shadows (12–14). - The research map's items are renamed `sun_map…`, so the cascades keep their names. - Its shadow and occlusion terms sit alongside master's sun transmittance, environment normal and sheen. - The mesh shaders now read 17 sampled textures in the fragment stage. The device asks for what the adapter supports, up to 32, instead of wgpu's default of 16. ## Verified - The `sixng-core` and `sixng-gui` tests pass in release (296 + 44). - The merged viewer renders a character with hair from four views (front, side, back-lit, top), with shadows on. The shader validates, and hair, sky and shadows look as they did before the merge. - Cat fur still looks right with the clump changes (its pieces use clump types 0 and 3). ## Not done / not verified - The 3D map was not opened after the merge; it shares the shader and the raised texture limit. - No side-by-side check against the game frames after the merge.
Lookup tables stored as R16F / RG16F / RGBA16F / R32F hold values outside 0..1, which the PNG export clamps and quantises to 8 bits. --float also writes <hash>_m<mip>.f32: little-endian 32-bit floats, every slice of the mip in order, channels interleaved; the JSON result gives width, height, slices and channels.
The game's strand generation compute program (smh_gen_1) was read from
the compiled code and checked with an interpreter. New module hairgen
has its arithmetic: the hashed choice of a root triangle weighted by the
triangle's density byte, the seed and barycentric weights of the root,
the per-strand draws, the strand length and the 2-bit variant.

Groom::coat uses it: strands are placed by the game's hashes, cut at
their own length (the blend of the guides' lengths, varied per strand)
and carry their variant. The first of a triangle's four count bytes is a
density weight under rejection sampling, not a strand count.

groom also reads the per-guide threshold bytes of the variant pick, the
groom's seed and its length variation.

Not covered: the strand count and density scale (run-time values), cull
groups, the length texture, and the other variants of the program, where
clumping and curl would be.
# Conflicts:
#	crates/sixng-cli/src/main.rs
Not for merge: the lobe shapes are published fits, not the game's tables,
and the colours it is fed are the raw preset colours, which come out
near-black. Waiting for the game's combining formula and the ramp bake.
Not for merge. hairlight loads the four lookup tables with their real
values; the renderer binds them; the mesh shader has the game's light
sum as transcribed from the compiled program (hair_game). With the raw
preset colours and stand-in material values the result is too dark:
waiting for the ramp bake and a check of the transcription.
hairtone: ParamRamp (four numbers and four Bezier curves of the game's
ramp files) and the curve evaluation. Coat ribbons can carry the ramp's
values per vertex; the hair shader takes g0, the unlit-side fill and the
profile scale from them. A research switch gives the strands shown one
ramp of a parsed ramp file, until those files are read from the game.
hairtone: ColourRamp (four stops and a curve) and the game's bake of it.
A research switch gives a character's hair the four ramps of a colour
set of a parsed ramp file, one per strand variant; the atlas colour is
read as gamma-encoded.
Reads each hair item's own layer (mask texture, opacity number) from the
appearance library and paints it into the head's colour texture. The
colour is a stand-in from the hair colour; the game's colour source and
the layer's other numbers and detail textures are not traced.
With the parsed hair LOD presets given, a character's hair pieces draw the
first round(count x share) strands, share from the game's count rule at the
eye-to-piece distance (presets with ThicknessCurveVersion 2 only). A second
research switch widens the strands by 1 / share at one distance, to test
whether the reduced count comes with wider strands.
SIXNG_SHOT_FRAMES=<n> steps the strand dither pattern per frame and saves
the mean of n frames, as the game's per-frame dither is averaged over time.
SIXNG_SHADOWS=1 draws the opaque surfaces and the strands into one depth
map from the sun and lights surfaces and strands through it. A stand-in
for the game's shadow maps: its cascades, bias and filter are not read.
Density from the mask between the layer's two bounds, broken up by the
hex-tiled detail texture turned by the direction map; colour from the
two-colour preset of the item's preset set, slot by slot. Replaces the
gradient stand-in. The strand count rule takes the mean width of the
set's first ramp.
The share now depends on the view's field of view and height, hair pieces
past their cutoff distance are not drawn, and an animal's fur follows the
rule of the version-1 presets. The research widening switch is removed.
Of the strands a piece draws, the first power-of-two share by GILodScale
enters the shadow map as flat ribbons with a random facing per strand,
each widened so the summed width stays. A shadow map of these ribbons
stands in for tracing rays against them. SIXNG_SHADOWS=map keeps the
cascade pass's rule.
An outfit's colour items (tag b28c2b3f: item category, colour set) give
every strand piece of that category its colour set, before the colour the
hair item itself names. Read from the wardrobe data and checked against
game pictures of one character.
With sun shadows on, the scene is drawn depth-only from the eye before the
main pass. Strands lit by the hair program scale their ambient by the
game's openness (16 weighted depth taps around the pixel) times the ramp
profile. Opaque surfaces get a horizon-style occlusion of ambient light,
the viewer's own stand-in for the game's screen-space occlusion.
Two perpendicular slices, two depth taps per side at j^2 R + 1.3 and
(1 + j)^2 R + 1.3 pixels, horizons blended to the tangent plane by the
depth difference in pixel units, the usual horizon integral. Replaces the
viewer's own stand-in. How the game mixes the result into its indirect
light is not read; the viewer scales ambient light by it.
The game's standard lighting uses the horizon pass on reflections, never on
diffuse ambient and never on hair. The viewer scales specular ambient by the
plain visibility (the game's cone test has constants that are not read).
The game's hair program adds its reflection buffer scaled by an environment
Fresnel factor that carries the openness (0.3 + 1.4 o), and keeps 1 - that
factor on the diffuse ambient. The viewer uses its sky along the reflection
about the tube normal and a published fit for the environment table.
strength = max(0, 1 - 2 x roughness): none from roughness 0.5 upward, so
skin reflections are no longer darkened by it.
The game's hair program samples the table at roughness 0.5 + 0.5 (1 - g0).
- Hair ambient: o = sqrt(profile / 15 x openness), as the game's hair
  program has it (an output modifier was missing from the earlier read).
- The hair reflection ambient reads the game's environment table,
  recomputed from its definition at 16 x 16 texel centres, in place of a
  published fit (within 0.01 of the game's sample values).
- Horizon occlusion taps at (j/2)^2 R + 1.3 and ((1 + j)/2)^2 R + 1.3 px.
- Research switch SIXNG_HAIR_GROOMS=slot:offset+offset draws chosen
  strand pieces for a slot.
# Conflicts:
#	crates/sixng-core/src/groom.rs
#	crates/sixng-core/src/pedlook.rs
#	crates/sixng-core/src/wardrobe.rs
#	crates/sixng-gui/src/model_view.rs
#	crates/sixng-gui/src/render3d.rs
#	crates/sixng-gui/src/shader.wgsl
# Conflicts:
#	crates/sixng-gui/src/render3d.rs
#	crates/sixng-gui/src/shader.wgsl
The hair research shadow map moves to frame bindings 19-21 and its items
are renamed sun_map, so master's cascades keep their names and bindings
12-14. The device asks for up to 32 sampled textures per stage: the mesh
shaders now read 17.
Pieces with clump type 1 (system +0x12D) grow one strand per thread: the
thread picks a guide by hash, starts at the guide's root offset by the
clump radius in the root triangle's UV frame (A1 gives the triangle), and
is walked toward the guide's own curve plus the pulled offset. Mode 2 is
unchanged and now shares the member walk.
The game's final gather looks hair up with the strand tangent in place of
the normal, through a plain Lambert lobe. The hair ambient now uses the
viewer's diffuse ambient (sky and ground bounce, or the HDR sky's ambient
cube) around the tangent instead of a sky gradient at the root normal.
# Conflicts:
#	crates/sixng-gui/src/model_view.rs
# Conflicts:
#	crates/sixng-gui/src/shader.wgsl
The game's tiled hair G-buffer resolve takes the position u across the
strand's tube from interleaved gradient noise at the pixel, offset per
frame by 5.58824 (frame & 63), not from the pixel's place in the drawn
ribbon; its temporal anti-aliasing averages that over the tube. Taking
the raster position left a dark half on every 2-pixel ribbon, which read
as fine lines over the hair; with the noise and the shot's accumulation
frames the hair reads smooth.
# Conflicts:
#	crates/sixng-gui/src/render3d.rs
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 20:25:58 +00:00
github manually merged commit 347285c531 into gh-pr/304/base 2026-11-26 20:26:00 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.