reze-engine 0.10.1 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/README.md +113 -20
  2. package/dist/asset-reader.d.ts +16 -0
  3. package/dist/asset-reader.d.ts.map +1 -0
  4. package/dist/asset-reader.js +74 -0
  5. package/dist/engine.d.ts +179 -36
  6. package/dist/engine.d.ts.map +1 -1
  7. package/dist/engine.js +1133 -321
  8. package/dist/folder-upload.d.ts +24 -0
  9. package/dist/folder-upload.d.ts.map +1 -0
  10. package/dist/folder-upload.js +50 -0
  11. package/dist/index.d.ts +3 -2
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +2 -2
  14. package/dist/model.d.ts +6 -1
  15. package/dist/model.d.ts.map +1 -1
  16. package/dist/model.js +34 -2
  17. package/dist/pmx-loader.d.ts +3 -0
  18. package/dist/pmx-loader.d.ts.map +1 -1
  19. package/dist/pmx-loader.js +9 -2
  20. package/dist/shaders/body.d.ts +2 -0
  21. package/dist/shaders/body.d.ts.map +1 -0
  22. package/dist/shaders/body.js +209 -0
  23. package/dist/shaders/classify.d.ts +4 -0
  24. package/dist/shaders/classify.d.ts.map +1 -0
  25. package/dist/shaders/classify.js +12 -0
  26. package/dist/shaders/cloth_rough.d.ts +2 -0
  27. package/dist/shaders/cloth_rough.d.ts.map +1 -0
  28. package/dist/shaders/cloth_rough.js +172 -0
  29. package/dist/shaders/cloth_smooth.d.ts +2 -0
  30. package/dist/shaders/cloth_smooth.d.ts.map +1 -0
  31. package/dist/shaders/cloth_smooth.js +171 -0
  32. package/dist/shaders/default.d.ts +2 -0
  33. package/dist/shaders/default.d.ts.map +1 -0
  34. package/dist/shaders/default.js +168 -0
  35. package/dist/shaders/dfg_lut.d.ts +4 -0
  36. package/dist/shaders/dfg_lut.d.ts.map +1 -0
  37. package/dist/shaders/dfg_lut.js +125 -0
  38. package/dist/shaders/eye.d.ts +2 -0
  39. package/dist/shaders/eye.d.ts.map +1 -0
  40. package/dist/shaders/eye.js +142 -0
  41. package/dist/shaders/face.d.ts +2 -0
  42. package/dist/shaders/face.d.ts.map +1 -0
  43. package/dist/shaders/face.js +211 -0
  44. package/dist/shaders/hair.d.ts +2 -0
  45. package/dist/shaders/hair.d.ts.map +1 -0
  46. package/dist/shaders/hair.js +186 -0
  47. package/dist/shaders/ltc_mag_lut.d.ts +3 -0
  48. package/dist/shaders/ltc_mag_lut.d.ts.map +1 -0
  49. package/dist/shaders/ltc_mag_lut.js +1033 -0
  50. package/dist/shaders/metal.d.ts +2 -0
  51. package/dist/shaders/metal.d.ts.map +1 -0
  52. package/dist/shaders/metal.js +171 -0
  53. package/dist/shaders/nodes.d.ts +2 -0
  54. package/dist/shaders/nodes.d.ts.map +1 -0
  55. package/dist/shaders/nodes.js +423 -0
  56. package/dist/shaders/stockings.d.ts +2 -0
  57. package/dist/shaders/stockings.d.ts.map +1 -0
  58. package/dist/shaders/stockings.js +229 -0
  59. package/package.json +1 -1
  60. package/src/asset-reader.ts +79 -0
  61. package/src/engine.ts +1352 -383
  62. package/src/folder-upload.ts +59 -0
  63. package/src/index.ts +12 -2
  64. package/src/model.ts +34 -2
  65. package/src/pmx-loader.ts +11 -2
  66. package/src/shaders/body.ts +211 -0
  67. package/src/shaders/classify.ts +25 -0
  68. package/src/shaders/cloth_rough.ts +174 -0
  69. package/src/shaders/cloth_smooth.ts +173 -0
  70. package/src/shaders/default.ts +169 -0
  71. package/src/shaders/dfg_lut.ts +127 -0
  72. package/src/shaders/eye.ts +143 -0
  73. package/src/shaders/face.ts +213 -0
  74. package/src/shaders/hair.ts +188 -0
  75. package/src/shaders/ltc_mag_lut.ts +1035 -0
  76. package/src/shaders/metal.ts +173 -0
  77. package/src/shaders/nodes.ts +424 -0
  78. package/src/shaders/stockings.ts +231 -0
