reze-engine 0.17.0 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +252 -250
- package/dist/engine.d.ts +36 -1
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +258 -15
- package/dist/gpu-profile.d.ts +19 -0
- package/dist/gpu-profile.d.ts.map +1 -0
- package/dist/gpu-profile.js +120 -0
- package/dist/graph/compile.d.ts +34 -0
- package/dist/graph/compile.d.ts.map +1 -0
- package/dist/graph/compile.js +299 -0
- package/dist/graph/presets/body.d.ts +3 -0
- package/dist/graph/presets/body.d.ts.map +1 -0
- package/dist/graph/presets/body.js +100 -0
- package/dist/graph/presets/cloth_rough.d.ts +3 -0
- package/dist/graph/presets/cloth_rough.d.ts.map +1 -0
- package/dist/graph/presets/cloth_rough.js +61 -0
- package/dist/graph/presets/cloth_smooth.d.ts +3 -0
- package/dist/graph/presets/cloth_smooth.d.ts.map +1 -0
- package/dist/graph/presets/cloth_smooth.js +53 -0
- package/dist/graph/presets/default.d.ts +3 -0
- package/dist/graph/presets/default.d.ts.map +1 -0
- package/dist/graph/presets/default.js +20 -0
- package/dist/graph/presets/hair.d.ts +3 -0
- package/dist/graph/presets/hair.d.ts.map +1 -0
- package/dist/graph/presets/hair.js +79 -0
- package/dist/graph/presets/metal.d.ts +3 -0
- package/dist/graph/presets/metal.d.ts.map +1 -0
- package/dist/graph/presets/metal.js +58 -0
- package/dist/graph/presets/stockings.d.ts +3 -0
- package/dist/graph/presets/stockings.d.ts.map +1 -0
- package/dist/graph/presets/stockings.js +54 -0
- package/dist/graph/registry.d.ts +28 -0
- package/dist/graph/registry.d.ts.map +1 -0
- package/dist/graph/registry.js +322 -0
- package/dist/graph/schema.d.ts +66 -0
- package/dist/graph/schema.d.ts.map +1 -0
- package/dist/graph/schema.js +6 -0
- package/dist/graph/slots.d.ts +14 -0
- package/dist/graph/slots.d.ts.map +1 -0
- package/dist/graph/slots.js +123 -0
- package/dist/index.d.ts +11 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -0
- package/dist/physics/profile.d.ts +18 -0
- package/dist/physics/profile.d.ts.map +1 -0
- package/dist/physics/profile.js +44 -0
- package/package.json +43 -42
- package/src/engine.ts +301 -20
- package/src/graph/compile.ts +342 -0
- package/src/graph/presets/body.ts +103 -0
- package/src/graph/presets/cloth_rough.ts +64 -0
- package/src/graph/presets/cloth_smooth.ts +56 -0
- package/src/graph/presets/default.ts +23 -0
- package/src/graph/presets/hair.ts +82 -0
- package/src/graph/presets/metal.ts +61 -0
- package/src/graph/presets/stockings.ts +57 -0
- package/src/graph/registry.ts +351 -0
- package/src/graph/schema.ts +60 -0
- package/src/graph/slots.ts +145 -0
- package/src/index.ts +54 -28
- package/dist/physics-debug.d.ts +0 -30
- package/dist/physics-debug.d.ts.map +0 -1
- package/dist/physics-debug.js +0 -526
- package/dist/shaders/passes/physics-debug.d.ts +0 -2
- package/dist/shaders/passes/physics-debug.d.ts.map +0 -1
- package/dist/shaders/passes/physics-debug.js +0 -69
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
// Per-slot WGSL templates. The graph computes only `final_color`; everything the slot
|
|
2
|
+
// owns — texture sample, MMD alpha semantics, discard, lighting context, FSOut/mask
|
|
3
|
+
// writes, and built-in pass effects like hair's over-eyes stencil variant — lives here,
|
|
4
|
+
// always on, graph-invisible. Mirrors the hand-written material shaders line-for-line.
|
|
5
|
+
|
|
6
|
+
import { NODES_WGSL } from "../shaders/materials/nodes"
|
|
7
|
+
import { COMMON_MATERIAL_PRELUDE_WGSL } from "../shaders/materials/common"
|
|
8
|
+
import type { MaterialPreset } from "../engine"
|
|
9
|
+
|
|
10
|
+
export type SlotTemplate = {
|
|
11
|
+
/** Module-scope declarations (pipeline-override constants, helper fns). */
|
|
12
|
+
decls: string
|
|
13
|
+
/** Optional replacement for the standard fs() prelude (custom alpha semantics). */
|
|
14
|
+
prelude?: string
|
|
15
|
+
/** Tail of fs(): consumes `final_color` + template locals, writes FSOut. */
|
|
16
|
+
epilogue: string
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const DEFAULT_EPILOGUE = ` var out: FSOut;
|
|
20
|
+
out.color = vec4f(final_color, alpha);
|
|
21
|
+
out.mask = vec4f(1.0, 1.0, 0.0, out.color.a);
|
|
22
|
+
return out;
|
|
23
|
+
`
|
|
24
|
+
|
|
25
|
+
const DEFAULT_TEMPLATE: SlotTemplate = { decls: "", epilogue: DEFAULT_EPILOGUE }
|
|
26
|
+
|
|
27
|
+
// Hair's built-in over-eyes effect (see hair.ts): the engine compiles two pipeline
|
|
28
|
+
// variants from the same module — normal opaque hair, and a stencil-matched re-draw
|
|
29
|
+
// at 25% alpha so eyes read through the silhouette. Always on for the hair slot.
|
|
30
|
+
const HAIR_TEMPLATE: SlotTemplate = {
|
|
31
|
+
decls: `override IS_OVER_EYES: bool = false;
|
|
32
|
+
|
|
33
|
+
`,
|
|
34
|
+
epilogue: ` var outAlpha = alpha;
|
|
35
|
+
if (IS_OVER_EYES) { outAlpha = alpha * 0.25; }
|
|
36
|
+
|
|
37
|
+
var out: FSOut;
|
|
38
|
+
out.color = vec4f(final_color, outAlpha);
|
|
39
|
+
out.mask = vec4f(1.0, 1.0, 0.0, out.color.a);
|
|
40
|
+
return out;
|
|
41
|
+
`,
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Stockings' built-in alpha behavior (see stockings.ts): Wyman & McGuire hashed
|
|
45
|
+
// alpha testing on bind-pose restPos replaces the standard threshold discard —
|
|
46
|
+
// sort-independent through self-overlap, dither pinned to the fabric. The graph
|
|
47
|
+
// only computes final_color; the hash gate and the alpha=1 output are slot-owned.
|
|
48
|
+
const STOCKINGS_TEMPLATE: SlotTemplate = {
|
|
49
|
+
decls: `fn _hash3d_wm(a: vec3f) -> f32 {
|
|
50
|
+
return _hash33(a).x * 0.5 + 0.5;
|
|
51
|
+
}
|
|
52
|
+
fn hashed_alpha_threshold(co: vec3f) -> f32 {
|
|
53
|
+
let alphaHashScale: f32 = 1.0;
|
|
54
|
+
let max_deriv = max(length(dpdx(co)), length(dpdy(co)));
|
|
55
|
+
let pix_scale = 1.0 / max(alphaHashScale * max_deriv, 1e-6);
|
|
56
|
+
let pix_scale_log = log2(pix_scale);
|
|
57
|
+
let px_lo = exp2(floor(pix_scale_log));
|
|
58
|
+
let px_hi = exp2(ceil(pix_scale_log));
|
|
59
|
+
let a_lo = _hash3d_wm(floor(px_lo * co));
|
|
60
|
+
let a_hi = _hash3d_wm(floor(px_hi * co));
|
|
61
|
+
let fac = fract(pix_scale_log);
|
|
62
|
+
let x = mix(a_lo, a_hi, fac);
|
|
63
|
+
let a = min(fac, 1.0 - fac);
|
|
64
|
+
let one_a = 1.0 - a;
|
|
65
|
+
let denom = 1.0 / max(2.0 * a * one_a, 1e-6);
|
|
66
|
+
let one_x = 1.0 - x;
|
|
67
|
+
let case_lo = (x * x) * denom;
|
|
68
|
+
let case_mid = (x - 0.5 * a) / max(one_a, 1e-6);
|
|
69
|
+
let case_hi = 1.0 - (one_x * one_x) * denom;
|
|
70
|
+
var threshold = select(case_hi, select(case_lo, case_mid, x >= a), x < one_a);
|
|
71
|
+
return clamp(threshold, 1e-6, 1.0);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
`,
|
|
75
|
+
prelude: `@fragment fn fs(input: VertexOutput) -> FSOut {
|
|
76
|
+
let tex_s = textureSample(diffuseTexture, diffuseSampler, input.uv);
|
|
77
|
+
// Hashed alpha test (EEVEE "Hashed" blend) instead of the standard threshold.
|
|
78
|
+
let alpha = material.alpha * tex_s.a;
|
|
79
|
+
if (alpha < hashed_alpha_threshold(input.restPos)) { discard; }
|
|
80
|
+
|
|
81
|
+
let n = safe_normal(input.normal);
|
|
82
|
+
let v = normalize(camera.viewPos - input.worldPos);
|
|
83
|
+
let l = -light.lights[0].direction.xyz;
|
|
84
|
+
let sun = light.lights[0].color.xyz * light.lights[0].color.w;
|
|
85
|
+
let amb = light.ambientColor.xyz;
|
|
86
|
+
let shadow = sampleShadow(input.worldPos, n);
|
|
87
|
+
let tex_color = tex_s.rgb;
|
|
88
|
+
|
|
89
|
+
`,
|
|
90
|
+
epilogue: ` var out: FSOut;
|
|
91
|
+
out.color = vec4f(final_color, 1.0);
|
|
92
|
+
out.mask = vec4f(1.0, 1.0, 0.0, out.color.a);
|
|
93
|
+
return out;
|
|
94
|
+
`,
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export const SLOT_TEMPLATES: Partial<Record<MaterialPreset, SlotTemplate>> = {
|
|
98
|
+
hair: HAIR_TEMPLATE,
|
|
99
|
+
stockings: STOCKINGS_TEMPLATE,
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function slotTemplate(slot: MaterialPreset): SlotTemplate {
|
|
103
|
+
return SLOT_TEMPLATES[slot] ?? DEFAULT_TEMPLATE
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Adjust-tier uniforms — fixed 16-vec4f block (256 B) so the single shared material
|
|
107
|
+
// bind group layout serves every graph; non-graph presets bind a zero buffer.
|
|
108
|
+
export const STYLE_UNIFORMS_WGSL = `struct StyleUniforms { p: array<vec4f, 16> };
|
|
109
|
+
@group(2) @binding(4) var<uniform> style: StyleUniforms;
|
|
110
|
+
|
|
111
|
+
`
|
|
112
|
+
|
|
113
|
+
// fs() prelude — identical to the hand-written materials so template locals keep the
|
|
114
|
+
// exact names the registry's context nodes and emit functions reference.
|
|
115
|
+
const FS_PRELUDE = `@fragment fn fs(input: VertexOutput) -> FSOut {
|
|
116
|
+
let tex_s = textureSample(diffuseTexture, diffuseSampler, input.uv);
|
|
117
|
+
// MMD alpha semantics: material alpha × texture alpha (hair/lace textures cut
|
|
118
|
+
// their shapes in the alpha channel).
|
|
119
|
+
let alpha = material.alpha * tex_s.a;
|
|
120
|
+
if (alpha < 0.001) { discard; }
|
|
121
|
+
|
|
122
|
+
let n = safe_normal(input.normal);
|
|
123
|
+
let v = normalize(camera.viewPos - input.worldPos);
|
|
124
|
+
let l = -light.lights[0].direction.xyz;
|
|
125
|
+
let sun = light.lights[0].color.xyz * light.lights[0].color.w;
|
|
126
|
+
let amb = light.ambientColor.xyz;
|
|
127
|
+
let shadow = sampleShadow(input.worldPos, n);
|
|
128
|
+
let tex_color = tex_s.rgb;
|
|
129
|
+
|
|
130
|
+
`
|
|
131
|
+
|
|
132
|
+
export function assembleModule(slot: MaterialPreset, fsBody: string, includeStyleUniforms: boolean): string {
|
|
133
|
+
const tmpl = slotTemplate(slot)
|
|
134
|
+
return (
|
|
135
|
+
NODES_WGSL +
|
|
136
|
+
COMMON_MATERIAL_PRELUDE_WGSL +
|
|
137
|
+
(includeStyleUniforms ? STYLE_UNIFORMS_WGSL : "") +
|
|
138
|
+
tmpl.decls +
|
|
139
|
+
(tmpl.prelude ?? FS_PRELUDE) +
|
|
140
|
+
fsBody +
|
|
141
|
+
"\n" +
|
|
142
|
+
tmpl.epilogue +
|
|
143
|
+
"}\n"
|
|
144
|
+
)
|
|
145
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,29 +1,55 @@
|
|
|
1
|
-
export {
|
|
2
|
-
Engine,
|
|
3
|
-
DEFAULT_BLOOM_OPTIONS,
|
|
4
|
-
DEFAULT_VIEW_TRANSFORM,
|
|
5
|
-
type EngineStats,
|
|
6
|
-
type EngineOptions,
|
|
7
|
-
type BloomOptions,
|
|
8
|
-
type ViewTransformOptions,
|
|
9
|
-
type LoadModelFromFilesOptions,
|
|
10
|
-
type MaterialPreset,
|
|
11
|
-
type
|
|
12
|
-
type
|
|
13
|
-
type
|
|
14
|
-
type
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
export {
|
|
19
|
-
export
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
1
|
+
export {
|
|
2
|
+
Engine,
|
|
3
|
+
DEFAULT_BLOOM_OPTIONS,
|
|
4
|
+
DEFAULT_VIEW_TRANSFORM,
|
|
5
|
+
type EngineStats,
|
|
6
|
+
type EngineOptions,
|
|
7
|
+
type BloomOptions,
|
|
8
|
+
type ViewTransformOptions,
|
|
9
|
+
type LoadModelFromFilesOptions,
|
|
10
|
+
type MaterialPreset,
|
|
11
|
+
type ResolvedMaterialPreset,
|
|
12
|
+
type MaterialPresetMap,
|
|
13
|
+
type ApplyStyleResult,
|
|
14
|
+
type GizmoDragEvent,
|
|
15
|
+
type GizmoDragCallback,
|
|
16
|
+
type GizmoDragKind,
|
|
17
|
+
} from "./engine"
|
|
18
|
+
export { parsePmxFolderInput, pmxFileAtRelativePath, type PmxFolderInputResult } from "./folder-upload"
|
|
19
|
+
export {
|
|
20
|
+
compileGraph,
|
|
21
|
+
validateGraph,
|
|
22
|
+
assignStyleSlots,
|
|
23
|
+
type CompileOptions,
|
|
24
|
+
type CompileResult,
|
|
25
|
+
type StyleSlot,
|
|
26
|
+
} from "./graph/compile"
|
|
27
|
+
export type {
|
|
28
|
+
StyleGraph,
|
|
29
|
+
GraphNode,
|
|
30
|
+
GraphLink,
|
|
31
|
+
ExposedParam,
|
|
32
|
+
SocketValue,
|
|
33
|
+
Diagnostic,
|
|
34
|
+
} from "./graph/schema"
|
|
35
|
+
export { NODE_REGISTRY, type NodeSpec, type SockT } from "./graph/registry"
|
|
36
|
+
export { HAIR_GRAPH } from "./graph/presets/hair"
|
|
37
|
+
export { DEFAULT_GRAPH } from "./graph/presets/default"
|
|
38
|
+
export { CLOTH_SMOOTH_GRAPH } from "./graph/presets/cloth_smooth"
|
|
39
|
+
export { CLOTH_ROUGH_GRAPH } from "./graph/presets/cloth_rough"
|
|
40
|
+
export { METAL_GRAPH } from "./graph/presets/metal"
|
|
41
|
+
export { BODY_GRAPH } from "./graph/presets/body"
|
|
42
|
+
export { STOCKINGS_GRAPH } from "./graph/presets/stockings"
|
|
43
|
+
export { Model } from "./model"
|
|
44
|
+
export { Vec3, Quat, Mat4 } from "./math"
|
|
45
|
+
export type {
|
|
46
|
+
AnimationClip,
|
|
47
|
+
AnimationPlayOptions,
|
|
48
|
+
AnimationProgress,
|
|
49
|
+
BoneKeyframe,
|
|
50
|
+
MorphKeyframe,
|
|
51
|
+
BoneInterpolation,
|
|
52
|
+
ControlPoint,
|
|
53
|
+
} from "./animation"
|
|
54
|
+
export { FPS } from "./animation"
|
|
29
55
|
export { RezePhysics } from "./physics"
|
package/dist/physics-debug.d.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { RezePhysics } from "./physics";
|
|
2
|
-
export declare class PhysicsDebugRenderer {
|
|
3
|
-
private device;
|
|
4
|
-
private bindGroup;
|
|
5
|
-
private wirePipelineSphere;
|
|
6
|
-
private wirePipelineBox;
|
|
7
|
-
private wirePipelineCapsule;
|
|
8
|
-
private wireSphereBuffer;
|
|
9
|
-
private wireBoxBuffer;
|
|
10
|
-
private wireCapsuleBuffer;
|
|
11
|
-
private wireSphereCount;
|
|
12
|
-
private wireBoxCount;
|
|
13
|
-
private wireCapsuleCount;
|
|
14
|
-
private solidPipelineSphere;
|
|
15
|
-
private solidPipelineBox;
|
|
16
|
-
private solidPipelineCapsule;
|
|
17
|
-
private solidSphereBuffer;
|
|
18
|
-
private solidBoxBuffer;
|
|
19
|
-
private solidCapsuleBuffer;
|
|
20
|
-
private solidSphereCount;
|
|
21
|
-
private solidBoxCount;
|
|
22
|
-
private solidCapsuleCount;
|
|
23
|
-
private instanceBuffer;
|
|
24
|
-
private instanceData;
|
|
25
|
-
private instanceCapacity;
|
|
26
|
-
constructor(device: GPUDevice, cameraUniformBuffer: GPUBuffer, presentationFormat: GPUTextureFormat);
|
|
27
|
-
render(pass: GPURenderPassEncoder, physics: RezePhysics): void;
|
|
28
|
-
destroy(): void;
|
|
29
|
-
}
|
|
30
|
-
//# sourceMappingURL=physics-debug.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"physics-debug.d.ts","sourceRoot":"","sources":["../src/physics-debug.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAmB5C,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,MAAM,CAAW;IACzB,OAAO,CAAC,SAAS,CAAc;IAG/B,OAAO,CAAC,kBAAkB,CAAmB;IAC7C,OAAO,CAAC,eAAe,CAAmB;IAC1C,OAAO,CAAC,mBAAmB,CAAmB;IAC9C,OAAO,CAAC,gBAAgB,CAAW;IACnC,OAAO,CAAC,aAAa,CAAW;IAChC,OAAO,CAAC,iBAAiB,CAAW;IACpC,OAAO,CAAC,eAAe,CAAQ;IAC/B,OAAO,CAAC,YAAY,CAAQ;IAC5B,OAAO,CAAC,gBAAgB,CAAQ;IAIhC,OAAO,CAAC,mBAAmB,CAAmB;IAC9C,OAAO,CAAC,gBAAgB,CAAmB;IAC3C,OAAO,CAAC,oBAAoB,CAAmB;IAC/C,OAAO,CAAC,iBAAiB,CAAW;IACpC,OAAO,CAAC,cAAc,CAAW;IACjC,OAAO,CAAC,kBAAkB,CAAW;IACrC,OAAO,CAAC,gBAAgB,CAAQ;IAChC,OAAO,CAAC,aAAa,CAAQ;IAC7B,OAAO,CAAC,iBAAiB,CAAQ;IAEjC,OAAO,CAAC,cAAc,CAAW;IACjC,OAAO,CAAC,YAAY,CAAc;IAClC,OAAO,CAAC,gBAAgB,CAAQ;gBAG9B,MAAM,EAAE,SAAS,EACjB,mBAAmB,EAAE,SAAS,EAC9B,kBAAkB,EAAE,gBAAgB;IA2HtC,MAAM,CAAC,IAAI,EAAE,oBAAoB,EAAE,OAAO,EAAE,WAAW,GAAG,IAAI;IAmI9D,OAAO,IAAI,IAAI;CAShB"}
|