reze-engine 0.11.3 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -12,12 +12,16 @@ npm install reze-engine
12
12
 
13
13
  ## Features
14
14
 
15
- - Anime/MMD-style hybrid renderer — toon-ramp NPR diffuse mixed with GGX specular (multi-scatter + LTC energy compensation), per-material presets (face / hair / body / eye / stockings / metal / cloth / default), HDR pipeline with bloom and Filmic tone mapping, alpha-hashed transparency, screen-space outlines, MSAA 4x
16
- - VMD animation with IK solver and Bullet physics
17
- - Orbit camera with bone-follow mode
18
- - GPU picking (double-click/tap)
19
- - Ground plane with PCF shadow mapping
20
- - Multi-model support
15
+ - **Anime/MMD-style hybrid renderer** — toon-ramp NPR diffuse mixed with PBR GGX specular (multi-scatter + LTC energy compensation)
16
+ - **Per-material presets** `face` / `hair` / `body` / `eye` / `stockings` / `metal` / `cloth_smooth` / `cloth_rough` / `default`, assigned by material name
17
+ - **HDR pipeline** with bloom mip pyramid, Filmic tone mapping, 4× MSAA
18
+ - **Alpha-hashed transparency** (Wyman & McGuire 2017) for self-overlapping transparent meshes like stockings
19
+ - **Screen-space outlines** on opaque + transparent materials
20
+ - **VMD animation** with IK solver and Bullet physics
21
+ - **Orbit camera** with bone-follow mode
22
+ - **GPU picking** (double-click/tap)
23
+ - **Ground plane** with PCF shadow mapping
24
+ - **Multi-model support**
21
25
 
22
26
  ## Usage
23
27
 
@@ -25,13 +29,36 @@ npm install reze-engine
25
29
  import { Engine, Vec3 } from "reze-engine";
26
30
 
27
31
  const engine = new Engine(canvas, {
28
- world: { color: new Vec3(0.4, 0.49, 0.65), strength: 1.0 },
29
- sun: { color: new Vec3(1, 1, 1), strength: 2.0, direction: new Vec3(0, -0.5, 1) },
32
+ world: { color: new Vec3(0.4, 0.49, 0.65), strength: 1.0 },
33
+ sun: {
34
+ color: new Vec3(1, 1, 1),
35
+ strength: 2.0,
36
+ direction: new Vec3(0, -0.5, 1),
37
+ },
30
38
  camera: { distance: 31.5, target: new Vec3(0, 11.5, 0) }, // MMD units (1 unit = 8 cm)
31
39
  });
32
40
  await engine.init();
33
41
 
42
+ engine.setBloomOptions({
43
+ color: new Vec3(0.9, 0.1, 0.8),
44
+ intensity: 0.05,
45
+ threshold: 0.5,
46
+ });
47
+
34
48
  const model = await engine.loadModel("hero", "/models/hero/hero.pmx");
49
+
50
+ // Map PMX material names to NPR presets (unlisted names fall back to `default`).
51
+ engine.setMaterialPresets("hero", {
52
+ face: ["face01"],
53
+ body: ["skin"],
54
+ hair: ["hair_f"],
55
+ eye: ["eye"],
56
+ cloth_smooth: ["shirt", "shorts", "dress", "shoes"],
57
+ cloth_rough: ["jacket", "pants"],
58
+ stockings: ["stockings"],
59
+ metal: ["metal01", "earring"],
60
+ });
61
+
35
62
  await model.loadVmd("idle", "/animations/idle.vmd");
36
63
  model.show("idle");
37
64
  model.play();
@@ -81,13 +108,17 @@ engine.dispose()
81
108
 
82
109
  Use a hidden `<input type="file" webkitdirectory multiple>` (or drag/drop) and pass the resulting `FileList` or `File[]` into the engine. Textures resolve relative to the chosen PMX file inside that tree.
83
110
 
84
- **Important:** read `input.files` into a normal array **before** setting `input.value = ""`. The browser’s `FileList` is *live* — clearing the input empties it.
111
+ **Important:** read `input.files` into a normal array **before** setting `input.value = ""`. The browser’s `FileList` is _live_ — clearing the input empties it.
85
112
 
86
113
  1. **`parsePmxFolderInput(fileList)`** — returns a tagged result (`empty` | `not_directory` | `no_pmx` | `single` | `multiple`). For `single`, you already have `files` and `pmxFile`. For `multiple`, show a picker (dropdown) of `pmxRelativePaths`, then resolve with **`pmxFileAtRelativePath(files, path)`**.
87
114
  2. **`engine.loadModel(name, { files, pmxFile })`** — `pmxFile` selects which `.pmx` when the folder contains several.
88
115
 
89
116
  ```javascript
90
- import { Engine, parsePmxFolderInput, pmxFileAtRelativePath } from "reze-engine";
117
+ import {
118
+ Engine,
119
+ parsePmxFolderInput,
120
+ pmxFileAtRelativePath,
121
+ } from "reze-engine";
91
122
 
92
123
  // In <input onChange>:
93
124
  const picked = parsePmxFolderInput(e.target.files);
@@ -103,7 +134,10 @@ if (picked.status === "single") {
103
134
  if (picked.status === "multiple") {
104
135
  // Let the user choose `chosenPath` from picked.pmxRelativePaths, then:
105
136
  const pmxFile = pmxFileAtRelativePath(picked.files, chosenPath);
106
- const model = await engine.loadModel("myModel", { files: picked.files, pmxFile });
137
+ const model = await engine.loadModel("myModel", {
138
+ files: picked.files,
139
+ pmxFile,
140
+ });
107
141
  }
108
142
  ```
109
143
 
@@ -165,8 +199,8 @@ Blender-style scene config — `world` = environment lighting, `sun` = the direc
165
199
  ```javascript
166
200
  {
167
201
  world: {
168
- color: Vec3, // World > Surface > Color (linear scene-referred)
169
- strength: number, // World > Surface > Strength
202
+ color: Vec3, // World > Surface > Color (linear scene-referred)
203
+ strength: number, // World > Surface > Strength
170
204
  },
171
205
  sun: {
172
206
  color: Vec3, // Light > Color
@@ -185,7 +219,7 @@ Blender-style scene config — `world` = environment lighting, `sun` = the direc
185
219
  }
186
220
  ```
187
221
 
188
- The shadow map is cast from `sun.direction` — same vector the shader lights with — so the visible shading and cast shadows stay coupled.
222
+ The shadow map is cast from `sun.direction` — same vector the shader lights with — so visible shading and cast shadows stay coupled.
189
223
 
190
224
  `engine.setWorld({ color?, strength? })` and `engine.setSun({ color?, strength?, direction? })` update lighting at runtime; changing `sun.direction` refreshes the shadow VP on the next frame.
191
225
 
@@ -217,17 +251,17 @@ Every preset is built out of the same NPR primitives:
217
251
 
218
252
  Each PMX material is dispatched to one of these shaders:
219
253
 
220
- | Preset | Look |
221
- | -------------- | ---- |
222
- | `face` | toon ramp + rim + warm subsurface bleed + Principled mix |
223
- | `hair` | layered hair toon + Fresnel rim + Principled spec mix |
224
- | `body` | toon ramp + AO modulation + rim + Principled mix |
225
- | `eye` | iris with emission boost (drives bloom) |
226
- | `stockings` | NPR-tinted Principled with sheen, alpha-hashed |
254
+ | Preset | Look |
255
+ | -------------- | ------------------------------------------------------------------------------ |
256
+ | `face` | toon ramp + rim + warm subsurface bleed + Principled mix |
257
+ | `hair` | layered hair toon + Fresnel rim + Principled spec mix |
258
+ | `body` | toon ramp + AO modulation + rim + Principled mix |
259
+ | `eye` | iris with emission boost (drives bloom) |
260
+ | `stockings` | NPR-tinted Principled with sheen, alpha-hashed |
227
261
  | `metal` | full-metallic Principled + reflection-coord Voronoi sparkle + NPR toon overlay |
228
- | `cloth_smooth` | Principled cloth with sheen, smoother variant |
229
- | `cloth_rough` | rougher cloth variant |
230
- | `default` | plain Principled BSDF (unmapped fallback) |
262
+ | `cloth_smooth` | Principled cloth with sheen, smoother variant |
263
+ | `cloth_rough` | rougher cloth variant |
264
+ | `default` | plain Principled BSDF (unmapped fallback) |
231
265
 
232
266
  ### Shadows, post, output
233
267
 
@@ -237,21 +271,7 @@ Each PMX material is dispatched to one of these shaders:
237
271
  - Filmic tone mapping (LUT sampled from the same view-transform curve used by "Filmic / Medium High Contrast"), exposure baked in
238
272
  - Screen-space outline pass (inverted-hull) on opaque and transparent materials
239
273
 