@@ -0,0 +1,168 @@
1
+ // Blender 3.6 Principled BSDF defaults + Filmic "Medium High Contrast" tone mapping.
2
+ // Metallic=0, Specular=0.5 (F0=0.04), Roughness=0.5.
3
+ // Tone mapping via LUT sampled from Blender's OCIO pipeline (exposure -0.3 baked in).
4
+ export const DEFAULT_SHADER_WGSL = /* wgsl */ `
5
+
6
+ const PI: f32 = 3.141592653589793;
7
+ const F0_DIELECTRIC: f32 = 0.04;
8
+ const ROUGHNESS: f32 = 0.5;
9
+
10
+ struct CameraUniforms {
11
+ view: mat4x4f,
12
+ projection: mat4x4f,
13
+ viewPos: vec3f,
14
+ _padding: f32,
15
+ };
16
+
17
+ struct Light {
18
+ direction: vec4f,
19
+ color: vec4f,
20
+ };
21
+
22
+ struct LightUniforms {
23
+ ambientColor: vec4f,
24
+ lights: array<Light, 4>,
25
+ };
26
+
27
+ // Per-material uniforms. Add fields here only when a shader actually reads them;
28
+ // preset-specific shaders (face.ts, future hair.ts) share this struct so the
29
+ // engine can use one material bind-group layout.
30
+ struct MaterialUniforms {
31
+ diffuseColor: vec3f, // tint; multiplies sampled albedo (unused by current fs, reserved)
32
+ alpha: f32, // 0 → discard; <1 → transparent draw call
33
+ };
34
+
35
+ struct VertexOutput {
36
+ @builtin(position) position: vec4f,
37
+ @location(0) normal: vec3f,
38
+ @location(1) uv: vec2f,
39
+ @location(2) worldPos: vec3f,
40
+ };
41
+
42
+ struct LightVP { viewProj: mat4x4f, };
43
+
44
+ @group(0) @binding(0) var<uniform> camera: CameraUniforms;
45
+ @group(0) @binding(1) var<uniform> light: LightUniforms;
46
+ @group(0) @binding(2) var diffuseSampler: sampler;
47
+ @group(0) @binding(3) var shadowMap: texture_depth_2d;
48
+ @group(0) @binding(4) var shadowSampler: sampler_comparison;
49
+ @group(0) @binding(5) var<uniform> lightVP: LightVP;
50
+ @group(1) @binding(0) var<storage, read> skinMats: array<mat4x4f>;
51
+ @group(2) @binding(0) var diffuseTexture: texture_2d<f32>;
52
+ @group(2) @binding(1) var<uniform> material: MaterialUniforms;
53
+
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
+ return f0 + (1.0 - f0) * pow(1.0 - cosTheta, 5.0);
67
+ }
68
+
69
+ // ─── Filmic tone mapping (LUT extracted from Blender 3.6 OCIO) ─────
70
+ // View transform = Filmic, Look = Medium High Contrast, Exposure = -0.3.
71
+ // 14 samples at integer log2 stops from -10 to +3 (inclusive).
72
+ // Extracted via scripts/extract_filmic_lut.py → probe image through scene
73
+ // color management. Input: linear scene-referred. Output: sRGB display.
74
+
75
+ fn filmic(x: f32) -> f32 {
76
+ var lut = array<f32, 14>(
77
+ 0.0067, 0.0141, 0.0272, 0.0499, 0.0885, 0.1512, 0.2462,
78
+ 0.3753, 0.5273, 0.6776, 0.8031, 0.8929, 0.9495, 0.9814
79
+ );
80
+ let t = clamp(log2(max(x, 1e-10)) + 10.0, 0.0, 13.0);
81
+ let i = u32(t);
82
+ let j = min(i + 1u, 13u);
83
+ return mix(lut[i], lut[j], t - f32(i));
84
+ }
85
+
86
+ fn tonemap(hdr: vec3f) -> vec3f {
87
+ return vec3f(filmic(hdr.x), filmic(hdr.y), filmic(hdr.z));
88
+ }
89
+
90
+ // ─── Shadow sampling (3×3 PCF) ──────────────────────────────────────
91
+
92
+ fn sampleShadow(worldPos: vec3f, n: vec3f) -> f32 {
93
+ let biasedPos = worldPos + n * 0.08;
94
+ let lclip = lightVP.viewProj * vec4f(biasedPos, 1.0);
95
+ let ndc = lclip.xyz / max(lclip.w, 1e-6);
96
+ let suv = vec2f(ndc.x * 0.5 + 0.5, 0.5 - ndc.y * 0.5);
97
+ let cmpZ = ndc.z - 0.001;
98
+ let ts = 1.0 / 4096.0;
99
+ var vis = 0.0;
100
+ for (var y = -1; y <= 1; y++) {
101
+ for (var x = -1; x <= 1; x++) {
102
+ vis += textureSampleCompare(shadowMap, shadowSampler, suv + vec2f(f32(x), f32(y)) * ts, cmpZ);
103
+ }
104
+ }
105
+ return vis / 9.0;
106
+ }
107
+
108
+ // ─── Vertex / Fragment ──────────────────────────────────────────────
109
+
110
+ @vertex fn vs(
111
+ @location(0) position: vec3f,
112
+ @location(1) normal: vec3f,
113
+ @location(2) uv: vec2f,
114
+ @location(3) joints0: vec4<u32>,
115
+ @location(4) weights0: vec4<f32>
116
+ ) -> VertexOutput {
117
+ var output: VertexOutput;
118
+ let pos4 = vec4f(position, 1.0);
119
+ let weightSum = weights0.x + weights0.y + weights0.z + weights0.w;
120
+ let invWeightSum = select(1.0, 1.0 / weightSum, weightSum > 0.0001);
121
+ let nw = select(vec4f(1.0, 0.0, 0.0, 0.0), weights0 * invWeightSum, weightSum > 0.0001);
122
+ var skinnedPos = vec4f(0.0);
123
+ var skinnedNrm = vec3f(0.0);
124
+ for (var i = 0u; i < 4u; i++) {
125
+ let m = skinMats[joints0[i]];
126
+ let w = nw[i];
127
+ skinnedPos += (m * pos4) * w;
128
+ skinnedNrm += (mat3x3f(m[0].xyz, m[1].xyz, m[2].xyz) * normal) * w;
129
+ }
130
+ output.position = camera.projection * camera.view * vec4f(skinnedPos.xyz, 1.0);
131
+ output.normal = normalize(skinnedNrm);
132
+ output.uv = uv;
133
+ output.worldPos = skinnedPos.xyz;
134
+ return output;
135
+ }
136
+
137
+ @fragment fn fs(input: VertexOutput) -> @location(0) vec4f {
138
+ let alpha = material.alpha;
139
+ if (alpha < 0.001) { discard; }
140
+
141
+ let n = normalize(input.normal);
142
+ let v = normalize(camera.viewPos - input.worldPos);
143
+ let albedo = textureSample(diffuseTexture, diffuseSampler, input.uv).rgb;
144
+
145
+ let l = -light.lights[0].direction.xyz;
146
+ let sunColor = light.lights[0].color.xyz * light.lights[0].color.w;
147
+ let h = normalize(l + v);
148
+
149
+ let ndotl = max(dot(n, l), 0.0);
150
+ let ndotv = max(dot(n, v), 0.001);
151
+ let ndoth = max(dot(n, h), 0.0);
152
+ let vdoth = max(dot(v, h), 0.0);
153
+
154
+ let a2 = ROUGHNESS * ROUGHNESS;
155
+ let D = ggx_d(ndoth, a2);
156
+ let G = smith_g1(ndotl, a2) * smith_g1(ndotv, a2);
157
+ let F = fresnel_schlick(vdoth, F0_DIELECTRIC);
158
+ let spec = (D * G * F) / max(4.0 * ndotl * ndotv, 0.001);
159
+
160
+ let shadow = sampleShadow(input.worldPos, n);
161
+ let kd = (1.0 - F) * albedo / PI;
162
+ let direct = (kd + spec) * sunColor * ndotl * shadow;
163
+ let ambient = albedo * light.ambientColor.xyz;
164
+
165
+ return vec4f(ambient + direct, alpha);
166
+ }
167
+
168
+ `;
@@ -0,0 +1,4 @@
1
+ export declare const DFG_LUT_SIZE = 64;
2
+ export declare const DFG_LUT_SAMPLE_COUNT = 32;
3
+ export declare const DFG_LUT_WGSL = "\nconst LUT_SIZE: f32 = 64.0;\nconst SAMPLE_COUNT: u32 = 32u;\nconst M_2PI: f32 = 6.283185307179586;\n\n@vertex fn vs(@builtin(vertex_index) vid: u32) -> @builtin(position) vec4f {\n // Full-screen triangle covering [-1,1]\u00B2 in NDC.\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\n// common_math_geom_lib.glsl:165 \u2014 make_orthonormal_basis.\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\n// bsdf_sampling_lib.glsl:27 \u2014 Heitz 2018 VNDF sampling in tangent space.\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\n// bsdf_common_lib.glsl:105 \u2014 G1 Smith GGX (Brian Karis opti form).\nfn G1_Smith_GGX_opti(NX: f32, a2: f32) -> f32 {\n return NX + sqrt(NX * (NX - NX * a2) + a2);\n}\n\n// bsdf_common_lib.glsl:50 \u2014 exact dielectric Fresnel (monochromatic).\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; // total internal reflection\n}\n\nfn f0_from_ior(eta: f32) -> f32 {\n let A = (eta - 1.0) / (eta + 1.0);\n return A * A;\n}\n\n// F_color_blend(eta, fresnel, vec3(0)).r \u2014 blend factor only.\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) vec2f {\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 // principled specular=1.0 \u2014 max value, matches bsdf_lut_frag.glsl:41.\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 // Xi.x = radial, Xi.yz = (cos, sin) of azimuth \u2014 bsdf_lut_frag.glsl:22.\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 // G_smith (divided form): 4\u00B7NV\u00B7NL / (G1_v\u00B7G1_l). See bsdf_common_lib.glsl:105.\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 return vec2f(brdf_accum / n2, fresnel_accum / n2);\n}\n";
4
+ //# sourceMappingURL=dfg_lut.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dfg_lut.d.ts","sourceRoot":"","sources":["../../src/shaders/dfg_lut.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,YAAY,KAAK,CAAA;AAC9B,eAAO,MAAM,oBAAoB,KAAK,CAAA;AAEtC,eAAO,MAAM,YAAY,otHAiHxB,CAAA"}
@@ -0,0 +1,125 @@
1
+ // One-shot bake pass that precomputes EEVEE's BRDF split-sum DFG LUT.
2
+ // Direct WGSL port of Blender 3.6 source/blender/draw/engines/eevee/shaders/
3
+ // bsdf_lut_frag.glsl + bsdf_sampling_lib.glsl (VNDF GGX branch).
4
+ //
5
+ // Output texture: 64×64 rg16float, written once at engine init.
6
+ // R = (1 - Fc) × BRDF integrated over GGX VNDF — scales f0
7
+ // G = Fc × BRDF integrated over GGX VNDF — scales f90
8
+ // Runtime sampler: see brdf_lut_baked() in nodes.ts. Plug into
9
+ // F_brdf_single_scatter / F_brdf_multi_scatter verbatim.
10
+ export const DFG_LUT_SIZE = 64;
11
+ export const DFG_LUT_SAMPLE_COUNT = 32;
12
+ export const DFG_LUT_WGSL = /* wgsl */ `
13
+ const LUT_SIZE: f32 = ${DFG_LUT_SIZE}.0;
14
+ const SAMPLE_COUNT: u32 = ${DFG_LUT_SAMPLE_COUNT}u;
15
+ const M_2PI: f32 = 6.283185307179586;
16
+
17
+ @vertex fn vs(@builtin(vertex_index) vid: u32) -> @builtin(position) vec4f {
18
+ // Full-screen triangle covering [-1,1]² in NDC.
19
+ let x = f32((vid << 1u) & 2u) * 2.0 - 1.0;
20
+ let y = f32(vid & 2u) * 2.0 - 1.0;
21
+ return vec4f(x, y, 0.0, 1.0);
22
+ }
23
+
24
+ // common_math_geom_lib.glsl:165 — make_orthonormal_basis.
25
+ fn orthonormal_basis(N: vec3f) -> mat2x3f {
26
+ let up = select(vec3f(1.0, 0.0, 0.0), vec3f(0.0, 0.0, 1.0), abs(N.z) < 0.99999);
27
+ let T = normalize(cross(up, N));
28
+ let B = cross(N, T);
29
+ return mat2x3f(T, B);
30
+ }
31
+
32
+ // bsdf_sampling_lib.glsl:27 — Heitz 2018 VNDF sampling in tangent space.
33
+ fn sample_ggx_vndf(rand: vec3f, alpha: f32, Vt: vec3f) -> vec3f {
34
+ let Vh = normalize(vec3f(alpha * Vt.xy, Vt.z));
35
+ let tb = orthonormal_basis(Vh);
36
+ let Th = tb[0];
37
+ let Bh = tb[1];
38
+ let r = sqrt(rand.x);
39
+ let x = r * rand.y;
40
+ var y = r * rand.z;
41
+ let s = 0.5 * (1.0 + Vh.z);
42
+ y = (1.0 - s) * sqrt(1.0 - x * x) + s * y;
43
+ let z = sqrt(saturate(1.0 - x * x - y * y));
44
+ let Hh = x * Th + y * Bh + z * Vh;
45
+ return normalize(vec3f(alpha * Hh.xy, saturate(Hh.z)));
46
+ }
47
+
48
+ // bsdf_common_lib.glsl:105 — G1 Smith GGX (Brian Karis opti form).
49
+ fn G1_Smith_GGX_opti(NX: f32, a2: f32) -> f32 {
50
+ return NX + sqrt(NX * (NX - NX * a2) + a2);
51
+ }
52
+
53
+ // bsdf_common_lib.glsl:50 — exact dielectric Fresnel (monochromatic).
54
+ fn F_eta(eta: f32, cos_theta: f32) -> f32 {
55
+ let c = abs(cos_theta);
56
+ var g = eta * eta - 1.0 + c * c;
57
+ if (g > 0.0) {
58
+ g = sqrt(g);
59
+ let A = (g - c) / (g + c);
60
+ let B = (c * (g + c) - 1.0) / (c * (g - c) + 1.0);
61
+ return 0.5 * A * A * (1.0 + B * B);
62
+ }
63
+ return 1.0; // total internal reflection
64
+ }
65
+
66
+ fn f0_from_ior(eta: f32) -> f32 {
67
+ let A = (eta - 1.0) / (eta + 1.0);
68
+ return A * A;
69
+ }
70
+
71
+ // F_color_blend(eta, fresnel, vec3(0)).r — blend factor only.
72
+ fn F_color_blend_zero(eta: f32, fresnel: f32) -> f32 {
73
+ let f0 = f0_from_ior(eta);
74
+ return saturate((fresnel - f0) / (1.0 - f0));
75
+ }
76
+
77
+ @fragment fn fs(@builtin(position) frag: vec4f) -> @location(0) vec2f {
78
+ let y_uv = floor(frag.y) / (LUT_SIZE - 1.0);
79
+ let x_uv = floor(frag.x) / (LUT_SIZE - 1.0);
80
+
81
+ let NV = clamp(1.0 - y_uv * y_uv, 1e-4, 0.9999);
82
+ let a = x_uv * x_uv;
83
+ let a2 = clamp(a * a, 1e-4, 0.9999);
84
+
85
+ let V = vec3f(sqrt(1.0 - NV * NV), 0.0, NV);
86
+
87
+ // principled specular=1.0 — max value, matches bsdf_lut_frag.glsl:41.
88
+ let eta = (2.0 / (1.0 - sqrt(0.08 * 1.0))) - 1.0;
89
+
90
+ var brdf_accum = 0.0;
91
+ var fresnel_accum = 0.0;
92
+ let sc_f = f32(SAMPLE_COUNT);
93
+ for (var j: u32 = 0u; j < SAMPLE_COUNT; j = j + 1u) {
94
+ for (var i: u32 = 0u; i < SAMPLE_COUNT; i = i + 1u) {
95
+ let ix = (f32(i) + 0.5) / sc_f;
96
+ let iy = (f32(j) + 0.5) / sc_f;
97
+ // Xi.x = radial, Xi.yz = (cos, sin) of azimuth — bsdf_lut_frag.glsl:22.
98
+ let Xi = vec3f(ix, cos(iy * M_2PI), sin(iy * M_2PI));
99
+
100
+ let H = sample_ggx_vndf(Xi, a, V);
101
+ let L = -reflect(V, H);
102
+ let NL = L.z;
103
+ if (NL > 0.0) {
104
+ let NH = max(H.z, 0.0);
105
+ let VH = max(dot(V, H), 0.0);
106
+
107
+ // G_smith (divided form): 4·NV·NL / (G1_v·G1_l). See bsdf_common_lib.glsl:105.
108
+ let G1v = G1_Smith_GGX_opti(NV, a2);
109
+ let G1l = G1_Smith_GGX_opti(NL, a2);
110
+ let G_smith = 4.0 * NV * NL / (G1v * G1l);
111
+
112
+ let brdf = (G_smith * VH) / (NH * NV);
113
+
114
+ let fresnel = F_eta(eta, VH);
115
+ let Fc = F_color_blend_zero(eta, fresnel);
116
+
117
+ brdf_accum = brdf_accum + (1.0 - Fc) * brdf;
118
+ fresnel_accum = fresnel_accum + Fc * brdf;
119
+ }
120
+ }
121
+ }
122
+ let n2 = sc_f * sc_f;
123
+ return vec2f(brdf_accum / n2, fresnel_accum / n2);
124
+ }
125
+ `;
@@ -0,0 +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 return f0 + (1.0 - f0) * pow(1.0 - cosTheta, 5.0);\n}\n\nfn sampleShadow(worldPos: vec3f, n: vec3f) -> f32 {\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 / 4096.0;\n var vis = 0.0;\n for (var y = -1; y <= 1; y++) {\n for (var x = -1; x <= 1; x++) {\n vis += textureSampleCompare(shadowMap, shadowSampler, suv + vec2f(f32(x), f32(y)) * ts, cmpZ);\n }\n }\n return vis / 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 output.normal = normalize(skinnedNrm);\n output.uv = uv;\n output.worldPos = skinnedPos.xyz;\n return output;\n}\n\n@fragment fn fs(input: VertexOutput) -> @location(0) vec4f {\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 return vec4f(ambient + direct + emission, alpha);\n}\n\n";
2
+ //# sourceMappingURL=eye.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eye.d.ts","sourceRoot":"","sources":["../../src/shaders/eye.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,eAAe,2tIA0I3B,CAAA"}
@@ -0,0 +1,142 @@
1
+ // Eye preset — default Principled BSDF (F0=0.04, Roughness=0.5) + Emission socket set to albedo × 1.5.
2
+ // Matches the published preset's instruction: "keep eyes in the default nodegraph, add emission 1.5".
3
+ // Blender's Principled BSDF Emission socket is added on top of the shaded output (pre-tonemap, feeds bloom).
4
+ export const EYE_SHADER_WGSL = /* wgsl */ `
5
+
6
+ const PI: f32 = 3.141592653589793;
7
+ const F0_DIELECTRIC: f32 = 0.04;
8
+ const ROUGHNESS: f32 = 0.5;
9
+ const EYE_EMISSION_STRENGTH: f32 = 1.5;
10
+
11
+ struct CameraUniforms {
12
+ view: mat4x4f,
13
+ projection: mat4x4f,
14
+ viewPos: vec3f,
15
+ _padding: f32,
16
+ };
17
+
18
+ struct Light {
19
+ direction: vec4f,
20
+ color: vec4f,
21
+ };
22
+
23
+ struct LightUniforms {
24
+ ambientColor: vec4f,
25
+ lights: array<Light, 4>,
26
+ };
27
+
28
+ struct MaterialUniforms {
29
+ diffuseColor: vec3f,
30
+ alpha: f32,
31
+ };
32
+
33
+ struct VertexOutput {
34
+ @builtin(position) position: vec4f,
35
+ @location(0) normal: vec3f,
36
+ @location(1) uv: vec2f,
37
+ @location(2) worldPos: vec3f,
38
+ };
39
+
40
+ struct LightVP { viewProj: mat4x4f, };
41
+
42
+ @group(0) @binding(0) var<uniform> camera: CameraUniforms;
43
+ @group(0) @binding(1) var<uniform> light: LightUniforms;
44
+ @group(0) @binding(2) var diffuseSampler: sampler;
45
+ @group(0) @binding(3) var shadowMap: texture_depth_2d;
46
+ @group(0) @binding(4) var shadowSampler: sampler_comparison;
47
+ @group(0) @binding(5) var<uniform> lightVP: LightVP;
48
+ @group(1) @binding(0) var<storage, read> skinMats: array<mat4x4f>;
49
+ @group(2) @binding(0) var diffuseTexture: texture_2d<f32>;
50
+ @group(2) @binding(1) var<uniform> material: MaterialUniforms;
51
+
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
+ return f0 + (1.0 - f0) * pow(1.0 - cosTheta, 5.0);
63
+ }
64
+
65
+ fn sampleShadow(worldPos: vec3f, n: vec3f) -> f32 {
66
+ let biasedPos = worldPos + n * 0.08;
67
+ let lclip = lightVP.viewProj * vec4f(biasedPos, 1.0);
68
+ let ndc = lclip.xyz / max(lclip.w, 1e-6);
69
+ let suv = vec2f(ndc.x * 0.5 + 0.5, 0.5 - ndc.y * 0.5);
70
+ let cmpZ = ndc.z - 0.001;
71
+ let ts = 1.0 / 4096.0;
72
+ var vis = 0.0;
73
+ for (var y = -1; y <= 1; y++) {
74
+ for (var x = -1; x <= 1; x++) {
75
+ vis += textureSampleCompare(shadowMap, shadowSampler, suv + vec2f(f32(x), f32(y)) * ts, cmpZ);
76
+ }
77
+ }
78
+ return vis / 9.0;
79
+ }
80
+
81
+ @vertex fn vs(
82
+ @location(0) position: vec3f,
83
+ @location(1) normal: vec3f,
84
+ @location(2) uv: vec2f,
85
+ @location(3) joints0: vec4<u32>,
86
+ @location(4) weights0: vec4<f32>
87
+ ) -> VertexOutput {
88
+ var output: VertexOutput;
89
+ let pos4 = vec4f(position, 1.0);
90
+ let weightSum = weights0.x + weights0.y + weights0.z + weights0.w;
91
+ let invWeightSum = select(1.0, 1.0 / weightSum, weightSum > 0.0001);
92
+ let nw = select(vec4f(1.0, 0.0, 0.0, 0.0), weights0 * invWeightSum, weightSum > 0.0001);
93
+ var skinnedPos = vec4f(0.0);
94
+ var skinnedNrm = vec3f(0.0);
95
+ for (var i = 0u; i < 4u; i++) {
96
+ let m = skinMats[joints0[i]];
97
+ let w = nw[i];
98
+ skinnedPos += (m * pos4) * w;
99
+ skinnedNrm += (mat3x3f(m[0].xyz, m[1].xyz, m[2].xyz) * normal) * w;
100
+ }
101
+ output.position = camera.projection * camera.view * vec4f(skinnedPos.xyz, 1.0);
102
+ output.normal = normalize(skinnedNrm);
103
+ output.uv = uv;
104
+ output.worldPos = skinnedPos.xyz;
105
+ return output;
106
+ }
107
+
108
+ @fragment fn fs(input: VertexOutput) -> @location(0) vec4f {
109
+ let alpha = material.alpha;
110
+ if (alpha < 0.001) { discard; }
111
+
112
+ let n = normalize(input.normal);
113
+ let v = normalize(camera.viewPos - input.worldPos);
114
+ let albedo = textureSample(diffuseTexture, diffuseSampler, input.uv).rgb;
115
+
116
+ let l = -light.lights[0].direction.xyz;
117
+ let sunColor = light.lights[0].color.xyz * light.lights[0].color.w;
118
+ let h = normalize(l + v);
119
+
120
+ let ndotl = max(dot(n, l), 0.0);
121
+ let ndotv = max(dot(n, v), 0.001);
122
+ let ndoth = max(dot(n, h), 0.0);
123
+ let vdoth = max(dot(v, h), 0.0);
124
+
125
+ let a2 = ROUGHNESS * ROUGHNESS;
126
+ let D = ggx_d(ndoth, a2);
127
+ let G = smith_g1(ndotl, a2) * smith_g1(ndotv, a2);
128
+ let F = fresnel_schlick(vdoth, F0_DIELECTRIC);
129
+ let spec = (D * G * F) / max(4.0 * ndotl * ndotv, 0.001);
130
+
131
+ let shadow = sampleShadow(input.worldPos, n);
132
+ let kd = (1.0 - F) * albedo / PI;
133
+ let direct = (kd + spec) * sunColor * ndotl * shadow;
134
+ let ambient = albedo * light.ambientColor.xyz;
135
+
136
+ // Principled Emission socket: emissive = emission_color × strength, added on top of shading.
137
+ let emission = albedo * EYE_EMISSION_STRENGTH;
138
+
139
+ return vec4f(ambient + direct + emission, alpha);
140
+ }
141
+
142
+ `;
@@ -0,0 +1,2 @@
1
+ export declare const FACE_SHADER_WGSL = "\n\n\n\n// Baked 64\u00D764 rg16float DFG LUT \u2014 created once at engine init by dfg_lut.ts.\n// Paired with group(0) binding(2) diffuseSampler (linear filter, clamp implicit\n// via the half-texel bias inside brdf_lut_baked). Bound by the main per-frame\n// bind group to every material pipeline that includes this module.\n@group(0) @binding(9) var dfgLut: texture_2d<f32>;\n\n// Baked 64\u00D764 rg16float LTC GGX magnitude LUT \u2014 ltc_mag_ggx from Blender eevee_lut.c.\n// Heitz 2016 LTC fit amplitude \u2014 same UV addressing as dfgLut.\n// Used for direct-specular energy compensation (ltc_brdf_scale in closure_eval_glossy_lib.glsl).\n@group(0) @binding(10) var ltcMag: 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// \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// \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 f0 = pow((ior - 1.0) / (ior + 1.0), 2.0);\n let cos_theta = clamp(dot(n, v), 0.0, 1.0);\n return f0 + (1.0 - f0) * pow(1.0 - cos_theta, 5.0);\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 f0 = pow((1.0 - eta) / (1.0 + eta), 2.0);\n let cos_theta = clamp(abs(dot(n, v)), 0.0, 1.0);\n return f0 + (1.0 - f0) * pow(1.0 - cos_theta, 5.0);\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\nfn _hash33(p: vec3f) -> vec3f {\n var q = vec3f(\n dot(p, vec3f(127.1, 311.7, 74.7)),\n dot(p, vec3f(269.5, 183.3, 246.1)),\n dot(p, vec3f(113.5, 271.9, 124.6))\n );\n return fract(sin(q) * 43758.5453123) * 2.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// \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.\nfn bsdf_ggx(N: vec3f, L: vec3f, V: vec3f, 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(dot(N, L), 1e-8);\n let NV = max(dot(N, V), 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 64\u00D764 EEVEE split-sum LUT \u2014 exact port of bsdf_lut_frag.glsl.\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) dfgLut + binding(2) diffuseSampler in the host shader.\nfn brdf_lut_baked(NV: f32, roughness: f32) -> vec2f {\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(dfgLut, diffuseSampler, uv, 0.0).rg;\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// Because Blender evaluates direct lights via LTC (Heitz 2016) but indirect via split-sum,\n// direct radiance is rescaled so total-energy matches what the split-sum LUT expects.\n// Sample both LUTs at identical lut_coords and return the ratio.\nfn ltc_brdf_scale(NV: f32, roughness: f32) -> f32 {\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 let ltc = textureSampleLevel(ltcMag, diffuseSampler, uv, 0.0).rg;\n let dfg = textureSampleLevel(dfgLut, diffuseSampler, uv, 0.0).rg;\n return (ltc.x + ltc.y) / max(dfg.x + dfg.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\n// 3x3 PCF shadow sampling, 4096 map, normal-bias 0.08, depth-bias 0.001\nfn sampleShadow(worldPos: vec3f, n: vec3f) -> f32 {\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 / 4096.0;\n var vis = 0.0;\n for (var y = -1; y <= 1; y++) {\n for (var x = -1; x <= 1; x++) {\n vis += textureSampleCompare(shadowMap, shadowSampler, suv + vec2f(f32(x), f32(y)) * ts, cmpZ);\n }\n }\n return vis / 9.0;\n}\n\nconst PI_F: f32 = 3.141592653589793;\nconst FACE_SPECULAR: f32 = 0.5;\nconst FACE_ROUGHNESS: f32 = 0.3;\n// Dump M_Face unlinked defaults (math op enum not serialized \u2014 warm clamp chain still from m_graphs)\nconst FACE_RIM2_POW: f32 = 0.6300000548362732;\nconst FACE_RIM2_BG: vec3f = vec3f(1.0, 0.4684903025627136, 0.3698573112487793);\nconst FACE_WARM_AO_MUL: f32 = 0.30000001192092896; // \u8FD0\u7B97.004 MULTIPLY after invert (was 0.5 in older trace)\nconst FACE_BRIGHT_TEX_THRESH: f32 = 0.9300000071525574; // \u8FD0\u7B97.005 GREATER_THAN Value_001\nconst FACE_MIX_NPR: f32 = 0.5; // \u6DF7\u5408\u7740\u8272\u5668.001 Fac\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 output.normal = normalize(skinnedNrm);\n output.uv = uv;\n output.worldPos = skinnedPos.xyz;\n return output;\n}\n\n// Fragment: M_Face NPR + Principled hybrid\n// TEX \u2192 HueSat shadow/lit \u2192 toon gate \u2192 BrightContrast \u2192 AO chain \u2192 emission stack\n// Fresnel rims, warm AO emission, bright-texture gate, noise-bumped Principled\n// Final = mix(Principled, NPR, 0.5)\n@fragment fn fs(input: VertexOutput) -> @location(0) vec4f {\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 intensity = light.lights[0].color.w;\n let sun = light.lights[0].color.xyz * intensity;\n\n let tex_color = textureSample(diffuseTexture, diffuseSampler, input.uv).rgb;\n let shadow = sampleShadow(input.worldPos, n);\n\n // \u2550\u2550\u2550 SOURCES \u2550\u2550\u2550\n // DiffuseBSDF(white) \u2192 ShaderToRGB (energy-matched); shadow on direct only\n let ndotl_raw = shader_to_rgb_diffuse(n, l, sun, light.ambientColor.xyz, shadow);\n // ramp.008 CONSTANT \u2014 edge AA avoids binary fac shimmer / white specks on terminator (fwidth + smoothstep)\n let toon = ramp_constant_edge_aa(ndotl_raw, 0.2966, vec4f(0,0,0,1), vec4f(1,1,1,1)).r;\n let ao = ao_fake(n, v);\n\n // \u2550\u2550\u2550 TOON COLOR \u2550\u2550\u2550\n let shadow_tint = hue_sat(0.46000000834465027, 2.0, 0.3499999940395355, 1.0, tex_color); // HueSat.002\n let lit_tint = hue_sat(0.46000000834465027, 1.600000023841858, 1.5, 1.0, tex_color); // HueSat.001\n let toon_color = mix_blend(toon, shadow_tint, lit_tint); // Mix.004\n let bc = bright_contrast(toon_color, 0.1, 0.2);\n\n // \u2550\u2550\u2550 AO CHAIN \u2550\u2550\u2550\n // ramp CONSTANT [0\u2192white, 0.5995\u2192black]\n let ao_ramp = ramp_constant(ao, 0.0, vec4f(1,1,1,1), 0.5995, vec4f(0,0,0,1)).r;\n // Mix.003(Factor=ao_ramp, A=bc, B=reddish tint)\n let ao_mixed = mix_blend(ao_ramp, bc, vec3f(0.8302, 0.3346, 0.2795));\n\n // \u2550\u2550\u2550 EMISSION 3 \u2550\u2550\u2550\n let emission3 = ao_mixed * 2.5; // Emission.003(Strength=2.5)\n\n // \u2550\u2550\u2550 WARM EMISSION \u2550\u2550\u2550\n let ao_inv = invert_f(1.0, ao_ramp);\n let warm_str = ao_inv * FACE_WARM_AO_MUL; // \u53CD\u8F6C \u2192 \u8FD0\u7B97.004 MULTIPLY Value_001\n let warm_input = clamp(toon * 0.5 + 0.5, 0.0, 1.0); // \u8FD0\u7B97.001\u2192\u8FD0\u7B97.006\u2192Clamp\n // ramp.003 CARDINAL [0.2409\u2192warm dark, 0.4663\u2192warm light]\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; // Emission.001\n\n // \u2550\u2550\u2550 RIM 1 \u2550\u2550\u2550\n // Fresnel(IOR=2.0) \u00D7 LayerWeight.001(Facing, Blend=0.24)\n let rim1_str = fresnel(2.0, n, v) * layer_weight_facing(0.24, n, v);\n let rim1 = vec3f(0.984157919883728, 0.6110184788703918, 0.5736401677131653) * rim1_str;\n\n // \u2550\u2550\u2550 RIM 2 \u2550\u2550\u2550\n // Fresnel.001(IOR=1.45) \u00D7 LayerWeight.002(Fresnel output, Blend=0.61)\n let rim2_raw = fresnel(1.45, n, v) * layer_weight_fresnel(0.61, n, v);\n let rim2_fac = math_power(rim2_raw, FACE_RIM2_POW);\n // MixShader.002: Shader=Emission.003, Shader_001=\u80CC\u666F\n let rim2_mixed = mix(emission3, FACE_RIM2_BG, rim2_fac);\n\n // \u8F6C\u63A5\u70B9.005(tex) \u2192 \u8FD0\u7B97.005 GREATER_THAN Value_001\n let tex_gate = math_greater_than(tex_color.r, FACE_BRIGHT_TEX_THRESH);\n let bright_emit = vec3f(tex_gate) * 3.0; // Emission.002(Strength=3.0)\n\n // \u2550\u2550\u2550 NPR STACK (AddShader chain) \u2550\u2550\u2550\n let add2 = rim2_mixed + bright_emit; // AddShader.002\n let add0 = rim1 + add2; // AddShader\n let npr_stack = add0 + warm_emission; // AddShader.001\n\n // \u2550\u2550\u2550 PRINCIPLED BSDF \u2550\u2550\u2550\n // Noise-based bump normal\n let gen = mapping_point(input.worldPos, vec3f(0.0), vec3f(0.0), vec3f(1.0, 1.0, 1.5));\n let noise_val = tex_noise(gen, 1.0, 2.0, 0.5, 0.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); // \u51F9\u51F8 Strength; LH bump\n\n // Mix.001(Factor=noise_ramp, A=bc, B=dark red)\n let principled_base = mix_blend(noise_ramp, bc, vec3f(0.6832, 0.1947, 0.1373));\n // Emission input from reroute.011 (bc), Strength=0.2\n let p_emission = bc * 0.2;\n // AO.002 \u2192 ramp.005 LINEAR [0.003\u2192black, 1.0\u2192gray] for subsurface approx\n let ao2 = ao_fake(n, v);\n let sss = ramp_linear(ao2, 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 let f0 = vec3f(0.08 * FACE_SPECULAR);\n let f90 = mix(f0, vec3f(1.0), sqrt(FACE_SPECULAR));\n let split_sum = brdf_lut_baked(NV, FACE_ROUGHNESS);\n let reflection_color = F_brdf_multi_scatter(f0, f90, split_sum);\n\n let spec_direct = bsdf_ggx(bumped_n, l, v, FACE_ROUGHNESS) * sun * shadow * ltc_brdf_scale(NV, FACE_ROUGHNESS);\n let spec_indirect = light.ambientColor.xyz;\n let spec_radiance = (spec_direct + spec_indirect) * reflection_color;\n\n // Indirect diffuse = base_color \u00D7 L_w per Blender closure_eval_surface_lib.glsl line 302;\n // probe_evaluate_world_diff returns radiance (SH-projected, not cosine-convolved).\n let diffuse_radiance = principled_base * (sun * NL * shadow / PI_F + 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 \u2014 Fac blends toward second\n let final_color = mix(npr_stack, principled, FACE_MIX_NPR);\n\n return vec4f(final_color, alpha);\n}\n\n";
2
+ //# sourceMappingURL=face.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"face.d.ts","sourceRoot":"","sources":["../../src/shaders/face.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,gBAAgB,o65BAgN5B,CAAA"}