reze-engine 0.16.2 → 0.16.3

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 (74) hide show
  1. package/dist/engine.d.ts.map +1 -1
  2. package/dist/engine.js +5 -5
  3. package/dist/model.d.ts +4 -1
  4. package/dist/model.d.ts.map +1 -1
  5. package/dist/model.js +14 -1
  6. package/dist/physics/body.d.ts +1 -0
  7. package/dist/physics/body.d.ts.map +1 -1
  8. package/dist/physics/body.js +2 -0
  9. package/dist/physics/constraint.d.ts +1 -1
  10. package/dist/physics/constraint.d.ts.map +1 -1
  11. package/dist/physics/constraint.js +6 -1
  12. package/dist/physics/physics.d.ts +3 -0
  13. package/dist/physics/physics.d.ts.map +1 -1
  14. package/dist/physics/physics.js +69 -1
  15. package/dist/physics/solver.js +16 -8
  16. package/dist/physics/types.d.ts +2 -1
  17. package/dist/physics/types.d.ts.map +1 -1
  18. package/dist/physics/types.js +5 -0
  19. package/dist/physics/world.d.ts +3 -0
  20. package/dist/physics/world.d.ts.map +1 -1
  21. package/dist/physics/world.js +19 -3
  22. package/dist/pmx-loader.d.ts +2 -0
  23. package/dist/pmx-loader.d.ts.map +1 -1
  24. package/dist/pmx-loader.js +37 -20
  25. package/dist/shaders/materials/body.d.ts +1 -1
  26. package/dist/shaders/materials/body.d.ts.map +1 -1
  27. package/dist/shaders/materials/body.js +90 -85
  28. package/dist/shaders/materials/cloth_rough.d.ts +1 -1
  29. package/dist/shaders/materials/cloth_rough.d.ts.map +1 -1
  30. package/dist/shaders/materials/cloth_rough.js +1 -1
  31. package/dist/shaders/materials/cloth_smooth.d.ts +1 -1
  32. package/dist/shaders/materials/cloth_smooth.d.ts.map +1 -1
  33. package/dist/shaders/materials/cloth_smooth.js +2 -2
  34. package/dist/shaders/materials/common.d.ts +1 -1
  35. package/dist/shaders/materials/common.d.ts.map +1 -1
  36. package/dist/shaders/materials/common.js +10 -0
  37. package/dist/shaders/materials/default.d.ts +1 -1
  38. package/dist/shaders/materials/default.d.ts.map +1 -1
  39. package/dist/shaders/materials/default.js +37 -32
  40. package/dist/shaders/materials/eye.d.ts +1 -1
  41. package/dist/shaders/materials/eye.d.ts.map +1 -1
  42. package/dist/shaders/materials/eye.js +40 -35
  43. package/dist/shaders/materials/face.d.ts +1 -1
  44. package/dist/shaders/materials/face.d.ts.map +1 -1
  45. package/dist/shaders/materials/face.js +90 -85
  46. package/dist/shaders/materials/hair.d.ts +1 -1
  47. package/dist/shaders/materials/hair.d.ts.map +1 -1
  48. package/dist/shaders/materials/hair.js +85 -75
  49. package/dist/shaders/materials/metal.d.ts +1 -1
  50. package/dist/shaders/materials/metal.d.ts.map +1 -1
  51. package/dist/shaders/materials/metal.js +1 -1
  52. package/dist/shaders/materials/stockings.d.ts +1 -1
  53. package/dist/shaders/materials/stockings.d.ts.map +1 -1
  54. package/dist/shaders/materials/stockings.js +1 -1
  55. package/package.json +1 -1
  56. package/src/engine.ts +36 -21
  57. package/src/model.ts +18 -1
  58. package/src/physics/body.ts +5 -0
  59. package/src/physics/constraint.ts +6 -1
  60. package/src/physics/physics.ts +68 -1
  61. package/src/physics/solver.ts +16 -8
  62. package/src/physics/types.ts +10 -2
  63. package/src/physics/world.ts +20 -3
  64. package/src/pmx-loader.ts +38 -20
  65. package/src/shaders/materials/body.ts +97 -92
  66. package/src/shaders/materials/cloth_rough.ts +1 -1
  67. package/src/shaders/materials/cloth_smooth.ts +2 -2
  68. package/src/shaders/materials/common.ts +10 -0
  69. package/src/shaders/materials/default.ts +45 -40
  70. package/src/shaders/materials/eye.ts +48 -43
  71. package/src/shaders/materials/face.ts +97 -92
  72. package/src/shaders/materials/hair.ts +92 -82
  73. package/src/shaders/materials/metal.ts +1 -1
  74. package/src/shaders/materials/stockings.ts +1 -1
@@ -73,6 +73,16 @@ struct LightVP { viewProj: mat4x4f, };
73
73
  @group(2) @binding(0) var diffuseTexture: texture_2d<f32>;