240
- Assign presets per-model:
241
-
242
- ```javascript
243
- engine.setMaterialPresets("hero", {
244
- face: ["顔", "白目", "口の中"],
245
- hair: ["髪", "前髪"],
246
- body: ["肌"],
247
- eye: ["瞳"],
248
- stockings: ["袜子"],
249
- cloth_smooth: ["制服", "スカート"],
250
- metal: ["ボタン"],
251
- });
252
- ```
253
-
254
- Material names not listed fall through to the `default` Principled BSDF.
274
+ Assign presets per-model with `engine.setMaterialPresets(name, map)` (see the [Usage](#usage) example). Material names not listed fall through to the `default` Principled BSDF.
255
275
 
256
276
  ### Alpha-hashed transparency
257
277
 
package/dist/engine.d.ts CHANGED
@@ -113,6 +113,7 @@ export declare class Engine {
113
113
  private metalPipeline;
114
114
  private bodyPipeline;
115
115
  private eyePipeline;
116
+ private hairOverEyesPipeline;
116
117
  private stockingsPipeline;
117
118
  private groundShadowPipeline;
118
119
  private groundShadowBindGroupLayout;
@@ -128,6 +129,9 @@ export declare class Engine {
128
129
  private hdrResolveTexture;
129
130
  private static readonly MULTISAMPLE_COUNT;
130
131
  private static readonly HDR_FORMAT;
132
+ /** Stencil value stamped by eye draws so hair can stencil-test against it and
133
+ * alpha-blend a second pass over eye silhouette pixels (see-through-hair effect). */
134
+ private static readonly STENCIL_EYE_VALUE;
131
135
  /** Single-channel mask written alongside HDR color — 1 = model geometry (contributes
132
136
  * to bloom), 0 = ground (never blooms). Sampled by the bloom blit pass to gate the
133
137
  * prefilter so ground brightness can't halo the scene. */
@@ -345,6 +349,13 @@ export declare class Engine {
345
349
  * pipelines is self-contained (no cross-batch dependencies).
346
350
  */
347
351
  private renderOneModel;
352
+ /**
353
+ * Second hair pass for the see-through-hair effect. Re-draws every hair opaque
354
+ * draw using `hairOverEyesPipeline` — which stencil-matches `EYE_VALUE` and runs
355
+ * the hair shader with `IS_OVER_EYES=true` so alpha is halved. depthWriteEnabled
356
+ * is off, so the eye's depth stays authoritative for anything drawn after.
357
+ */
358
+ private drawHairOverEyes;
348
359
  private updateCameraUniforms;
349
360
  private updateSkinMatrices;
350
361
  private updateStats;
@@ -1 +1 @@
1
- {"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AACA,OAAO,EAAQ,IAAI,EAAE,MAAM,QAAQ,CAAA;AACnC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAE/B,OAAO,EAAW,KAAK,cAAc,EAAE,MAAM,WAAW,CAAA;AACxD,OAAO,EAQL,KAAK,WAAW,EACjB,MAAM,gBAAgB,CAAA;AA0BvB,MAAM,MAAM,cAAc,GACtB,SAAS,GACT,MAAM,GACN,MAAM,GACN,MAAM,GACN,KAAK,GACL,WAAW,GACX,OAAO,GACP,cAAc,GACd,aAAa,CAAA;AAEjB,MAAM,MAAM,iBAAiB,GAAG,OAAO,CAAC,MAAM,CAAC,cAAc,EAAE,MAAM,EAAE,CAAC,CAAC,CAAA;AAUzE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IA6CvB,OAAO,CAAC,YAAY;IASpB,OAAO,CAAC,uBAAuB,CAI9B;IAED,OAAO,CAAC,iBAAiB,CA0BxB;IAED,OAAO,CAAC,cAAc;IAStB,OAAO,CAAC,cAAc;YA+CR,iBAAiB;IA6C/B,MAAM;IAiHN,OAAO,CAAC,kBAAkB;IAW1B,OAAO,CAAC,iBAAiB;IAYzB;;;;;OAKG;IACH,OAAO,CAAC,aAAa;IAoBrB;;;;;OAKG;IACH,OAAO,CAAC,YAAY;IAepB;;;;;OAKG;IACH,OAAO,CAAC,cAAc;IAiBtB;;;;;OAKG;IACH,OAAO,CAAC,gBAAgB;IAexB,OAAO,CAAC,oBAAoB;IAY5B,OAAO,CAAC,kBAAkB;IAa1B,OAAO,CAAC,WAAW;CAwBpB"}
package/dist/engine.js CHANGED
@@ -554,6 +554,9 @@ export class Engine {
554
554
  depthCompare: "less-equal",
555
555
  },
556
556
  });
557
+ // Hair opaque: stencil != EYE_VALUE so fragments on top of eyes are skipped entirely —
558
+ // depth and color stay as the eye wrote them; the follow-up hairOverEyesPipeline then
559
+ // draws those skipped fragments alpha-blended so the eye reads through the hair.
557
560
  this.hairPipeline = this.createRenderPipeline({
558
561
  label: "hair NPR pipeline",
559
562
  layout: mainPipelineLayout,
@@ -565,8 +568,37 @@ export class Engine {
565
568
  format: "depth24plus-stencil8",
566
569
  depthWriteEnabled: true,
567
570
  depthCompare: "less-equal",
571
+ stencilFront: { compare: "not-equal", failOp: "keep", depthFailOp: "keep", passOp: "keep" },
572
+ stencilBack: { compare: "not-equal", failOp: "keep", depthFailOp: "keep", passOp: "keep" },
573
+ stencilReadMask: 0xff,
574
+ stencilWriteMask: 0,
568
575
  },
569
576
  });
577
+ // Hair-over-eyes: same shader with IS_OVER_EYES=true so alpha is halved at compile time.
578
+ // Only fragments where eye stencil == EYE_VALUE pass; depth test still culls fragments
579
+ // that are further from camera than the eye, so hair behind the eye never shows through.
580
+ // depthWriteEnabled=false keeps the eye's depth authoritative for everything drawn after.
581
+ this.hairOverEyesPipeline = this.device.createRenderPipeline({
582
+ label: "hair over eyes pipeline",
583
+ layout: mainPipelineLayout,
584
+ vertex: { module: hairShaderModule, buffers: fullVertexBuffers },
585
+ fragment: {
586
+ module: hairShaderModule,
587
+ constants: { IS_OVER_EYES: 1 },
588
+ targets: sceneTargets,
589
+ },
590
+ primitive: { cullMode: "none" },
591
+ depthStencil: {
592
+ format: "depth24plus-stencil8",
593
+ depthWriteEnabled: false,
594
+ depthCompare: "less-equal",
595
+ stencilFront: { compare: "equal", failOp: "keep", depthFailOp: "keep", passOp: "keep" },
596
+ stencilBack: { compare: "equal", failOp: "keep", depthFailOp: "keep", passOp: "keep" },
597
+ stencilReadMask: 0xff,
598
+ stencilWriteMask: 0,
599
+ },
600
+ multisample: { count: Engine.MULTISAMPLE_COUNT },
601
+ });
570
602
  this.clothSmoothPipeline = this.createRenderPipeline({
571
603
  label: "cloth smooth NPR pipeline",
572
604
  layout: mainPipelineLayout,
@@ -619,17 +651,30 @@ export class Engine {
619
651
  depthCompare: "less-equal",
620
652
  },
621
653
  });
654
+ // Eye: stamps stencil = EYE_VALUE on every fragment it writes. Later hair passes read
655
+ // this stamp to split into "draw normally (not over eye)" vs "draw alpha-blended".
656
+ // cullMode="front" + small negative depthBias is the MMD post-alpha-eye trick: only the
657
+ // back half of the eye sphere renders, it passes depth against the face (via bias) when
658
+ // viewed from the front, and it gets culled when viewed from behind — so eye fragments
659
+ // can't leak through the back of the head without needing a per-model skull occluder.
622
660
  this.eyePipeline = this.createRenderPipeline({
623
661
  label: "eye pipeline",
624
662
  layout: mainPipelineLayout,
625
663
  shaderModule: eyeShaderModule,
626
664
  vertexBuffers: fullVertexBuffers,
627
665
  fragmentTargets: sceneTargets,
628
- cullMode: "none",
666
+ cullMode: "front",
629
667
  depthStencil: {
630
668
  format: "depth24plus-stencil8",
631
669
  depthWriteEnabled: true,
632
670
  depthCompare: "less-equal",
671
+ depthBias: -0.00005,
672
+ depthBiasSlopeScale: 0.0,
673
+ depthBiasClamp: 0.0,
674
+ stencilFront: { compare: "always", failOp: "keep", depthFailOp: "keep", passOp: "replace" },
675
+ stencilBack: { compare: "always", failOp: "keep", depthFailOp: "keep", passOp: "replace" },
676
+ stencilReadMask: 0xff,
677
+ stencilWriteMask: 0xff,
633
678
  },
634
679
  });
635
680
  this.stockingsPipeline = this.createRenderPipeline({
@@ -769,6 +814,13 @@ export class Engine {
769
814
  // Don’t write outline into depth buffer — stops z-fighting / black cracks vs body (MMD-style; body depth stays authoritative)
770
815
  depthWriteEnabled: false,
771
816
  depthCompare: "less-equal",
817
+ // Skip fragments where the eye stamped stencil=EYE_VALUE. Those pixels are owned by
818
+ // the see-through-hair blend (hair-over-eyes), so letting the outline's near-black
819
+ // edge color overwrite them would re-introduce the dark almond we just killed.
820
+ stencilFront: { compare: "not-equal", failOp: "keep", depthFailOp: "keep", passOp: "keep" },
821
+ stencilBack: { compare: "not-equal", failOp: "keep", depthFailOp: "keep", passOp: "keep" },
822
+ stencilReadMask: 0xff,
823
+ stencilWriteMask: 0,
772
824
  },
773
825
  });
774
826
  // ─── Bloom (EEVEE 3.6 pyramid): blit(Karis prefilter) → 13-tap downsamples → 9-tap tent upsamples ───
@@ -1785,6 +1837,26 @@ export class Engine {
1785
1837
  }
1786
1838
  currentIndexOffset += indexCount;
1787
1839
  }
1840
+ // Sort so the opaque bucket is emitted in the order the stencil-based
1841
+ // see-through-hair effect requires: {non-hair, non-eye} → {eye} → {hair}.
1842
+ // Eye writes stencil=EYE_VALUE; hair's pipeline stencil-tests "not equal" so
1843
+ // it skips eye pixels; a follow-up hairOverEyes pass (see renderOneModel)
1844
+ // re-fills those skipped pixels alpha-blended. Array.sort is stable in
1845
+ // ES2019+, so within a bucket the PMX material order is preserved.
1846
+ const typeOrder = {
1847
+ opaque: 0,
1848
+ "opaque-outline": 1,
1849
+ transparent: 2,
1850
+ "transparent-outline": 3,
1851
+ ground: 4,
1852
+ };
1853
+ const presetRank = (p) => (p === "hair" ? 2 : p === "eye" ? 1 : 0);
1854
+ inst.drawCalls.sort((a, b) => {
1855
+ const ta = typeOrder[a.type] - typeOrder[b.type];
1856
+ if (ta !== 0)
1857
+ return ta;
1858
+ return presetRank(a.preset) - presetRank(b.preset);
1859
+ });
1788
1860
  for (const d of inst.drawCalls) {
1789
1861
  if (d.type === "opaque")
1790
1862
  inst.shadowDrawCalls.push(d);
@@ -2176,11 +2248,36 @@ export class Engine {
2176
2248
  pass.setVertexBuffer(1, inst.jointsBuffer);
2177
2249
  pass.setVertexBuffer(2, inst.weightsBuffer);
2178
2250
  pass.setIndexBuffer(inst.indexBuffer, "uint32");
2251
+ // Single stencil-reference set covers eye (write), hair (read not-equal),
2252
+ // and hairOverEyes (read equal). Non-stencil pipelines ignore the value.
2253
+ pass.setStencilReference(Engine.STENCIL_EYE_VALUE);
2179
2254
  this.drawMaterials(pass, inst, "opaque");
2180
2255
  this.drawOutlines(pass, inst, "opaque-outline");
2256
+ this.drawHairOverEyes(pass, inst);
2181
2257
  this.drawMaterials(pass, inst, "transparent");
2182
2258
  this.drawOutlines(pass, inst, "transparent-outline");
2183
2259
  }
2260
+ /**
2261
+ * Second hair pass for the see-through-hair effect. Re-draws every hair opaque
2262
+ * draw using `hairOverEyesPipeline` — which stencil-matches `EYE_VALUE` and runs
2263
+ * the hair shader with `IS_OVER_EYES=true` so alpha is halved. depthWriteEnabled
2264
+ * is off, so the eye's depth stays authoritative for anything drawn after.
2265
+ */
2266
+ drawHairOverEyes(pass, inst) {
2267
+ let bound = false;
2268
+ for (const draw of inst.drawCalls) {
2269
+ if (draw.type !== "opaque" || draw.preset !== "hair" || !this.shouldRenderDrawCall(inst, draw))
2270
+ continue;
2271
+ if (!bound) {
2272
+ pass.setPipeline(this.hairOverEyesPipeline);
2273
+ pass.setBindGroup(0, this.perFrameBindGroup);
2274
+ pass.setBindGroup(1, inst.mainPerInstanceBindGroup);
2275
+ bound = true;
2276
+ }
2277
+ pass.setBindGroup(2, draw.bindGroup);
2278
+ pass.drawIndexed(draw.count, 1, draw.firstIndex, 0, 0);
2279
+ }
2280
+ }
2184
2281
  updateCameraUniforms() {
2185
2282
  const viewMatrix = this.camera.getViewMatrix();
2186
2283
  const projectionMatrix = this.camera.getProjectionMatrix();
@@ -2224,6 +2321,9 @@ export class Engine {
2224
2321
  Engine.instance = null;
2225
2322
  Engine.MULTISAMPLE_COUNT = 4;
2226
2323
  Engine.HDR_FORMAT = "rgba16float";
2324
+ /** Stencil value stamped by eye draws so hair can stencil-test against it and
2325
+ * alpha-blend a second pass over eye silhouette pixels (see-through-hair effect). */
2326
+ Engine.STENCIL_EYE_VALUE = 1;
2227
2327
  /** Single-channel mask written alongside HDR color — 1 = model geometry (contributes
2228
2328
  * to bloom), 0 = ground (never blooms). Sampled by the bloom blit pass to gate the
2229
2329
  * prefilter so ground brightness can't halo the scene. */
@@ -1,2 +1,2 @@
1
- export declare const HAIR_SHADER_WGSL = "\n\n\n\n// Baked 64\u00D764 rgba8unorm combined BRDF LUT \u2014 created once at engine init by dfg_lut.ts.\n// .rg = split-sum DFG (Karis: tint = f0\u00B7x + f90\u00B7y) \u2192 F_brdf_*_scatter\n// .ba = Heitz 2016 LTC magnitude (ltc_mag_ggx) \u2192 ltc_brdf_scale_from_lut\n// Paired with group(0) binding(2) diffuseSampler (linear filter). Sample once per\n// fragment via brdf_lut_sample() \u2014 callers feed .rg and the whole vec4 into the\n// helpers below, halving LUT taps on the default Principled path.\n@group(0) @binding(9) var brdfLut: texture_2d<f32>;\n\n// \u2500\u2500\u2500 RGB \u2194 HSV \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nfn rgb_to_hsv(rgb: vec3f) -> vec3f {\n let c_max = max(rgb.r, max(rgb.g, rgb.b));\n let c_min = min(rgb.r, min(rgb.g, rgb.b));\n let delta = c_max - c_min;\n\n var h = 0.0;\n if (delta > 1e-6) {\n if (c_max == rgb.r) {\n h = (rgb.g - rgb.b) / delta;\n if (h < 0.0) { h += 6.0; }\n } else if (c_max == rgb.g) {\n h = 2.0 + (rgb.b - rgb.r) / delta;\n } else {\n h = 4.0 + (rgb.r - rgb.g) / delta;\n }\n h /= 6.0;\n }\n let s = select(0.0, delta / c_max, c_max > 1e-6);\n return vec3f(h, s, c_max);\n}\n\nfn hsv_to_rgb(hsv: vec3f) -> vec3f {\n let h = hsv.x;\n let s = hsv.y;\n let v = hsv.z;\n if (s < 1e-6) { return vec3f(v); }\n\n let hh = fract(h) * 6.0;\n let sector = u32(hh);\n let f = hh - f32(sector);\n let p = v * (1.0 - s);\n let q = v * (1.0 - s * f);\n let t = v * (1.0 - s * (1.0 - f));\n\n switch (sector) {\n case 0u: { return vec3f(v, t, p); }\n case 1u: { return vec3f(q, v, p); }\n case 2u: { return vec3f(p, v, t); }\n case 3u: { return vec3f(p, q, v); }\n case 4u: { return vec3f(t, p, v); }\n default: { return vec3f(v, p, q); }\n }\n}\n\n// \u2500\u2500\u2500 HUE_SAT node \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nfn hue_sat(hue: f32, saturation: f32, value: f32, fac: f32, color: vec3f) -> vec3f {\n var hsv = rgb_to_hsv(color);\n hsv.x = fract(hsv.x + hue - 0.5);\n hsv.y = clamp(hsv.y * saturation, 0.0, 1.0);\n hsv.z *= value;\n return mix(color, hsv_to_rgb(hsv), fac);\n}\n\n// hue_sat specialization for hue=0.5 (identity hue shift \u2014 fract(h + 0.5 - 0.5) = h).\n// Branchless equivalent that skips the rgb_to_hsv \u2192 hsv_to_rgb roundtrip: WebKit's\n// Metal backend serializes the 3-way if chain in rgb_to_hsv and the 6-way switch in\n// hsv_to_rgb, where this form compiles to linear SIMD ops + a single select.\nfn hue_sat_id(saturation: f32, value: f32, fac: f32, color: vec3f) -> vec3f {\n let m = max(max(color.r, color.g), color.b);\n let n = min(min(color.r, color.g), color.b);\n // Unclamped (sat*old_s \u2264 1): reproj = mix(vec3f(m), color, saturation).\n // Clamped (saturated to 1): reproj = (color - n) * m / (m - n).\n let range = max(m - n, 1e-6);\n let unclamped = mix(vec3f(m), color, saturation);\n let clamped = (color - vec3f(n)) * m / range;\n let needs_clamp = (m - n) * saturation >= m;\n let reproj = select(unclamped, clamped, needs_clamp);\n return mix(color, reproj * value, fac);\n}\n\n// \u2500\u2500\u2500 BRIGHTCONTRAST node \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nfn bright_contrast(color: vec3f, bright: f32, contrast: f32) -> vec3f {\n let a = 1.0 + contrast;\n let b = bright - contrast * 0.5;\n return max(vec3f(0.0), color * a + vec3f(b));\n}\n\n// \u2500\u2500\u2500 INVERT node \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nfn invert(fac: f32, color: vec3f) -> vec3f {\n return mix(color, vec3f(1.0) - color, fac);\n}\n\nfn invert_f(fac: f32, val: f32) -> f32 {\n return mix(val, 1.0 - val, fac);\n}\n\n// \u2500\u2500\u2500 Color ramp (VALTORGB) \u2014 2-stop variants \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n// All 7 presets use exclusively 2-stop ramps.\n\nfn ramp_constant(f: f32, p0: f32, c0: vec4f, p1: f32, c1: vec4f) -> vec4f {\n return select(c0, c1, f >= p1);\n}\n\n// CONSTANT ramp with screen-space edge AA \u2014 kills sparkle where fwidth(f) straddles a hard step (NPR terminator)\nfn ramp_constant_edge_aa(f: f32, edge: f32, c0: vec4f, c1: vec4f) -> vec4f {\n let w = max(fwidth(f) * 1.75, 6e-6);\n let t = smoothstep(edge - w, edge + w, f);\n return mix(c0, c1, t);\n}\n\nfn ramp_linear(f: f32, p0: f32, c0: vec4f, p1: f32, c1: vec4f) -> vec4f {\n let t = saturate((f - p0) / max(p1 - p0, 1e-6));\n return mix(c0, c1, t);\n}\n\nfn ramp_cardinal(f: f32, p0: f32, c0: vec4f, p1: f32, c1: vec4f) -> vec4f {\n // cardinal spline with 2 stops degrades to smoothstep\n let t = saturate((f - p0) / max(p1 - p0, 1e-6));\n let ss = t * t * (3.0 - 2.0 * t);\n return mix(c0, c1, ss);\n}\n\n// \u2500\u2500\u2500 MATH node operations \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nfn math_add(a: f32, b: f32) -> f32 { return a + b; }\nfn math_multiply(a: f32, b: f32) -> f32 { return a * b; }\nfn math_power(a: f32, b: f32) -> f32 { return pow(max(a, 0.0), b); }\nfn math_greater_than(a: f32, b: f32) -> f32 { return select(0.0, 1.0, a > b); }\n\n// Blender's implicit Color \u2192 Float socket conversion uses BT.601 grayscale\n// (rgb_to_grayscale in blenkernel/intern/node.cc). When a material graph plugs a\n// Color output into a Math node's Value input, this is the scalar it actually sees.\nfn color_to_value(c: vec3f) -> f32 {\n return 0.299 * c.r + 0.587 * c.g + 0.114 * c.b;\n}\n\n// \u2500\u2500\u2500 MIX node (blend_type variants) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nfn mix_blend(fac: f32, a: vec3f, b: vec3f) -> vec3f {\n return mix(a, b, fac);\n}\n\nfn mix_overlay(fac: f32, a: vec3f, b: vec3f) -> vec3f {\n let lo = 2.0 * a * b;\n let hi = vec3f(1.0) - 2.0 * (vec3f(1.0) - a) * (vec3f(1.0) - b);\n let overlay = select(hi, lo, a < vec3f(0.5));\n return mix(a, overlay, fac);\n}\n\nfn mix_multiply(fac: f32, a: vec3f, b: vec3f) -> vec3f {\n return mix(a, a * b, fac);\n}\n\nfn mix_lighten(fac: f32, a: vec3f, b: vec3f) -> vec3f {\n return mix(a, max(a, b), fac);\n}\n\n// Blender Mix (Color) blend LINEAR_LIGHT: result = mix(A, A + 2*B - 1, Fac)\nfn mix_linear_light(fac: f32, a: vec3f, b: vec3f) -> vec3f {\n return mix(a, a + 2.0 * b - vec3f(1.0), fac);\n}\n\n// Luminance for Shader\u2192RGB scalar gates (linear RGB, Rec.709 weights)\nfn luminance_rec709_linear(c: vec3f) -> f32 {\n return dot(max(c, vec3f(0.0)), vec3f(0.2126, 0.7152, 0.0722));\n}\n\n// \u2500\u2500\u2500 FRESNEL node \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n// Schlick approximation matching Blender's Fresnel node\n\nfn fresnel(ior: f32, n: vec3f, v: vec3f) -> f32 {\n let r = (ior - 1.0) / (ior + 1.0);\n let f0 = r * r;\n let cos_theta = clamp(dot(n, v), 0.0, 1.0);\n let m = 1.0 - cos_theta;\n let m2 = m * m;\n let m5 = m2 * m2 * m;\n return f0 + (1.0 - f0) * m5;\n}\n\n// \u2500\u2500\u2500 LAYER_WEIGHT node \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nfn layer_weight_fresnel(blend: f32, n: vec3f, v: vec3f) -> f32 {\n let eta = max(1.0 - blend, 1e-4);\n let r = (1.0 - eta) / (1.0 + eta);\n let f0 = r * r;\n let cos_theta = clamp(abs(dot(n, v)), 0.0, 1.0);\n let m = 1.0 - cos_theta;\n let m2 = m * m;\n let m5 = m2 * m2 * m;\n return f0 + (1.0 - f0) * m5;\n}\n\nfn layer_weight_facing(blend: f32, n: vec3f, v: vec3f) -> f32 {\n var facing = abs(dot(n, v));\n let b = clamp(blend, 0.0, 0.99999);\n if (b != 0.5) {\n let exponent = select(2.0 * b, 0.5 / (1.0 - b), b >= 0.5);\n facing = pow(facing, exponent);\n }\n return 1.0 - facing;\n}\n\n// \u2500\u2500\u2500 SHADER_TO_RGB (white DiffuseBSDF) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n// Eevee captures lit diffuse: (albedo/\u03C0)*sun*N\u00B7L*shadow + ambient (linear). Albedo=1.\n// Matches default.ts direct term scale so VALTORGB thresholds from Blender JSON stay valid.\n\nfn shader_to_rgb_diffuse(n: vec3f, l: vec3f, sun_rgb: vec3f, ambient_rgb: vec3f, shadow: f32) -> f32 {\n const PI_S: f32 = 3.141592653589793;\n let ndotl = max(dot(n, l), 0.0);\n let rgb = sun_rgb * (ndotl * shadow / PI_S) + ambient_rgb;\n return luminance_rec709_linear(rgb);\n}\n\n// \u2500\u2500\u2500 BUMP node \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n// Screen-space bump from a scalar height field. Needs dFdx/dFdy which\n// WGSL provides as dpdx/dpdy.\n\nfn bump(strength: f32, height: f32, normal: vec3f, world_pos: vec3f) -> vec3f {\n let dhdx = dpdx(height);\n let dhdy = dpdy(height);\n let dpdx_pos = dpdx(world_pos);\n let dpdy_pos = dpdy(world_pos);\n let perturbed = normalize(normal) - strength * (dhdx * normalize(cross(dpdy_pos, normal)) + dhdy * normalize(cross(normal, dpdx_pos)));\n return normalize(perturbed);\n}\n\n// LH engine + WebGPU fragment Y: flip dhdy contribution so height peaks read as outward bumps vs Blender reference\nfn bump_lh(strength: f32, height: f32, normal: vec3f, world_pos: vec3f) -> vec3f {\n let dhdx = dpdx(height);\n let dhdy = dpdy(height);\n let dpdx_pos = dpdx(world_pos);\n let dpdy_pos = dpdy(world_pos);\n let perturbed = normalize(normal) - strength * (dhdx * normalize(cross(dpdy_pos, normal)) - dhdy * normalize(cross(normal, dpdx_pos)));\n return normalize(perturbed);\n}\n\n// \u2500\u2500\u2500 NOISE texture (Perlin-style) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n// Simplified gradient noise matching Blender's default noise output.\n\n// PCG-style integer hash. Replaces the classic 'fract(sin(q) * LARGE)' trick because\n// WebKit's Metal backend compiles 'sin' to a full transcendental op (slow), while\n// Safari's Apple-GPU scalar ALU handles int muls/xors near free. Inputs arrive as\n// integer-valued floats (floor(p) + unit offsets) from _noise3, so vec3i cast is exact.\nfn _hash33(p: vec3f) -> vec3f {\n var h = vec3u(vec3i(p) + vec3i(32768));\n h = h * vec3u(1664525u, 1013904223u, 2654435761u);\n h = (h.yzx ^ h) * vec3u(2246822519u, 3266489917u, 668265263u);\n h = h ^ (h >> vec3u(16u));\n // Mask to 24 bits \u2014 above that f32 loses precision on the u32\u2192f32 convert.\n let hm = h & vec3u(16777215u);\n return vec3f(hm) * (2.0 / 16777216.0) - 1.0;\n}\n\nfn _noise3(p: vec3f) -> f32 {\n let i = floor(p);\n let f = fract(p);\n let u = f * f * (3.0 - 2.0 * f);\n\n return mix(\n mix(\n mix(dot(_hash33(i + vec3f(0,0,0)), f - vec3f(0,0,0)),\n dot(_hash33(i + vec3f(1,0,0)), f - vec3f(1,0,0)), u.x),\n mix(dot(_hash33(i + vec3f(0,1,0)), f - vec3f(0,1,0)),\n dot(_hash33(i + vec3f(1,1,0)), f - vec3f(1,1,0)), u.x), u.y),\n mix(\n mix(dot(_hash33(i + vec3f(0,0,1)), f - vec3f(0,0,1)),\n dot(_hash33(i + vec3f(1,0,1)), f - vec3f(1,0,1)), u.x),\n mix(dot(_hash33(i + vec3f(0,1,1)), f - vec3f(0,1,1)),\n dot(_hash33(i + vec3f(1,1,1)), f - vec3f(1,1,1)), u.x), u.y),\n u.z);\n}\n\nfn tex_noise(p: vec3f, scale: f32, detail: f32, roughness: f32, distortion: f32) -> f32 {\n var q = p;\n if (abs(distortion) > 1e-6) {\n let w = _noise3(p * scale * 1.37 + vec3f(2.31, 5.17, 8.09));\n q = p + (w * 2.0 - 1.0) * distortion;\n }\n let coords = q * scale;\n var value = 0.0;\n var amplitude = 1.0;\n var frequency = 1.0;\n var total_amp = 0.0;\n let octaves = i32(clamp(detail, 0.0, 15.0)) + 1;\n for (var i = 0; i < octaves; i++) {\n value += amplitude * _noise3(coords * frequency);\n total_amp += amplitude;\n amplitude *= roughness;\n frequency *= 2.0;\n }\n return value / max(total_amp, 1e-6) * 0.5 + 0.5;\n}\n\n// tex_noise specialization: detail=2.0 (3 octaves), roughness=0.5, distortion=0.\n// WebKit can't unroll tex_noise's for-loop because 'octaves' is a runtime value;\n// this variant is fully unrolled with constants folded (total_amp = 1.75).\nfn tex_noise_d2(p: vec3f, scale: f32) -> f32 {\n let c = p * scale;\n let v = _noise3(c) + 0.5 * _noise3(c * 2.0) + 0.25 * _noise3(c * 4.0);\n return v * (1.0 / 1.75) * 0.5 + 0.5;\n}\n\n// \u2500\u2500\u2500 TEX_GRADIENT (linear) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n// Used by Stockings preset. Maps the input vector's X to a 0\u20131 gradient.\n\nfn tex_gradient_linear(uv: vec3f) -> f32 {\n return clamp(uv.x, 0.0, 1.0);\n}\n\n// \u2500\u2500\u2500 TEX_VORONOI \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n// 3D F1 voronoi. _f1 returns Distance; _color returns per-cell hash color\n// (matches Blender voronoi.cc: outColor = hash_int3_to_float3(cell + targetOffset)).\n\nfn tex_voronoi_f1(p: vec3f, scale: f32) -> f32 {\n let coords = p * scale;\n let i = floor(coords);\n let f = fract(coords);\n var min_dist = 1e10;\n for (var z = -1; z <= 1; z++) {\n for (var y = -1; y <= 1; y++) {\n for (var x = -1; x <= 1; x++) {\n let neighbor = vec3f(f32(x), f32(y), f32(z));\n let point = _hash33(i + neighbor) * 0.5 + 0.5;\n let diff = neighbor + point - f;\n min_dist = min(min_dist, dot(diff, diff));\n }\n }\n }\n return sqrt(min_dist);\n}\n\n// The per-cell jitter hash IS the Color output in Blender \u2014 reuse the same hash\n// tap for jitter + color instead of computing two.\nfn tex_voronoi_color(p: vec3f, scale: f32) -> vec3f {\n let coords = p * scale;\n let i = floor(coords);\n let f = fract(coords);\n var min_dist = 1e10;\n var min_hash = vec3f(0.5);\n for (var z = -1; z <= 1; z++) {\n for (var y = -1; y <= 1; y++) {\n for (var x = -1; x <= 1; x++) {\n let neighbor = vec3f(f32(x), f32(y), f32(z));\n let h = _hash33(i + neighbor) * 0.5 + 0.5;\n let diff = neighbor + h - f;\n let d = dot(diff, diff);\n if (d < min_dist) {\n min_dist = d;\n min_hash = h;\n }\n }\n }\n }\n return min_hash;\n}\n\n// \u2500\u2500\u2500 SEPXYZ node \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nfn separate_xyz(v: vec3f) -> vec3f { return v; }\n\n// \u2500\u2500\u2500 VECT_MATH (cross product) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nfn vect_math_cross(a: vec3f, b: vec3f) -> vec3f { return cross(a, b); }\n\n// \u2500\u2500\u2500 MAPPING node \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n// Point-type mapping: scale, rotate (euler XYZ), translate.\n\nfn mapping_point(v: vec3f, loc: vec3f, rot: vec3f, scl: vec3f) -> vec3f {\n var p = v * scl;\n // simplified: skip rotation when all angles are zero (common case)\n if (abs(rot.x) + abs(rot.y) + abs(rot.z) > 1e-6) {\n let cx = cos(rot.x); let sx = sin(rot.x);\n let cy = cos(rot.y); let sy = sin(rot.y);\n let cz = cos(rot.z); let sz = sin(rot.z);\n let rx = vec3f(p.x, cx*p.y - sx*p.z, sx*p.y + cx*p.z);\n let ry = vec3f(cy*rx.x + sy*rx.z, rx.y, -sy*rx.x + cy*rx.z);\n p = vec3f(cz*ry.x - sz*ry.y, sz*ry.x + cz*ry.y, ry.z);\n }\n return p + loc;\n}\n\n// \u2500\u2500\u2500 NORMAL_MAP node (tangent-space) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n// Applies a tangent-space normal map. Requires TBN from vertex stage.\n\nfn normal_map(strength: f32, map_color: vec3f, normal: vec3f, tangent: vec3f, bitangent: vec3f) -> vec3f {\n let ts = map_color * 2.0 - 1.0;\n let perturbed = normalize(tangent * ts.x + bitangent * ts.y + normal * ts.z);\n return normalize(mix(normal, perturbed, strength));\n}\n\n// \u2500\u2500\u2500 EEVEE Principled BSDF primitives \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n// Ports from Blender 3.6 source/blender/draw/engines/eevee/shaders/\n// bsdf_common_lib.glsl + gpu_shader_material_principled.glsl.\n// Usage pattern (see material shaders): direct spec = bsdf_ggx \u00D7 sun \u00D7 shadow\n// (NL baked in, no F yet); ambient spec = probe_radiance; tint both with\n// reflection_color = F_brdf_multi_scatter(f0, f90, split_sum) AFTER summing.\n\nconst EEVEE_PI: f32 = 3.141592653589793;\n\n// Fused analytic GGX specular (direct lights). Returns BRDF \u00D7 NL.\n// 4\u00B7NL\u00B7NV is cancelled via G1_Smith reciprocal form \u2014 see bsdf_common_lib.glsl:115.\n// Caller passes NL, NV (already computed for diffuse + brdf_lut_sample) so WebKit\n// can reuse them instead of recomputing dot products across the function boundary.\nfn bsdf_ggx(N: vec3f, L: vec3f, V: vec3f, NL_in: f32, NV_in: f32, roughness: f32) -> f32 {\n let a = max(roughness, 1e-4);\n let a2 = a * a;\n let H = normalize(L + V);\n let NH = max(dot(N, H), 1e-8);\n let NL = max(NL_in, 1e-8);\n let NV = max(NV_in, 1e-8);\n // G1_Smith_GGX_opti reciprocal form \u2014 denominator piece only.\n let G1L = NL + sqrt(NL * (NL - NL * a2) + a2);\n let G1V = NV + sqrt(NV * (NV - NV * a2) + a2);\n let G = G1L * G1V;\n // D_ggx_opti = pi * denom\u00B2 \u2014 reciprocal D \u00D7 a\u00B2.\n let tmp = (NH * a2 - NH) * NH + 1.0;\n let D_opti = EEVEE_PI * tmp * tmp;\n return NL * a2 / (D_opti * G);\n}\n\n// Split-sum DFG LUT \u2014 Karis 2013 curve fit stand-in for the 64\u00D764 baked LUT.\n// Returns (lut.x, lut.y) in Blender convention: tint = f0\u00B7lut.x + f90\u00B7lut.y.\nfn brdf_lut_approx(NV: f32, roughness: f32) -> vec2f {\n let c0 = vec4f(-1.0, -0.0275, -0.572, 0.022);\n let c1 = vec4f(1.0, 0.0425, 1.04, -0.04);\n let r = roughness * c0 + c1;\n let a004 = min(r.x * r.x, exp2(-9.28 * NV)) * r.x + r.y;\n return vec2f(-1.04, 1.04) * a004 + r.zw;\n}\n\n// Baked combined BRDF LUT \u2014 exact port of Blender bsdf_lut_frag.glsl packed with\n// ltc_mag_ggx from eevee_lut.c. Single sample returns DFG (.rg) and LTC mag (.ba).\n// Addressed as Blender's common_utiltex_lib.glsl:lut_coords:\n// coords = (roughness, sqrt(1 - NV)), then half-texel bias for filtering.\n// Requires group(0) binding(9) brdfLut + binding(2) diffuseSampler in the host shader.\nfn brdf_lut_sample(NV: f32, roughness: f32) -> vec4f {\n let LUT_SIZE: f32 = 64.0;\n var uv = vec2f(saturate(roughness), sqrt(saturate(1.0 - NV)));\n uv = uv * ((LUT_SIZE - 1.0) / LUT_SIZE) + 0.5 / LUT_SIZE;\n return textureSampleLevel(brdfLut, diffuseSampler, uv, 0.0);\n}\n\nfn F_brdf_single_scatter(f0: vec3f, f90: vec3f, lut: vec2f) -> vec3f {\n return lut.y * f90 + lut.x * f0;\n}\n\n// Fdez-Ag\u00FCera 2019 multi-scatter compensation (EEVEE do_multiscatter=1).\nfn F_brdf_multi_scatter(f0: vec3f, f90: vec3f, lut: vec2f) -> vec3f {\n let FssEss = lut.y * f90 + lut.x * f0;\n let Ess = lut.x + lut.y;\n let Ems = 1.0 - Ess;\n let Favg = f0 + (1.0 - f0) / 21.0;\n let Fms = FssEss * Favg / (1.0 - (1.0 - Ess) * Favg);\n return FssEss + Fms * Ems;\n}\n\n// EEVEE direct-specular energy compensation factor \u2014 closure_eval_glossy_lib.glsl:79-81:\n// ltc_brdf_scale = (ltc.x + ltc.y) / (split_sum.x + split_sum.y)\n// Blender evaluates direct lights via LTC (Heitz 2016) but indirect via split-sum;\n// direct radiance is rescaled so total-energy matches the split-sum LUT.\n// Takes a pre-sampled vec4f from brdf_lut_sample() to share the fetch with\n// F_brdf_multi_scatter on the same fragment.\nfn ltc_brdf_scale_from_lut(lut: vec4f) -> f32 {\n return (lut.z + lut.w) / max(lut.x + lut.y, 1e-6);\n}\n\n// Luminance-normalized hue extraction \u2014 Blender tint_from_color (isolates hue+sat).\nfn tint_from_color(color: vec3f) -> vec3f {\n let lum = dot(color, vec3f(0.3, 0.6, 0.1));\n return select(vec3f(1.0), color / lum, lum > 0.0);\n}\n\n\n\nstruct CameraUniforms {\n view: mat4x4f,\n projection: mat4x4f,\n viewPos: vec3f,\n _padding: f32,\n};\n\nstruct Light {\n direction: vec4f,\n color: vec4f,\n};\n\nstruct LightUniforms {\n ambientColor: vec4f,\n lights: array<Light, 4>,\n};\n\nstruct MaterialUniforms {\n diffuseColor: vec3f,\n alpha: f32,\n};\n\nstruct VertexOutput {\n @builtin(position) position: vec4f,\n @location(0) normal: vec3f,\n @location(1) uv: vec2f,\n @location(2) worldPos: vec3f,\n};\n\nstruct LightVP { viewProj: mat4x4f, };\n\n@group(0) @binding(0) var<uniform> camera: CameraUniforms;\n@group(0) @binding(1) var<uniform> light: LightUniforms;\n@group(0) @binding(2) var diffuseSampler: sampler;\n@group(0) @binding(3) var shadowMap: texture_depth_2d;\n@group(0) @binding(4) var shadowSampler: sampler_comparison;\n@group(0) @binding(5) var<uniform> lightVP: LightVP;\n@group(1) @binding(0) var<storage, read> skinMats: array<mat4x4f>;\n@group(2) @binding(0) var diffuseTexture: texture_2d<f32>;\n@group(2) @binding(1) var<uniform> material: MaterialUniforms;\n\nfn sampleShadow(worldPos: vec3f, n: vec3f) -> f32 {\n // Back-facing to key light: direct contribution is zero anyway, skip 9 texture samples.\n if (dot(n, -light.lights[0].direction.xyz) <= 0.0) { return 0.0; }\n let biasedPos = worldPos + n * 0.08;\n let lclip = lightVP.viewProj * vec4f(biasedPos, 1.0);\n let ndc = lclip.xyz / max(lclip.w, 1e-6);\n let suv = vec2f(ndc.x * 0.5 + 0.5, 0.5 - ndc.y * 0.5);\n let cmpZ = ndc.z - 0.001;\n let ts = 1.0 / 2048.0;\n // 3x3 PCF unrolled \u2014 Safari's Metal backend doesn't unroll nested shadow loops reliably.\n let s00 = textureSampleCompareLevel(shadowMap, shadowSampler, suv + vec2f(-ts, -ts), cmpZ);\n let s10 = textureSampleCompareLevel(shadowMap, shadowSampler, suv + vec2f(0.0, -ts), cmpZ);\n let s20 = textureSampleCompareLevel(shadowMap, shadowSampler, suv + vec2f( ts, -ts), cmpZ);\n let s01 = textureSampleCompareLevel(shadowMap, shadowSampler, suv + vec2f(-ts, 0.0), cmpZ);\n let s11 = textureSampleCompareLevel(shadowMap, shadowSampler, suv, cmpZ);\n let s21 = textureSampleCompareLevel(shadowMap, shadowSampler, suv + vec2f( ts, 0.0), cmpZ);\n let s02 = textureSampleCompareLevel(shadowMap, shadowSampler, suv + vec2f(-ts, ts), cmpZ);\n let s12 = textureSampleCompareLevel(shadowMap, shadowSampler, suv + vec2f(0.0, ts), cmpZ);\n let s22 = textureSampleCompareLevel(shadowMap, shadowSampler, suv + vec2f( ts, ts), cmpZ);\n return (s00 + s10 + s20 + s01 + s11 + s21 + s02 + s12 + s22) * (1.0 / 9.0);\n}\n\nconst PI_H: f32 = 3.141592653589793;\nconst HAIR_SPECULAR: f32 = 1.0;\nconst HAIR_ROUGHNESS: f32 = 0.3;\nconst HAIR_TEX_GATE_THRESH: f32 = 0.15000000596046448;\nconst HAIR_RIM2_POW: f32 = 0.6300000548362732;\nconst HAIR_MIX_BG: vec3f = vec3f(0.1673291176557541);\n\n@vertex fn vs(\n @location(0) position: vec3f,\n @location(1) normal: vec3f,\n @location(2) uv: vec2f,\n @location(3) joints0: vec4<u32>,\n @location(4) weights0: vec4<f32>\n) -> VertexOutput {\n var output: VertexOutput;\n let pos4 = vec4f(position, 1.0);\n let weightSum = weights0.x + weights0.y + weights0.z + weights0.w;\n let invWeightSum = select(1.0, 1.0 / weightSum, weightSum > 0.0001);\n let nw = select(vec4f(1.0, 0.0, 0.0, 0.0), weights0 * invWeightSum, weightSum > 0.0001);\n var skinnedPos = vec4f(0.0);\n var skinnedNrm = vec3f(0.0);\n for (var i = 0u; i < 4u; i++) {\n let m = skinMats[joints0[i]];\n let w = nw[i];\n skinnedPos += (m * pos4) * w;\n skinnedNrm += (mat3x3f(m[0].xyz, m[1].xyz, m[2].xyz) * normal) * w;\n }\n output.position = camera.projection * camera.view * vec4f(skinnedPos.xyz, 1.0);\n // Skip VS normalize \u2014 interpolation denormalizes anyway, and FS always does normalize(input.normal).\n output.normal = skinnedNrm;\n output.uv = uv;\n output.worldPos = skinnedPos.xyz;\n return output;\n}\n\nstruct FSOut {\n @location(0) color: vec4f,\n @location(1) mask: f32,\n};\n\n@fragment fn fs(input: VertexOutput) -> FSOut {\n let alpha = material.alpha;\n if (alpha < 0.001) { discard; }\n\n let n = normalize(input.normal);\n let v = normalize(camera.viewPos - input.worldPos);\n let l = -light.lights[0].direction.xyz;\n let sun = light.lights[0].color.xyz * light.lights[0].color.w;\n\n let tex_color = textureSample(diffuseTexture, diffuseSampler, input.uv).rgb;\n let shadow = sampleShadow(input.worldPos, n);\n\n let hue_sat_shadow = hue_sat_id(1.2, 0.5, 1.0, tex_color);\n let hue_sat_002 = hue_sat(0.48, 1.2, 0.7, 1.0, hue_sat_shadow);\n let hue_sat_001 = hue_sat_id(1.5, 1.0, 1.0, tex_color);\n\n let ndotl_raw = shader_to_rgb_diffuse(n, l, sun, light.ambientColor.xyz, shadow);\n let ramp_008 = ramp_constant(ndotl_raw, 0.0, vec4f(0,0,0,1), 0.2966, vec4f(1,1,1,1)).r;\n\n let mix_004 = mix_blend(ramp_008, hue_sat_002, hue_sat_001);\n let bc = bright_contrast(mix_004, 0.1, 0.2);\n\n let bevel_z = clamp(n.y, 0.0, 1.0);\n let mix_003 = mix_blend(bevel_z, bc, hue_sat_002);\n\n let rim2_raw = fresnel(1.45, n, v) * layer_weight_fresnel(0.61, n, v);\n let rim2_fac = math_power(rim2_raw, HAIR_RIM2_POW);\n let mix_shader_002 = mix(mix_003, HAIR_MIX_BG, rim2_fac);\n\n // Blender's GREATER_THAN converts Color\u2192Float via BT.601 luminance, not raw R \u2014 same\n // socket-semantic fix as M_Face.\n let tex_gate = math_greater_than(color_to_value(tex_color), HAIR_TEX_GATE_THRESH);\n let gate_emit = vec3f(tex_gate) * 0.1;\n\n let add_shader = mix_shader_002 + gate_emit;\n\n // Principled BSDF (EEVEE port): metallic=0, specular=1.0, roughness=0.3, specular_tint=0.\n // Graph has a noise\u2192normal_map bump (Strength=0.1) on Principled.Normal, but MixShader.001\n // weights Principled at only 0.2 \u2014 the bumped spec \u00D7 that weight is imperceptible, so we\n // drop the subtree and keep plain n (saves a tex_noise + bump_lh per hair fragment).\n let NL = max(dot(n, l), 0.0);\n let NV = max(dot(n, v), 1e-4);\n\n let f0 = vec3f(0.08 * HAIR_SPECULAR);\n let f90 = mix(f0, vec3f(1.0), sqrt(HAIR_SPECULAR));\n let brdf_lut = brdf_lut_sample(NV, HAIR_ROUGHNESS);\n let reflection_color = F_brdf_multi_scatter(f0, f90, brdf_lut.xy);\n\n let spec_direct = bsdf_ggx(n, l, v, NL, NV, HAIR_ROUGHNESS) * sun * shadow * ltc_brdf_scale_from_lut(brdf_lut);\n let spec_indirect = light.ambientColor.xyz;\n let spec_radiance = (spec_direct + spec_indirect) * reflection_color;\n\n // Indirect diffuse = base_color \u00D7 L_w per Blender closure_eval_surface_lib.glsl line 302;\n // probe_evaluate_world_diff returns radiance (SH-projected, not cosine-convolved).\n let diffuse_radiance = bc * (sun * NL * shadow / PI_H + light.ambientColor.xyz);\n let principled = diffuse_radiance + spec_radiance;\n\n let final_color = mix(add_shader, principled, 0.2);\n\n var out: FSOut;\n out.color = vec4f(final_color, alpha);\n out.mask = 1.0;\n return out;\n}\n\n";
1
+ export declare const HAIR_SHADER_WGSL = "\n\n\n\n// Baked 64\u00D764 rgba8unorm combined BRDF LUT \u2014 created once at engine init by dfg_lut.ts.\n// .rg = split-sum DFG (Karis: tint = f0\u00B7x + f90\u00B7y) \u2192 F_brdf_*_scatter\n// .ba = Heitz 2016 LTC magnitude (ltc_mag_ggx) \u2192 ltc_brdf_scale_from_lut\n// Paired with group(0) binding(2) diffuseSampler (linear filter). Sample once per\n// fragment via brdf_lut_sample() \u2014 callers feed .rg and the whole vec4 into the\n// helpers below, halving LUT taps on the default Principled path.\n@group(0) @binding(9) var brdfLut: texture_2d<f32>;\n\n// \u2500\u2500\u2500 RGB \u2194 HSV \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nfn rgb_to_hsv(rgb: vec3f) -> vec3f {\n let c_max = max(rgb.r, max(rgb.g, rgb.b));\n let c_min = min(rgb.r, min(rgb.g, rgb.b));\n let delta = c_max - c_min;\n\n var h = 0.0;\n if (delta > 1e-6) {\n if (c_max == rgb.r) {\n h = (rgb.g - rgb.b) / delta;\n if (h < 0.0) { h += 6.0; }\n } else if (c_max == rgb.g) {\n h = 2.0 + (rgb.b - rgb.r) / delta;\n } else {\n h = 4.0 + (rgb.r - rgb.g) / delta;\n }\n h /= 6.0;\n }\n let s = select(0.0, delta / c_max, c_max > 1e-6);\n return vec3f(h, s, c_max);\n}\n\nfn hsv_to_rgb(hsv: vec3f) -> vec3f {\n let h = hsv.x;\n let s = hsv.y;\n let v = hsv.z;\n if (s < 1e-6) { return vec3f(v); }\n\n let hh = fract(h) * 6.0;\n let sector = u32(hh);\n let f = hh - f32(sector);\n let p = v * (1.0 - s);\n let q = v * (1.0 - s * f);\n let t = v * (1.0 - s * (1.0 - f));\n\n switch (sector) {\n case 0u: { return vec3f(v, t, p); }\n case 1u: { return vec3f(q, v, p); }\n case 2u: { return vec3f(p, v, t); }\n case 3u: { return vec3f(p, q, v); }\n case 4u: { return vec3f(t, p, v); }\n default: { return vec3f(v, p, q); }\n }\n}\n\n// \u2500\u2500\u2500 HUE_SAT node \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nfn hue_sat(hue: f32, saturation: f32, value: f32, fac: f32, color: vec3f) -> vec3f {\n var hsv = rgb_to_hsv(color);\n hsv.x = fract(hsv.x + hue - 0.5);\n hsv.y = clamp(hsv.y * saturation, 0.0, 1.0);\n hsv.z *= value;\n return mix(color, hsv_to_rgb(hsv), fac);\n}\n\n// hue_sat specialization for hue=0.5 (identity hue shift \u2014 fract(h + 0.5 - 0.5) = h).\n// Branchless equivalent that skips the rgb_to_hsv \u2192 hsv_to_rgb roundtrip: WebKit's\n// Metal backend serializes the 3-way if chain in rgb_to_hsv and the 6-way switch in\n// hsv_to_rgb, where this form compiles to linear SIMD ops + a single select.\nfn hue_sat_id(saturation: f32, value: f32, fac: f32, color: vec3f) -> vec3f {\n let m = max(max(color.r, color.g), color.b);\n let n = min(min(color.r, color.g), color.b);\n // Unclamped (sat*old_s \u2264 1): reproj = mix(vec3f(m), color, saturation).\n // Clamped (saturated to 1): reproj = (color - n) * m / (m - n).\n let range = max(m - n, 1e-6);\n let unclamped = mix(vec3f(m), color, saturation);\n let clamped = (color - vec3f(n)) * m / range;\n let needs_clamp = (m - n) * saturation >= m;\n let reproj = select(unclamped, clamped, needs_clamp);\n return mix(color, reproj * value, fac);\n}\n\n// \u2500\u2500\u2500 BRIGHTCONTRAST node \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nfn bright_contrast(color: vec3f, bright: f32, contrast: f32) -> vec3f {\n let a = 1.0 + contrast;\n let b = bright - contrast * 0.5;\n return max(vec3f(0.0), color * a + vec3f(b));\n}\n\n// \u2500\u2500\u2500 INVERT node \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nfn invert(fac: f32, color: vec3f) -> vec3f {\n return mix(color, vec3f(1.0) - color, fac);\n}\n\nfn invert_f(fac: f32, val: f32) -> f32 {\n return mix(val, 1.0 - val, fac);\n}\n\n// \u2500\u2500\u2500 Color ramp (VALTORGB) \u2014 2-stop variants \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n// All 7 presets use exclusively 2-stop ramps.\n\nfn ramp_constant(f: f32, p0: f32, c0: vec4f, p1: f32, c1: vec4f) -> vec4f {\n return select(c0, c1, f >= p1);\n}\n\n// CONSTANT ramp with screen-space edge AA \u2014 kills sparkle where fwidth(f) straddles a hard step (NPR terminator)\nfn ramp_constant_edge_aa(f: f32, edge: f32, c0: vec4f, c1: vec4f) -> vec4f {\n let w = max(fwidth(f) * 1.75, 6e-6);\n let t = smoothstep(edge - w, edge + w, f);\n return mix(c0, c1, t);\n}\n\nfn ramp_linear(f: f32, p0: f32, c0: vec4f, p1: f32, c1: vec4f) -> vec4f {\n let t = saturate((f - p0) / max(p1 - p0, 1e-6));\n return mix(c0, c1, t);\n}\n\nfn ramp_cardinal(f: f32, p0: f32, c0: vec4f, p1: f32, c1: vec4f) -> vec4f {\n // cardinal spline with 2 stops degrades to smoothstep\n let t = saturate((f - p0) / max(p1 - p0, 1e-6));\n let ss = t * t * (3.0 - 2.0 * t);\n return mix(c0, c1, ss);\n}\n\n// \u2500\u2500\u2500 MATH node operations \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nfn math_add(a: f32, b: f32) -> f32 { return a + b; }\nfn math_multiply(a: f32, b: f32) -> f32 { return a * b; }\nfn math_power(a: f32, b: f32) -> f32 { return pow(max(a, 0.0), b); }\nfn math_greater_than(a: f32, b: f32) -> f32 { return select(0.0, 1.0, a > b); }\n\n// Blender's implicit Color \u2192 Float socket conversion uses BT.601 grayscale\n// (rgb_to_grayscale in blenkernel/intern/node.cc). When a material graph plugs a\n// Color output into a Math node's Value input, this is the scalar it actually sees.\nfn color_to_value(c: vec3f) -> f32 {\n return 0.299 * c.r + 0.587 * c.g + 0.114 * c.b;\n}\n\n// \u2500\u2500\u2500 MIX node (blend_type variants) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nfn mix_blend(fac: f32, a: vec3f, b: vec3f) -> vec3f {\n return mix(a, b, fac);\n}\n\nfn mix_overlay(fac: f32, a: vec3f, b: vec3f) -> vec3f {\n let lo = 2.0 * a * b;\n let hi = vec3f(1.0) - 2.0 * (vec3f(1.0) - a) * (vec3f(1.0) - b);\n let overlay = select(hi, lo, a < vec3f(0.5));\n return mix(a, overlay, fac);\n}\n\nfn mix_multiply(fac: f32, a: vec3f, b: vec3f) -> vec3f {\n return mix(a, a * b, fac);\n}\n\nfn mix_lighten(fac: f32, a: vec3f, b: vec3f) -> vec3f {\n return mix(a, max(a, b), fac);\n}\n\n// Blender Mix (Color) blend LINEAR_LIGHT: result = mix(A, A + 2*B - 1, Fac)\nfn mix_linear_light(fac: f32, a: vec3f, b: vec3f) -> vec3f {\n return mix(a, a + 2.0 * b - vec3f(1.0), fac);\n}\n\n// Luminance for Shader\u2192RGB scalar gates (linear RGB, Rec.709 weights)\nfn luminance_rec709_linear(c: vec3f) -> f32 {\n return dot(max(c, vec3f(0.0)), vec3f(0.2126, 0.7152, 0.0722));\n}\n\n// \u2500\u2500\u2500 FRESNEL node \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n// Schlick approximation matching Blender's Fresnel node\n\nfn fresnel(ior: f32, n: vec3f, v: vec3f) -> f32 {\n let r = (ior - 1.0) / (ior + 1.0);\n let f0 = r * r;\n let cos_theta = clamp(dot(n, v), 0.0, 1.0);\n let m = 1.0 - cos_theta;\n let m2 = m * m;\n let m5 = m2 * m2 * m;\n return f0 + (1.0 - f0) * m5;\n}\n\n// \u2500\u2500\u2500 LAYER_WEIGHT node \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nfn layer_weight_fresnel(blend: f32, n: vec3f, v: vec3f) -> f32 {\n let eta = max(1.0 - blend, 1e-4);\n let r = (1.0 - eta) / (1.0 + eta);\n let f0 = r * r;\n let cos_theta = clamp(abs(dot(n, v)), 0.0, 1.0);\n let m = 1.0 - cos_theta;\n let m2 = m * m;\n let m5 = m2 * m2 * m;\n return f0 + (1.0 - f0) * m5;\n}\n\nfn layer_weight_facing(blend: f32, n: vec3f, v: vec3f) -> f32 {\n var facing = abs(dot(n, v));\n let b = clamp(blend, 0.0, 0.99999);\n if (b != 0.5) {\n let exponent = select(2.0 * b, 0.5 / (1.0 - b), b >= 0.5);\n facing = pow(facing, exponent);\n }\n return 1.0 - facing;\n}\n\n// \u2500\u2500\u2500 SHADER_TO_RGB (white DiffuseBSDF) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n// Eevee captures lit diffuse: (albedo/\u03C0)*sun*N\u00B7L*shadow + ambient (linear). Albedo=1.\n// Matches default.ts direct term scale so VALTORGB thresholds from Blender JSON stay valid.\n\nfn shader_to_rgb_diffuse(n: vec3f, l: vec3f, sun_rgb: vec3f, ambient_rgb: vec3f, shadow: f32) -> f32 {\n const PI_S: f32 = 3.141592653589793;\n let ndotl = max(dot(n, l), 0.0);\n let rgb = sun_rgb * (ndotl * shadow / PI_S) + ambient_rgb;\n return luminance_rec709_linear(rgb);\n}\n\n// \u2500\u2500\u2500 BUMP node \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n// Screen-space bump from a scalar height field. Needs dFdx/dFdy which\n// WGSL provides as dpdx/dpdy.\n\nfn bump(strength: f32, height: f32, normal: vec3f, world_pos: vec3f) -> vec3f {\n let dhdx = dpdx(height);\n let dhdy = dpdy(height);\n let dpdx_pos = dpdx(world_pos);\n let dpdy_pos = dpdy(world_pos);\n let perturbed = normalize(normal) - strength * (dhdx * normalize(cross(dpdy_pos, normal)) + dhdy * normalize(cross(normal, dpdx_pos)));\n return normalize(perturbed);\n}\n\n// LH engine + WebGPU fragment Y: flip dhdy contribution so height peaks read as outward bumps vs Blender reference\nfn bump_lh(strength: f32, height: f32, normal: vec3f, world_pos: vec3f) -> vec3f {\n let dhdx = dpdx(height);\n let dhdy = dpdy(height);\n let dpdx_pos = dpdx(world_pos);\n let dpdy_pos = dpdy(world_pos);\n let perturbed = normalize(normal) - strength * (dhdx * normalize(cross(dpdy_pos, normal)) - dhdy * normalize(cross(normal, dpdx_pos)));\n return normalize(perturbed);\n}\n\n// \u2500\u2500\u2500 NOISE texture (Perlin-style) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n// Simplified gradient noise matching Blender's default noise output.\n\n// PCG-style integer hash. Replaces the classic 'fract(sin(q) * LARGE)' trick because\n// WebKit's Metal backend compiles 'sin' to a full transcendental op (slow), while\n// Safari's Apple-GPU scalar ALU handles int muls/xors near free. Inputs arrive as\n// integer-valued floats (floor(p) + unit offsets) from _noise3, so vec3i cast is exact.\nfn _hash33(p: vec3f) -> vec3f {\n var h = vec3u(vec3i(p) + vec3i(32768));\n h = h * vec3u(1664525u, 1013904223u, 2654435761u);\n h = (h.yzx ^ h) * vec3u(2246822519u, 3266489917u, 668265263u);\n h = h ^ (h >> vec3u(16u));\n // Mask to 24 bits \u2014 above that f32 loses precision on the u32\u2192f32 convert.\n let hm = h & vec3u(16777215u);\n return vec3f(hm) * (2.0 / 16777216.0) - 1.0;\n}\n\nfn _noise3(p: vec3f) -> f32 {\n let i = floor(p);\n let f = fract(p);\n let u = f * f * (3.0 - 2.0 * f);\n\n return mix(\n mix(\n mix(dot(_hash33(i + vec3f(0,0,0)), f - vec3f(0,0,0)),\n dot(_hash33(i + vec3f(1,0,0)), f - vec3f(1,0,0)), u.x),\n mix(dot(_hash33(i + vec3f(0,1,0)), f - vec3f(0,1,0)),\n dot(_hash33(i + vec3f(1,1,0)), f - vec3f(1,1,0)), u.x), u.y),\n mix(\n mix(dot(_hash33(i + vec3f(0,0,1)), f - vec3f(0,0,1)),\n dot(_hash33(i + vec3f(1,0,1)), f - vec3f(1,0,1)), u.x),\n mix(dot(_hash33(i + vec3f(0,1,1)), f - vec3f(0,1,1)),\n dot(_hash33(i + vec3f(1,1,1)), f - vec3f(1,1,1)), u.x), u.y),\n u.z);\n}\n\nfn tex_noise(p: vec3f, scale: f32, detail: f32, roughness: f32, distortion: f32) -> f32 {\n var q = p;\n if (abs(distortion) > 1e-6) {\n let w = _noise3(p * scale * 1.37 + vec3f(2.31, 5.17, 8.09));\n q = p + (w * 2.0 - 1.0) * distortion;\n }\n let coords = q * scale;\n var value = 0.0;\n var amplitude = 1.0;\n var frequency = 1.0;\n var total_amp = 0.0;\n let octaves = i32(clamp(detail, 0.0, 15.0)) + 1;\n for (var i = 0; i < octaves; i++) {\n value += amplitude * _noise3(coords * frequency);\n total_amp += amplitude;\n amplitude *= roughness;\n frequency *= 2.0;\n }\n return value / max(total_amp, 1e-6) * 0.5 + 0.5;\n}\n\n// tex_noise specialization: detail=2.0 (3 octaves), roughness=0.5, distortion=0.\n// WebKit can't unroll tex_noise's for-loop because 'octaves' is a runtime value;\n// this variant is fully unrolled with constants folded (total_amp = 1.75).\nfn tex_noise_d2(p: vec3f, scale: f32) -> f32 {\n let c = p * scale;\n let v = _noise3(c) + 0.5 * _noise3(c * 2.0) + 0.25 * _noise3(c * 4.0);\n return v * (1.0 / 1.75) * 0.5 + 0.5;\n}\n\n// \u2500\u2500\u2500 TEX_GRADIENT (linear) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n// Used by Stockings preset. Maps the input vector's X to a 0\u20131 gradient.\n\nfn tex_gradient_linear(uv: vec3f) -> f32 {\n return clamp(uv.x, 0.0, 1.0);\n}\n\n// \u2500\u2500\u2500 TEX_VORONOI \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n// 3D F1 voronoi. _f1 returns Distance; _color returns per-cell hash color\n// (matches Blender voronoi.cc: outColor = hash_int3_to_float3(cell + targetOffset)).\n\nfn tex_voronoi_f1(p: vec3f, scale: f32) -> f32 {\n let coords = p * scale;\n let i = floor(coords);\n let f = fract(coords);\n var min_dist = 1e10;\n for (var z = -1; z <= 1; z++) {\n for (var y = -1; y <= 1; y++) {\n for (var x = -1; x <= 1; x++) {\n let neighbor = vec3f(f32(x), f32(y), f32(z));\n let point = _hash33(i + neighbor) * 0.5 + 0.5;\n let diff = neighbor + point - f;\n min_dist = min(min_dist, dot(diff, diff));\n }\n }\n }\n return sqrt(min_dist);\n}\n\n// The per-cell jitter hash IS the Color output in Blender \u2014 reuse the same hash\n// tap for jitter + color instead of computing two.\nfn tex_voronoi_color(p: vec3f, scale: f32) -> vec3f {\n let coords = p * scale;\n let i = floor(coords);\n let f = fract(coords);\n var min_dist = 1e10;\n var min_hash = vec3f(0.5);\n for (var z = -1; z <= 1; z++) {\n for (var y = -1; y <= 1; y++) {\n for (var x = -1; x <= 1; x++) {\n let neighbor = vec3f(f32(x), f32(y), f32(z));\n let h = _hash33(i + neighbor) * 0.5 + 0.5;\n let diff = neighbor + h - f;\n let d = dot(diff, diff);\n if (d < min_dist) {\n min_dist = d;\n min_hash = h;\n }\n }\n }\n }\n return min_hash;\n}\n\n// \u2500\u2500\u2500 SEPXYZ node \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nfn separate_xyz(v: vec3f) -> vec3f { return v; }\n\n// \u2500\u2500\u2500 VECT_MATH (cross product) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nfn vect_math_cross(a: vec3f, b: vec3f) -> vec3f { return cross(a, b); }\n\n// \u2500\u2500\u2500 MAPPING node \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n// Point-type mapping: scale, rotate (euler XYZ), translate.\n\nfn mapping_point(v: vec3f, loc: vec3f, rot: vec3f, scl: vec3f) -> vec3f {\n var p = v * scl;\n // simplified: skip rotation when all angles are zero (common case)\n if (abs(rot.x) + abs(rot.y) + abs(rot.z) > 1e-6) {\n let cx = cos(rot.x); let sx = sin(rot.x);\n let cy = cos(rot.y); let sy = sin(rot.y);\n let cz = cos(rot.z); let sz = sin(rot.z);\n let rx = vec3f(p.x, cx*p.y - sx*p.z, sx*p.y + cx*p.z);\n let ry = vec3f(cy*rx.x + sy*rx.z, rx.y, -sy*rx.x + cy*rx.z);\n p = vec3f(cz*ry.x - sz*ry.y, sz*ry.x + cz*ry.y, ry.z);\n }\n return p + loc;\n}\n\n// \u2500\u2500\u2500 NORMAL_MAP node (tangent-space) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n// Applies a tangent-space normal map. Requires TBN from vertex stage.\n\nfn normal_map(strength: f32, map_color: vec3f, normal: vec3f, tangent: vec3f, bitangent: vec3f) -> vec3f {\n let ts = map_color * 2.0 - 1.0;\n let perturbed = normalize(tangent * ts.x + bitangent * ts.y + normal * ts.z);\n return normalize(mix(normal, perturbed, strength));\n}\n\n// \u2500\u2500\u2500 EEVEE Principled BSDF primitives \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n// Ports from Blender 3.6 source/blender/draw/engines/eevee/shaders/\n// bsdf_common_lib.glsl + gpu_shader_material_principled.glsl.\n// Usage pattern (see material shaders): direct spec = bsdf_ggx \u00D7 sun \u00D7 shadow\n// (NL baked in, no F yet); ambient spec = probe_radiance; tint both with\n// reflection_color = F_brdf_multi_scatter(f0, f90, split_sum) AFTER summing.\n\nconst EEVEE_PI: f32 = 3.141592653589793;\n\n// Fused analytic GGX specular (direct lights). Returns BRDF \u00D7 NL.\n// 4\u00B7NL\u00B7NV is cancelled via G1_Smith reciprocal form \u2014 see bsdf_common_lib.glsl:115.\n// Caller passes NL, NV (already computed for diffuse + brdf_lut_sample) so WebKit\n// can reuse them instead of recomputing dot products across the function boundary.\nfn bsdf_ggx(N: vec3f, L: vec3f, V: vec3f, NL_in: f32, NV_in: f32, roughness: f32) -> f32 {\n let a = max(roughness, 1e-4);\n let a2 = a * a;\n let H = normalize(L + V);\n let NH = max(dot(N, H), 1e-8);\n let NL = max(NL_in, 1e-8);\n let NV = max(NV_in, 1e-8);\n // G1_Smith_GGX_opti reciprocal form \u2014 denominator piece only.\n let G1L = NL + sqrt(NL * (NL - NL * a2) + a2);\n let G1V = NV + sqrt(NV * (NV - NV * a2) + a2);\n let G = G1L * G1V;\n // D_ggx_opti = pi * denom\u00B2 \u2014 reciprocal D \u00D7 a\u00B2.\n let tmp = (NH * a2 - NH) * NH + 1.0;\n let D_opti = EEVEE_PI * tmp * tmp;\n return NL * a2 / (D_opti * G);\n}\n\n// Split-sum DFG LUT \u2014 Karis 2013 curve fit stand-in for the 64\u00D764 baked LUT.\n// Returns (lut.x, lut.y) in Blender convention: tint = f0\u00B7lut.x + f90\u00B7lut.y.\nfn brdf_lut_approx(NV: f32, roughness: f32) -> vec2f {\n let c0 = vec4f(-1.0, -0.0275, -0.572, 0.022);\n let c1 = vec4f(1.0, 0.0425, 1.04, -0.04);\n let r = roughness * c0 + c1;\n let a004 = min(r.x * r.x, exp2(-9.28 * NV)) * r.x + r.y;\n return vec2f(-1.04, 1.04) * a004 + r.zw;\n}\n\n// Baked combined BRDF LUT \u2014 exact port of Blender bsdf_lut_frag.glsl packed with\n// ltc_mag_ggx from eevee_lut.c. Single sample returns DFG (.rg) and LTC mag (.ba).\n// Addressed as Blender's common_utiltex_lib.glsl:lut_coords:\n// coords = (roughness, sqrt(1 - NV)), then half-texel bias for filtering.\n// Requires group(0) binding(9) brdfLut + binding(2) diffuseSampler in the host shader.\nfn brdf_lut_sample(NV: f32, roughness: f32) -> vec4f {\n let LUT_SIZE: f32 = 64.0;\n var uv = vec2f(saturate(roughness), sqrt(saturate(1.0 - NV)));\n uv = uv * ((LUT_SIZE - 1.0) / LUT_SIZE) + 0.5 / LUT_SIZE;\n return textureSampleLevel(brdfLut, diffuseSampler, uv, 0.0);\n}\n\nfn F_brdf_single_scatter(f0: vec3f, f90: vec3f, lut: vec2f) -> vec3f {\n return lut.y * f90 + lut.x * f0;\n}\n\n// Fdez-Ag\u00FCera 2019 multi-scatter compensation (EEVEE do_multiscatter=1).\nfn F_brdf_multi_scatter(f0: vec3f, f90: vec3f, lut: vec2f) -> vec3f {\n let FssEss = lut.y * f90 + lut.x * f0;\n let Ess = lut.x + lut.y;\n let Ems = 1.0 - Ess;\n let Favg = f0 + (1.0 - f0) / 21.0;\n let Fms = FssEss * Favg / (1.0 - (1.0 - Ess) * Favg);\n return FssEss + Fms * Ems;\n}\n\n// EEVEE direct-specular energy compensation factor \u2014 closure_eval_glossy_lib.glsl:79-81:\n// ltc_brdf_scale = (ltc.x + ltc.y) / (split_sum.x + split_sum.y)\n// Blender evaluates direct lights via LTC (Heitz 2016) but indirect via split-sum;\n// direct radiance is rescaled so total-energy matches the split-sum LUT.\n// Takes a pre-sampled vec4f from brdf_lut_sample() to share the fetch with\n// F_brdf_multi_scatter on the same fragment.\nfn ltc_brdf_scale_from_lut(lut: vec4f) -> f32 {\n return (lut.z + lut.w) / max(lut.x + lut.y, 1e-6);\n}\n\n// Luminance-normalized hue extraction \u2014 Blender tint_from_color (isolates hue+sat).\nfn tint_from_color(color: vec3f) -> vec3f {\n let lum = dot(color, vec3f(0.3, 0.6, 0.1));\n return select(vec3f(1.0), color / lum, lum > 0.0);\n}\n\n\n\n// Pipeline-override: the engine compiles two variants \u2014 the normal opaque hair pipeline\n// (IS_OVER_EYES=false) and a second pipeline that re-draws hair fragments stencil-matched\n// against the eye stamp with 50% alpha so eyes read through the hair silhouette. Resolved\n// at pipeline-compile time; the dead branch is dropped by the shader compiler.\noverride IS_OVER_EYES: bool = false;\n\nstruct CameraUniforms {\n view: mat4x4f,\n projection: mat4x4f,\n viewPos: vec3f,\n _padding: f32,\n};\n\nstruct Light {\n direction: vec4f,\n color: vec4f,\n};\n\nstruct LightUniforms {\n ambientColor: vec4f,\n lights: array<Light, 4>,\n};\n\nstruct MaterialUniforms {\n diffuseColor: vec3f,\n alpha: f32,\n};\n\nstruct VertexOutput {\n @builtin(position) position: vec4f,\n @location(0) normal: vec3f,\n @location(1) uv: vec2f,\n @location(2) worldPos: vec3f,\n};\n\nstruct LightVP { viewProj: mat4x4f, };\n\n@group(0) @binding(0) var<uniform> camera: CameraUniforms;\n@group(0) @binding(1) var<uniform> light: LightUniforms;\n@group(0) @binding(2) var diffuseSampler: sampler;\n@group(0) @binding(3) var shadowMap: texture_depth_2d;\n@group(0) @binding(4) var shadowSampler: sampler_comparison;\n@group(0) @binding(5) var<uniform> lightVP: LightVP;\n@group(1) @binding(0) var<storage, read> skinMats: array<mat4x4f>;\n@group(2) @binding(0) var diffuseTexture: texture_2d<f32>;\n@group(2) @binding(1) var<uniform> material: MaterialUniforms;\n\nfn sampleShadow(worldPos: vec3f, n: vec3f) -> f32 {\n // Back-facing to key light: direct contribution is zero anyway, skip 9 texture samples.\n if (dot(n, -light.lights[0].direction.xyz) <= 0.0) { return 0.0; }\n let biasedPos = worldPos + n * 0.08;\n let lclip = lightVP.viewProj * vec4f(biasedPos, 1.0);\n let ndc = lclip.xyz / max(lclip.w, 1e-6);\n let suv = vec2f(ndc.x * 0.5 + 0.5, 0.5 - ndc.y * 0.5);\n let cmpZ = ndc.z - 0.001;\n let ts = 1.0 / 2048.0;\n // 3x3 PCF unrolled \u2014 Safari's Metal backend doesn't unroll nested shadow loops reliably.\n let s00 = textureSampleCompareLevel(shadowMap, shadowSampler, suv + vec2f(-ts, -ts), cmpZ);\n let s10 = textureSampleCompareLevel(shadowMap, shadowSampler, suv + vec2f(0.0, -ts), cmpZ);\n let s20 = textureSampleCompareLevel(shadowMap, shadowSampler, suv + vec2f( ts, -ts), cmpZ);\n let s01 = textureSampleCompareLevel(shadowMap, shadowSampler, suv + vec2f(-ts, 0.0), cmpZ);\n let s11 = textureSampleCompareLevel(shadowMap, shadowSampler, suv, cmpZ);\n let s21 = textureSampleCompareLevel(shadowMap, shadowSampler, suv + vec2f( ts, 0.0), cmpZ);\n let s02 = textureSampleCompareLevel(shadowMap, shadowSampler, suv + vec2f(-ts, ts), cmpZ);\n let s12 = textureSampleCompareLevel(shadowMap, shadowSampler, suv + vec2f(0.0, ts), cmpZ);\n let s22 = textureSampleCompareLevel(shadowMap, shadowSampler, suv + vec2f( ts, ts), cmpZ);\n return (s00 + s10 + s20 + s01 + s11 + s21 + s02 + s12 + s22) * (1.0 / 9.0);\n}\n\nconst PI_H: f32 = 3.141592653589793;\nconst HAIR_SPECULAR: f32 = 1.0;\nconst HAIR_ROUGHNESS: f32 = 0.3;\nconst HAIR_TEX_GATE_THRESH: f32 = 0.15000000596046448;\nconst HAIR_RIM2_POW: f32 = 0.6300000548362732;\nconst HAIR_MIX_BG: vec3f = vec3f(0.1673291176557541);\n\n@vertex fn vs(\n @location(0) position: vec3f,\n @location(1) normal: vec3f,\n @location(2) uv: vec2f,\n @location(3) joints0: vec4<u32>,\n @location(4) weights0: vec4<f32>\n) -> VertexOutput {\n var output: VertexOutput;\n let pos4 = vec4f(position, 1.0);\n let weightSum = weights0.x + weights0.y + weights0.z + weights0.w;\n let invWeightSum = select(1.0, 1.0 / weightSum, weightSum > 0.0001);\n let nw = select(vec4f(1.0, 0.0, 0.0, 0.0), weights0 * invWeightSum, weightSum > 0.0001);\n var skinnedPos = vec4f(0.0);\n var skinnedNrm = vec3f(0.0);\n for (var i = 0u; i < 4u; i++) {\n let m = skinMats[joints0[i]];\n let w = nw[i];\n skinnedPos += (m * pos4) * w;\n skinnedNrm += (mat3x3f(m[0].xyz, m[1].xyz, m[2].xyz) * normal) * w;\n }\n output.position = camera.projection * camera.view * vec4f(skinnedPos.xyz, 1.0);\n // Skip VS normalize \u2014 interpolation denormalizes anyway, and FS always does normalize(input.normal).\n output.normal = skinnedNrm;\n output.uv = uv;\n output.worldPos = skinnedPos.xyz;\n return output;\n}\n\nstruct FSOut {\n @location(0) color: vec4f,\n @location(1) mask: f32,\n};\n\n@fragment fn fs(input: VertexOutput) -> FSOut {\n let alpha = material.alpha;\n if (alpha < 0.001) { discard; }\n\n let n = normalize(input.normal);\n let v = normalize(camera.viewPos - input.worldPos);\n let l = -light.lights[0].direction.xyz;\n let sun = light.lights[0].color.xyz * light.lights[0].color.w;\n\n let tex_color = textureSample(diffuseTexture, diffuseSampler, input.uv).rgb;\n let shadow = sampleShadow(input.worldPos, n);\n\n let hue_sat_shadow = hue_sat_id(1.2, 0.5, 1.0, tex_color);\n let hue_sat_002 = hue_sat(0.48, 1.2, 0.7, 1.0, hue_sat_shadow);\n let hue_sat_001 = hue_sat_id(1.5, 1.0, 1.0, tex_color);\n\n let ndotl_raw = shader_to_rgb_diffuse(n, l, sun, light.ambientColor.xyz, shadow);\n let ramp_008 = ramp_constant(ndotl_raw, 0.0, vec4f(0,0,0,1), 0.2966, vec4f(1,1,1,1)).r;\n\n let mix_004 = mix_blend(ramp_008, hue_sat_002, hue_sat_001);\n let bc = bright_contrast(mix_004, 0.1, 0.2);\n\n let bevel_z = clamp(n.y, 0.0, 1.0);\n let mix_003 = mix_blend(bevel_z, bc, hue_sat_002);\n\n let rim2_raw = fresnel(1.45, n, v) * layer_weight_fresnel(0.61, n, v);\n let rim2_fac = math_power(rim2_raw, HAIR_RIM2_POW);\n let mix_shader_002 = mix(mix_003, HAIR_MIX_BG, rim2_fac);\n\n // Blender's GREATER_THAN converts Color\u2192Float via BT.601 luminance, not raw R \u2014 same\n // socket-semantic fix as M_Face.\n let tex_gate = math_greater_than(color_to_value(tex_color), HAIR_TEX_GATE_THRESH);\n let gate_emit = vec3f(tex_gate) * 0.1;\n\n let add_shader = mix_shader_002 + gate_emit;\n\n // Principled BSDF (EEVEE port): metallic=0, specular=1.0, roughness=0.3, specular_tint=0.\n // Graph has a noise\u2192normal_map bump (Strength=0.1) on Principled.Normal, but MixShader.001\n // weights Principled at only 0.2 \u2014 the bumped spec \u00D7 that weight is imperceptible, so we\n // drop the subtree and keep plain n (saves a tex_noise + bump_lh per hair fragment).\n let NL = max(dot(n, l), 0.0);\n let NV = max(dot(n, v), 1e-4);\n\n let f0 = vec3f(0.08 * HAIR_SPECULAR);\n let f90 = mix(f0, vec3f(1.0), sqrt(HAIR_SPECULAR));\n let brdf_lut = brdf_lut_sample(NV, HAIR_ROUGHNESS);\n let reflection_color = F_brdf_multi_scatter(f0, f90, brdf_lut.xy);\n\n let spec_direct = bsdf_ggx(n, l, v, NL, NV, HAIR_ROUGHNESS) * sun * shadow * ltc_brdf_scale_from_lut(brdf_lut);\n let spec_indirect = light.ambientColor.xyz;\n let spec_radiance = (spec_direct + spec_indirect) * reflection_color;\n\n // Indirect diffuse = base_color \u00D7 L_w per Blender closure_eval_surface_lib.glsl line 302;\n // probe_evaluate_world_diff returns radiance (SH-projected, not cosine-convolved).\n let diffuse_radiance = bc * (sun * NL * shadow / PI_H + light.ambientColor.xyz);\n let principled = diffuse_radiance + spec_radiance;\n\n let final_color = mix(add_shader, principled, 0.2);\n\n var outAlpha = alpha;\n if (IS_OVER_EYES) { outAlpha = alpha * 0.6; }\n\n var out: FSOut;\n out.color = vec4f(final_color, outAlpha);\n out.mask = 1.0;\n return out;\n}\n\n";
2
2
  //# sourceMappingURL=hair.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"hair.d.ts","sourceRoot":"","sources":["../../../src/shaders/materials/hair.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,gBAAgB,iy6BA4K5B,CAAA"}
1
+ {"version":3,"file":"hair.d.ts","sourceRoot":"","sources":["../../../src/shaders/materials/hair.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,gBAAgB,gw7BAqL5B,CAAA"}
@@ -5,6 +5,12 @@ export const HAIR_SHADER_WGSL = /* wgsl */ `
5
5
 
6
6
  ${NODES_WGSL}
7
7
 
8
+ // Pipeline-override: the engine compiles two variants — the normal opaque hair pipeline
9
+ // (IS_OVER_EYES=false) and a second pipeline that re-draws hair fragments stencil-matched
10
+ // against the eye stamp with 50% alpha so eyes read through the hair silhouette. Resolved
11
+ // at pipeline-compile time; the dead branch is dropped by the shader compiler.
12
+ override IS_OVER_EYES: bool = false;
13
+
8
14
  struct CameraUniforms {
9
15
  view: mat4x4f,
10
16
  projection: mat4x4f,
@@ -167,8 +173,11 @@ struct FSOut {
167
173
 
168
174
  let final_color = mix(add_shader, principled, 0.2);
169
175
 
176
+ var outAlpha = alpha;
177
+ if (IS_OVER_EYES) { outAlpha = alpha * 0.6; }
178
+
170
179
  var out: FSOut;
171
- out.color = vec4f(final_color, alpha);
180
+ out.color = vec4f(final_color, outAlpha);
172
181
  out.mask = 1.0;
173
182
  return out;
174
183
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reze-engine",
3
- "version": "0.11.3",
3
+ "version": "0.12.0",
4
4
  "description": "A lightweight WebGPU engine for real-time 3D MMD/PMX model rendering",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
package/src/engine.ts CHANGED
@@ -232,6 +232,7 @@ export class Engine {
232
232
  private metalPipeline!: GPURenderPipeline
233
233
  private bodyPipeline!: GPURenderPipeline
234
234
  private eyePipeline!: GPURenderPipeline
235
+ private hairOverEyesPipeline!: GPURenderPipeline
235
236
  private stockingsPipeline!: GPURenderPipeline
236
237
  private groundShadowPipeline!: GPURenderPipeline
237
238
  private groundShadowBindGroupLayout!: GPUBindGroupLayout
@@ -247,6 +248,9 @@ export class Engine {
247
248
  private hdrResolveTexture!: GPUTexture
248
249
  private static readonly MULTISAMPLE_COUNT = 4
249
250
  private static readonly HDR_FORMAT: GPUTextureFormat = "rgba16float"
251
+ /** Stencil value stamped by eye draws so hair can stencil-test against it and
252
+ * alpha-blend a second pass over eye silhouette pixels (see-through-hair effect). */
253
+ private static readonly STENCIL_EYE_VALUE = 1
250
254
  /** Single-channel mask written alongside HDR color — 1 = model geometry (contributes
251
255
  * to bloom), 0 = ground (never blooms). Sampled by the bloom blit pass to gate the
252
256
  * prefilter so ground brightness can't halo the scene. */
@@ -822,6 +826,9 @@ export class Engine {
822
826
  },
823
827
  })
824
828
 
829
+ // Hair opaque: stencil != EYE_VALUE so fragments on top of eyes are skipped entirely —
830
+ // depth and color stay as the eye wrote them; the follow-up hairOverEyesPipeline then
831
+ // draws those skipped fragments alpha-blended so the eye reads through the hair.
825
832
  this.hairPipeline = this.createRenderPipeline({
826
833
  label: "hair NPR pipeline",
827
834
  layout: mainPipelineLayout,
@@ -833,9 +840,39 @@ export class Engine {
833
840
  format: "depth24plus-stencil8",
834
841
  depthWriteEnabled: true,
835
842
  depthCompare: "less-equal",
843
+ stencilFront: { compare: "not-equal", failOp: "keep", depthFailOp: "keep", passOp: "keep" },
844
+ stencilBack: { compare: "not-equal", failOp: "keep", depthFailOp: "keep", passOp: "keep" },
845
+ stencilReadMask: 0xff,
846
+ stencilWriteMask: 0,
836
847
  },
837
848
  })
838
849
 
850
+ // Hair-over-eyes: same shader with IS_OVER_EYES=true so alpha is halved at compile time.
851
+ // Only fragments where eye stencil == EYE_VALUE pass; depth test still culls fragments
852
+ // that are further from camera than the eye, so hair behind the eye never shows through.
853
+ // depthWriteEnabled=false keeps the eye's depth authoritative for everything drawn after.
854
+ this.hairOverEyesPipeline = this.device.createRenderPipeline({
855
+ label: "hair over eyes pipeline",
856
+ layout: mainPipelineLayout,
857
+ vertex: { module: hairShaderModule, buffers: fullVertexBuffers },
858
+ fragment: {
859
+ module: hairShaderModule,
860
+ constants: { IS_OVER_EYES: 1 },
861
+ targets: sceneTargets,
862
+ },
863
+ primitive: { cullMode: "none" },
864
+ depthStencil: {
865
+ format: "depth24plus-stencil8",
866
+ depthWriteEnabled: false,
867
+ depthCompare: "less-equal",
868
+ stencilFront: { compare: "equal", failOp: "keep", depthFailOp: "keep", passOp: "keep" },
869
+ stencilBack: { compare: "equal", failOp: "keep", depthFailOp: "keep", passOp: "keep" },
870
+ stencilReadMask: 0xff,
871
+ stencilWriteMask: 0,
872
+ },
873
+ multisample: { count: Engine.MULTISAMPLE_COUNT },
874
+ })
875
+
839
876
  this.clothSmoothPipeline = this.createRenderPipeline({
840
877
  label: "cloth smooth NPR pipeline",
841
878
  layout: mainPipelineLayout,
@@ -892,17 +929,30 @@ export class Engine {
892
929
  },
893
930
  })
894
931
 
932
+ // Eye: stamps stencil = EYE_VALUE on every fragment it writes. Later hair passes read
933
+ // this stamp to split into "draw normally (not over eye)" vs "draw alpha-blended".
934
+ // cullMode="front" + small negative depthBias is the MMD post-alpha-eye trick: only the
935
+ // back half of the eye sphere renders, it passes depth against the face (via bias) when
936
+ // viewed from the front, and it gets culled when viewed from behind — so eye fragments
937
+ // can't leak through the back of the head without needing a per-model skull occluder.
895
938
  this.eyePipeline = this.createRenderPipeline({
896
939
  label: "eye pipeline",
897
940
  layout: mainPipelineLayout,
898
941
  shaderModule: eyeShaderModule,
899
942
  vertexBuffers: fullVertexBuffers,
900
943
  fragmentTargets: sceneTargets,
901
- cullMode: "none",
944
+ cullMode: "front",
902
945
  depthStencil: {
903
946
  format: "depth24plus-stencil8",
904
947
  depthWriteEnabled: true,
905
948
  depthCompare: "less-equal",
949
+ depthBias: -0.00005,
950
+ depthBiasSlopeScale: 0.0,
951
+ depthBiasClamp: 0.0,
952
+ stencilFront: { compare: "always", failOp: "keep", depthFailOp: "keep", passOp: "replace" },
953
+ stencilBack: { compare: "always", failOp: "keep", depthFailOp: "keep", passOp: "replace" },
954
+ stencilReadMask: 0xff,
955
+ stencilWriteMask: 0xff,
906
956
  },
907
957
  })
908
958
 
@@ -1052,6 +1102,13 @@ export class Engine {
1052
1102
  // Don’t write outline into depth buffer — stops z-fighting / black cracks vs body (MMD-style; body depth stays authoritative)
1053
1103
  depthWriteEnabled: false,
1054
1104
  depthCompare: "less-equal",
1105
+ // Skip fragments where the eye stamped stencil=EYE_VALUE. Those pixels are owned by
1106
+ // the see-through-hair blend (hair-over-eyes), so letting the outline's near-black
1107
+ // edge color overwrite them would re-introduce the dark almond we just killed.
1108
+ stencilFront: { compare: "not-equal", failOp: "keep", depthFailOp: "keep", passOp: "keep" },
1109
+ stencilBack: { compare: "not-equal", failOp: "keep", depthFailOp: "keep", passOp: "keep" },
1110
+ stencilReadMask: 0xff,
1111
+ stencilWriteMask: 0,
1055
1112
  },
1056
1113
  })
1057
1114
 
@@ -2223,6 +2280,26 @@ export class Engine {
2223
2280
  currentIndexOffset += indexCount
2224
2281
  }
2225
2282
 
2283
+ // Sort so the opaque bucket is emitted in the order the stencil-based
2284
+ // see-through-hair effect requires: {non-hair, non-eye} → {eye} → {hair}.
2285
+ // Eye writes stencil=EYE_VALUE; hair's pipeline stencil-tests "not equal" so
2286
+ // it skips eye pixels; a follow-up hairOverEyes pass (see renderOneModel)
2287
+ // re-fills those skipped pixels alpha-blended. Array.sort is stable in
2288
+ // ES2019+, so within a bucket the PMX material order is preserved.
2289
+ const typeOrder: Record<DrawCallType, number> = {
2290
+ opaque: 0,
2291
+ "opaque-outline": 1,
2292
+ transparent: 2,
2293
+ "transparent-outline": 3,
2294
+ ground: 4,
2295
+ }
2296
+ const presetRank = (p: MaterialPreset): number => (p === "hair" ? 2 : p === "eye" ? 1 : 0)
2297
+ inst.drawCalls.sort((a, b) => {
2298
+ const ta = typeOrder[a.type] - typeOrder[b.type]
2299
+ if (ta !== 0) return ta
2300
+ return presetRank(a.preset) - presetRank(b.preset)
2301
+ })
2302
+
2226
2303
  for (const d of inst.drawCalls) {
2227
2304
  if (d.type === "opaque") inst.shadowDrawCalls.push(d)
2228
2305
  }
@@ -2675,12 +2752,38 @@ export class Engine {
2675
2752
  pass.setVertexBuffer(2, inst.weightsBuffer)
2676
2753
  pass.setIndexBuffer(inst.indexBuffer, "uint32")
2677
2754
 
2755
+ // Single stencil-reference set covers eye (write), hair (read not-equal),
2756
+ // and hairOverEyes (read equal). Non-stencil pipelines ignore the value.
2757
+ pass.setStencilReference(Engine.STENCIL_EYE_VALUE)
2758
+
2678
2759
  this.drawMaterials(pass, inst, "opaque")
2679
2760
  this.drawOutlines(pass, inst, "opaque-outline")
2761
+ this.drawHairOverEyes(pass, inst)
2680
2762
  this.drawMaterials(pass, inst, "transparent")
2681
2763
  this.drawOutlines(pass, inst, "transparent-outline")
2682
2764
  }
2683
2765
 
2766
+ /**
2767
+ * Second hair pass for the see-through-hair effect. Re-draws every hair opaque
2768
+ * draw using `hairOverEyesPipeline` — which stencil-matches `EYE_VALUE` and runs
2769
+ * the hair shader with `IS_OVER_EYES=true` so alpha is halved. depthWriteEnabled
2770
+ * is off, so the eye's depth stays authoritative for anything drawn after.
2771
+ */
2772
+ private drawHairOverEyes(pass: GPURenderPassEncoder, inst: ModelInstance): void {
2773
+ let bound = false
2774
+ for (const draw of inst.drawCalls) {
2775
+ if (draw.type !== "opaque" || draw.preset !== "hair" || !this.shouldRenderDrawCall(inst, draw)) continue
2776
+ if (!bound) {
2777
+ pass.setPipeline(this.hairOverEyesPipeline)
2778
+ pass.setBindGroup(0, this.perFrameBindGroup)
2779
+ pass.setBindGroup(1, inst.mainPerInstanceBindGroup)
2780
+ bound = true
2781
+ }
2782
+ pass.setBindGroup(2, draw.bindGroup)
2783
+ pass.drawIndexed(draw.count, 1, draw.firstIndex, 0, 0)
2784
+ }
2785
+ }
2786
+
2684
2787
  private updateCameraUniforms() {
2685
2788
  const viewMatrix = this.camera.getViewMatrix()
2686
2789
  const projectionMatrix = this.camera.getProjectionMatrix()
@@ -7,6 +7,12 @@ export const HAIR_SHADER_WGSL = /* wgsl */ `
7
7
 
8
8
  ${NODES_WGSL}
9
9
 
10
+ // Pipeline-override: the engine compiles two variants — the normal opaque hair pipeline
11
+ // (IS_OVER_EYES=false) and a second pipeline that re-draws hair fragments stencil-matched
12
+ // against the eye stamp with 50% alpha so eyes read through the hair silhouette. Resolved
13
+ // at pipeline-compile time; the dead branch is dropped by the shader compiler.
14
+ override IS_OVER_EYES: bool = false;
15
+
10
16
  struct CameraUniforms {
11
17
  view: mat4x4f,
12
18
  projection: mat4x4f,
@@ -169,8 +175,11 @@ struct FSOut {
169
175
 
170
176
  let final_color = mix(add_shader, principled, 0.2);
171
177
 
178
+ var outAlpha = alpha;
179
+ if (IS_OVER_EYES) { outAlpha = alpha * 0.6; }
180
+
172
181
  var out: FSOut;
173
- out.color = vec4f(final_color, alpha);
182
+ out.color = vec4f(final_color, outAlpha);
174
183
  out.mask = 1.0;
175
184
  return out;
176
185
  }