reze-engine 0.11.1 → 0.11.2

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/dist/engine.d.ts CHANGED
@@ -44,7 +44,7 @@ export type BloomOptions = {
44
44
  export declare const DEFAULT_BLOOM_OPTIONS: BloomOptions;
45
45
  /** Blender Color Management / View (rendering.txt: Filmic, exposure, gamma). `look` is reserved for future curve tweaks. */
46
46
  export type ViewTransformOptions = {
47
- /** Stops applied before Filmic: `linear *= 2^exposure` (Blender default often ~−0.3). */
47
+ /** Stops applied before Filmic: `linear *= 2^exposure`. */
48
48
  exposure: number;
49
49
  /** After Filmic, display gamma (`pow(rgb, 1/gamma)`). */
50
50
  gamma: number;
@@ -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;AAYvB,OAAO,EAAsC,KAAK,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAE/F,MAAM,MAAM,eAAe,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;AAEpH,kHAAkH;AAClH,MAAM,MAAM,yBAAyB,GAAG;IACtC,KAAK,EAAE,QAAQ,GAAG,IAAI,EAAE,CAAA;IACxB,OAAO,CAAC,EAAE,IAAI,CAAA;CACf,CAAA;AAID,MAAM,MAAM,YAAY,GAAG;IACzB,8FAA8F;IAC9F,KAAK,CAAC,EAAE,IAAI,CAAA;IACZ,uEAAuE;IACvE,QAAQ,CAAC,EAAE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AO,GAAG,IAAI;IAIpC,YAAY,IAAI,OAAO;IAIvB,iBAAiB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAIzC,iBAAiB,IAAI,OAAO;IAI5B,OAAO,CAAC,eAAe;IAIvB,OAAO,CAAC,eAAe;IAWvB,OAAO,CAAC,kBAAkB;YAOZ,kBAAkB;IAiHhC,OAAO,CAAC,oBAAoB;IAwE5B,OAAO,CAAC,2BAA2B;IA4DnC,OAAO,CAAC,kBAAkB,CAAO;IACjC,OAAO,CAAC,mBAAmB;YAeb,yBAAyB;IAyGvC,OAAO,CAAC,2BAA2B;IAUnC,OAAO,CAAC,mBAAmB;IAU3B,OAAO,CAAC,oBAAoB;YAId,4BAA4B;IAuC1C,OAAO,CAAC,eAAe;IA0DvB,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;IA+GN,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;IAYtB,OAAO,CAAC,oBAAoB;IAY5B,OAAO,CAAC,kBAAkB;IAa1B,OAAO,CAAC,WAAW;CAwBpB"}
package/dist/engine.js CHANGED
@@ -24,8 +24,10 @@ export const DEFAULT_BLOOM_OPTIONS = {
24
24
  intensity: 0.05,
25
25
  clamp: 0.0,
26
26
  };
27
+ // Matches the reference Blender project: Filmic view, Medium High Contrast look,
28
+ // exposure 0.3, gamma 1.0, sRGB display, no curves.
27
29
  export const DEFAULT_VIEW_TRANSFORM = {
28
- exposure: -0.30000001192092896,
30
+ exposure: 0.6,
29
31
  gamma: 1.0,
30
32
  look: "medium_high_contrast",
31
33
  };
@@ -236,9 +238,12 @@ export class Engine {
236
238
  writeBloomUniforms() {
237
239
  const b = this.bloomSettings;
238
240
  const bu = this.bloomBlitUniformData;
239
- // EEVEE prefilter: threshold, knee, clamp (0 → disabled), _unused
241
+ // EEVEE prefilter: threshold, knee_half, clamp (0 → disabled), _unused
242
+ // Blender halves the knee before passing to the shader (eevee_bloom.c: knee * 0.5f).
243
+ // The blit shader's quadratic soft-knee curve uses knee_half as the offset from threshold,
244
+ // so the soft ramp spans [threshold - knee/2 .. threshold + knee/2] — NOT [threshold - knee .. threshold + knee].
240
245
  bu[0] = b.threshold;
241
- bu[1] = b.knee;
246
+ bu[1] = b.knee * 0.5;
242
247
  bu[2] = b.clamp;
243
248
  bu[3] = 0.0;
244
249
  this.device.queue.writeBuffer(this.bloomBlitUniformBuffer, 0, bu);
@@ -1105,7 +1110,9 @@ export class Engine {
1105
1110
  `,
1106
1111
  });
1107
1112
  const bloomBlitLayout = this.device.createPipelineLayout({ bindGroupLayouts: [this.bloomBlitBindGroupLayout] });
1108
- const bloomDownLayout = this.device.createPipelineLayout({ bindGroupLayouts: [this.bloomDownsampleBindGroupLayout] });
1113
+ const bloomDownLayout = this.device.createPipelineLayout({
1114
+ bindGroupLayouts: [this.bloomDownsampleBindGroupLayout],
1115
+ });
1109
1116
  const bloomUpLayout = this.device.createPipelineLayout({ bindGroupLayouts: [this.bloomUpsampleBindGroupLayout] });
1110
1117
  this.bloomBlitPipeline = this.device.createRenderPipeline({
1111
1118
  label: "bloom blit pipeline",
@@ -1155,9 +1162,14 @@ export class Engine {
1155
1162
  // viewU[0] = (exposure, gamma, _, _); viewU[1] = (tint.rgb, intensity)
1156
1163
 
1157
1164
  fn filmic(x: f32) -> f32 {
1165
+ // Re-fit against Blender 3.6 Filmic MHC anchors (sobotka/filmic-blender
1166
+ // look_medium-high-contrast.spi1d). Previous curve was compressed:
1167
+ // midtones too bright, highlights too dim — flattened contrast, read
1168
+ // as "washed-out" on saturated surfaces (hair especially).
1169
+ // Reference checkpoints: linear 0.18 → ~0.395, linear 1.0 → ~0.83.
1158
1170
  var lut = array<f32, 14>(
1159
- 0.0067, 0.0141, 0.0272, 0.0499, 0.0885, 0.1512, 0.2462,
1160
- 0.3753, 0.5273, 0.6776, 0.8031, 0.8929, 0.9495, 0.9814
1171
+ 0.0028, 0.0068, 0.0151, 0.0313, 0.0610, 0.1120, 0.1920,
1172
+ 0.3060, 0.4590, 0.6310, 0.8200, 0.9070, 0.9620, 0.9890
1161
1173
  );
1162
1174
  let t = clamp(log2(max(x, 1e-10)) + 10.0, 0.0, 13.0);
1163
1175
  let i = u32(t);
@@ -1178,7 +1190,8 @@ export class Engine {
1178
1190
  let fullSz = vec2f(textureDimensions(hdrTex));
1179
1191
  let bloomSz = vec2f(textureDimensions(bloomTex));
1180
1192
  // Bloom is at half-res (pyramid mip 0). Sampler interpolates back to full-res UVs.
1181
- let bloomUv = (fragCoord.xy + vec2f(0.5)) / max(fullSz, vec2f(1.0));
1193
+ // fragCoord.xy is already at pixel center (e.g. 0.5, 0.5 for first pixel).
1194
+ let bloomUv = fragCoord.xy / max(fullSz, vec2f(1.0));
1182
1195
  let tint = viewU[1].xyz;
1183
1196
  let intensity = viewU[1].w;
1184
1197
  let bloom = textureSampleLevel(bloomTex, bloomSamp, bloomUv, 0.0).rgb * tint * intensity;
@@ -2235,7 +2248,9 @@ export class Engine {
2235
2248
  ],
2236
2249
  });
2237
2250
  const pass = encoder.beginRenderPass({
2238
- colorAttachments: [{ view: dstView, clearValue: { r: 0, g: 0, b: 0, a: 0 }, loadOp: "clear", storeOp: "store" }],
2251
+ colorAttachments: [
2252
+ { view: dstView, clearValue: { r: 0, g: 0, b: 0, a: 0 }, loadOp: "clear", storeOp: "store" },
2253
+ ],
2239
2254
  });
2240
2255
  pass.setPipeline(this.mipBlitPipeline);
2241
2256
  pass.setBindGroup(0, bindGroup);
@@ -1,2 +1,2 @@
1
- export declare const BODY_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 AMBIENT_OCCLUSION node (faked) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\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// Real SSAO is a non-goal. We approximate: use the \"inside\" value from\n// concavity heuristic: 1.0 = fully lit, lower = occluded.\n// For now returns 1.0 (no darkening). Individual presets can override.\n\nfn ao_fake(n: vec3f, v: vec3f) -> f32 {\n return 1.0;\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 (distance only) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\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 Metal preset. Simplified F1 cell noise.\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// \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_B: f32 = 3.141592653589793;\nconst F0_BODY: f32 = 0.04;\nconst BODY_ROUGHNESS: f32 = 0.3;\n// Dump: \u5C42\u6743\u91CD.002 Blend; \u8FD0\u7B97.007 POWER exponent Value_001; \u80CC\u666F Color; \u8FD0\u7B97.004 after invert\nconst BODY_RIM2_LAYER_BLEND: f32 = 0.20000000298023224;\nconst BODY_RIM2_POW: f32 = 1.4300000667572021;\nconst BODY_RIM2_BG: vec3f = vec3f(1.0, 0.4303792119026184, 0.3315804898738861);\nconst BODY_WARM_AO_MUL: f32 = 0.30000001192092896;\nconst BODY_MIX_NPR: f32 = 0.5;\n// EEVEE Light Clamp equivalent \u2014 caps firefly specular from noise-bumped NDF aliasing.\nconst BODY_SPEC_CLAMP: f32 = 10.0;\n\nfn ggx_d_body(ndoth: f32, a2: f32) -> f32 {\n let denom = ndoth * ndoth * (a2 - 1.0) + 1.0;\n return a2 / (PI_B * denom * denom);\n}\n\nfn smith_g1_body(ndotx: f32, a2: f32) -> f32 {\n return 2.0 * ndotx / (ndotx + sqrt(a2 + (1.0 - a2) * ndotx * ndotx));\n}\n\nfn fresnel_schlick_body(cosTheta: f32, f0: f32) -> f32 {\n let m = 1.0 - cosTheta;\n let m2 = m * m;\n return f0 + (1.0 - f0) * (m2 * m2 * m);\n}\n\n// smoothstep-based ramp: t*t*(3-2*t) between two color stops\nfn ramp_ease(f: f32, p0: f32, c0: vec4f, p1: f32, c1: vec4f) -> vec4f {\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@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 // \u2550\u2550\u2550 TOON MASK: ShaderToRGB \u2192 ramp.008 CONSTANT [0\u2192black, 0.2966\u2192white] \u2550\u2550\u2550\n let ndotl_raw = shader_to_rgb_diffuse(n, l, sun, light.ambientColor.xyz, shadow);\n let toon = ramp_constant(ndotl_raw, 0.0, vec4f(0,0,0,1), 0.2966, vec4f(1,1,1,1)).r;\n\n // \u2550\u2550\u2550 TOON COLOR: Mix.004 A=HueSat, B=HueSat.001, Fac=ramp.008 (R) \u2550\u2550\u2550\n let shadow_tint = hue_sat_id(2.0, 0.3499999940395355, 1.0, tex_color);\n let lit_tint = hue_sat_id(1.5, 1.0, 1.0, tex_color);\n let toon_color = mix_blend(toon, shadow_tint, lit_tint);\n let bc = bright_contrast(toon_color, 0.1, 0.2);\n\n // \u2550\u2550\u2550 AO CHAIN: AO \u2192 ramp CONSTANT [0\u2192white, 0.5995\u2192black] \u2192 Mix.003 \u2550\u2550\u2550\n let ao = 1.0; // ao_fake(n, v) \u2014 no SSAO yet; inline 1.0 so the ramp/mix chain folds at compile time.\n let ao_ramp = ramp_constant(ao, 0.0, vec4f(1,1,1,1), 0.5995, vec4f(0,0,0,1)).r;\n let ao_mixed = mix_blend(ao_ramp, bc, vec3f(0.8301780223846436, 0.3345769941806793, 0.27946099638938904));\n\n // \u2550\u2550\u2550 EMISSION.003 (strength=4.0) \u2550\u2550\u2550\n let emission3 = ao_mixed * 4.0;\n\n // \u2550\u2550\u2550 WARM: \u989C\u8272\u6E10\u53D8.008 \u2192 \u8FD0\u7B97.006 ADD +0.5 (m_graphs) \u2192 clamp \u2192 \u989C\u8272\u6E10\u53D8.003 \u2550\u2550\u2550\n let ao_inv = invert_f(1.0, ao_ramp);\n let warm_str = ao_inv * BODY_WARM_AO_MUL;\n let warm_input = clamp(toon + 0.5, 0.0, 1.0);\n let warm_color = ramp_cardinal(warm_input, 0.2409,\n vec4f(0.2426, 0.068, 0.0588, 1.0), 0.4663,\n vec4f(0.6677, 0.5024, 0.5126, 1.0)).rgb;\n let warm_emission = warm_color * warm_str;\n\n // \u2550\u2550\u2550 RIM 1: \u83F2\u6D85\u5C14 \u00D7 \u5C42\u6743\u91CD.001 Facing Blend=0.24 \u2192 \u81EA\u53D1\u5149 Strength \u2550\u2550\u2550\n let rim1_str = fresnel(2.0, n, v) * layer_weight_facing(0.24000005424022675, n, v);\n let rim1 = vec3f(0.984157919883728, 0.6110184788703918, 0.5736401677131653) * rim1_str;\n\n // \u2550\u2550\u2550 RIM 2: \u5C42\u6743\u91CD.002 Facing \u2192 \u8FD0\u7B97.007 POWER \u2192 \u989C\u8272\u6E10\u53D8.010 EASE \u2192 MixShader.002 Fac \u2550\u2550\u2550\n let facing_raw = layer_weight_facing(BODY_RIM2_LAYER_BLEND, n, v);\n let facing_pow = math_power(facing_raw, BODY_RIM2_POW);\n let rim2_fac = ramp_ease(facing_pow, 0.0, vec4f(0,0,0,1), 0.5052, vec4f(1,1,1,1)).r;\n let rim2_mixed = mix(emission3, BODY_RIM2_BG, rim2_fac);\n\n // \u2550\u2550\u2550 NPR STACK: AddShader chain (no bright gate in body) \u2550\u2550\u2550\n let add0 = rim1 + rim2_mixed;\n let npr_stack = add0 + warm_emission;\n\n // \u2550\u2550\u2550 PRINCIPLED BSDF: noise bump, GGX specular, SSS from AO \u2550\u2550\u2550\n // Mapping loc=rot=0 \u2192 plain scale multiply, inline.\n let noise_val = tex_noise_d2(input.worldPos * vec3f(1.0, 1.0, 1.5), 1.0);\n let noise_ramp = ramp_linear(noise_val, 0.0, vec4f(0,0,0,1), 1.0, vec4f(1,1,1,1)).r;\n let bumped_n = bump_lh(0.324644535779953, noise_ramp, n, input.worldPos);\n\n let principled_base = mix_blend(noise_ramp, bc, vec3f(0.6831911206245422, 0.19474034011363983, 0.13732507824897766));\n let p_emission = bc * 0.2;\n\n // Reuse 'ao' (ao_fake(n, v) above) \u2014 identical inputs, avoid a second procedural AO pass.\n let sss = ramp_linear(ao, 0.003, vec4f(0,0,0,1), 1.0, vec4f(0.0786, 0.0786, 0.0786, 1.0)).r;\n\n let p_ndotl = max(dot(bumped_n, l), 0.0);\n let p_ndotv = max(dot(bumped_n, v), 0.001);\n let h = normalize(l + v);\n let p_ndoth = max(dot(bumped_n, h), 0.0);\n let p_vdoth = max(dot(v, h), 0.0);\n let a2 = BODY_ROUGHNESS * BODY_ROUGHNESS;\n let D = ggx_d_body(p_ndoth, a2);\n let G = smith_g1_body(p_ndotl, a2) * smith_g1_body(p_ndotv, a2);\n let F = fresnel_schlick_body(p_vdoth, F0_BODY);\n let brdf_lut = brdf_lut_sample(p_ndotv, BODY_ROUGHNESS);\n let spec = (D * G * F) / max(4.0 * p_ndotl * p_ndotv, 0.001) * ltc_brdf_scale_from_lut(brdf_lut);\n let kd = (1.0 - F) * principled_base / PI_B;\n // Split so we can clamp only the spec firefly contribution (EEVEE Light Clamp).\n let spec_radiance = vec3f(spec) * sun * p_ndotl * shadow;\n let spec_clamped = min(spec_radiance, vec3f(BODY_SPEC_CLAMP));\n let direct = kd * sun * p_ndotl * shadow + spec_clamped;\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 ambient = principled_base * light.ambientColor.xyz;\n let principled = ambient + direct + p_emission + vec3f(sss);\n\n // \u6DF7\u5408\u7740\u8272\u5668.001: Shader=\u76F8\u52A0\u7740\u8272\u5668.001, Shader_001=\u539F\u7406\u5316BSDF\n let final_color = mix(npr_stack, principled, BODY_MIX_NPR);\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 BODY_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 AMBIENT_OCCLUSION node (faked) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\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// Real SSAO is a non-goal. We approximate: use the \"inside\" value from\n// concavity heuristic: 1.0 = fully lit, lower = occluded.\n// For now returns 1.0 (no darkening). Individual presets can override.\n\nfn ao_fake(n: vec3f, v: vec3f) -> f32 {\n return 1.0;\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 (distance only) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\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 Metal preset. Simplified F1 cell noise.\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// \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_B: f32 = 3.141592653589793;\nconst BODY_ROUGHNESS: f32 = 0.3;\n// Dump: \u5C42\u6743\u91CD.002 Blend; \u8FD0\u7B97.007 POWER exponent Value_001; \u80CC\u666F Color; \u8FD0\u7B97.004 after invert\nconst BODY_RIM2_LAYER_BLEND: f32 = 0.20000000298023224;\nconst BODY_RIM2_POW: f32 = 1.4300000667572021;\nconst BODY_RIM2_BG: vec3f = vec3f(1.0, 0.4303792119026184, 0.3315804898738861);\nconst BODY_WARM_AO_MUL: f32 = 0.30000001192092896;\nconst BODY_SPECULAR: f32 = 0.5;\nconst BODY_MIX_NPR: f32 = 0.5;\n// EEVEE Light Clamp equivalent \u2014 caps firefly specular from noise-bumped NDF aliasing.\nconst BODY_SPEC_CLAMP: f32 = 10.0;\n\n// smoothstep-based ramp: t*t*(3-2*t) between two color stops\nfn ramp_ease(f: f32, p0: f32, c0: vec4f, p1: f32, c1: vec4f) -> vec4f {\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@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 // \u2550\u2550\u2550 TOON MASK: ShaderToRGB \u2192 ramp.008 CONSTANT [0\u2192black, 0.2966\u2192white] \u2550\u2550\u2550\n let ndotl_raw = shader_to_rgb_diffuse(n, l, sun, light.ambientColor.xyz, shadow);\n let toon = ramp_constant(ndotl_raw, 0.0, vec4f(0,0,0,1), 0.2966, vec4f(1,1,1,1)).r;\n\n // \u2550\u2550\u2550 TOON COLOR: Mix.004 A=HueSat, B=HueSat.001, Fac=ramp.008 (R) \u2550\u2550\u2550\n let shadow_tint = hue_sat_id(2.0, 0.3499999940395355, 1.0, tex_color);\n let lit_tint = hue_sat_id(1.5, 1.0, 1.0, tex_color);\n let toon_color = mix_blend(toon, shadow_tint, lit_tint);\n let bc = bright_contrast(toon_color, 0.1, 0.2);\n\n // \u2550\u2550\u2550 AO CHAIN: AO \u2192 ramp CONSTANT [0\u2192white, 0.5995\u2192black] \u2192 Mix.003 \u2550\u2550\u2550\n let ao = 1.0; // ao_fake(n, v) \u2014 no SSAO yet; inline 1.0 so the ramp/mix chain folds at compile time.\n let ao_ramp = ramp_constant(ao, 0.0, vec4f(1,1,1,1), 0.5995, vec4f(0,0,0,1)).r;\n let ao_mixed = mix_blend(ao_ramp, bc, vec3f(0.8301780223846436, 0.3345769941806793, 0.27946099638938904));\n\n // \u2550\u2550\u2550 EMISSION.003 (strength=4.0) \u2550\u2550\u2550\n let emission3 = ao_mixed * 4.0;\n\n // \u2550\u2550\u2550 WARM: \u989C\u8272\u6E10\u53D8.008 \u2192 \u8FD0\u7B97.006 ADD +0.5 (m_graphs) \u2192 clamp \u2192 \u989C\u8272\u6E10\u53D8.003 \u2550\u2550\u2550\n let ao_inv = invert_f(1.0, ao_ramp);\n let warm_str = ao_inv * BODY_WARM_AO_MUL;\n let warm_input = clamp(toon + 0.5, 0.0, 1.0);\n let warm_color = ramp_cardinal(warm_input, 0.2409,\n vec4f(0.2426, 0.068, 0.0588, 1.0), 0.4663,\n vec4f(0.6677, 0.5024, 0.5126, 1.0)).rgb;\n let warm_emission = warm_color * warm_str;\n\n // \u2550\u2550\u2550 RIM 1: \u83F2\u6D85\u5C14 \u00D7 \u5C42\u6743\u91CD.001 Facing Blend=0.24 \u2192 \u81EA\u53D1\u5149 Strength \u2550\u2550\u2550\n let rim1_str = fresnel(2.0, n, v) * layer_weight_facing(0.24000005424022675, n, v);\n let rim1 = vec3f(0.984157919883728, 0.6110184788703918, 0.5736401677131653) * rim1_str;\n\n // \u2550\u2550\u2550 RIM 2: \u5C42\u6743\u91CD.002 Facing \u2192 \u8FD0\u7B97.007 POWER \u2192 \u989C\u8272\u6E10\u53D8.010 EASE \u2192 MixShader.002 Fac \u2550\u2550\u2550\n let facing_raw = layer_weight_facing(BODY_RIM2_LAYER_BLEND, n, v);\n let facing_pow = math_power(facing_raw, BODY_RIM2_POW);\n let rim2_fac = ramp_ease(facing_pow, 0.0, vec4f(0,0,0,1), 0.5052, vec4f(1,1,1,1)).r;\n let rim2_mixed = mix(emission3, BODY_RIM2_BG, rim2_fac);\n\n // \u2550\u2550\u2550 NPR STACK: AddShader chain (no bright gate in body) \u2550\u2550\u2550\n let add0 = rim1 + rim2_mixed;\n let npr_stack = add0 + warm_emission;\n\n // \u2550\u2550\u2550 PRINCIPLED BSDF: noise bump, GGX specular, SSS from AO \u2550\u2550\u2550\n // Mapping loc=rot=0 \u2192 plain scale multiply, inline.\n let noise_val = tex_noise_d2(input.worldPos * vec3f(1.0, 1.0, 1.5), 1.0);\n let noise_ramp = ramp_linear(noise_val, 0.0, vec4f(0,0,0,1), 1.0, vec4f(1,1,1,1)).r;\n let bumped_n = bump_lh(0.324644535779953, noise_ramp, n, input.worldPos);\n\n let principled_base = mix_blend(noise_ramp, bc, vec3f(0.6831911206245422, 0.19474034011363983, 0.13732507824897766));\n let p_emission = bc * 0.2;\n\n // Reuse 'ao' (ao_fake(n, v) above) \u2014 identical inputs, avoid a second procedural AO pass.\n let sss = ramp_linear(ao, 0.003, vec4f(0,0,0,1), 1.0, vec4f(0.0786, 0.0786, 0.0786, 1.0)).r;\n\n // \u539F\u7406\u5316BSDF (EEVEE port): metallic=0, specular=0.5, roughness=0.3, specular_tint=0.\n let NL = max(dot(bumped_n, l), 0.0);\n let NV = max(dot(bumped_n, v), 1e-4);\n\n // f0/f90 per gpu_shader_material_principled.glsl \u2014 specular_tint=0 \u2192 dielectric_f0_color=white.\n let f0 = vec3f(0.08 * BODY_SPECULAR);\n let f90 = mix(f0, vec3f(1.0), sqrt(BODY_SPECULAR));\n let brdf_lut = brdf_lut_sample(NV, BODY_ROUGHNESS);\n let reflection_color = F_brdf_multi_scatter(f0, f90, brdf_lut.xy);\n\n // Direct glossy \u2014 bsdf_ggx already includes NL; no F applied here (tinted after accum).\n // ltc_brdf_scale: EEVEE direct path uses LTC; split-sum LUT path is rescaled to match.\n let spec_direct_raw = bsdf_ggx(bumped_n, l, v, NL, NV, BODY_ROUGHNESS) * sun * shadow * ltc_brdf_scale_from_lut(brdf_lut);\n let spec_direct = min(spec_direct_raw, vec3f(BODY_SPEC_CLAMP));\n // Indirect glossy \u2014 flat world probe (solid color). Phase 2 adds cubemap.\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 // No (1-F) factor per EEVEE \u2014 it doesn't energy-conserve spec<->diffuse.\n let diffuse_radiance = principled_base * (sun * NL * shadow / PI_B + light.ambientColor.xyz);\n let principled = diffuse_radiance + spec_radiance + p_emission + vec3f(sss);\n\n // \u6DF7\u5408\u7740\u8272\u5668.001: Shader=\u76F8\u52A0\u7740\u8272\u5668.001, Shader_001=\u539F\u7406\u5316BSDF\n let final_color = mix(npr_stack, principled, BODY_MIX_NPR);\n\n var out: FSOut;\n out.color = vec4f(final_color, alpha);\n out.mask = 1.0;\n return out;\n}\n\n";
2
2
  //# sourceMappingURL=body.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"body.d.ts","sourceRoot":"","sources":["../../src/shaders/body.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,gBAAgB,gvgCAqO5B,CAAA"}
1
+ {"version":3,"file":"body.d.ts","sourceRoot":"","sources":["../../src/shaders/body.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,gBAAgB,wrgCAyN5B,CAAA"}
@@ -68,32 +68,17 @@ fn sampleShadow(worldPos: vec3f, n: vec3f) -> f32 {
68
68
  }
69
69
 
70
70
  const PI_B: f32 = 3.141592653589793;
71
- const F0_BODY: f32 = 0.04;
72
71
  const BODY_ROUGHNESS: f32 = 0.3;
73
72
  // Dump: 层权重.002 Blend; 运算.007 POWER exponent Value_001; 背景 Color; 运算.004 after invert
74
73
  const BODY_RIM2_LAYER_BLEND: f32 = 0.20000000298023224;
75
74
  const BODY_RIM2_POW: f32 = 1.4300000667572021;
76
75
  const BODY_RIM2_BG: vec3f = vec3f(1.0, 0.4303792119026184, 0.3315804898738861);
77
76
  const BODY_WARM_AO_MUL: f32 = 0.30000001192092896;
77
+ const BODY_SPECULAR: f32 = 0.5;
78
78
  const BODY_MIX_NPR: f32 = 0.5;
79
79
  // EEVEE Light Clamp equivalent — caps firefly specular from noise-bumped NDF aliasing.
80
80
  const BODY_SPEC_CLAMP: f32 = 10.0;
81
81
 
82
- fn ggx_d_body(ndoth: f32, a2: f32) -> f32 {
83
- let denom = ndoth * ndoth * (a2 - 1.0) + 1.0;
84
- return a2 / (PI_B * denom * denom);
85
- }
86
-
87
- fn smith_g1_body(ndotx: f32, a2: f32) -> f32 {
88
- return 2.0 * ndotx / (ndotx + sqrt(a2 + (1.0 - a2) * ndotx * ndotx));
89
- }
90
-
91
- fn fresnel_schlick_body(cosTheta: f32, f0: f32) -> f32 {
92
- let m = 1.0 - cosTheta;
93
- let m2 = m * m;
94
- return f0 + (1.0 - f0) * (m2 * m2 * m);
95
- }
96
-
97
82
  // smoothstep-based ramp: t*t*(3-2*t) between two color stops
98
83
  fn ramp_ease(f: f32, p0: f32, c0: vec4f, p1: f32, c1: vec4f) -> vec4f {
99
84
  let t = saturate((f - p0) / max(p1 - p0, 1e-6));
@@ -199,26 +184,29 @@ struct FSOut {
199
184
  // Reuse 'ao' (ao_fake(n, v) above) — identical inputs, avoid a second procedural AO pass.
200
185
  let sss = ramp_linear(ao, 0.003, vec4f(0,0,0,1), 1.0, vec4f(0.0786, 0.0786, 0.0786, 1.0)).r;
201
186
 
202
- let p_ndotl = max(dot(bumped_n, l), 0.0);
203
- let p_ndotv = max(dot(bumped_n, v), 0.001);
204
- let h = normalize(l + v);
205
- let p_ndoth = max(dot(bumped_n, h), 0.0);
206
- let p_vdoth = max(dot(v, h), 0.0);
207
- let a2 = BODY_ROUGHNESS * BODY_ROUGHNESS;
208
- let D = ggx_d_body(p_ndoth, a2);
209
- let G = smith_g1_body(p_ndotl, a2) * smith_g1_body(p_ndotv, a2);
210
- let F = fresnel_schlick_body(p_vdoth, F0_BODY);
211
- let brdf_lut = brdf_lut_sample(p_ndotv, BODY_ROUGHNESS);
212
- let spec = (D * G * F) / max(4.0 * p_ndotl * p_ndotv, 0.001) * ltc_brdf_scale_from_lut(brdf_lut);
213
- let kd = (1.0 - F) * principled_base / PI_B;
214
- // Split so we can clamp only the spec firefly contribution (EEVEE Light Clamp).
215
- let spec_radiance = vec3f(spec) * sun * p_ndotl * shadow;
216
- let spec_clamped = min(spec_radiance, vec3f(BODY_SPEC_CLAMP));
217
- let direct = kd * sun * p_ndotl * shadow + spec_clamped;
187
+ // 原理化BSDF (EEVEE port): metallic=0, specular=0.5, roughness=0.3, specular_tint=0.
188
+ let NL = max(dot(bumped_n, l), 0.0);
189
+ let NV = max(dot(bumped_n, v), 1e-4);
190
+
191
+ // f0/f90 per gpu_shader_material_principled.glsl specular_tint=0 → dielectric_f0_color=white.
192
+ let f0 = vec3f(0.08 * BODY_SPECULAR);
193
+ let f90 = mix(f0, vec3f(1.0), sqrt(BODY_SPECULAR));
194
+ let brdf_lut = brdf_lut_sample(NV, BODY_ROUGHNESS);
195
+ let reflection_color = F_brdf_multi_scatter(f0, f90, brdf_lut.xy);
196
+
197
+ // Direct glossy bsdf_ggx already includes NL; no F applied here (tinted after accum).
198
+ // ltc_brdf_scale: EEVEE direct path uses LTC; split-sum LUT path is rescaled to match.
199
+ let spec_direct_raw = bsdf_ggx(bumped_n, l, v, NL, NV, BODY_ROUGHNESS) * sun * shadow * ltc_brdf_scale_from_lut(brdf_lut);
200
+ let spec_direct = min(spec_direct_raw, vec3f(BODY_SPEC_CLAMP));
201
+ // Indirect glossy — flat world probe (solid color). Phase 2 adds cubemap.
202
+ let spec_indirect = light.ambientColor.xyz;
203
+ let spec_radiance = (spec_direct + spec_indirect) * reflection_color;
204
+
218
205
  // Indirect diffuse = base_color × L_w per Blender closure_eval_surface_lib.glsl line 302;
219
206
  // probe_evaluate_world_diff returns radiance (SH-projected, not cosine-convolved).
220
- let ambient = principled_base * light.ambientColor.xyz;
221
- let principled = ambient + direct + p_emission + vec3f(sss);
207
+ // No (1-F) factor per EEVEE — it doesn't energy-conserve spec<->diffuse.
208
+ let diffuse_radiance = principled_base * (sun * NL * shadow / PI_B + light.ambientColor.xyz);
209
+ let principled = diffuse_radiance + spec_radiance + p_emission + vec3f(sss);
222
210
 
223
211
  // 混合着色器.001: Shader=相加着色器.001, Shader_001=原理化BSDF
224
212
  let final_color = mix(npr_stack, principled, BODY_MIX_NPR);
@@ -1,2 +1,2 @@
1
- export declare const DEFAULT_SHADER_WGSL = "\n\nconst PI: f32 = 3.141592653589793;\nconst F0_DIELECTRIC: f32 = 0.04;\nconst ROUGHNESS: f32 = 0.5;\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\n// Per-material uniforms. Add fields here only when a shader actually reads them;\n// preset-specific shaders (face.ts, future hair.ts) share this struct so the\n// engine can use one material bind-group layout.\nstruct MaterialUniforms {\n diffuseColor: vec3f, // tint; multiplies sampled albedo (unused by current fs, reserved)\n alpha: f32, // 0 \u2192 discard; <1 \u2192 transparent draw call\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\n// \u2500\u2500\u2500 GGX specular helpers \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\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 ggx_d(ndoth: f32, a2: f32) -> f32 {\n let denom = ndoth * ndoth * (a2 - 1.0) + 1.0;\n return a2 / (PI * denom * denom);\n}\n\nfn smith_g1(ndotx: f32, a2: f32) -> f32 {\n return 2.0 * ndotx / (ndotx + sqrt(a2 + (1.0 - a2) * ndotx * ndotx));\n}\n\nfn fresnel_schlick(cosTheta: f32, f0: f32) -> f32 {\n let m = 1.0 - cosTheta;\n let m2 = m * m;\n return f0 + (1.0 - f0) * (m2 * m2 * m);\n}\n\n// \u2500\u2500\u2500 Filmic tone mapping (LUT extracted from Blender 3.6 OCIO) \u2500\u2500\u2500\u2500\u2500\n// View transform = Filmic, Look = Medium High Contrast, Exposure = -0.3.\n// 14 samples at integer log2 stops from -10 to +3 (inclusive).\n// Extracted via scripts/extract_filmic_lut.py \u2192 probe image through scene\n// color management. Input: linear scene-referred. Output: sRGB display.\n\nfn filmic(x: f32) -> f32 {\n var lut = array<f32, 14>(\n 0.0067, 0.0141, 0.0272, 0.0499, 0.0885, 0.1512, 0.2462,\n 0.3753, 0.5273, 0.6776, 0.8031, 0.8929, 0.9495, 0.9814\n );\n let t = clamp(log2(max(x, 1e-10)) + 10.0, 0.0, 13.0);\n let i = u32(t);\n let j = min(i + 1u, 13u);\n return mix(lut[i], lut[j], t - f32(i));\n}\n\nfn tonemap(hdr: vec3f) -> vec3f {\n return vec3f(filmic(hdr.x), filmic(hdr.y), filmic(hdr.z));\n}\n\n// \u2500\u2500\u2500 Shadow sampling (3\u00D73 PCF) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\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 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\n// \u2500\u2500\u2500 Vertex / Fragment \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\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\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 albedo = textureSample(diffuseTexture, diffuseSampler, input.uv).rgb;\n\n let l = -light.lights[0].direction.xyz;\n let sunColor = light.lights[0].color.xyz * light.lights[0].color.w;\n let h = normalize(l + v);\n\n let ndotl = max(dot(n, l), 0.0);\n let ndotv = max(dot(n, v), 0.001);\n let ndoth = max(dot(n, h), 0.0);\n let vdoth = max(dot(v, h), 0.0);\n\n let a2 = ROUGHNESS * ROUGHNESS;\n let D = ggx_d(ndoth, a2);\n let G = smith_g1(ndotl, a2) * smith_g1(ndotv, a2);\n let F = fresnel_schlick(vdoth, F0_DIELECTRIC);\n let spec = (D * G * F) / max(4.0 * ndotl * ndotv, 0.001);\n\n let shadow = sampleShadow(input.worldPos, n);\n let kd = (1.0 - F) * albedo / PI;\n let direct = (kd + spec) * sunColor * ndotl * shadow;\n let ambient = albedo * light.ambientColor.xyz;\n\n var out: FSOut;\n out.color = vec4f(ambient + direct, alpha);\n out.mask = 1.0;\n return out;\n}\n\n";
1
+ export declare const DEFAULT_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 AMBIENT_OCCLUSION node (faked) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\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// Real SSAO is a non-goal. We approximate: use the \"inside\" value from\n// concavity heuristic: 1.0 = fully lit, lower = occluded.\n// For now returns 1.0 (no darkening). Individual presets can override.\n\nfn ao_fake(n: vec3f, v: vec3f) -> f32 {\n return 1.0;\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 (distance only) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\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 Metal preset. Simplified F1 cell noise.\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// \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\nconst PI: f32 = 3.141592653589793;\nconst DEFAULT_SPECULAR: f32 = 0.5;\nconst ROUGHNESS: f32 = 0.5;\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\n// Per-material uniforms. Add fields here only when a shader actually reads them;\n// preset-specific shaders (face.ts, future hair.ts) share this struct so the\n// engine can use one material bind-group layout.\nstruct MaterialUniforms {\n diffuseColor: vec3f, // tint; multiplies sampled albedo (unused by current fs, reserved)\n alpha: f32, // 0 \u2192 discard; <1 \u2192 transparent draw call\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\n// \u2500\u2500\u2500 Filmic tone mapping (LUT extracted from Blender 3.6 OCIO) \u2500\u2500\u2500\u2500\u2500\n// View transform = Filmic, Look = Medium High Contrast, Exposure = -0.3.\n// 14 samples at integer log2 stops from -10 to +3 (inclusive).\n// Extracted via scripts/extract_filmic_lut.py \u2192 probe image through scene\n// color management. Input: linear scene-referred. Output: sRGB display.\n\nfn filmic(x: f32) -> f32 {\n var lut = array<f32, 14>(\n 0.0067, 0.0141, 0.0272, 0.0499, 0.0885, 0.1512, 0.2462,\n 0.3753, 0.5273, 0.6776, 0.8031, 0.8929, 0.9495, 0.9814\n );\n let t = clamp(log2(max(x, 1e-10)) + 10.0, 0.0, 13.0);\n let i = u32(t);\n let j = min(i + 1u, 13u);\n return mix(lut[i], lut[j], t - f32(i));\n}\n\nfn tonemap(hdr: vec3f) -> vec3f {\n return vec3f(filmic(hdr.x), filmic(hdr.y), filmic(hdr.z));\n}\n\n// \u2500\u2500\u2500 Shadow sampling (3\u00D73 PCF) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\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 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\n// \u2500\u2500\u2500 Vertex / Fragment \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\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\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 albedo = textureSample(diffuseTexture, diffuseSampler, input.uv).rgb;\n\n let l = -light.lights[0].direction.xyz;\n let sun = light.lights[0].color.xyz * light.lights[0].color.w;\n let amb = light.ambientColor.xyz;\n let shadow = sampleShadow(input.worldPos, n);\n\n // \u539F\u7406\u5316BSDF (EEVEE port): metallic=0, specular=0.5, roughness=0.5, specular_tint=0.\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 * DEFAULT_SPECULAR);\n let f90 = mix(f0, vec3f(1.0), sqrt(DEFAULT_SPECULAR));\n let brdf_lut = brdf_lut_sample(NV, 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, ROUGHNESS) * sun * shadow * ltc_brdf_scale_from_lut(brdf_lut);\n let spec_indirect = amb;\n let spec_radiance = (spec_direct + spec_indirect) * reflection_color;\n\n let diffuse_radiance = albedo * (sun * NL * shadow / PI + amb);\n\n var out: FSOut;\n out.color = vec4f(diffuse_radiance + spec_radiance, alpha);\n out.mask = 1.0;\n return out;\n}\n\n";
2
2
  //# sourceMappingURL=default.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"default.d.ts","sourceRoot":"","sources":["../../src/shaders/default.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,mBAAmB,8vOAqL/B,CAAA"}
1
+ {"version":3,"file":"default.d.ts","sourceRoot":"","sources":["../../src/shaders/default.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,mBAAmB,425BAsK/B,CAAA"}
@@ -1,10 +1,13 @@
1
1
  // Blender 3.6 Principled BSDF defaults + Filmic "Medium High Contrast" tone mapping.
2
2
  // Metallic=0, Specular=0.5 (F0=0.04), Roughness=0.5.
3
3
  // Tone mapping via LUT sampled from Blender's OCIO pipeline (exposure -0.3 baked in).
4
+ import { NODES_WGSL } from "./nodes";
4
5
  export const DEFAULT_SHADER_WGSL = /* wgsl */ `
5
6
 
7
+ ${NODES_WGSL}
8
+
6
9
  const PI: f32 = 3.141592653589793;
7
- const F0_DIELECTRIC: f32 = 0.04;
10
+ const DEFAULT_SPECULAR: f32 = 0.5;
8
11
  const ROUGHNESS: f32 = 0.5;
9
12
 
10
13
  struct CameraUniforms {
@@ -51,23 +54,6 @@ struct LightVP { viewProj: mat4x4f, };
51
54
  @group(2) @binding(0) var diffuseTexture: texture_2d<f32>;
52
55
  @group(2) @binding(1) var<uniform> material: MaterialUniforms;
53
56
 
54
- // ─── GGX specular helpers ───────────────────────────────────────────
55
-
56
- fn ggx_d(ndoth: f32, a2: f32) -> f32 {
57
- let denom = ndoth * ndoth * (a2 - 1.0) + 1.0;
58
- return a2 / (PI * denom * denom);
59
- }
60
-
61
- fn smith_g1(ndotx: f32, a2: f32) -> f32 {
62
- return 2.0 * ndotx / (ndotx + sqrt(a2 + (1.0 - a2) * ndotx * ndotx));
63
- }
64
-
65
- fn fresnel_schlick(cosTheta: f32, f0: f32) -> f32 {
66
- let m = 1.0 - cosTheta;
67
- let m2 = m * m;
68
- return f0 + (1.0 - f0) * (m2 * m2 * m);
69
- }
70
-
71
57
  // ─── Filmic tone mapping (LUT extracted from Blender 3.6 OCIO) ─────
72
58
  // View transform = Filmic, Look = Medium High Contrast, Exposure = -0.3.
73
59
  // 14 samples at integer log2 stops from -10 to +3 (inclusive).
@@ -157,27 +143,27 @@ struct FSOut {
157
143
  let albedo = textureSample(diffuseTexture, diffuseSampler, input.uv).rgb;
158
144
 
159
145
  let l = -light.lights[0].direction.xyz;
160
- let sunColor = light.lights[0].color.xyz * light.lights[0].color.w;
161
- let h = normalize(l + v);
146
+ let sun = light.lights[0].color.xyz * light.lights[0].color.w;
147
+ let amb = light.ambientColor.xyz;
148
+ let shadow = sampleShadow(input.worldPos, n);
162
149
 
163
- let ndotl = max(dot(n, l), 0.0);
164
- let ndotv = max(dot(n, v), 0.001);
165
- let ndoth = max(dot(n, h), 0.0);
166
- let vdoth = max(dot(v, h), 0.0);
150
+ // 原理化BSDF (EEVEE port): metallic=0, specular=0.5, roughness=0.5, specular_tint=0.
151
+ let NL = max(dot(n, l), 0.0);
152
+ let NV = max(dot(n, v), 1e-4);
167
153
 
168
- let a2 = ROUGHNESS * ROUGHNESS;
169
- let D = ggx_d(ndoth, a2);
170
- let G = smith_g1(ndotl, a2) * smith_g1(ndotv, a2);
171
- let F = fresnel_schlick(vdoth, F0_DIELECTRIC);
172
- let spec = (D * G * F) / max(4.0 * ndotl * ndotv, 0.001);
154
+ let f0 = vec3f(0.08 * DEFAULT_SPECULAR);
155
+ let f90 = mix(f0, vec3f(1.0), sqrt(DEFAULT_SPECULAR));
156
+ let brdf_lut = brdf_lut_sample(NV, ROUGHNESS);
157
+ let reflection_color = F_brdf_multi_scatter(f0, f90, brdf_lut.xy);
173
158
 
174
- let shadow = sampleShadow(input.worldPos, n);
175
- let kd = (1.0 - F) * albedo / PI;
176
- let direct = (kd + spec) * sunColor * ndotl * shadow;
177
- let ambient = albedo * light.ambientColor.xyz;
159
+ let spec_direct = bsdf_ggx(n, l, v, NL, NV, ROUGHNESS) * sun * shadow * ltc_brdf_scale_from_lut(brdf_lut);
160
+ let spec_indirect = amb;
161
+ let spec_radiance = (spec_direct + spec_indirect) * reflection_color;
162
+
163
+ let diffuse_radiance = albedo * (sun * NL * shadow / PI + amb);
178
164
 
179
165
  var out: FSOut;
180
- out.color = vec4f(ambient + direct, alpha);
166
+ out.color = vec4f(diffuse_radiance + spec_radiance, alpha);
181
167
  out.mask = 1.0;
182
168
  return out;
183
169
  }
@@ -1,3 +1,3 @@
1
1
  export declare const BRDF_LUT_SIZE = 64;
2
- export declare const BRDF_LUT_BAKE_WGSL = "\nconst LUT_SIZE: f32 = 64.0;\nconst SAMPLE_COUNT: u32 = 32u;\nconst M_2PI: f32 = 6.283185307179586;\n\n// Temp LTC magnitude source (rg16float, uploaded from eevee_lut.c ltc_mag_ggx).\n// Sampled 1:1 by pixel \u2014 bake coord mapping matches runtime sample coord mapping.\n@group(0) @binding(0) var ltcSrc: texture_2d<f32>;\n\n@vertex fn vs(@builtin(vertex_index) vid: u32) -> @builtin(position) vec4f {\n let x = f32((vid << 1u) & 2u) * 2.0 - 1.0;\n let y = f32(vid & 2u) * 2.0 - 1.0;\n return vec4f(x, y, 0.0, 1.0);\n}\n\nfn orthonormal_basis(N: vec3f) -> mat2x3f {\n let up = select(vec3f(1.0, 0.0, 0.0), vec3f(0.0, 0.0, 1.0), abs(N.z) < 0.99999);\n let T = normalize(cross(up, N));\n let B = cross(N, T);\n return mat2x3f(T, B);\n}\n\nfn sample_ggx_vndf(rand: vec3f, alpha: f32, Vt: vec3f) -> vec3f {\n let Vh = normalize(vec3f(alpha * Vt.xy, Vt.z));\n let tb = orthonormal_basis(Vh);\n let Th = tb[0];\n let Bh = tb[1];\n let r = sqrt(rand.x);\n let x = r * rand.y;\n var y = r * rand.z;\n let s = 0.5 * (1.0 + Vh.z);\n y = (1.0 - s) * sqrt(1.0 - x * x) + s * y;\n let z = sqrt(saturate(1.0 - x * x - y * y));\n let Hh = x * Th + y * Bh + z * Vh;\n return normalize(vec3f(alpha * Hh.xy, saturate(Hh.z)));\n}\n\nfn G1_Smith_GGX_opti(NX: f32, a2: f32) -> f32 {\n return NX + sqrt(NX * (NX - NX * a2) + a2);\n}\n\nfn F_eta(eta: f32, cos_theta: f32) -> f32 {\n let c = abs(cos_theta);\n var g = eta * eta - 1.0 + c * c;\n if (g > 0.0) {\n g = sqrt(g);\n let A = (g - c) / (g + c);\n let B = (c * (g + c) - 1.0) / (c * (g - c) + 1.0);\n return 0.5 * A * A * (1.0 + B * B);\n }\n return 1.0;\n}\n\nfn f0_from_ior(eta: f32) -> f32 {\n let A = (eta - 1.0) / (eta + 1.0);\n return A * A;\n}\n\nfn F_color_blend_zero(eta: f32, fresnel: f32) -> f32 {\n let f0 = f0_from_ior(eta);\n return saturate((fresnel - f0) / (1.0 - f0));\n}\n\n@fragment fn fs(@builtin(position) frag: vec4f) -> @location(0) vec4f {\n let y_uv = floor(frag.y) / (LUT_SIZE - 1.0);\n let x_uv = floor(frag.x) / (LUT_SIZE - 1.0);\n\n let NV = clamp(1.0 - y_uv * y_uv, 1e-4, 0.9999);\n let a = x_uv * x_uv;\n let a2 = clamp(a * a, 1e-4, 0.9999);\n\n let V = vec3f(sqrt(1.0 - NV * NV), 0.0, NV);\n\n let eta = (2.0 / (1.0 - sqrt(0.08 * 1.0))) - 1.0;\n\n var brdf_accum = 0.0;\n var fresnel_accum = 0.0;\n let sc_f = f32(SAMPLE_COUNT);\n for (var j: u32 = 0u; j < SAMPLE_COUNT; j = j + 1u) {\n for (var i: u32 = 0u; i < SAMPLE_COUNT; i = i + 1u) {\n let ix = (f32(i) + 0.5) / sc_f;\n let iy = (f32(j) + 0.5) / sc_f;\n let Xi = vec3f(ix, cos(iy * M_2PI), sin(iy * M_2PI));\n\n let H = sample_ggx_vndf(Xi, a, V);\n let L = -reflect(V, H);\n let NL = L.z;\n if (NL > 0.0) {\n let NH = max(H.z, 0.0);\n let VH = max(dot(V, H), 0.0);\n\n let G1v = G1_Smith_GGX_opti(NV, a2);\n let G1l = G1_Smith_GGX_opti(NL, a2);\n let G_smith = 4.0 * NV * NL / (G1v * G1l);\n\n let brdf = (G_smith * VH) / (NH * NV);\n\n let fresnel = F_eta(eta, VH);\n let Fc = F_color_blend_zero(eta, fresnel);\n\n brdf_accum = brdf_accum + (1.0 - Fc) * brdf;\n fresnel_accum = fresnel_accum + Fc * brdf;\n }\n }\n }\n let n2 = sc_f * sc_f;\n let dfg = vec2f(brdf_accum / n2, fresnel_accum / n2);\n // Pack preloaded LTC magnitude at matching (roughness, sqrt(1-NV)) pixel.\n let ltc = textureLoad(ltcSrc, vec2i(i32(frag.x), i32(frag.y)), 0).rg;\n return vec4f(dfg, ltc);\n}\n";
2
+ export declare const BRDF_LUT_BAKE_WGSL = "\nconst LUT_SIZE: f32 = 64.0;\nconst SAMPLE_COUNT: u32 = 32u;\nconst M_2PI: f32 = 6.283185307179586;\n\n// Temp LTC magnitude source (rg16float, uploaded from eevee_lut.c ltc_mag_ggx).\n// Sampled 1:1 by pixel \u2014 bake coord mapping matches runtime sample coord mapping.\n@group(0) @binding(0) var ltcSrc: texture_2d<f32>;\n\n@vertex fn vs(@builtin(vertex_index) vid: u32) -> @builtin(position) vec4f {\n let x = f32((vid << 1u) & 2u) * 2.0 - 1.0;\n let y = f32(vid & 2u) * 2.0 - 1.0;\n return vec4f(x, y, 0.0, 1.0);\n}\n\nfn orthonormal_basis(N: vec3f) -> mat2x3f {\n let up = select(vec3f(1.0, 0.0, 0.0), vec3f(0.0, 0.0, 1.0), abs(N.z) < 0.99999);\n let T = normalize(cross(up, N));\n let B = cross(N, T);\n return mat2x3f(T, B);\n}\n\nfn sample_ggx_vndf(rand: vec3f, alpha: f32, Vt: vec3f) -> vec3f {\n let Vh = normalize(vec3f(alpha * Vt.xy, Vt.z));\n let tb = orthonormal_basis(Vh);\n let Th = tb[0];\n let Bh = tb[1];\n let r = sqrt(rand.x);\n let x = r * rand.y;\n var y = r * rand.z;\n let s = 0.5 * (1.0 + Vh.z);\n y = (1.0 - s) * sqrt(1.0 - x * x) + s * y;\n let z = sqrt(saturate(1.0 - x * x - y * y));\n let Hh = x * Th + y * Bh + z * Vh;\n return normalize(vec3f(alpha * Hh.xy, saturate(Hh.z)));\n}\n\nfn G1_Smith_GGX_opti(NX: f32, a2: f32) -> f32 {\n return NX + sqrt(NX * (NX - NX * a2) + a2);\n}\n\nfn F_eta(eta: f32, cos_theta: f32) -> f32 {\n let c = abs(cos_theta);\n var g = eta * eta - 1.0 + c * c;\n if (g > 0.0) {\n g = sqrt(g);\n let A = (g - c) / (g + c);\n let B = (c * (g + c) - 1.0) / (c * (g - c) + 1.0);\n return 0.5 * A * A * (1.0 + B * B);\n }\n return 1.0;\n}\n\nfn f0_from_ior(eta: f32) -> f32 {\n let A = (eta - 1.0) / (eta + 1.0);\n return A * A;\n}\n\nfn F_color_blend_zero(eta: f32, fresnel: f32) -> f32 {\n let f0 = f0_from_ior(eta);\n return saturate((fresnel - f0) / (1.0 - f0));\n}\n\n@fragment fn fs(@builtin(position) frag: vec4f) -> @location(0) vec4f {\n let y_uv = floor(frag.y) / (LUT_SIZE - 1.0);\n let x_uv = floor(frag.x) / (LUT_SIZE - 1.0);\n\n let NV = clamp(1.0 - y_uv * y_uv, 1e-4, 0.9999);\n let a = max(x_uv, 1e-4);\n let a2 = clamp(a * a, 1e-4, 0.9999);\n\n let V = vec3f(sqrt(1.0 - NV * NV), 0.0, NV);\n\n let eta = (2.0 / (1.0 - sqrt(0.08 * 1.0))) - 1.0;\n\n var brdf_accum = 0.0;\n var fresnel_accum = 0.0;\n let sc_f = f32(SAMPLE_COUNT);\n for (var j: u32 = 0u; j < SAMPLE_COUNT; j = j + 1u) {\n for (var i: u32 = 0u; i < SAMPLE_COUNT; i = i + 1u) {\n let ix = (f32(i) + 0.5) / sc_f;\n let iy = (f32(j) + 0.5) / sc_f;\n let Xi = vec3f(ix, cos(iy * M_2PI), sin(iy * M_2PI));\n\n let H = sample_ggx_vndf(Xi, a, V);\n let L = -reflect(V, H);\n let NL = L.z;\n if (NL > 0.0) {\n let NH = max(H.z, 0.0);\n let VH = max(dot(V, H), 0.0);\n\n let G1v = G1_Smith_GGX_opti(NV, a2);\n let G1l = G1_Smith_GGX_opti(NL, a2);\n let G_smith = 4.0 * NV * NL / (G1v * G1l);\n\n let brdf = (G_smith * VH) / (NH * NV);\n\n let fresnel = F_eta(eta, VH);\n let Fc = F_color_blend_zero(eta, fresnel);\n\n brdf_accum = brdf_accum + (1.0 - Fc) * brdf;\n fresnel_accum = fresnel_accum + Fc * brdf;\n }\n }\n }\n let n2 = sc_f * sc_f;\n let dfg = vec2f(brdf_accum / n2, fresnel_accum / n2);\n // Pack preloaded LTC magnitude at matching (roughness, sqrt(1-NV)) pixel.\n let ltc = textureLoad(ltcSrc, vec2i(i32(frag.x), i32(frag.y)), 0).rg;\n return vec4f(dfg, ltc);\n}\n";
3
3
  //# sourceMappingURL=dfg_lut.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"dfg_lut.d.ts","sourceRoot":"","sources":["../../src/shaders/dfg_lut.ts"],"names":[],"mappings":"AAgBA,eAAO,MAAM,aAAa,KAAK,CAAA;AAG/B,eAAO,MAAM,kBAAkB,25GA+G9B,CAAA"}
1
+ {"version":3,"file":"dfg_lut.d.ts","sourceRoot":"","sources":["../../src/shaders/dfg_lut.ts"],"names":[],"mappings":"AAgBA,eAAO,MAAM,aAAa,KAAK,CAAA;AAG/B,eAAO,MAAM,kBAAkB,+5GA+G9B,CAAA"}
@@ -83,7 +83,7 @@ fn F_color_blend_zero(eta: f32, fresnel: f32) -> f32 {
83
83
  let x_uv = floor(frag.x) / (LUT_SIZE - 1.0);
84
84
 
85
85
  let NV = clamp(1.0 - y_uv * y_uv, 1e-4, 0.9999);
86
- let a = x_uv * x_uv;
86
+ let a = max(x_uv, 1e-4);
87
87
  let a2 = clamp(a * a, 1e-4, 0.9999);
88
88
 
89
89
  let V = vec3f(sqrt(1.0 - NV * NV), 0.0, NV);
@@ -1,2 +1,2 @@
1
- export declare const EYE_SHADER_WGSL = "\n\nconst PI: f32 = 3.141592653589793;\nconst F0_DIELECTRIC: f32 = 0.04;\nconst ROUGHNESS: f32 = 0.5;\nconst EYE_EMISSION_STRENGTH: f32 = 1.5;\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 ggx_d(ndoth: f32, a2: f32) -> f32 {\n let denom = ndoth * ndoth * (a2 - 1.0) + 1.0;\n return a2 / (PI * denom * denom);\n}\n\nfn smith_g1(ndotx: f32, a2: f32) -> f32 {\n return 2.0 * ndotx / (ndotx + sqrt(a2 + (1.0 - a2) * ndotx * ndotx));\n}\n\nfn fresnel_schlick(cosTheta: f32, f0: f32) -> f32 {\n let m = 1.0 - cosTheta;\n let m2 = m * m;\n return f0 + (1.0 - f0) * (m2 * m2 * m);\n}\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\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 albedo = textureSample(diffuseTexture, diffuseSampler, input.uv).rgb;\n\n let l = -light.lights[0].direction.xyz;\n let sunColor = light.lights[0].color.xyz * light.lights[0].color.w;\n let h = normalize(l + v);\n\n let ndotl = max(dot(n, l), 0.0);\n let ndotv = max(dot(n, v), 0.001);\n let ndoth = max(dot(n, h), 0.0);\n let vdoth = max(dot(v, h), 0.0);\n\n let a2 = ROUGHNESS * ROUGHNESS;\n let D = ggx_d(ndoth, a2);\n let G = smith_g1(ndotl, a2) * smith_g1(ndotv, a2);\n let F = fresnel_schlick(vdoth, F0_DIELECTRIC);\n let spec = (D * G * F) / max(4.0 * ndotl * ndotv, 0.001);\n\n let shadow = sampleShadow(input.worldPos, n);\n let kd = (1.0 - F) * albedo / PI;\n let direct = (kd + spec) * sunColor * ndotl * shadow;\n let ambient = albedo * light.ambientColor.xyz;\n\n // Principled Emission socket: emissive = emission_color \u00D7 strength, added on top of shading.\n let emission = albedo * EYE_EMISSION_STRENGTH;\n\n var out: FSOut;\n out.color = vec4f(ambient + direct + emission, alpha);\n out.mask = 1.0;\n return out;\n}\n\n";
1
+ export declare const EYE_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 AMBIENT_OCCLUSION node (faked) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\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// Real SSAO is a non-goal. We approximate: use the \"inside\" value from\n// concavity heuristic: 1.0 = fully lit, lower = occluded.\n// For now returns 1.0 (no darkening). Individual presets can override.\n\nfn ao_fake(n: vec3f, v: vec3f) -> f32 {\n return 1.0;\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 (distance only) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\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 Metal preset. Simplified F1 cell noise.\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// \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\nconst PI_E: f32 = 3.141592653589793;\nconst EYE_SPECULAR: f32 = 0.5;\nconst EYE_ROUGHNESS: f32 = 0.5;\nconst EYE_EMISSION_STRENGTH: f32 = 1.5;\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\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 albedo = textureSample(diffuseTexture, diffuseSampler, input.uv).rgb;\n\n let l = -light.lights[0].direction.xyz;\n let sun = light.lights[0].color.xyz * light.lights[0].color.w;\n let amb = light.ambientColor.xyz;\n let shadow = sampleShadow(input.worldPos, n);\n\n // \u539F\u7406\u5316BSDF (EEVEE port): metallic=0, specular=0.5, roughness=0.5, specular_tint=0.\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 * EYE_SPECULAR);\n let f90 = mix(f0, vec3f(1.0), sqrt(EYE_SPECULAR));\n let brdf_lut = brdf_lut_sample(NV, EYE_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, EYE_ROUGHNESS) * sun * shadow * ltc_brdf_scale_from_lut(brdf_lut);\n let spec_indirect = amb;\n let spec_radiance = (spec_direct + spec_indirect) * reflection_color;\n\n let diffuse_radiance = albedo * (sun * NL * shadow / PI_E + amb);\n // Principled Emission socket: emissive = emission_color \u00D7 strength, added on top of shading.\n let emission = albedo * EYE_EMISSION_STRENGTH;\n\n var out: FSOut;\n out.color = vec4f(diffuse_radiance + spec_radiance + emission, alpha);\n out.mask = 1.0;\n return out;\n}\n\n";
2
2
  //# sourceMappingURL=eye.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"eye.d.ts","sourceRoot":"","sources":["../../src/shaders/eye.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,eAAe,o5KA2J3B,CAAA"}
1
+ {"version":3,"file":"eye.d.ts","sourceRoot":"","sources":["../../src/shaders/eye.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,eAAe,qz2BA6I3B,CAAA"}
@@ -1,11 +1,14 @@
1
- // Eye preset — default Principled BSDF (F0=0.04, Roughness=0.5) + Emission socket set to albedo × 1.5.
1
+ // Eye preset — default Principled BSDF (Specular=0.5, Roughness=0.5) + Emission socket set to albedo × 1.5.
2
2
  // Matches the published preset's instruction: "keep eyes in the default nodegraph, add emission 1.5".
3
3
  // Blender's Principled BSDF Emission socket is added on top of the shaded output (pre-tonemap, feeds bloom).
4
+ import { NODES_WGSL } from "./nodes";
4
5
  export const EYE_SHADER_WGSL = /* wgsl */ `
5
6
 
6
- const PI: f32 = 3.141592653589793;
7
- const F0_DIELECTRIC: f32 = 0.04;
8
- const ROUGHNESS: f32 = 0.5;
7
+ ${NODES_WGSL}
8
+
9
+ const PI_E: f32 = 3.141592653589793;
10
+ const EYE_SPECULAR: f32 = 0.5;
11
+ const EYE_ROUGHNESS: f32 = 0.5;
9
12
  const EYE_EMISSION_STRENGTH: f32 = 1.5;
10
13
 
11
14
  struct CameraUniforms {
@@ -49,21 +52,6 @@ struct LightVP { viewProj: mat4x4f, };
49
52
  @group(2) @binding(0) var diffuseTexture: texture_2d<f32>;
50
53
  @group(2) @binding(1) var<uniform> material: MaterialUniforms;
51
54
 
52
- fn ggx_d(ndoth: f32, a2: f32) -> f32 {
53
- let denom = ndoth * ndoth * (a2 - 1.0) + 1.0;
54
- return a2 / (PI * denom * denom);
55
- }
56
-
57
- fn smith_g1(ndotx: f32, a2: f32) -> f32 {
58
- return 2.0 * ndotx / (ndotx + sqrt(a2 + (1.0 - a2) * ndotx * ndotx));
59
- }
60
-
61
- fn fresnel_schlick(cosTheta: f32, f0: f32) -> f32 {
62
- let m = 1.0 - cosTheta;
63
- let m2 = m * m;
64
- return f0 + (1.0 - f0) * (m2 * m2 * m);
65
- }
66
-
67
55
  fn sampleShadow(worldPos: vec3f, n: vec3f) -> f32 {
68
56
  // Back-facing to key light: direct contribution is zero anyway, skip 9 texture samples.
69
57
  if (dot(n, -light.lights[0].direction.xyz) <= 0.0) { return 0.0; }
@@ -128,30 +116,29 @@ struct FSOut {
128
116
  let albedo = textureSample(diffuseTexture, diffuseSampler, input.uv).rgb;
129
117
 
130
118
  let l = -light.lights[0].direction.xyz;
131
- let sunColor = light.lights[0].color.xyz * light.lights[0].color.w;
132
- let h = normalize(l + v);
119
+ let sun = light.lights[0].color.xyz * light.lights[0].color.w;
120
+ let amb = light.ambientColor.xyz;
121
+ let shadow = sampleShadow(input.worldPos, n);
133
122
 
134
- let ndotl = max(dot(n, l), 0.0);
135
- let ndotv = max(dot(n, v), 0.001);
136
- let ndoth = max(dot(n, h), 0.0);
137
- let vdoth = max(dot(v, h), 0.0);
123
+ // 原理化BSDF (EEVEE port): metallic=0, specular=0.5, roughness=0.5, specular_tint=0.
124
+ let NL = max(dot(n, l), 0.0);
125
+ let NV = max(dot(n, v), 1e-4);
138
126
 
139
- let a2 = ROUGHNESS * ROUGHNESS;
140
- let D = ggx_d(ndoth, a2);
141
- let G = smith_g1(ndotl, a2) * smith_g1(ndotv, a2);
142
- let F = fresnel_schlick(vdoth, F0_DIELECTRIC);
143
- let spec = (D * G * F) / max(4.0 * ndotl * ndotv, 0.001);
127
+ let f0 = vec3f(0.08 * EYE_SPECULAR);
128
+ let f90 = mix(f0, vec3f(1.0), sqrt(EYE_SPECULAR));
129
+ let brdf_lut = brdf_lut_sample(NV, EYE_ROUGHNESS);
130
+ let reflection_color = F_brdf_multi_scatter(f0, f90, brdf_lut.xy);
144
131
 
145
- let shadow = sampleShadow(input.worldPos, n);
146
- let kd = (1.0 - F) * albedo / PI;
147
- let direct = (kd + spec) * sunColor * ndotl * shadow;
148
- let ambient = albedo * light.ambientColor.xyz;
132
+ let spec_direct = bsdf_ggx(n, l, v, NL, NV, EYE_ROUGHNESS) * sun * shadow * ltc_brdf_scale_from_lut(brdf_lut);
133
+ let spec_indirect = amb;
134
+ let spec_radiance = (spec_direct + spec_indirect) * reflection_color;
149
135
 
136
+ let diffuse_radiance = albedo * (sun * NL * shadow / PI_E + amb);
150
137
  // Principled Emission socket: emissive = emission_color × strength, added on top of shading.
151
138
  let emission = albedo * EYE_EMISSION_STRENGTH;
152
139
 
153
140
  var out: FSOut;
154
- out.color = vec4f(ambient + direct + emission, alpha);
141
+ out.color = vec4f(diffuse_radiance + spec_radiance + emission, alpha);
155
142
  out.mask = 1.0;
156
143
  return out;
157
144
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reze-engine",
3
- "version": "0.11.1",
3
+ "version": "0.11.2",
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",
@@ -43,4 +43,4 @@
43
43
  "@types/node": "^20",
44
44
  "typescript": "^5"
45
45
  }
46
- }
46
+ }
package/src/engine.ts CHANGED
@@ -84,15 +84,17 @@ export const DEFAULT_BLOOM_OPTIONS: BloomOptions = {
84
84
 
85
85
  /** Blender Color Management / View (rendering.txt: Filmic, exposure, gamma). `look` is reserved for future curve tweaks. */
86
86
  export type ViewTransformOptions = {
87
- /** Stops applied before Filmic: `linear *= 2^exposure` (Blender default often ~−0.3). */
87
+ /** Stops applied before Filmic: `linear *= 2^exposure`. */
88
88
  exposure: number
89
89
  /** After Filmic, display gamma (`pow(rgb, 1/gamma)`). */
90
90
  gamma: number
91
91
  look: "default" | "medium_high_contrast"
92
92
  }
93
93
 
94
+ // Matches the reference Blender project: Filmic view, Medium High Contrast look,
95
+ // exposure 0.3, gamma 1.0, sRGB display, no curves.
94
96
  export const DEFAULT_VIEW_TRANSFORM: ViewTransformOptions = {
95
- exposure: -0.30000001192092896,
97
+ exposure: 0.6,
96
98
  gamma: 1.0,
97
99
  look: "medium_high_contrast",
98
100
  }
@@ -435,9 +437,12 @@ export class Engine {
435
437
  private writeBloomUniforms(): void {
436
438
  const b = this.bloomSettings
437
439
  const bu = this.bloomBlitUniformData
438
- // EEVEE prefilter: threshold, knee, clamp (0 → disabled), _unused
440
+ // EEVEE prefilter: threshold, knee_half, clamp (0 → disabled), _unused
441
+ // Blender halves the knee before passing to the shader (eevee_bloom.c: knee * 0.5f).
442
+ // The blit shader's quadratic soft-knee curve uses knee_half as the offset from threshold,
443
+ // so the soft ramp spans [threshold - knee/2 .. threshold + knee/2] — NOT [threshold - knee .. threshold + knee].
439
444
  bu[0] = b.threshold
440
- bu[1] = b.knee
445
+ bu[1] = b.knee * 0.5
441
446
  bu[2] = b.clamp
442
447
  bu[3] = 0.0
443
448
  this.device.queue.writeBuffer(this.bloomBlitUniformBuffer, 0, bu)
@@ -520,7 +525,7 @@ export class Engine {
520
525
  { texture: ltcTemp },
521
526
  half,
522
527
  { bytesPerRow: LTC_MAG_LUT_SIZE * 4, rowsPerImage: LTC_MAG_LUT_SIZE },
523
- { width: LTC_MAG_LUT_SIZE, height: LTC_MAG_LUT_SIZE, depthOrArrayLayers: 1 }
528
+ { width: LTC_MAG_LUT_SIZE, height: LTC_MAG_LUT_SIZE, depthOrArrayLayers: 1 },
524
529
  )
525
530
 
526
531
  this.brdfLutTexture = this.device.createTexture({
@@ -1373,7 +1378,9 @@ export class Engine {
1373
1378
  })
1374
1379
 
1375
1380
  const bloomBlitLayout = this.device.createPipelineLayout({ bindGroupLayouts: [this.bloomBlitBindGroupLayout] })
1376
- const bloomDownLayout = this.device.createPipelineLayout({ bindGroupLayouts: [this.bloomDownsampleBindGroupLayout] })
1381
+ const bloomDownLayout = this.device.createPipelineLayout({
1382
+ bindGroupLayouts: [this.bloomDownsampleBindGroupLayout],
1383
+ })
1377
1384
  const bloomUpLayout = this.device.createPipelineLayout({ bindGroupLayouts: [this.bloomUpsampleBindGroupLayout] })
1378
1385
 
1379
1386
  this.bloomBlitPipeline = this.device.createRenderPipeline({
@@ -1426,9 +1433,14 @@ export class Engine {
1426
1433
  // viewU[0] = (exposure, gamma, _, _); viewU[1] = (tint.rgb, intensity)
1427
1434
 
1428
1435
  fn filmic(x: f32) -> f32 {
1436
+ // Re-fit against Blender 3.6 Filmic MHC anchors (sobotka/filmic-blender
1437
+ // look_medium-high-contrast.spi1d). Previous curve was compressed:
1438
+ // midtones too bright, highlights too dim — flattened contrast, read
1439
+ // as "washed-out" on saturated surfaces (hair especially).
1440
+ // Reference checkpoints: linear 0.18 → ~0.395, linear 1.0 → ~0.83.
1429
1441
  var lut = array<f32, 14>(
1430
- 0.0067, 0.0141, 0.0272, 0.0499, 0.0885, 0.1512, 0.2462,
1431
- 0.3753, 0.5273, 0.6776, 0.8031, 0.8929, 0.9495, 0.9814
1442
+ 0.0028, 0.0068, 0.0151, 0.0313, 0.0610, 0.1120, 0.1920,
1443
+ 0.3060, 0.4590, 0.6310, 0.8200, 0.9070, 0.9620, 0.9890
1432
1444
  );
1433
1445
  let t = clamp(log2(max(x, 1e-10)) + 10.0, 0.0, 13.0);
1434
1446
  let i = u32(t);
@@ -1449,7 +1461,8 @@ export class Engine {
1449
1461
  let fullSz = vec2f(textureDimensions(hdrTex));
1450
1462
  let bloomSz = vec2f(textureDimensions(bloomTex));
1451
1463
  // Bloom is at half-res (pyramid mip 0). Sampler interpolates back to full-res UVs.
1452
- let bloomUv = (fragCoord.xy + vec2f(0.5)) / max(fullSz, vec2f(1.0));
1464
+ // fragCoord.xy is already at pixel center (e.g. 0.5, 0.5 for first pixel).
1465
+ let bloomUv = fragCoord.xy / max(fullSz, vec2f(1.0));
1453
1466
  let tint = viewU[1].xyz;
1454
1467
  let intensity = viewU[1].w;
1455
1468
  let bloom = textureSampleLevel(bloomTex, bloomSamp, bloomUv, 0.0).rgb * tint * intensity;
@@ -1643,10 +1656,7 @@ export class Engine {
1643
1656
  const bw = Math.max(1, Math.floor(width / 2))
1644
1657
  const bh = Math.max(1, Math.floor(height / 2))
1645
1658
  const shortSide = Math.max(1, Math.min(bw, bh))
1646
- this.bloomMipCount = Math.max(
1647
- 1,
1648
- Math.min(Engine.BLOOM_MAX_LEVELS, Math.floor(Math.log2(shortSide)) - 1),
1649
- )
1659
+ this.bloomMipCount = Math.max(1, Math.min(Engine.BLOOM_MAX_LEVELS, Math.floor(Math.log2(shortSide)) - 1))
1650
1660
  this.bloomDownTexture = this.device.createTexture({
1651
1661
  label: "bloom down pyramid",
1652
1662
  size: [bw, bh],
@@ -1663,16 +1673,12 @@ export class Engine {
1663
1673
  })
1664
1674
  this.bloomDownMipViews = []
1665
1675
  for (let i = 0; i < this.bloomMipCount; i++) {
1666
- this.bloomDownMipViews.push(
1667
- this.bloomDownTexture.createView({ baseMipLevel: i, mipLevelCount: 1 }),
1668
- )
1676
+ this.bloomDownMipViews.push(this.bloomDownTexture.createView({ baseMipLevel: i, mipLevelCount: 1 }))
1669
1677
  }
1670
1678
  this.bloomUpMipViews = []
1671
1679
  const upLevels = Math.max(1, this.bloomMipCount - 1)
1672
1680
  for (let i = 0; i < upLevels; i++) {
1673
- this.bloomUpMipViews.push(
1674
- this.bloomUpTexture.createView({ baseMipLevel: i, mipLevelCount: 1 }),
1675
- )
1681
+ this.bloomUpMipViews.push(this.bloomUpTexture.createView({ baseMipLevel: i, mipLevelCount: 1 }))
1676
1682
  }
1677
1683
 
1678
1684
  this.depthTexture = this.device.createTexture({
@@ -2665,7 +2671,9 @@ export class Engine {
2665
2671
  ],
2666
2672
  })
2667
2673
  const pass = encoder.beginRenderPass({
2668
- colorAttachments: [{ view: dstView, clearValue: { r: 0, g: 0, b: 0, a: 0 }, loadOp: "clear", storeOp: "store" }],
2674
+ colorAttachments: [
2675
+ { view: dstView, clearValue: { r: 0, g: 0, b: 0, a: 0 }, loadOp: "clear", storeOp: "store" },
2676
+ ],
2669
2677
  })
2670
2678
  pass.setPipeline(this.mipBlitPipeline)
2671
2679
  pass.setBindGroup(0, bindGroup)
@@ -70,32 +70,17 @@ fn sampleShadow(worldPos: vec3f, n: vec3f) -> f32 {
70
70
  }
71
71
 
72
72
  const PI_B: f32 = 3.141592653589793;
73
- const F0_BODY: f32 = 0.04;
74
73
  const BODY_ROUGHNESS: f32 = 0.3;
75
74
  // Dump: 层权重.002 Blend; 运算.007 POWER exponent Value_001; 背景 Color; 运算.004 after invert
76
75
  const BODY_RIM2_LAYER_BLEND: f32 = 0.20000000298023224;
77
76
  const BODY_RIM2_POW: f32 = 1.4300000667572021;
78
77
  const BODY_RIM2_BG: vec3f = vec3f(1.0, 0.4303792119026184, 0.3315804898738861);
79
78
  const BODY_WARM_AO_MUL: f32 = 0.30000001192092896;
79
+ const BODY_SPECULAR: f32 = 0.5;
80
80
  const BODY_MIX_NPR: f32 = 0.5;
81
81
  // EEVEE Light Clamp equivalent — caps firefly specular from noise-bumped NDF aliasing.
82
82
  const BODY_SPEC_CLAMP: f32 = 10.0;
83
83
 
84
- fn ggx_d_body(ndoth: f32, a2: f32) -> f32 {
85
- let denom = ndoth * ndoth * (a2 - 1.0) + 1.0;
86
- return a2 / (PI_B * denom * denom);
87
- }
88
-
89
- fn smith_g1_body(ndotx: f32, a2: f32) -> f32 {
90
- return 2.0 * ndotx / (ndotx + sqrt(a2 + (1.0 - a2) * ndotx * ndotx));
91
- }
92
-
93
- fn fresnel_schlick_body(cosTheta: f32, f0: f32) -> f32 {
94
- let m = 1.0 - cosTheta;
95
- let m2 = m * m;
96
- return f0 + (1.0 - f0) * (m2 * m2 * m);
97
- }
98
-
99
84
  // smoothstep-based ramp: t*t*(3-2*t) between two color stops
100
85
  fn ramp_ease(f: f32, p0: f32, c0: vec4f, p1: f32, c1: vec4f) -> vec4f {
101
86
  let t = saturate((f - p0) / max(p1 - p0, 1e-6));
@@ -201,26 +186,29 @@ struct FSOut {
201
186
  // Reuse 'ao' (ao_fake(n, v) above) — identical inputs, avoid a second procedural AO pass.
202
187
  let sss = ramp_linear(ao, 0.003, vec4f(0,0,0,1), 1.0, vec4f(0.0786, 0.0786, 0.0786, 1.0)).r;
203
188
 
204
- let p_ndotl = max(dot(bumped_n, l), 0.0);
205
- let p_ndotv = max(dot(bumped_n, v), 0.001);
206
- let h = normalize(l + v);
207
- let p_ndoth = max(dot(bumped_n, h), 0.0);
208
- let p_vdoth = max(dot(v, h), 0.0);
209
- let a2 = BODY_ROUGHNESS * BODY_ROUGHNESS;
210
- let D = ggx_d_body(p_ndoth, a2);
211
- let G = smith_g1_body(p_ndotl, a2) * smith_g1_body(p_ndotv, a2);
212
- let F = fresnel_schlick_body(p_vdoth, F0_BODY);
213
- let brdf_lut = brdf_lut_sample(p_ndotv, BODY_ROUGHNESS);
214
- let spec = (D * G * F) / max(4.0 * p_ndotl * p_ndotv, 0.001) * ltc_brdf_scale_from_lut(brdf_lut);
215
- let kd = (1.0 - F) * principled_base / PI_B;
216
- // Split so we can clamp only the spec firefly contribution (EEVEE Light Clamp).
217
- let spec_radiance = vec3f(spec) * sun * p_ndotl * shadow;
218
- let spec_clamped = min(spec_radiance, vec3f(BODY_SPEC_CLAMP));
219
- let direct = kd * sun * p_ndotl * shadow + spec_clamped;
189
+ // 原理化BSDF (EEVEE port): metallic=0, specular=0.5, roughness=0.3, specular_tint=0.
190
+ let NL = max(dot(bumped_n, l), 0.0);
191
+ let NV = max(dot(bumped_n, v), 1e-4);
192
+
193
+ // f0/f90 per gpu_shader_material_principled.glsl specular_tint=0 → dielectric_f0_color=white.
194
+ let f0 = vec3f(0.08 * BODY_SPECULAR);
195
+ let f90 = mix(f0, vec3f(1.0), sqrt(BODY_SPECULAR));
196
+ let brdf_lut = brdf_lut_sample(NV, BODY_ROUGHNESS);
197
+ let reflection_color = F_brdf_multi_scatter(f0, f90, brdf_lut.xy);
198
+
199
+ // Direct glossy bsdf_ggx already includes NL; no F applied here (tinted after accum).
200
+ // ltc_brdf_scale: EEVEE direct path uses LTC; split-sum LUT path is rescaled to match.
201
+ let spec_direct_raw = bsdf_ggx(bumped_n, l, v, NL, NV, BODY_ROUGHNESS) * sun * shadow * ltc_brdf_scale_from_lut(brdf_lut);
202
+ let spec_direct = min(spec_direct_raw, vec3f(BODY_SPEC_CLAMP));
203
+ // Indirect glossy — flat world probe (solid color). Phase 2 adds cubemap.
204
+ let spec_indirect = light.ambientColor.xyz;
205
+ let spec_radiance = (spec_direct + spec_indirect) * reflection_color;
206
+
220
207
  // Indirect diffuse = base_color × L_w per Blender closure_eval_surface_lib.glsl line 302;
221
208
  // probe_evaluate_world_diff returns radiance (SH-projected, not cosine-convolved).
222
- let ambient = principled_base * light.ambientColor.xyz;
223
- let principled = ambient + direct + p_emission + vec3f(sss);
209
+ // No (1-F) factor per EEVEE — it doesn't energy-conserve spec<->diffuse.
210
+ let diffuse_radiance = principled_base * (sun * NL * shadow / PI_B + light.ambientColor.xyz);
211
+ let principled = diffuse_radiance + spec_radiance + p_emission + vec3f(sss);
224
212
 
225
213
  // 混合着色器.001: Shader=相加着色器.001, Shader_001=原理化BSDF
226
214
  let final_color = mix(npr_stack, principled, BODY_MIX_NPR);
@@ -2,10 +2,14 @@
2
2
  // Metallic=0, Specular=0.5 (F0=0.04), Roughness=0.5.
3
3
  // Tone mapping via LUT sampled from Blender's OCIO pipeline (exposure -0.3 baked in).
4
4
 
5
+ import { NODES_WGSL } from "./nodes"
6
+
5
7
  export const DEFAULT_SHADER_WGSL = /* wgsl */ `
6
8
 
9
+ ${NODES_WGSL}
10
+
7
11
  const PI: f32 = 3.141592653589793;
8
- const F0_DIELECTRIC: f32 = 0.04;
12
+ const DEFAULT_SPECULAR: f32 = 0.5;
9
13
  const ROUGHNESS: f32 = 0.5;
10
14
 
11
15
  struct CameraUniforms {
@@ -52,23 +56,6 @@ struct LightVP { viewProj: mat4x4f, };
52
56
  @group(2) @binding(0) var diffuseTexture: texture_2d<f32>;
53
57
  @group(2) @binding(1) var<uniform> material: MaterialUniforms;
54
58
 
55
- // ─── GGX specular helpers ───────────────────────────────────────────
56
-
57
- fn ggx_d(ndoth: f32, a2: f32) -> f32 {
58
- let denom = ndoth * ndoth * (a2 - 1.0) + 1.0;
59
- return a2 / (PI * denom * denom);
60
- }
61
-
62
- fn smith_g1(ndotx: f32, a2: f32) -> f32 {
63
- return 2.0 * ndotx / (ndotx + sqrt(a2 + (1.0 - a2) * ndotx * ndotx));
64
- }
65
-
66
- fn fresnel_schlick(cosTheta: f32, f0: f32) -> f32 {
67
- let m = 1.0 - cosTheta;
68
- let m2 = m * m;
69
- return f0 + (1.0 - f0) * (m2 * m2 * m);
70
- }
71
-
72
59
  // ─── Filmic tone mapping (LUT extracted from Blender 3.6 OCIO) ─────
73
60
  // View transform = Filmic, Look = Medium High Contrast, Exposure = -0.3.
74
61
  // 14 samples at integer log2 stops from -10 to +3 (inclusive).
@@ -158,27 +145,27 @@ struct FSOut {
158
145
  let albedo = textureSample(diffuseTexture, diffuseSampler, input.uv).rgb;
159
146
 
160
147
  let l = -light.lights[0].direction.xyz;
161
- let sunColor = light.lights[0].color.xyz * light.lights[0].color.w;
162
- let h = normalize(l + v);
148
+ let sun = light.lights[0].color.xyz * light.lights[0].color.w;
149
+ let amb = light.ambientColor.xyz;
150
+ let shadow = sampleShadow(input.worldPos, n);
163
151
 
164
- let ndotl = max(dot(n, l), 0.0);
165
- let ndotv = max(dot(n, v), 0.001);
166
- let ndoth = max(dot(n, h), 0.0);
167
- let vdoth = max(dot(v, h), 0.0);
152
+ // 原理化BSDF (EEVEE port): metallic=0, specular=0.5, roughness=0.5, specular_tint=0.
153
+ let NL = max(dot(n, l), 0.0);
154
+ let NV = max(dot(n, v), 1e-4);
168
155
 
169
- let a2 = ROUGHNESS * ROUGHNESS;
170
- let D = ggx_d(ndoth, a2);
171
- let G = smith_g1(ndotl, a2) * smith_g1(ndotv, a2);
172
- let F = fresnel_schlick(vdoth, F0_DIELECTRIC);
173
- let spec = (D * G * F) / max(4.0 * ndotl * ndotv, 0.001);
156
+ let f0 = vec3f(0.08 * DEFAULT_SPECULAR);
157
+ let f90 = mix(f0, vec3f(1.0), sqrt(DEFAULT_SPECULAR));
158
+ let brdf_lut = brdf_lut_sample(NV, ROUGHNESS);
159
+ let reflection_color = F_brdf_multi_scatter(f0, f90, brdf_lut.xy);
174
160
 
175
- let shadow = sampleShadow(input.worldPos, n);
176
- let kd = (1.0 - F) * albedo / PI;
177
- let direct = (kd + spec) * sunColor * ndotl * shadow;
178
- let ambient = albedo * light.ambientColor.xyz;
161
+ let spec_direct = bsdf_ggx(n, l, v, NL, NV, ROUGHNESS) * sun * shadow * ltc_brdf_scale_from_lut(brdf_lut);
162
+ let spec_indirect = amb;
163
+ let spec_radiance = (spec_direct + spec_indirect) * reflection_color;
164
+
165
+ let diffuse_radiance = albedo * (sun * NL * shadow / PI + amb);
179
166
 
180
167
  var out: FSOut;
181
- out.color = vec4f(ambient + direct, alpha);
168
+ out.color = vec4f(diffuse_radiance + spec_radiance, alpha);
182
169
  out.mask = 1.0;
183
170
  return out;
184
171
  }
@@ -85,7 +85,7 @@ fn F_color_blend_zero(eta: f32, fresnel: f32) -> f32 {
85
85
  let x_uv = floor(frag.x) / (LUT_SIZE - 1.0);
86
86
 
87
87
  let NV = clamp(1.0 - y_uv * y_uv, 1e-4, 0.9999);
88
- let a = x_uv * x_uv;
88
+ let a = max(x_uv, 1e-4);
89
89
  let a2 = clamp(a * a, 1e-4, 0.9999);
90
90
 
91
91
  let V = vec3f(sqrt(1.0 - NV * NV), 0.0, NV);
@@ -1,12 +1,16 @@
1
- // Eye preset — default Principled BSDF (F0=0.04, Roughness=0.5) + Emission socket set to albedo × 1.5.
1
+ // Eye preset — default Principled BSDF (Specular=0.5, Roughness=0.5) + Emission socket set to albedo × 1.5.
2
2
  // Matches the published preset's instruction: "keep eyes in the default nodegraph, add emission 1.5".
3
3
  // Blender's Principled BSDF Emission socket is added on top of the shaded output (pre-tonemap, feeds bloom).
4
4
 
5
+ import { NODES_WGSL } from "./nodes"
6
+
5
7
  export const EYE_SHADER_WGSL = /* wgsl */ `
6
8
 
7
- const PI: f32 = 3.141592653589793;
8
- const F0_DIELECTRIC: f32 = 0.04;
9
- const ROUGHNESS: f32 = 0.5;
9
+ ${NODES_WGSL}
10
+
11
+ const PI_E: f32 = 3.141592653589793;
12
+ const EYE_SPECULAR: f32 = 0.5;
13
+ const EYE_ROUGHNESS: f32 = 0.5;
10
14
  const EYE_EMISSION_STRENGTH: f32 = 1.5;
11
15
 
12
16
  struct CameraUniforms {
@@ -50,21 +54,6 @@ struct LightVP { viewProj: mat4x4f, };
50
54
  @group(2) @binding(0) var diffuseTexture: texture_2d<f32>;
51
55
  @group(2) @binding(1) var<uniform> material: MaterialUniforms;
52
56
 
53
- fn ggx_d(ndoth: f32, a2: f32) -> f32 {
54
- let denom = ndoth * ndoth * (a2 - 1.0) + 1.0;
55
- return a2 / (PI * denom * denom);
56
- }
57
-
58
- fn smith_g1(ndotx: f32, a2: f32) -> f32 {
59
- return 2.0 * ndotx / (ndotx + sqrt(a2 + (1.0 - a2) * ndotx * ndotx));
60
- }
61
-
62
- fn fresnel_schlick(cosTheta: f32, f0: f32) -> f32 {
63
- let m = 1.0 - cosTheta;
64
- let m2 = m * m;
65
- return f0 + (1.0 - f0) * (m2 * m2 * m);
66
- }
67
-
68
57
  fn sampleShadow(worldPos: vec3f, n: vec3f) -> f32 {
69
58
  // Back-facing to key light: direct contribution is zero anyway, skip 9 texture samples.
70
59
  if (dot(n, -light.lights[0].direction.xyz) <= 0.0) { return 0.0; }
@@ -129,30 +118,29 @@ struct FSOut {
129
118
  let albedo = textureSample(diffuseTexture, diffuseSampler, input.uv).rgb;
130
119
 
131
120
  let l = -light.lights[0].direction.xyz;
132
- let sunColor = light.lights[0].color.xyz * light.lights[0].color.w;
133
- let h = normalize(l + v);
121
+ let sun = light.lights[0].color.xyz * light.lights[0].color.w;
122
+ let amb = light.ambientColor.xyz;
123
+ let shadow = sampleShadow(input.worldPos, n);
134
124
 
135
- let ndotl = max(dot(n, l), 0.0);
136
- let ndotv = max(dot(n, v), 0.001);
137
- let ndoth = max(dot(n, h), 0.0);
138
- let vdoth = max(dot(v, h), 0.0);
125
+ // 原理化BSDF (EEVEE port): metallic=0, specular=0.5, roughness=0.5, specular_tint=0.
126
+ let NL = max(dot(n, l), 0.0);
127
+ let NV = max(dot(n, v), 1e-4);
139
128
 
140
- let a2 = ROUGHNESS * ROUGHNESS;
141
- let D = ggx_d(ndoth, a2);
142
- let G = smith_g1(ndotl, a2) * smith_g1(ndotv, a2);
143
- let F = fresnel_schlick(vdoth, F0_DIELECTRIC);
144
- let spec = (D * G * F) / max(4.0 * ndotl * ndotv, 0.001);
129
+ let f0 = vec3f(0.08 * EYE_SPECULAR);
130
+ let f90 = mix(f0, vec3f(1.0), sqrt(EYE_SPECULAR));
131
+ let brdf_lut = brdf_lut_sample(NV, EYE_ROUGHNESS);
132
+ let reflection_color = F_brdf_multi_scatter(f0, f90, brdf_lut.xy);
145
133
 
146
- let shadow = sampleShadow(input.worldPos, n);
147
- let kd = (1.0 - F) * albedo / PI;
148
- let direct = (kd + spec) * sunColor * ndotl * shadow;
149
- let ambient = albedo * light.ambientColor.xyz;
134
+ let spec_direct = bsdf_ggx(n, l, v, NL, NV, EYE_ROUGHNESS) * sun * shadow * ltc_brdf_scale_from_lut(brdf_lut);
135
+ let spec_indirect = amb;
136
+ let spec_radiance = (spec_direct + spec_indirect) * reflection_color;
150
137
 
138
+ let diffuse_radiance = albedo * (sun * NL * shadow / PI_E + amb);
151
139
  // Principled Emission socket: emissive = emission_color × strength, added on top of shading.
152
140
  let emission = albedo * EYE_EMISSION_STRENGTH;
153
141
 
154
142
  var out: FSOut;
155
- out.color = vec4f(ambient + direct + emission, alpha);
143
+ out.color = vec4f(diffuse_radiance + spec_radiance + emission, alpha);
156
144
  out.mask = 1.0;
157
145
  return out;
158
146
  }