reze-engine 0.62.1 → 0.64.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/dist/engine.d.ts +95 -57
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +466 -162
- package/dist/graph/compile.d.ts.map +1 -1
- package/dist/graph/compile.js +4 -1
- package/dist/graph/registry.d.ts +3 -0
- package/dist/graph/registry.d.ts.map +1 -1
- package/dist/graph/registry.js +133 -0
- package/dist/graph/schema.d.ts +12 -0
- package/dist/graph/schema.d.ts.map +1 -1
- package/dist/graph/slots.d.ts.map +1 -1
- package/dist/graph/slots.js +11 -20
- package/dist/index.d.ts +9 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/shaders/lights.d.ts +3 -2
- package/dist/shaders/lights.d.ts.map +1 -1
- package/dist/shaders/lights.js +16 -3
- package/dist/shaders/materials/common.d.ts.map +1 -1
- package/dist/shaders/materials/common.js +63 -56
- package/dist/shaders/materials/nodes.d.ts +1 -1
- package/dist/shaders/materials/nodes.d.ts.map +1 -1
- package/dist/shaders/materials/nodes.js +210 -0
- package/dist/shaders/passes/composite.d.ts.map +1 -1
- package/dist/shaders/passes/composite.js +13 -1
- package/dist/shaders/passes/cull.d.ts +1 -1
- package/dist/shaders/passes/cull.d.ts.map +1 -1
- package/dist/shaders/passes/cull.js +7 -3
- package/dist/shaders/passes/ground.d.ts.map +1 -1
- package/dist/shaders/passes/ground.js +32 -55
- package/dist/shaders/passes/particles.d.ts +11 -1
- package/dist/shaders/passes/particles.d.ts.map +1 -1
- package/dist/shaders/passes/particles.js +9 -4
- package/dist/shaders/scene-light-api.d.ts +18 -10
- package/dist/shaders/scene-light-api.d.ts.map +1 -1
- package/dist/shaders/scene-light-api.js +58 -46
- package/dist/shadow-cascades.d.ts +47 -20
- package/dist/shadow-cascades.d.ts.map +1 -1
- package/dist/shadow-cascades.js +36 -13
- package/dist/unity/character.d.ts +59 -0
- package/dist/unity/character.d.ts.map +1 -0
- package/dist/unity/character.js +120 -0
- package/dist/unity/globals.d.ts +93 -0
- package/dist/unity/globals.d.ts.map +1 -0
- package/dist/unity/globals.js +340 -0
- package/dist/unity/host.d.ts +137 -0
- package/dist/unity/host.d.ts.map +1 -0
- package/dist/unity/host.js +489 -0
- package/dist/unity/looks.d.ts +88 -0
- package/dist/unity/looks.d.ts.map +1 -0
- package/dist/unity/looks.js +295 -0
- package/dist/unity/skin.d.ts +9 -0
- package/dist/unity/skin.d.ts.map +1 -0
- package/dist/unity/skin.js +117 -0
- package/dist/unity/stage.d.ts +148 -0
- package/dist/unity/stage.d.ts.map +1 -0
- package/dist/unity/stage.js +375 -0
- package/dist/unity/state.d.ts +22 -0
- package/dist/unity/state.d.ts.map +1 -0
- package/dist/unity/state.js +170 -0
- package/package.json +1 -1
- package/src/engine.ts +504 -176
- package/src/graph/compile.ts +3 -1
- package/src/graph/registry.ts +142 -0
- package/src/graph/schema.ts +9 -0
- package/src/graph/slots.ts +11 -20
- package/src/index.ts +11 -0
- package/src/shaders/lights.ts +16 -3
- package/src/shaders/materials/common.ts +63 -57
- package/src/shaders/materials/nodes.ts +210 -0
- package/src/shaders/passes/composite.ts +13 -1
- package/src/shaders/passes/cull.ts +7 -3
- package/src/shaders/passes/ground.ts +32 -55
- package/src/shaders/passes/particles.ts +19 -5
- package/src/shaders/scene-light-api.ts +59 -46
- package/src/shadow-cascades.ts +61 -32
- package/src/unity/character.ts +169 -0
- package/src/unity/globals.ts +443 -0
- package/src/unity/host.ts +587 -0
- package/src/unity/looks.ts +372 -0
- package/src/unity/skin.ts +128 -0
- package/src/unity/stage.ts +568 -0
- package/src/unity/state.ts +172 -0
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
// A Unity pass's fixed-function state (Blend, ZTest, Cull, Stencil, ColorMask,
|
|
2
|
+
// Offset), as its ShaderLab names or UnityEngine.Rendering enum numbers, into
|
|
3
|
+
// WebGPU's. Ported from the compare page's unity.js, where these were checked
|
|
4
|
+
// draw for draw against the game's frames.
|
|
5
|
+
|
|
6
|
+
/** A pass's state as the exporter writes it: each key's ShaderLab arguments. */
|
|
7
|
+
export type PassState = Record<string, (string | number)[]>
|
|
8
|
+
|
|
9
|
+
const BLEND: GPUBlendFactor[] = [
|
|
10
|
+
"zero",
|
|
11
|
+
"one",
|
|
12
|
+
"dst",
|
|
13
|
+
"src",
|
|
14
|
+
"one-minus-dst",
|
|
15
|
+
"src-alpha",
|
|
16
|
+
"one-minus-src",
|
|
17
|
+
"dst-alpha",
|
|
18
|
+
"one-minus-dst-alpha",
|
|
19
|
+
"src-alpha-saturated",
|
|
20
|
+
"one-minus-src-alpha",
|
|
21
|
+
]
|
|
22
|
+
const BLEND_NAMES: Record<string, GPUBlendFactor> = {
|
|
23
|
+
zero: "zero",
|
|
24
|
+
one: "one",
|
|
25
|
+
dstcolor: "dst",
|
|
26
|
+
srccolor: "src",
|
|
27
|
+
oneminusdstcolor: "one-minus-dst",
|
|
28
|
+
srcalpha: "src-alpha",
|
|
29
|
+
oneminussrccolor: "one-minus-src",
|
|
30
|
+
dstalpha: "dst-alpha",
|
|
31
|
+
oneminusdstalpha: "one-minus-dst-alpha",
|
|
32
|
+
srcalphasaturate: "src-alpha-saturated",
|
|
33
|
+
oneminussrcalpha: "one-minus-src-alpha",
|
|
34
|
+
}
|
|
35
|
+
const isNum = (v: unknown) => typeof v === "number" || /^-?\d+(\.\d+)?$/.test(String(v))
|
|
36
|
+
|
|
37
|
+
export function blendFactor(v: string | number | undefined): GPUBlendFactor {
|
|
38
|
+
if (v == null) return "one"
|
|
39
|
+
if (isNum(v)) return BLEND[Math.round(+v)] ?? "one"
|
|
40
|
+
return BLEND_NAMES[String(v).toLowerCase()] ?? "one"
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const BLEND_OP: GPUBlendOperation[] = ["add", "subtract", "reverse-subtract", "min", "max"]
|
|
44
|
+
export function blendOp(v: string | number | undefined): GPUBlendOperation {
|
|
45
|
+
if (v == null) return "add"
|
|
46
|
+
if (isNum(v)) return BLEND_OP[+v] ?? "add"
|
|
47
|
+
const s = String(v).toLowerCase()
|
|
48
|
+
return s === "sub" ? "subtract" : s === "revsub" ? "reverse-subtract" : s === "min" ? "min" : s === "max" ? "max" : "add"
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// CompareFunction: 0 Disabled 1 Never 2 Less 3 Equal 4 LessEqual 5 Greater 6 NotEqual 7 GreaterEqual 8 Always
|
|
52
|
+
const CMP: (GPUCompareFunction | null)[] = [null, "never", "less", "equal", "less-equal", "greater", "not-equal", "greater-equal", "always"]
|
|
53
|
+
const CMP_NAMES: Record<string, number> = {
|
|
54
|
+
never: 1,
|
|
55
|
+
less: 2,
|
|
56
|
+
equal: 3,
|
|
57
|
+
lequal: 4,
|
|
58
|
+
lessequal: 4,
|
|
59
|
+
greater: 5,
|
|
60
|
+
notequal: 6,
|
|
61
|
+
gequal: 7,
|
|
62
|
+
greaterequal: 7,
|
|
63
|
+
always: 8,
|
|
64
|
+
disabled: 8,
|
|
65
|
+
}
|
|
66
|
+
export function compare(v: string | number | undefined, fallback: GPUCompareFunction = "always"): GPUCompareFunction {
|
|
67
|
+
const n = v != null && isNum(v) ? +v : CMP_NAMES[String(v ?? "").toLowerCase()]
|
|
68
|
+
if (n == null) return fallback
|
|
69
|
+
return CMP[n] ?? "always"
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const REVERSE: Partial<Record<GPUCompareFunction, GPUCompareFunction>> = {
|
|
73
|
+
less: "greater",
|
|
74
|
+
"less-equal": "greater-equal",
|
|
75
|
+
greater: "less",
|
|
76
|
+
"greater-equal": "less-equal",
|
|
77
|
+
}
|
|
78
|
+
/** A ZTest, flipped when the depth buffer is reversed — as Unity flips it on D3D. */
|
|
79
|
+
export function depthCompare(v: string | number | undefined, reversed: boolean): GPUCompareFunction {
|
|
80
|
+
const c = compare(v ?? "LEqual", "less-equal")
|
|
81
|
+
return reversed ? (REVERSE[c] ?? c) : c
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// StencilOp: 0 Keep 1 Zero 2 Replace 3 IncrSat 4 DecrSat 5 Invert 6 IncrWrap 7 DecrWrap
|
|
85
|
+
const SOP: GPUStencilOperation[] = [
|
|
86
|
+
"keep",
|
|
87
|
+
"zero",
|
|
88
|
+
"replace",
|
|
89
|
+
"increment-clamp",
|
|
90
|
+
"decrement-clamp",
|
|
91
|
+
"invert",
|
|
92
|
+
"increment-wrap",
|
|
93
|
+
"decrement-wrap",
|
|
94
|
+
]
|
|
95
|
+
const SOP_NAMES: Record<string, number> = {
|
|
96
|
+
keep: 0,
|
|
97
|
+
zero: 1,
|
|
98
|
+
replace: 2,
|
|
99
|
+
incrsat: 3,
|
|
100
|
+
decrsat: 4,
|
|
101
|
+
invert: 5,
|
|
102
|
+
incrwrap: 6,
|
|
103
|
+
decrwrap: 7,
|
|
104
|
+
}
|
|
105
|
+
export function stencilOp(v: string | number | undefined): GPUStencilOperation {
|
|
106
|
+
if (v == null) return "keep"
|
|
107
|
+
const n = isNum(v) ? +v : SOP_NAMES[String(v).toLowerCase()]
|
|
108
|
+
return SOP[n ?? 0] ?? "keep"
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// CullMode: 0 Off 1 Front 2 Back
|
|
112
|
+
export function cull(v: string | number | undefined): GPUCullMode {
|
|
113
|
+
if (v == null) return "back"
|
|
114
|
+
const s = String(v).toLowerCase()
|
|
115
|
+
if (s === "0" || s === "off") return "none"
|
|
116
|
+
if (s === "1" || s === "front") return "front"
|
|
117
|
+
return "back"
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function zwrite(v: string | number | undefined): boolean {
|
|
121
|
+
if (v == null) return true
|
|
122
|
+
const s = String(v).toLowerCase()
|
|
123
|
+
return !(s === "0" || s === "off" || s === "false")
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** Unity ColorWriteMask (A 1, B 2, G 4, R 8, or letters) to WebGPU's (R 1, G 2, B 4, A 8). */
|
|
127
|
+
export function colorMask(v: string | number | undefined): number {
|
|
128
|
+
if (v == null) return 0xf
|
|
129
|
+
const s = String(v).toUpperCase()
|
|
130
|
+
if (/^\d+$/.test(s)) {
|
|
131
|
+
const n = +s
|
|
132
|
+
return (n & 8 ? 1 : 0) | (n & 4 ? 2 : 0) | (n & 2 ? 4 : 0) | (n & 1 ? 8 : 0)
|
|
133
|
+
}
|
|
134
|
+
return (s.includes("R") ? 1 : 0) | (s.includes("G") ? 2 : 0) | (s.includes("B") ? 4 : 0) | (s.includes("A") ? 8 : 0)
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** The colour blend a pass declares, or undefined for opaque (One Zero). */
|
|
138
|
+
export function blendState(st: PassState): GPUBlendState | undefined {
|
|
139
|
+
const b = st.Blend?.map(String)
|
|
140
|
+
if (!b?.length || b[0].toLowerCase() === "off") return undefined
|
|
141
|
+
const color: GPUBlendComponent = {
|
|
142
|
+
srcFactor: blendFactor(b[0]),
|
|
143
|
+
dstFactor: blendFactor(b[1] ?? "zero"),
|
|
144
|
+
operation: blendOp(st.BlendOp?.[0]),
|
|
145
|
+
}
|
|
146
|
+
const alpha: GPUBlendComponent =
|
|
147
|
+
b.length >= 4
|
|
148
|
+
? {
|
|
149
|
+
srcFactor: blendFactor(b[2]),
|
|
150
|
+
dstFactor: blendFactor(b[3]),
|
|
151
|
+
operation: blendOp(st.BlendOp?.[1] ?? st.BlendOp?.[0]),
|
|
152
|
+
}
|
|
153
|
+
: color
|
|
154
|
+
const opaque = (c: GPUBlendComponent) => c.srcFactor === "one" && c.dstFactor === "zero"
|
|
155
|
+
return opaque(color) && opaque(alpha) ? undefined : { color, alpha }
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** The stencil a pass declares, or undefined when it touches none. */
|
|
159
|
+
export function stencilState(st: PassState): { face: GPUStencilFaceState; read: number; write: number; ref: number } | undefined {
|
|
160
|
+
if (!st.StencilRef && !st.StencilComp) return undefined
|
|
161
|
+
return {
|
|
162
|
+
face: {
|
|
163
|
+
compare: compare(st.StencilComp?.[0] ?? "Always"),
|
|
164
|
+
passOp: stencilOp(st.StencilPass?.[0]),
|
|
165
|
+
failOp: stencilOp(st.StencilFail?.[0]),
|
|
166
|
+
depthFailOp: stencilOp(st.StencilZFail?.[0]),
|
|
167
|
+
},
|
|
168
|
+
read: +(st.StencilReadMask?.[0] ?? 255),
|
|
169
|
+
write: +(st.StencilWriteMask?.[0] ?? 255),
|
|
170
|
+
ref: st.StencilRef ? +st.StencilRef[0] : 0,
|
|
171
|
+
}
|
|
172
|
+
}
|