74
74
  @group(2) @binding(1) var<uniform> material: MaterialUniforms;
75
75
 
76
+ // Four-bone blended normals can cancel to ~zero on physics-driven parts
77
+ // (opposing bone rotations at 50/50 weights) — normalize(0) is 0/0 = NaN,
78
+ // which poisons the whole shading stack and flashes through bloom. Fall
79
+ // back to up for degenerate normals instead.
80
+ fn safe_normal(nIn: vec3f) -> vec3f {
81
+ let l2 = dot(nIn, nIn);
82
+ if (l2 < 1e-12) { return vec3f(0.0, 1.0, 0.0); }
83
+ return nIn * inverseSqrt(l2);
84
+ }
85
+
76
86
  `;
77
87
 
78
88
  // ─── Shadow sampler (3×3 PCF) ───────────────────────────────────────
@@ -1,40 +1,45 @@
1
- // Default material — Blender 3.6 Principled BSDF defaults, no NPR stack.
2
- // Metallic=0, Specular=0.5 (F0=0.04), Roughness=0.5. Serves as the EEVEE reference
3
- // path that every NPR material mixes against in its final stage.
4
-
5
- import { NODES_WGSL } from "./nodes"
6
- import { COMMON_MATERIAL_PRELUDE_WGSL } from "./common"
7
-
8
- export const DEFAULT_SHADER_WGSL = /* wgsl */ `
9
-
10
- ${NODES_WGSL}
11
- ${COMMON_MATERIAL_PRELUDE_WGSL}
12
-
13
- const DEFAULT_SPECULAR: f32 = 0.5;
14
- const DEFAULT_ROUGHNESS: f32 = 0.5;
15
-
16
- @fragment fn fs(input: VertexOutput) -> FSOut {
17
- let alpha = material.alpha;
18
- if (alpha < 0.001) { discard; }
19
-
20
- let n = normalize(input.normal);
21
- let v = normalize(camera.viewPos - input.worldPos);
22
- let l = -light.lights[0].direction.xyz;
23
- let sun = light.lights[0].color.xyz * light.lights[0].color.w;
24
- let amb = light.ambientColor.xyz;
25
- let shadow = sampleShadow(input.worldPos, n);
26
-
27
- let albedo = textureSample(diffuseTexture, diffuseSampler, input.uv).rgb;
28
-
29
- let color = eval_principled(
30
- PrincipledIn(albedo, 0.0, DEFAULT_SPECULAR, DEFAULT_ROUGHNESS, 1e30, 0.0, 0.0),
31
- n, l, v, sun, amb, shadow
32
- );
33
-
34
- var out: FSOut;
35
- out.color = vec4f(color, alpha);
36
- out.mask = vec4f(1.0, 1.0, 0.0, out.color.a);
37
- return out;
38
- }
39
-
40
- `
1
+ // Default material — Blender 3.6 Principled BSDF defaults, no NPR stack.
2
+ // Metallic=0, Specular=0.5 (F0=0.04), Roughness=0.5. Serves as the EEVEE reference
3
+ // path that every NPR material mixes against in its final stage.
4
+
5
+ import { NODES_WGSL } from "./nodes"
6
+ import { COMMON_MATERIAL_PRELUDE_WGSL } from "./common"
7
+
8
+ export const DEFAULT_SHADER_WGSL = /* wgsl */ `
9
+
10
+ ${NODES_WGSL}
11
+ ${COMMON_MATERIAL_PRELUDE_WGSL}
12
+
13
+ const DEFAULT_SPECULAR: f32 = 0.5;
14
+ const DEFAULT_ROUGHNESS: f32 = 0.5;
15
+
16
+ @fragment fn fs(input: VertexOutput) -> FSOut {
17
+ let tex_s = textureSample(diffuseTexture, diffuseSampler, input.uv);
18
+ // MMD alpha semantics: material alpha × texture alpha. Hair/lace/accessory
19
+ // textures cut their shapes in the alpha channel — ignoring it renders each
20
+ // card's full quad with the texture's padding color (white shimmer on dark
21
+ // hair for models whose textures pad with white).
22
+ let alpha = material.alpha * tex_s.a;
23
+ if (alpha < 0.001) { discard; }
24
+
25
+ let n = safe_normal(input.normal);
26
+ let v = normalize(camera.viewPos - input.worldPos);
27
+ let l = -light.lights[0].direction.xyz;
28
+ let sun = light.lights[0].color.xyz * light.lights[0].color.w;
29
+ let amb = light.ambientColor.xyz;
30
+ let shadow = sampleShadow(input.worldPos, n);
31
+
32
+ let albedo = tex_s.rgb;
33
+
34
+ let color = eval_principled(
35
+ PrincipledIn(albedo, 0.0, DEFAULT_SPECULAR, DEFAULT_ROUGHNESS, 10.0, 0.0, 0.0),
36
+ n, l, v, sun, amb, shadow
37
+ );
38
+
39
+ var out: FSOut;
40
+ out.color = vec4f(color, alpha);
41
+ out.mask = vec4f(1.0, 1.0, 0.0, out.color.a);
42
+ return out;
43
+ }
44
+
45
+ `
@@ -1,43 +1,48 @@
1
- // Eye preset — default Principled BSDF + Emission socket set to albedo × 1.5.
2
- // Matches the published preset author's instruction: "keep eyes in the default
3
- // nodegraph, add emission 1.5". Emission feeds bloom pre-tonemap.
4
-
5
- import { NODES_WGSL } from "./nodes"
6
- import { COMMON_MATERIAL_PRELUDE_WGSL } from "./common"
7
-
8
- export const EYE_SHADER_WGSL = /* wgsl */ `
9
-
10
- ${NODES_WGSL}
11
- ${COMMON_MATERIAL_PRELUDE_WGSL}
12
-
13
- const EYE_SPECULAR: f32 = 0.5;
14
- const EYE_ROUGHNESS: f32 = 0.5;
15
- const EYE_EMISSION_STRENGTH: f32 = 1.5;
16
-
17
- @fragment fn fs(input: VertexOutput) -> FSOut {
18
- let alpha = material.alpha;
19
- if (alpha < 0.001) { discard; }
20
-
21
- let n = normalize(input.normal);
22
- let v = normalize(camera.viewPos - input.worldPos);
23
- let l = -light.lights[0].direction.xyz;
24
- let sun = light.lights[0].color.xyz * light.lights[0].color.w;
25
- let amb = light.ambientColor.xyz;
26
- let shadow = sampleShadow(input.worldPos, n);
27
-
28
- let albedo = textureSample(diffuseTexture, diffuseSampler, input.uv).rgb;
29
-
30
- let shaded = eval_principled(
31
- PrincipledIn(albedo, 0.0, EYE_SPECULAR, EYE_ROUGHNESS, 1e30, 0.0, 0.0),
32
- n, l, v, sun, amb, shadow
33
- );
34
- // Principled Emission socket: emissive = emission_color × strength, added on top.
35
- let emission = albedo * EYE_EMISSION_STRENGTH;
36
-
37
- var out: FSOut;
38
- out.color = vec4f(shaded + emission, alpha);
39
- out.mask = vec4f(1.0, 1.0, 0.0, out.color.a);
40
- return out;
41
- }
42
-
43
- `
1
+ // Eye preset — default Principled BSDF + Emission socket set to albedo × 1.5.
2
+ // Matches the published preset author's instruction: "keep eyes in the default
3
+ // nodegraph, add emission 1.5". Emission feeds bloom pre-tonemap.
4
+
5
+ import { NODES_WGSL } from "./nodes"
6
+ import { COMMON_MATERIAL_PRELUDE_WGSL } from "./common"
7
+
8
+ export const EYE_SHADER_WGSL = /* wgsl */ `
9
+
10
+ ${NODES_WGSL}
11
+ ${COMMON_MATERIAL_PRELUDE_WGSL}
12
+
13
+ const EYE_SPECULAR: f32 = 0.5;
14
+ const EYE_ROUGHNESS: f32 = 0.5;
15
+ const EYE_EMISSION_STRENGTH: f32 = 1.5;
16
+
17
+ @fragment fn fs(input: VertexOutput) -> FSOut {
18
+ let tex_s = textureSample(diffuseTexture, diffuseSampler, input.uv);
19
+ // MMD alpha semantics: material alpha × texture alpha. Hair/lace/accessory
20
+ // textures cut their shapes in the alpha channel — ignoring it renders each
21
+ // card's full quad with the texture's padding color (white shimmer on dark
22
+ // hair for models whose textures pad with white).
23
+ let alpha = material.alpha * tex_s.a;
24
+ if (alpha < 0.001) { discard; }
25
+
26
+ let n = safe_normal(input.normal);
27
+ let v = normalize(camera.viewPos - input.worldPos);
28
+ let l = -light.lights[0].direction.xyz;
29
+ let sun = light.lights[0].color.xyz * light.lights[0].color.w;
30
+ let amb = light.ambientColor.xyz;
31
+ let shadow = sampleShadow(input.worldPos, n);
32
+
33
+ let albedo = tex_s.rgb;
34
+
35
+ let shaded = eval_principled(
36
+ PrincipledIn(albedo, 0.0, EYE_SPECULAR, EYE_ROUGHNESS, 1e30, 0.0, 0.0),
37
+ n, l, v, sun, amb, shadow
38
+ );
39
+ // Principled Emission socket: emissive = emission_color × strength, added on top.
40
+ let emission = albedo * EYE_EMISSION_STRENGTH;
41
+
42
+ var out: FSOut;
43
+ out.color = vec4f(shaded + emission, alpha);
44
+ out.mask = vec4f(1.0, 1.0, 0.0, out.color.a);
45
+ return out;
46
+ }
47
+
48
+ `
@@ -1,92 +1,97 @@
1
- // M_Face — 仿深空之眼渲染预设v1.0_by_小绿毛猫 "M_Face". Toon + warm rim + dual fresnel
2
- // rim + BT.601 bright-tex gate, mixed 50/50 against a Principled BSDF with noise bump.
3
-
4
- import { NODES_WGSL } from "./nodes"
5
- import { COMMON_MATERIAL_PRELUDE_WGSL } from "./common"
6
-
7
- export const FACE_SHADER_WGSL = /* wgsl */ `
8
-
9
- ${NODES_WGSL}
10
- ${COMMON_MATERIAL_PRELUDE_WGSL}
11
-
12
- const FACE_SPECULAR: f32 = 0.5;
13
- const FACE_ROUGHNESS: f32 = 0.3;
14
- const FACE_MIX_NPR: f32 = 0.5;
15
- const FACE_SPEC_CLAMP: f32 = 10.0;
16
- const FACE_RIM2_POW: f32 = 0.6300000548362732;
17
- const FACE_RIM2_BG: vec3f = vec3f(1.0, 0.4684903025627136, 0.3698573112487793);
18
- const FACE_WARM_STR: f32 = 0.30000001192092896;
19
- const FACE_BRIGHT_TEX_THRESH: f32 = 0.9300000071525574;
20
-
21
- @fragment fn fs(input: VertexOutput) -> FSOut {
22
- let alpha = material.alpha;
23
- if (alpha < 0.001) { discard; }
24
-
25
- let n = normalize(input.normal);
26
- let v = normalize(camera.viewPos - input.worldPos);
27
- let l = -light.lights[0].direction.xyz;
28
- let sun = light.lights[0].color.xyz * light.lights[0].color.w;
29
- let amb = light.ambientColor.xyz;
30
- let shadow = sampleShadow(input.worldPos, n);
31
-
32
- let tex_color = textureSample(diffuseTexture, diffuseSampler, input.uv).rgb;
33
-
34
- // ═══ NPR STACK ═══
35
- let ndotl_raw = shader_to_rgb_diffuse(n, l, sun, amb, shadow);
36
- // ramp_constant_edge_aa: avoids binary fac shimmer on terminator (fwidth + smoothstep).
37
- let toon = ramp_constant_edge_aa(ndotl_raw, 0.2966, vec4f(0,0,0,1), vec4f(1,1,1,1)).r;
38
-
39
- let shadow_tint = hue_sat(0.46000000834465027, 2.0, 0.3499999940395355, 1.0, tex_color);
40
- let lit_tint = hue_sat(0.46000000834465027, 1.600000023841858, 1.5, 1.0, tex_color);
41
- let toon_color = mix_blend(toon, shadow_tint, lit_tint);
42
- let bc = bright_contrast(toon_color, 0.1, 0.2);
43
-
44
- let emission3 = bc * 2.5;
45
-
46
- let warm_input = clamp(toon * 0.5 + 0.5, 0.0, 1.0);
47
- let warm_color = ramp_cardinal(warm_input, 0.2409,
48
- vec4f(0.2426, 0.068, 0.0588, 1.0), 0.4663,
49
- vec4f(0.6677, 0.5024, 0.5126, 1.0)).rgb;
50
- let warm_emission = warm_color * FACE_WARM_STR;
51
-
52
- let rim1_str = fresnel(2.0, n, v) * layer_weight_facing(0.24, n, v);
53
- let rim1 = vec3f(0.984157919883728, 0.6110184788703918, 0.5736401677131653) * rim1_str;
54
-
55
- let rim2_raw = fresnel(1.45, n, v) * layer_weight_fresnel(0.61, n, v);
56
- let rim2_fac = math_power(rim2_raw, FACE_RIM2_POW);
57
- let rim2_mixed = mix(emission3, FACE_RIM2_BG, rim2_fac);
58
-
59
- // Blender implicitly converts Color → Float via BT.601 grayscale when a color output
60
- // feeds a Math node's Value input. Using tex_color.r instead fires on R-dominant skin
61
- // and produces firefly speckles on near-white R pixels — color_to_value matches the
62
- // Blender socket semantic and only gates genuinely near-white painted features.
63
- let tex_gate = math_greater_than(color_to_value(tex_color), FACE_BRIGHT_TEX_THRESH);
64
- let bright_emit = vec3f(tex_gate) * 3.0;
65
-
66
- let npr_stack = rim1 + rim2_mixed + bright_emit + warm_emission;
67
-
68
- // ═══ PRINCIPLED BSDF with noise bump ═══
69
- // Height sampled in rest space (restPos) so the micro-bump doesn't swim under motion;
70
- // bump_lh's geometric basis stays in worldPos so the perturbed normal lands in the same
71
- // world frame as n (screen-space height gradient still pairs correctly with it).
72
- let noise_val = tex_noise_d2(input.restPos * vec3f(1.0, 1.0, 1.5), 1.0);
73
- let noise_ramp = ramp_linear(noise_val, 0.0, vec4f(0,0,0,1), 1.0, vec4f(1,1,1,1)).r;
74
- let bumped_n = bump_lh(0.324644535779953, noise_ramp, n, input.worldPos);
75
-
76
- let principled_base = mix_blend(noise_ramp, bc, vec3f(0.6832, 0.1947, 0.1373));
77
- let p_emission = bc * 0.2;
78
-
79
- let principled = eval_principled(
80
- PrincipledIn(principled_base, 0.0, FACE_SPECULAR, FACE_ROUGHNESS, FACE_SPEC_CLAMP, 0.0, 0.0),
81
- bumped_n, l, v, sun, amb, shadow
82
- ) + p_emission;
83
-
84
- let final_color = mix(npr_stack, principled, FACE_MIX_NPR);
85
-
86
- var out: FSOut;
87
- out.color = vec4f(final_color, alpha);
88
- out.mask = vec4f(1.0, 1.0, 0.0, out.color.a);
89
- return out;
90
- }
91
-
92
- `
1
+ // M_Face — 仿深空之眼渲染预设v1.0_by_小绿毛猫 "M_Face". Toon + warm rim + dual fresnel
2
+ // rim + BT.601 bright-tex gate, mixed 50/50 against a Principled BSDF with noise bump.
3
+
4
+ import { NODES_WGSL } from "./nodes"
5
+ import { COMMON_MATERIAL_PRELUDE_WGSL } from "./common"
6
+
7
+ export const FACE_SHADER_WGSL = /* wgsl */ `
8
+
9
+ ${NODES_WGSL}
10
+ ${COMMON_MATERIAL_PRELUDE_WGSL}
11
+
12
+ const FACE_SPECULAR: f32 = 0.5;
13
+ const FACE_ROUGHNESS: f32 = 0.3;
14
+ const FACE_MIX_NPR: f32 = 0.5;
15
+ const FACE_SPEC_CLAMP: f32 = 10.0;
16
+ const FACE_RIM2_POW: f32 = 0.6300000548362732;
17
+ const FACE_RIM2_BG: vec3f = vec3f(1.0, 0.4684903025627136, 0.3698573112487793);
18
+ const FACE_WARM_STR: f32 = 0.30000001192092896;
19
+ const FACE_BRIGHT_TEX_THRESH: f32 = 0.9300000071525574;
20
+
21
+ @fragment fn fs(input: VertexOutput) -> FSOut {
22
+ let tex_s = textureSample(diffuseTexture, diffuseSampler, input.uv);
23
+ // MMD alpha semantics: material alpha × texture alpha. Hair/lace/accessory
24
+ // textures cut their shapes in the alpha channel — ignoring it renders each
25
+ // card's full quad with the texture's padding color (white shimmer on dark
26
+ // hair for models whose textures pad with white).
27
+ let alpha = material.alpha * tex_s.a;
28
+ if (alpha < 0.001) { discard; }
29
+
30
+ let n = safe_normal(input.normal);
31
+ let v = normalize(camera.viewPos - input.worldPos);
32
+ let l = -light.lights[0].direction.xyz;
33
+ let sun = light.lights[0].color.xyz * light.lights[0].color.w;
34
+ let amb = light.ambientColor.xyz;
35
+ let shadow = sampleShadow(input.worldPos, n);
36
+
37
+ let tex_color = tex_s.rgb;
38
+
39
+ // ═══ NPR STACK ═══
40
+ let ndotl_raw = shader_to_rgb_diffuse(n, l, sun, amb, shadow);
41
+ // ramp_constant_edge_aa: avoids binary fac shimmer on terminator (fwidth + smoothstep).
42
+ let toon = ramp_constant_edge_aa(ndotl_raw, 0.2966, vec4f(0,0,0,1), vec4f(1,1,1,1)).r;
43
+
44
+ let shadow_tint = hue_sat(0.46000000834465027, 2.0, 0.3499999940395355, 1.0, tex_color);
45
+ let lit_tint = hue_sat(0.46000000834465027, 1.600000023841858, 1.5, 1.0, tex_color);
46
+ let toon_color = mix_blend(toon, shadow_tint, lit_tint);
47
+ let bc = bright_contrast(toon_color, 0.1, 0.2);
48
+
49
+ let emission3 = bc * 2.5;
50
+
51
+ let warm_input = clamp(toon * 0.5 + 0.5, 0.0, 1.0);
52
+ let warm_color = ramp_cardinal(warm_input, 0.2409,
53
+ vec4f(0.2426, 0.068, 0.0588, 1.0), 0.4663,
54
+ vec4f(0.6677, 0.5024, 0.5126, 1.0)).rgb;
55
+ let warm_emission = warm_color * FACE_WARM_STR;
56
+
57
+ let rim1_str = fresnel(2.0, n, v) * layer_weight_facing(0.24, n, v);
58
+ let rim1 = vec3f(0.984157919883728, 0.6110184788703918, 0.5736401677131653) * rim1_str;
59
+
60
+ let rim2_raw = fresnel(1.45, n, v) * layer_weight_fresnel(0.61, n, v);
61
+ let rim2_fac = math_power(rim2_raw, FACE_RIM2_POW);
62
+ let rim2_mixed = mix(emission3, FACE_RIM2_BG, rim2_fac);
63
+
64
+ // Blender implicitly converts Color → Float via BT.601 grayscale when a color output
65
+ // feeds a Math node's Value input. Using tex_color.r instead fires on R-dominant skin
66
+ // and produces firefly speckles on near-white R pixels — color_to_value matches the
67
+ // Blender socket semantic and only gates genuinely near-white painted features.
68
+ let tex_gate = math_greater_than(color_to_value(tex_color), FACE_BRIGHT_TEX_THRESH);
69
+ let bright_emit = vec3f(tex_gate) * 3.0;
70
+
71
+ let npr_stack = rim1 + rim2_mixed + bright_emit + warm_emission;
72
+
73
+ // ═══ PRINCIPLED BSDF with noise bump ═══
74
+ // Height sampled in rest space (restPos) so the micro-bump doesn't swim under motion;
75
+ // bump_lh's geometric basis stays in worldPos so the perturbed normal lands in the same
76
+ // world frame as n (screen-space height gradient still pairs correctly with it).
77
+ let noise_val = tex_noise_d2(input.restPos * vec3f(1.0, 1.0, 1.5), 1.0);
78
+ let noise_ramp = ramp_linear(noise_val, 0.0, vec4f(0,0,0,1), 1.0, vec4f(1,1,1,1)).r;
79
+ let bumped_n = bump_lh(0.324644535779953, noise_ramp, n, input.worldPos);
80
+
81
+ let principled_base = mix_blend(noise_ramp, bc, vec3f(0.6832, 0.1947, 0.1373));
82
+ let p_emission = bc * 0.2;
83
+
84
+ let principled = eval_principled(
85
+ PrincipledIn(principled_base, 0.0, FACE_SPECULAR, FACE_ROUGHNESS, FACE_SPEC_CLAMP, 0.0, 0.0),
86
+ bumped_n, l, v, sun, amb, shadow
87
+ ) + p_emission;
88
+
89
+ let final_color = mix(npr_stack, principled, FACE_MIX_NPR);
90
+
91
+ var out: FSOut;
92
+ out.color = vec4f(final_color, alpha);
93
+ out.mask = vec4f(1.0, 1.0, 0.0, out.color.a);
94
+ return out;
95
+ }
96
+
97
+ `
@@ -1,82 +1,92 @@
1
- // M_Hair — 仿深空之眼渲染预设v1.0_by_小绿毛猫 "M_Hair". Toon + fresnel rim + bevel +
2
- // bright-tex gate, mixed 80/20 NPR/PBR. MixShader.001 Fac=0.2 keeps Principled subtle.
3
-
4
- import { NODES_WGSL } from "./nodes"
5
- import { COMMON_MATERIAL_PRELUDE_WGSL } from "./common"
6
-
7
- export const HAIR_SHADER_WGSL = /* wgsl */ `
8
-
9
- ${NODES_WGSL}
10
- ${COMMON_MATERIAL_PRELUDE_WGSL}
11
-
12
- // Pipeline-override: the engine compiles two variants — the normal opaque hair pipeline
13
- // (IS_OVER_EYES=false) and a second pipeline that re-draws hair fragments stencil-matched
14
- // against the eye stamp with 25% alpha so eyes read through the hair silhouette. Resolved
15
- // at pipeline-compile time; the dead branch is dropped by the shader compiler.
16
- override IS_OVER_EYES: bool = false;
17
-
18
- const HAIR_SPECULAR: f32 = 1.0;
19
- const HAIR_ROUGHNESS: f32 = 0.3;
20
- const HAIR_TEX_GATE_THRESH: f32 = 0.15000000596046448;
21
- const HAIR_RIM2_POW: f32 = 0.6300000548362732;
22
- const HAIR_MIX_BG: vec3f = vec3f(0.1673291176557541);
23
- const HAIR_MIX_NPR: f32 = 0.2;
24
-
25
- @fragment fn fs(input: VertexOutput) -> FSOut {
26
- let alpha = material.alpha;
27
- if (alpha < 0.001) { discard; }
28
-
29
- let n = normalize(input.normal);
30
- let v = normalize(camera.viewPos - input.worldPos);
31
- let l = -light.lights[0].direction.xyz;
32
- let sun = light.lights[0].color.xyz * light.lights[0].color.w;
33
- let amb = light.ambientColor.xyz;
34
- let shadow = sampleShadow(input.worldPos, n);
35
-
36
- let tex_color = textureSample(diffuseTexture, diffuseSampler, input.uv).rgb;
37
-
38
- // ═══ NPR STACK ═══
39
- let hue_sat_shadow = hue_sat_id(1.2, 0.5, 1.0, tex_color);
40
- let hue_sat_002 = hue_sat(0.48, 1.2, 0.7, 1.0, hue_sat_shadow);
41
- let hue_sat_001 = hue_sat_id(1.5, 1.0, 1.0, tex_color);
42
-
43
- let ndotl_raw = shader_to_rgb_diffuse(n, l, sun, amb, shadow);
44
- let ramp_008 = ramp_constant(ndotl_raw, 0.0, vec4f(0,0,0,1), 0.2966, vec4f(1,1,1,1)).r;
45
-
46
- let mix_004 = mix_blend(ramp_008, hue_sat_002, hue_sat_001);
47
- let bc = bright_contrast(mix_004, 0.1, 0.2);
48
-
49
- let bevel_z = clamp(n.y, 0.0, 1.0);
50
- let mix_003 = mix_blend(bevel_z, bc, hue_sat_002);
51
-
52
- let rim2_raw = fresnel(1.45, n, v) * layer_weight_fresnel(0.61, n, v);
53
- let rim2_fac = math_power(rim2_raw, HAIR_RIM2_POW);
54
- let mix_shader_002 = mix(mix_003, HAIR_MIX_BG, rim2_fac);
55
-
56
- // GREATER_THAN on a color input uses BT.601 luminance — same socket-semantic fix as face.ts.
57
- let tex_gate = math_greater_than(color_to_value(tex_color), HAIR_TEX_GATE_THRESH);
58
- let gate_emit = vec3f(tex_gate) * 0.1;
59
-
60
- let npr_stack = mix_shader_002 + gate_emit;
61
-
62
- // ═══ PRINCIPLED BSDF ═══
63
- // Graph has a noise→normal_map bump (Strength=0.1) on Principled.Normal, but MixShader.001
64
- // weights Principled at only 0.2 — the bumped spec × that weight is imperceptible, so we
65
- // drop the subtree and keep plain n (saves a tex_noise + bump_lh per hair fragment).
66
- let principled = eval_principled(
67
- PrincipledIn(bc, 0.0, HAIR_SPECULAR, HAIR_ROUGHNESS, 1e30, 0.0, 0.0),
68
- n, l, v, sun, amb, shadow
69
- );
70
-
71
- let final_color = mix(npr_stack, principled, HAIR_MIX_NPR);
72
-
73
- var outAlpha = alpha;
74
- if (IS_OVER_EYES) { outAlpha = alpha * 0.25; }
75
-
76
- var out: FSOut;
77
- out.color = vec4f(final_color, outAlpha);
78
- out.mask = vec4f(1.0, 1.0, 0.0, out.color.a);
79
- return out;
80
- }
81
-
82
- `
1
+ // M_Hair — 仿深空之眼渲染预设v1.0_by_小绿毛猫 "M_Hair". Toon + fresnel rim + bevel +
2
+ // bright-tex gate, mixed 80/20 NPR/PBR. MixShader.001 Fac=0.2 keeps Principled subtle.
3
+
4
+ import { NODES_WGSL } from "./nodes"
5
+ import { COMMON_MATERIAL_PRELUDE_WGSL } from "./common"
6
+
7
+ export const HAIR_SHADER_WGSL = /* wgsl */ `
8
+
9
+ ${NODES_WGSL}
10
+ ${COMMON_MATERIAL_PRELUDE_WGSL}
11
+
12
+ // Pipeline-override: the engine compiles two variants — the normal opaque hair pipeline
13
+ // (IS_OVER_EYES=false) and a second pipeline that re-draws hair fragments stencil-matched
14
+ // against the eye stamp with 25% alpha so eyes read through the hair silhouette. Resolved
15
+ // at pipeline-compile time; the dead branch is dropped by the shader compiler.
16
+ override IS_OVER_EYES: bool = false;
17
+
18
+ const HAIR_SPECULAR: f32 = 1.0;
19
+ const HAIR_ROUGHNESS: f32 = 0.3;
20
+ // EEVEE Light Clamp equivalent (same value as body/face/cloth_rough). Hair
21
+ // is the firefly-prone material: physics-animated with the noisiest blended
22
+ // normals, so grazing NV spikes the GGX term and flashes white through
23
+ // bloom without this.
24
+ const HAIR_SPEC_CLAMP: f32 = 10.0;
25
+ const HAIR_TEX_GATE_THRESH: f32 = 0.15000000596046448;
26
+ const HAIR_RIM2_POW: f32 = 0.6300000548362732;
27
+ const HAIR_MIX_BG: vec3f = vec3f(0.1673291176557541);
28
+ const HAIR_MIX_NPR: f32 = 0.2;
29
+
30
+ @fragment fn fs(input: VertexOutput) -> FSOut {
31
+ let tex_s = textureSample(diffuseTexture, diffuseSampler, input.uv);
32
+ // MMD alpha semantics: material alpha × texture alpha. Hair/lace/accessory
33
+ // textures cut their shapes in the alpha channel — ignoring it renders each
34
+ // card's full quad with the texture's padding color (white shimmer on dark
35
+ // hair for models whose textures pad with white).
36
+ let alpha = material.alpha * tex_s.a;
37
+ if (alpha < 0.001) { discard; }
38
+
39
+ let n = safe_normal(input.normal);
40
+ let v = normalize(camera.viewPos - input.worldPos);
41
+ let l = -light.lights[0].direction.xyz;
42
+ let sun = light.lights[0].color.xyz * light.lights[0].color.w;
43
+ let amb = light.ambientColor.xyz;
44
+ let shadow = sampleShadow(input.worldPos, n);
45
+
46
+ let tex_color = tex_s.rgb;
47
+
48
+ // ═══ NPR STACK ═══
49
+ let hue_sat_shadow = hue_sat_id(1.2, 0.5, 1.0, tex_color);
50
+ let hue_sat_002 = hue_sat(0.48, 1.2, 0.7, 1.0, hue_sat_shadow);
51
+ let hue_sat_001 = hue_sat_id(1.5, 1.0, 1.0, tex_color);
52
+
53
+ let ndotl_raw = shader_to_rgb_diffuse(n, l, sun, amb, shadow);
54
+ let ramp_008 = ramp_constant(ndotl_raw, 0.0, vec4f(0,0,0,1), 0.2966, vec4f(1,1,1,1)).r;
55
+
56
+ let mix_004 = mix_blend(ramp_008, hue_sat_002, hue_sat_001);
57
+ let bc = bright_contrast(mix_004, 0.1, 0.2);
58
+
59
+ let bevel_z = clamp(n.y, 0.0, 1.0);
60
+ let mix_003 = mix_blend(bevel_z, bc, hue_sat_002);
61
+
62
+ let rim2_raw = fresnel(1.45, n, v) * layer_weight_fresnel(0.61, n, v);
63
+ let rim2_fac = math_power(rim2_raw, HAIR_RIM2_POW);
64
+ let mix_shader_002 = mix(mix_003, HAIR_MIX_BG, rim2_fac);
65
+
66
+ // GREATER_THAN on a color input uses BT.601 luminance — same socket-semantic fix as face.ts.
67
+ let tex_gate = math_greater_than(color_to_value(tex_color), HAIR_TEX_GATE_THRESH);
68
+ let gate_emit = vec3f(tex_gate) * 0.1;
69
+
70
+ let npr_stack = mix_shader_002 + gate_emit;
71
+
72
+ // ═══ PRINCIPLED BSDF ═══
73
+ // Graph has a noise→normal_map bump (Strength=0.1) on Principled.Normal, but MixShader.001
74
+ // weights Principled at only 0.2 — the bumped spec × that weight is imperceptible, so we
75
+ // drop the subtree and keep plain n (saves a tex_noise + bump_lh per hair fragment).
76
+ let principled = eval_principled(
77
+ PrincipledIn(bc, 0.0, HAIR_SPECULAR, HAIR_ROUGHNESS, HAIR_SPEC_CLAMP, 0.0, 0.0),
78
+ n, l, v, sun, amb, shadow
79
+ );
80
+
81
+ let final_color = mix(npr_stack, principled, HAIR_MIX_NPR);
82
+
83
+ var outAlpha = alpha;
84
+ if (IS_OVER_EYES) { outAlpha = alpha * 0.25; }
85
+
86
+ var out: FSOut;
87
+ out.color = vec4f(final_color, outAlpha);
88
+ out.mask = vec4f(1.0, 1.0, 0.0, out.color.a);
89
+ return out;
90
+ }
91
+
92
+ `
@@ -26,7 +26,7 @@ const METAL_MIX_SHADER_FAC: f32 = 0.6967;
26
26
  const METAL_VORONOI_SCALE: f32 = 4.3;
27
27
 
28
28
  @fragment fn fs(input: VertexOutput) -> FSOut {
29
- let n = normalize(input.normal);
29
+ let n = safe_normal(input.normal);
30
30
  let v = normalize(camera.viewPos - input.worldPos);
31
31
  let l = -light.lights[0].direction.xyz;
32
32
  let sun = light.lights[0].color.xyz * light.lights[0].color.w;
@@ -66,7 +66,7 @@ fn ramp_ease_s(f: f32, p0: f32, p1: f32) -> f32 {
66
66
  }
67
67
 
68
68
  @fragment fn fs(input: VertexOutput) -> FSOut {
69
- let n = normalize(input.normal);
69
+ let n = safe_normal(input.normal);
70
70
  let v = normalize(camera.viewPos - input.worldPos);
71
71
  let l = -light.lights[0].direction.xyz;
72
72
  let sun = light.lights[0].color.xyz * light.lights[0].color.w;