@margoengine/gltf 0.0.0-stage → 0.1.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 (129) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +4 -0
  3. package/README.md +1438 -3
  4. package/dist/accessor-DuqjpuxI.js +1 -0
  5. package/dist/accessor-nVsu_f1L.js +1 -0
  6. package/dist/accessor.d.ts +12 -0
  7. package/dist/asset-1b8ejkZX.js +4 -0
  8. package/dist/asset-entry.d.ts +1 -0
  9. package/dist/asset-entry.js +1 -0
  10. package/dist/asset.d.ts +319 -0
  11. package/dist/audio.d.ts +47 -0
  12. package/dist/audio.js +1 -0
  13. package/dist/auto.d.ts +29 -0
  14. package/dist/auto.js +1 -0
  15. package/dist/base-textures.d.ts +20 -0
  16. package/dist/coalesce.d.ts +29 -0
  17. package/dist/compression-D4IkO5vE.js +1 -0
  18. package/dist/compression.d.ts +15 -0
  19. package/dist/coordinates.d.ts +1 -0
  20. package/dist/coordinates.js +1 -0
  21. package/dist/dds.d.ts +7 -0
  22. package/dist/dds.js +1 -0
  23. package/dist/decoder-default-CxLH8Vz0.js +1 -0
  24. package/dist/decoder-default.d.ts +5 -0
  25. package/dist/default-materials.d.ts +8 -0
  26. package/dist/draco-state.d.ts +7 -0
  27. package/dist/draw-batch.d.ts +83 -0
  28. package/dist/draw-memo.d.ts +136 -0
  29. package/dist/errors-THVaUwlL.js +1 -0
  30. package/dist/extended.d.ts +12 -0
  31. package/dist/extended.js +1 -0
  32. package/dist/gltf.worker.d.ts +1 -0
  33. package/dist/group.d.ts +6 -0
  34. package/dist/image-limit-DvFSfR5T.js +1 -0
  35. package/dist/image-limit.d.ts +6 -0
  36. package/dist/index.d.ts +84 -0
  37. package/dist/index.js +1 -0
  38. package/dist/instanced-shader-BebTnbkj.js +5 -0
  39. package/dist/instanced-shader.d.ts +14 -0
  40. package/dist/instancing.d.ts +9 -0
  41. package/dist/instancing.js +1 -0
  42. package/dist/interactivity-graph.d.ts +193 -0
  43. package/dist/interactivity-model.d.ts +94 -0
  44. package/dist/interactivity-ops.d.ts +20 -0
  45. package/dist/interactivity.d.ts +33 -0
  46. package/dist/interactivity.js +1 -0
  47. package/dist/lights.d.ts +98 -0
  48. package/dist/lights.js +1 -0
  49. package/dist/limits-_LZ441oV.js +1 -0
  50. package/dist/material-draw-state-BHeTb1FP.js +1 -0
  51. package/dist/material-draw-state.d.ts +7 -0
  52. package/dist/material-draw.d.ts +18 -0
  53. package/dist/material-draw.js +1 -0
  54. package/dist/material-extension.d.ts +96 -0
  55. package/dist/mesh-source-DvU8YvMc.js +1 -0
  56. package/dist/meshopt.d.ts +9 -0
  57. package/dist/meshopt.js +1 -0
  58. package/dist/metadata.d.ts +114 -0
  59. package/dist/metadata.js +1 -0
  60. package/dist/model-entry.d.ts +2 -0
  61. package/dist/model-entry.js +1 -0
  62. package/dist/model-iRvuj19h.js +39 -0
  63. package/dist/model.d.ts +1011 -0
  64. package/dist/node-image-decode.d.ts +6 -0
  65. package/dist/node-matrix-R9BipGnp.js +1 -0
  66. package/dist/node-matrix.d.ts +16 -0
  67. package/dist/occlusion.d.ts +8 -0
  68. package/dist/optimize-7SEzNA23.js +1 -0
  69. package/dist/pack-BVDYuqZe.js +1 -0
  70. package/dist/pack.d.ts +27 -0
  71. package/dist/parts.d.ts +54 -0
  72. package/dist/pbr-instancing.d.ts +83 -0
  73. package/dist/pbr-instancing.js +1 -0
  74. package/dist/pbr.d.ts +13 -0
  75. package/dist/pbr.js +1 -0
  76. package/dist/physics.d.ts +148 -0
  77. package/dist/physics.js +1 -0
  78. package/dist/prepare.d.ts +26 -0
  79. package/dist/prepare.js +1 -0
  80. package/dist/progressive.d.ts +59 -0
  81. package/dist/progressive.js +4 -0
  82. package/dist/progressive.worker.d.ts +1 -0
  83. package/dist/quantized.d.ts +8 -0
  84. package/dist/quantized.js +1 -0
  85. package/dist/render-state.d.ts +18 -0
  86. package/dist/replica.d.ts +37 -0
  87. package/dist/report.d.ts +128 -0
  88. package/dist/report.js +1 -0
  89. package/dist/scene-data.d.ts +61 -0
  90. package/dist/scene-data.js +1 -0
  91. package/dist/scene-scope-CZDEkd24.js +4 -0
  92. package/dist/scene.d.ts +61 -0
  93. package/dist/scene.js +4 -0
  94. package/dist/shader-DPqfUcmp.js +405 -0
  95. package/dist/shader.d.ts +222 -0
  96. package/dist/shared/caster.d.ts +152 -0
  97. package/dist/shared/gltf.d.ts +257 -0
  98. package/dist/shared/iridescence.d.ts +2 -0
  99. package/dist/shared/prepared-geometry.d.ts +8 -0
  100. package/dist/side-shader.d.ts +1 -0
  101. package/dist/soft-mesh.d.ts +94 -0
  102. package/dist/soft-mesh.js +4 -0
  103. package/dist/spec-gloss.d.ts +21 -0
  104. package/dist/spec-gloss.js +18 -0
  105. package/dist/splat-state.d.ts +7 -0
  106. package/dist/splats.d.ts +18 -0
  107. package/dist/splats.js +1 -0
  108. package/dist/src-WMRHArDp.js +4 -0
  109. package/dist/stream-C3bKMy1B.js +1 -0
  110. package/dist/stream.d.ts +87 -0
  111. package/dist/texture-coordinates-XFsEMdU6.js +2 -0
  112. package/dist/texture-coordinates.d.ts +26 -0
  113. package/dist/texture-stream-Cu_XpyVO.js +4 -0
  114. package/dist/texture-stream.d.ts +88 -0
  115. package/dist/textured.d.ts +34 -0
  116. package/dist/textured.js +5 -0
  117. package/dist/uniform-arena.d.ts +78 -0
  118. package/dist/unit-light-DvtsuFYP.js +109 -0
  119. package/dist/version-BmU1nesQ.js +1 -0
  120. package/dist/version.d.ts +8 -0
  121. package/dist/vertex-inputs.d.ts +47 -0
  122. package/dist/view-uniform.d.ts +13 -0
  123. package/dist/visibility-C_Oqz9Sr.js +1 -0
  124. package/dist/worker-CY1TQnYX.js +1 -0
  125. package/dist/worker.d.ts +21 -0
  126. package/dist/worker.js +4 -0
  127. package/dist/workers/gltf.js +322 -0
  128. package/dist/workers/progressive.js +1 -0
  129. package/package.json +213 -6
@@ -0,0 +1,222 @@
1
+ export { iridescenceWgsl } from './shared/iridescence.js';
2
+ export declare const pbrShader: string;
3
+ export declare const extendedPBRShader: string;
4
+ /**
5
+ * Lighting hooks of the PBR fragment (contract version 1, README "Lighting hooks"). A `LightingEffect.pbr(group)` returns one;
6
+ * gltf/pbr composes it into the standard and physical shaders, so effects never search gltf/pbr's WGSL. In scope: `i` (Out),
7
+ * `s` (Surface: base, n, roughness, metal, occlusion, emissive), `v` (to the eye), `f` (Frame: eye, light, radiance...).
8
+ */
9
+ export interface PBRLighting {
10
+ /** Module-scope WGSL put before the shader: the effect's bindings in the group passed to `pbr(group)`, helper functions. */
11
+ readonly declarations: string;
12
+ /**
13
+ * Wraps the directional light term (shadows), e.g. `direct => \`shadowLit(${direct},i.position,s.n)\``. `normal`, when
14
+ * given, is the WGSL of the normal to use there in place of `s.n`: a surface lit from behind gives the side facing the light.
15
+ */
16
+ direct?(direct: string, normal?: string): string;
17
+ /** vec3f light added before the directional term (local lights). */
18
+ readonly light?: string;
19
+ /** vec3f replacing the hemisphere ambient (image-based lighting). SSAO's ambient replay returns it. At most one effect. */
20
+ readonly ambient?: string;
21
+ /**
22
+ * vec3f sky light toward the unit normal `n`, an expression in `n` (environment's HemisphereLight): it replaces the
23
+ * built-in sky gradient times its strength `f.radiance.w` wherever the shader uses it (the hemisphere ambient, the
24
+ * clearcoat and sheen defaults, an ambient hook's own fallback to it such as light probes'). An ambient hook that does
25
+ * not fall back to the gradient (image-based lighting) keeps the sky ambient beside its own, in either order. At most
26
+ * one effect.
27
+ */
28
+ readonly sky?: string;
29
+ /**
30
+ * vec3f ambient light of the clearcoat layer, before its Fresnel, in terms of `s` (Surface: `s.cn` coat normal, `s.cr`
31
+ * coat roughness) and `v` (unit vector to the eye); replaces the hemisphere in physical materials (image-based
32
+ * lighting: prefiltered radiance along the coat's reflection). Shaders without a coat ignore it. At most one effect.
33
+ */
34
+ readonly coat?: string;
35
+ /** vec3f ambient light of the sheen layer, before its colour (`s`, `v` as for `coat`); as `coat`, for sheen. */
36
+ readonly sheen?: string;
37
+ /** Wraps the display colour after tone mapping, before sRGB encoding (fog). */
38
+ output?(color: string): string;
39
+ }
40
+ /**
41
+ * Transparency hook (contract version 1, README "Transparency hook"), set with `PBRModel.setTransparency`. While set, BLEND
42
+ * primitives (no transmission, no `renderState`) leave the beauty pass and draw only when the owner calls
43
+ * `model.draw(c, 'transparent', ...)`, into `begin()`'s pass with these `targets`, depth tested (greater-equal) and not
44
+ * written. Their fragment returns `margoTransparent(color, i)` instead of `color` (the beauty colour, alpha included).
45
+ * `targets` may be empty for a hook that writes storage: `MargoTransparent` then still needs one member. Declarations
46
+ * holding `var<private> margoCoverage:u32` get the fragment's sample coverage in it before the call.
47
+ * With `blends` the hook also takes additive and multiply materials and native transmission (see `blends`).
48
+ */
49
+ export interface PBRTransparency {
50
+ /** Module-scope WGSL: `struct MargoTransparent` (one output per target), `fn margoTransparent(color:vec4f,i:Out)->MargoTransparent`, its bindings in `group`. Return the same string on steady frames. */
51
+ declarations(group: number): string;
52
+ /** Group-2 entries for those bindings (after any lighting effects' entries). */
53
+ bindings(): GPUBindGroupEntry[];
54
+ /**
55
+ * True: BLEND materials whose `renderState` holds nothing but an additive (`src-alpha`, `one`) or multiply (`zero`,
56
+ * `src`) colour blend, and native transmission when no transmission hook is set, draw here too. Declarations then hold
57
+ * `override margoKind:u32`, set per pipeline: 0 normal, 1 additive, 2 multiply, 3 the lit draw of a transmissive surface.
58
+ * Its tint draw runs first, entry `margoTint`, through `fn margoTransparentTint(share:vec4f)->MargoTransparent`, which
59
+ * may use no bindings: a tint with no maps binds only the frame group.
60
+ */
61
+ readonly blends?: boolean;
62
+ /**
63
+ * True: the surfaces write depth, and native transmission draws here whatever transmission hook is set, without its
64
+ * tint draw. For a hook used through `PBRModel.drawTransparent` after the colour has drawn.
65
+ */
66
+ readonly depthWrite?: boolean;
67
+ /**
68
+ * Present: BLEND materials whose `renderState` holds nothing but `blendSpace: 'linear'` draw here too, with the
69
+ * pipeline constant `margoLinear` true on a display-encoded target (declarations then hold `override margoLinear:bool`).
70
+ * A draw holding such a surface calls it once with `scene`, which copies the colour drawn so far into the native glass
71
+ * capture's snapshot and returns that view, for a composite in linear light; `scene` is absent until the capture runs
72
+ * (from the frame after a model first draws the option). KB3148d.
73
+ */
74
+ linearLayers?(scene?: () => GPUTextureView): void;
75
+ /** Colour targets of the transparent pass, in `MargoTransparent` location order. */
76
+ readonly targets: readonly GPUColorTargetState[];
77
+ /** This frame's transparent pass: the scene depth read-only and these targets; begun on the first draw, ended by the owner. */
78
+ begin(): GPURenderPassEncoder;
79
+ }
80
+ /**
81
+ * `code` with its face and alpha tests behind pipeline constants (margoFaceTest, margoAlphaTest): a pipeline that sets
82
+ * both false compiles without a discard and keeps early depth testing. Every compact-path pipeline sets them.
83
+ */
84
+ export declare function compactTests(code: string): string;
85
+ /** `code` (the lit PBR shader) with a `transparent` entry point returning `margoTransparent(<beauty colour>, i)`. */
86
+ export declare function transparentPBR(code: string, declarations: string): string;
87
+ /** `code` (`transparentPBR`, tint variants applied) with the transmission tint draw returning `margoTransparentTint`. */
88
+ export declare function transparentTintPBR(code: string): string;
89
+ /**
90
+ * Material capture hook (contract version 1, README "Capture hook"), set with `PBRModel.setCapture`; screen-space
91
+ * reflections (`@margoengine/post` SSR) use it. While set, `model.draw(c, 'capture', ...)` draws the model's opaque and
92
+ * MASK primitives (not BLEND, transmission or unlit) into `begin()`'s pass with these `targets`, depth tested
93
+ * (greater-equal) and written. The shader is the lit beauty shader, its lighting in a dead block (every binding stays,
94
+ * nothing is lit), with an entry point `capture` returning `margoCapture(s, v, k)`: `s` the Surface, `v` toward the eye,
95
+ * `k` the share of the base layer's light left after clearcoat and sheen, a material extension's coat included
96
+ * (vec3f(1) for standard materials). Declarations holding `var<private> margoBeauty:vec4f` turn the block on: the entry
97
+ * point stores the beauty colour there first.
98
+ */
99
+ export interface PBRCapture {
100
+ /** Module-scope WGSL for the lit shader `code`: `struct MargoCapture` (one output per target) and `fn margoCapture(s:Surface,v:vec3f,k:vec3f)->MargoCapture`. Return the same string for the same code. */
101
+ declarations(code: string): string;
102
+ /** Colour targets of the capture pass, in `MargoCapture` location order. */
103
+ readonly targets: readonly GPUColorTargetState[];
104
+ /** This frame's capture pass: these targets and a depth attachment of the context's format; begun on the first draw, ended by the owner. */
105
+ begin(): GPURenderPassEncoder;
106
+ }
107
+ /** `code` (the lit PBR shader) with a `capture` entry point returning `margoCapture(s,v,k)`; the beauty fragment becomes a dead `margoShade` call. */
108
+ export declare function capturePBR(code: string, declarations: string, keep?: string): string;
109
+ export declare const physicalMaps: string[];
110
+ export declare const extendedMaps: string[];
111
+ /** Stable unmodified physical source contract for material and node-shader consumers. */
112
+ export declare const physicalShader: () => string;
113
+ /** Map slots whose textures decode as sRGB: base colour, emissive, sheen colour, specular colour, diffuse transmission colour, multi-scatter colour. */
114
+ export declare const srgbSlots: readonly number[];
115
+ /**
116
+ * The slot whose texture binding extension slot `k` (5 or more) samples, among slots 5 to `end - 1`: `k` itself, or a slot
117
+ * holding the same glTF texture (the same image and sampler) in a view that decodes `k`'s channels right; -1 when `k` has
118
+ * no map. Slots of one colour space share; a slot reading only alpha also joins an sRGB view. sRGB slots own first, so
119
+ * specular (A) and specular colour (RGB) in one texture, the layout KHR_materials_specular suggests, share its sRGB view,
120
+ * while clearcoat (R, linear) and sheen colour (RGB, sRGB) in one texture keep two views. Each slot keeps its UV row.
121
+ */
122
+ export declare function shareOwner(maps: readonly unknown[], k: number, end?: number): number;
123
+ /**
124
+ * Native glTF physical maps: absent extension slots have their exact one-texel fallback value without a sampler, and
125
+ * slots sharing a glTF texture sample one binding (`shareOwner`), so a material with clearcoat R + roughness G, sheen
126
+ * RGB + A and specular A + RGB packed as the extensions suggest binds 5 extension textures, not 8. `packed` reads the
127
+ * five base maps from one array (`packBaseShader`); gltf/pbr asks for it only when the composed shader would pass the
128
+ * device's per-stage texture limit. Defaults to false.
129
+ */
130
+ export declare function sparsePhysicalShader(maps: readonly unknown[], packed?: boolean): string;
131
+ /** Retain the complete material/effect resource interface for a texture-dependent tint draw. */
132
+ export declare function texturedTintPBR(code: string): string;
133
+ /** `code` with a tint draw that reads the whole surface: the same bindings as the lit draw, the base colour and transmission maps included. The tint lanes hold optical depth (-1 for an opaque channel). */
134
+ export declare function surfaceTintPBR(code: string): string;
135
+ /**
136
+ * `code` (physicalShader, or factorPhysicalShader for materials built in code) for KHR_materials_transmission
137
+ * materials. Ambient and local-light hooks are evaluated (by lightPBR)
138
+ * on `margoFront(s)`, whose diffuse colour keeps only the untransmitted share (1 - transmission), as the physical
139
+ * shader's own direct and hemisphere terms do; before, an IBL lit clear glass as an opaque white diffuser. The
140
+ * `margoTint` entry is the draw that multiplies the background by the transmission tint.
141
+ */
142
+ export declare function transmissiveShader(code?: string): string;
143
+ /** physicalShader with extension maps replaced by their neutral values: factors only, extendedPBRShader's five group-1 textures.
144
+ * Drawn for physical materials whose `maps` hold only the five core slots (`@margoengine/materials`). */
145
+ export declare const factorPhysicalShader: () => string;
146
+ /**
147
+ * Transmission hook (contract version 1, README "Transmission hook"), set with `PBRModel.setTransmission`;
148
+ * `@margoengine/materials/transmission` uses it to refract the scene. While set, primitives with transmission (no
149
+ * `renderState`) leave the beauty pass and draw only when the owner calls `model.draw(c, 'transmission', ...)`, into
150
+ * `begin()`'s pass with these `targets`, depth tested (greater-equal) and not written. Their shader is the lit physical
151
+ * beauty shader with `margoTransmission(s, v, i)` (vec3f: light arriving through the surface) added to the base layer under
152
+ * clearcoat and sheen; `margoVolume` (group 0) holds the thickness factor and the per-unit-length transmittance of KHR_materials_volume.
153
+ */
154
+ export interface PBRTransmission {
155
+ /** Module-scope WGSL: `fn margoTransmission(s:Surface,v:vec3f,i:Out)->vec3f` and its bindings in `group`. Return the same string on steady frames. */
156
+ declarations(group: number): string;
157
+ /** Group-2 entries for those bindings (after any lighting effects' entries). */
158
+ bindings(): GPUBindGroupEntry[];
159
+ /** Colour targets of the transmission pass. */
160
+ readonly targets: readonly GPUColorTargetState[];
161
+ /** This frame's transmission pass: the scene colour and depth (read-only); begun on the first draw, ended by the owner. */
162
+ begin(): GPURenderPassEncoder;
163
+ }
164
+ /** `code` (the lit physical shader) with `margoTransmission(s,v,i)` added under the clearcoat and sheen layers. */
165
+ export declare function transmissionPBR(code: string, declarations: string): string;
166
+ /**
167
+ * What an extended material shades (KHR_materials_iridescence, anisotropy, diffuse_transmission and EXT_materials_bump
168
+ * and KHR_materials_volume_scatter
169
+ * in use) and which group-1 texture each map slot 5-20 samples: `slots[k]` is a binding index j (`margoMap{j}` at binding 10 + 2j) or
170
+ * -1 for the slot's default value. Base slots 0-4 always keep their own bindings 0-9 (text patches use them).
171
+ */
172
+ export interface ExtendedPlan {
173
+ /**
174
+ * The five base maps read from one array, freeing four texture units. gltf/pbr sets it on the plan it composes only when
175
+ * the shader with its lighting would pass the device's per-stage texture limit; `extendedPlan` leaves it unset.
176
+ */
177
+ readonly packedBase?: boolean;
178
+ /** Optional spec/gloss conversion, implemented only by the spec-gloss entry. Defaults to false. */
179
+ readonly specularGlossiness?: boolean;
180
+ readonly slots: readonly number[];
181
+ readonly iridescence: boolean;
182
+ readonly anisotropy: boolean;
183
+ readonly diffuseTransmission: boolean;
184
+ readonly bump?: boolean;
185
+ readonly scatter?: boolean;
186
+ /** KHR_materials_diffuse_roughness in use: the energy-preserving rough diffuse lobe. Defaults to false. */
187
+ readonly diffuseRoughness?: boolean;
188
+ }
189
+ /** Extension textures an extended material may bind: 5 base + 8 = 13, so shadows, IBL and LocalShadows (3) still fit WebGPU's 16. */
190
+ export declare const extendedTextureLimit = 8;
191
+ /**
192
+ * Binding plan for an extended material's 21 map slots (22 with a diffuse roughness texture): slots sharing a glTF texture
193
+ * in one colour space share one binding (`shareOwner`, over slots 5 to the last; their UV rows stay per slot), so specular
194
+ * (A) and specular colour (RGB) packed in one texture read its sRGB view, while clearcoat (R, linear) and sheen colour
195
+ * (RGB, sRGB) in one texture bind twice. Bindings follow each group's first slot; at most `extendedTextureLimit`, later
196
+ * groups beyond that fall back to their defaults. The view a binding holds is its first sRGB slot's, else its first slot's.
197
+ */
198
+ export declare function extendedPlan(maps: readonly ({
199
+ index: number;
200
+ } | undefined)[], features: Omit<ExtendedPlan, 'slots'>): ExtendedPlan;
201
+ export declare const eonWgsl = "fn margoEONE(mu:f32,r:f32)->f32 {let m=1-mu; return (1+r*m*(0.0571085289+m*(0.491881867+m*(-0.332181442+m*0.0714429953))))/(1+0.28779341*r);}\nfn margoEONScatter(rho:vec3f,r:f32)->vec4f {let avg=(1+0.07248822*r)/(1+0.28779341*r); let c=clamp(rho,vec3f(0),vec3f(1)); return vec4f(c*c*avg/(1-c*(1-avg)),avg);}\nfn margoEON(rho:vec3f,r:f32,nl:f32,nv:f32,st:f32)->vec3f {\n let t=st/select(1.0,max(max(nl,nv),0.0001),st>0.0); let m=margoEONScatter(rho,r);\n return rho*((1+r*t)/(1+0.28779341*r))+m.rgb*(max(1-margoEONE(nv,r),0.0)*max(1-margoEONE(nl,r),0.0)/max(1-m.a,0.0000001));\n}\nfn margoEONAlbedo(rho:vec3f,r:f32,nv:f32)->vec3f {let e=margoEONE(nv,r); return rho*e+margoEONScatter(rho,r).rgb*(1-e);}\n";
202
+ /**
203
+ * Direct light: GGX (Burley's anisotropic form when anisotropic, with the height-correlated visibility of the
204
+ * KHR_materials_anisotropy notes), Fresnel mixed with the thin-film Fresnel (diffuse weighted by 1 - its largest channel),
205
+ * diffuse reduced by transmission and split into reflection and back-side transmission (KHR_materials_diffuse_transmission),
206
+ * both rough (`eonWgsl`) when `rough` (KHR_materials_diffuse_roughness; the transmitted side mirrors the light, which keeps
207
+ * the tangent-plane dot).
208
+ * Sources: anisotropic D and V: KHR_materials_anisotropy "Implementation" (Burley 2012; Heitz 2014); isotropic
209
+ * height-correlated Smith V = G2 / (4 nl nv) = 0.5 / (nl sqrt(a2 + (1 - a2) nv^2) + nv sqrt(a2 + (1 - a2) nl^2)):
210
+ * Heitz 2014, JCGT 3(2), and glTF 2.0 Appendix B.3.2 (current revision), as `smithGCorrelated` in core's direct light.
211
+ */
212
+ export declare const directWgsl: (anisotropic: boolean, scatter?: boolean, rough?: boolean) => string;
213
+ /**
214
+ * Physical variant for an extended material (`ExtendedPlan`), cached per plan: only the extension maps the material uses
215
+ * are bound (shared textures once), the thin-film, anisotropic, diffuse-transmission and bump terms only when used, and
216
+ * a Frame with 21 slots of UV rows and six more factor rows (iri: factor, film IOR, thickness min, max; aniso: strength, cos, sin;
217
+ * its w: diffuse roughness; dtr: factor, colour; bump: factor, 1 for object space; scatter: multi-scatter colour, anisotropy; extinction: per unit
218
+ * length, thickness). Hook points and text-patch anchors are those of `physicalShader`.
219
+ */
220
+ export declare function extendedShader(plan: ExtendedPlan): string;
221
+ /** `code` reading its view rows from `margoView` (group 0, binding 3); `code` itself when it reads none. Cached. */
222
+ export declare function viewShader(code: string): string;
@@ -0,0 +1,152 @@
1
+ /** Vertex buffers of a 24-byte (core) or 80-byte (gltf/pbr) caster, plus instance matrices when `instanced`. */
2
+ export function casterBuffers(stride: number, displaced?: boolean, instanced?: boolean): GPUVertexBufferLayout[];
3
+ /** How a caster cuts its surface out like its colour pass, besides its alpha texture and cutoff. */
4
+ export interface CasterCutout {
5
+ /** UV transform of `alphaTexture` (80-byte vertices): 8 finite floats, rows (a, b, offset, unused) for u and then v. */
6
+ alphaTransform?: Float32Array;
7
+ /** Opacity map of the cut-out (materials `alphaMap`, 80-byte vertices): its green channel multiplies the alpha tested. */
8
+ opacity?: { readonly buffer: GPUBuffer; readonly view: GPUTextureView; readonly sampler: GPUSampler };
9
+ /**
10
+ * Moving UVs of the cut-out (VRMC_materials_mtoon 1.0 UV animation, 80-byte vertices): an 80-byte uniform (scroll x,
11
+ * scroll y, rotation, time; the base map's affine rows; the mask's affine rows), the mask view and its sampler. The
12
+ * alpha map is read at the animated UV in place of `alphaTransform`'s, as the colour pass reads it.
13
+ */
14
+ animation?: { readonly buffer: GPUBuffer; readonly view: GPUTextureView; readonly sampler: GPUSampler };
15
+ /** False keeps vertex alpha out of the cut-out, as the colour pass does (materials `vertexColors: false`). Default true. */
16
+ vertexAlpha?: boolean;
17
+ /**
18
+ * Cuts against hashed noise instead of `cutoff`, as materials `alphaHash()` does in its colour pass, so the shadow
19
+ * keeps a share of texels equal to the opacity: the caster shader edit (shared/alpha-hash.js `hashedDepth`) that a
20
+ * materials record hands over as `castHashed`, so only an app that imports `alphaHash` carries its WGSL. Only a
21
+ * primitive that cuts (`cutoff` above 0) uses it. Default none.
22
+ */
23
+ hashed?: (code: string) => string;
24
+ /** Vertex displacement along the normal (materials `displacementMap`, 80-byte vertices). */
25
+ displacement?: CasterDisplacement;
26
+ /** Planes that clip the shadow (materials `clippingPlanes` with `clipShadows`, 80-byte vertices). */
27
+ clip?: GPUBufferBinding;
28
+ /** Planes that clip the surface, whatever `clipShadows` says (80-byte vertices). */
29
+ surfaceClip?: GPUBufferBinding;
30
+ }
31
+ /**
32
+ * What moves a caster's vertices: a displacement map's uniform, view and sampler, or a shader patch of its own (a
33
+ * NodeMaterial's graph), with a `key` for its pipeline and its bind group.
34
+ */
35
+ export type CasterDisplacement =
36
+ | {
37
+ readonly buffer: GPUBuffer;
38
+ readonly view: GPUTextureView;
39
+ readonly sampler: GPUSampler;
40
+ readonly key?: undefined;
41
+ readonly depth?: undefined;
42
+ readonly velocity?: undefined;
43
+ readonly entries?: undefined;
44
+ readonly layout?: undefined;
45
+ readonly cuts?: undefined;
46
+ readonly move?: undefined;
47
+ readonly program?: undefined;
48
+ }
49
+ | {
50
+ readonly key: string;
51
+ depth(code: string, group: number): string;
52
+ /** TAA's object velocity shader, moved and cut as `depth` does it. Absent on a patch that does not support it. */
53
+ velocity?(code: string, group: number): string;
54
+ entries(): GPUBindGroupEntry[];
55
+ /** The group's layout, for passes that build their pipeline layouts by hand. */
56
+ layout(): GPUBindGroupLayout;
57
+ /** The patch discards fragments, so a pass that skips the fragment stage of opaque casters needs it here. */
58
+ readonly cuts: boolean;
59
+ /**
60
+ * The WGSL lines of the patch's move of `margoPosition` alone (empty: no move), and its program: TAA runs a move
61
+ * that reads the uniform block `ndu` again on last frame's bytes of it, bound at `program.next`.
62
+ */
63
+ readonly move?: readonly string[];
64
+ readonly program?: { readonly next: number; readonly buffers: WeakMap<GPUDevice, { bytes: Uint8Array }> };
65
+ };
66
+ /** A depth-only caster pipeline (less-equal depth into depth32float, line lists for `lines`). */
67
+ export function casterPipeline(
68
+ device: GPUDevice,
69
+ module: GPUShaderModule,
70
+ stride: number,
71
+ displaced: boolean,
72
+ instanced: boolean,
73
+ lines: boolean | undefined,
74
+ ): GPURenderPipeline;
75
+ /** The per-primitive draw records of `node` in `draws`, created empty on first use. */
76
+ export function nodeRecords<N, K, R>(draws: Map<N, Map<K, R>>, node: N): Map<K, R>;
77
+ /** The runtime object of a caster source; throws MargoError 'disposed' or 'attached'. */
78
+ export function casterRuntime<S extends object, R>(source: S, engine: unknown, noun: string): R;
79
+ /**
80
+ * The bind group of a displaced caster: its feature uniform, map and sampler; else undefined. Also undefined when the
81
+ * displacement binds nothing and `layout` is an automatic layout's group (`explicit` false, the default), which a
82
+ * default pipeline layout does not hold.
83
+ */
84
+ export function displacementGroup(
85
+ device: GPUDevice,
86
+ layout: () => GPUBindGroupLayout,
87
+ displacement: CasterDisplacement | undefined,
88
+ explicit?: boolean,
89
+ ): GPUBindGroup | undefined;
90
+ /** WGSL of a moving cut-out (MToon UV animation) at bindings `first` to `first` + 2 (default 7), and `margoAnimatedUV`. */
91
+ export function animationCode(group: number, first?: number): string;
92
+ /** A caster depth shader whose cut-out reads its alpha map at the animated UV, bound at 7-9 of `group`. */
93
+ export function animatedDepth(code: string, group: number, first?: number): string;
94
+ /** The bind group entries of a caster's UV `animation`, from binding `first` (default 7). */
95
+ export function animationEntries(
96
+ animation: { readonly buffer: GPUBuffer; readonly view: GPUTextureView; readonly sampler: GPUSampler },
97
+ first?: number,
98
+ ): GPUBindGroupEntry[];
99
+ /** WGSL of an opacity map at bindings `first` to `first` + 2 (default 4) of `group`, and `margoOpacityAt` of both UV sets. */
100
+ export function opacityCode(group: number, first?: number): string;
101
+ /** A caster depth shader whose cut-out also multiplies by an opacity map's green channel, bound at 4-6 of `group`. */
102
+ export function opacityDepth(code: string, group: number): string;
103
+ /** The bind group entries of a caster's `opacity`, from binding `first` (default 4). */
104
+ export function opacityEntries(
105
+ opacity: {
106
+ buffer: GPUBuffer;
107
+ view: GPUTextureView;
108
+ sampler: GPUSampler;
109
+ },
110
+ first?: number,
111
+ ): GPUBindGroupEntry[];
112
+ /** A caster shader that leaves vertex alpha out of its cut-out (a primitive with `vertexAlpha: false`). */
113
+ export function solidVertexDepth(code: string): string;
114
+ /** A caster shader that discards what uniform `name`'s planes cut away, bound at `binding` of group 0. */
115
+ export function clippedDepth(code: string, binding: number, name: string, hardware?: boolean): string;
116
+ /** A cleared depth-only pass descriptor; set `depthStencilAttachment.view` before each use. */
117
+ export function depthPassDescriptor(): GPURenderPassDescriptor & {
118
+ depthStencilAttachment: GPURenderPassDepthStencilAttachment;
119
+ };
120
+ /** Writes one caster's uniform (view, node matrix, alpha, cutoff at least `floor`, uv set, alpha transform), uploads it and draws. */
121
+ export function drawCaster(
122
+ pass: GPURenderPassEncoder,
123
+ device: GPUDevice,
124
+ pipeline: GPURenderPipeline,
125
+ group: GPUBindGroup,
126
+ uniform: GPUBuffer,
127
+ values: Float32Array<ArrayBuffer>,
128
+ view: ArrayLike<number>,
129
+ p: {
130
+ node: { matrix: ArrayLike<number> };
131
+ alpha?: number;
132
+ cutoff?: number;
133
+ texCoord?: number;
134
+ vertex: GPUBuffer;
135
+ /** Byte offset of the caster's vertices in `vertex`. Default 0. */
136
+ vertexOffset?: number;
137
+ index: GPUBuffer;
138
+ count: number;
139
+ },
140
+ transform: ArrayLike<number> | undefined | null,
141
+ displaced: GPUBindGroup | undefined,
142
+ instances: { upload(device: GPUDevice): GPUBuffer; count: number } | undefined | null,
143
+ /** Lowest cutoff written: the larger of this and `p.cutoff`. Default 0. */
144
+ floor?: number,
145
+ ): void;
146
+ /** Whether a caster's cached draw `record` no longer fits primitive `p` drawn with `pipeline` and `displacement`. */
147
+ export function staleCaster<R extends object>(
148
+ record: R | undefined,
149
+ p: { vertex: GPUBuffer; alphaTexture?: unknown; alphaSampler?: unknown; opacity?: unknown; animation?: unknown },
150
+ pipeline: GPURenderPipeline,
151
+ displacement: unknown,
152
+ ): record is undefined;
@@ -0,0 +1,257 @@
1
+ /** Structural glTF 2.0 data consumed by the optional loaders. Runtime validation stays at each use site. */
2
+ export interface GLTFProperty<E extends Record<string, unknown> = GLTFExtensions> {
3
+ name?: string;
4
+ extras?: unknown;
5
+ extensions?: E;
6
+ [key: string]: unknown;
7
+ }
8
+
9
+ /** One entry of EXT_lights_image_based `lights`. */
10
+ export interface GLTFImageBasedLight extends GLTFProperty {
11
+ rotation?: number[];
12
+ intensity?: number;
13
+ irradianceCoefficients: number[][];
14
+ specularImages: number[][];
15
+ specularImageSize: number;
16
+ }
17
+
18
+ /** Known extension payloads retain their schema; application-specific extensions remain unknown. */
19
+ export interface GLTFExtensions {
20
+ [key: string]: unknown;
21
+ KHR_draco_mesh_compression?: { bufferView: number; attributes: Record<string, number> };
22
+ EXT_meshopt_compression?: GLTFMeshopt;
23
+ KHR_meshopt_compression?: GLTFMeshopt;
24
+ KHR_texture_basisu?: { source: number };
25
+ MSFT_texture_dds?: { source: number };
26
+ EXT_texture_webp?: { source: number };
27
+ EXT_texture_avif?: { source: number };
28
+ KHR_texture_transform?: GLTFTextureTransform;
29
+ EXT_mesh_gpu_instancing?: GLTFInstancing;
30
+ KHR_lights_punctual?: { light?: number; lights?: GLTFLightDefinition[] };
31
+ // On the document: `lights`. On a node: `light`, `multiplier`, `color`.
32
+ EXT_lights_ies?: {
33
+ lights?: { name?: string; uri?: string; bufferView?: number; mimeType?: string }[];
34
+ light?: number;
35
+ multiplier?: number;
36
+ color?: number[];
37
+ };
38
+ // On the document: `lights`. On a scene: `light`.
39
+ EXT_lights_image_based?: { lights?: GLTFImageBasedLight[]; light?: number };
40
+ KHR_node_visibility?: { visible?: boolean };
41
+ KHR_materials_variants?: { variants?: { name: string }[]; mappings?: { material: number; variants: number[] }[] };
42
+ KHR_materials_unlit?: object;
43
+ KHR_materials_emissive_strength?: { emissiveStrength?: number };
44
+ KHR_materials_ior?: { ior?: number };
45
+ KHR_materials_dispersion?: { dispersion?: number };
46
+ KHR_materials_clearcoat?: {
47
+ clearcoatFactor?: number;
48
+ clearcoatRoughnessFactor?: number;
49
+ clearcoatTexture?: GLTFTextureInfo;
50
+ clearcoatRoughnessTexture?: GLTFTextureInfo;
51
+ clearcoatNormalTexture?: GLTFTextureInfo;
52
+ };
53
+ KHR_materials_transmission?: { transmissionFactor?: number; transmissionTexture?: GLTFTextureInfo };
54
+ KHR_materials_volume?: {
55
+ thicknessFactor?: number;
56
+ thicknessTexture?: GLTFTextureInfo;
57
+ attenuationDistance?: number;
58
+ attenuationColor?: number[];
59
+ };
60
+ KHR_materials_sheen?: {
61
+ sheenColorFactor?: number[];
62
+ sheenRoughnessFactor?: number;
63
+ sheenColorTexture?: GLTFTextureInfo;
64
+ sheenRoughnessTexture?: GLTFTextureInfo;
65
+ };
66
+ KHR_materials_specular?: {
67
+ specularFactor?: number;
68
+ specularColorFactor?: number[];
69
+ specularTexture?: GLTFTextureInfo;
70
+ specularColorTexture?: GLTFTextureInfo;
71
+ };
72
+ KHR_materials_iridescence?: {
73
+ iridescenceFactor?: number;
74
+ iridescenceIor?: number;
75
+ iridescenceThicknessMinimum?: number;
76
+ iridescenceThicknessMaximum?: number;
77
+ iridescenceTexture?: GLTFTextureInfo;
78
+ iridescenceThicknessTexture?: GLTFTextureInfo;
79
+ };
80
+ KHR_materials_anisotropy?: {
81
+ anisotropyStrength?: number;
82
+ anisotropyRotation?: number;
83
+ anisotropyTexture?: GLTFTextureInfo;
84
+ };
85
+ KHR_materials_diffuse_roughness?: {
86
+ diffuseRoughnessFactor?: number;
87
+ diffuseRoughnessTexture?: GLTFTextureInfo;
88
+ };
89
+ KHR_materials_diffuse_transmission?: {
90
+ diffuseTransmissionFactor?: number;
91
+ diffuseTransmissionColorFactor?: number[];
92
+ diffuseTransmissionTexture?: GLTFTextureInfo;
93
+ diffuseTransmissionColorTexture?: GLTFTextureInfo;
94
+ };
95
+ KHR_materials_volume_scatter?: {
96
+ multiscatterColorFactor?: number[];
97
+ multiscatterColorTexture?: GLTFTextureInfo;
98
+ scatterAnisotropy?: number;
99
+ };
100
+ EXT_materials_bump?: {
101
+ bumpFactor?: number;
102
+ bumpTexture?: GLTFTextureInfo;
103
+ heightSpace?: 'world' | 'object';
104
+ };
105
+ }
106
+ export interface GLTFMeshopt {
107
+ fallback?: boolean;
108
+ buffer: number;
109
+ byteOffset?: number;
110
+ byteLength: number;
111
+ byteStride: number;
112
+ count: number;
113
+ mode: string;
114
+ filter?: string;
115
+ }
116
+ export interface GLTFInstancing {
117
+ attributes: Record<string, number>;
118
+ }
119
+ export interface GLTFTextureTransform {
120
+ offset?: readonly [number, number];
121
+ rotation?: number;
122
+ scale?: readonly [number, number];
123
+ texCoord?: number;
124
+ }
125
+ export interface GLTFTextureInfo extends GLTFProperty {
126
+ index: number;
127
+ texCoord?: number;
128
+ scale?: number;
129
+ strength?: number;
130
+ }
131
+ export interface GLTFBufferExtensions {
132
+ [key: string]: unknown;
133
+ EXT_meshopt_compression?: { fallback?: boolean };
134
+ }
135
+ export interface GLTFBuffer extends GLTFProperty<GLTFBufferExtensions> {
136
+ byteLength: number;
137
+ uri?: string;
138
+ }
139
+ export interface GLTFBufferView extends GLTFProperty {
140
+ buffer: number;
141
+ byteLength: number;
142
+ byteOffset?: number;
143
+ byteStride?: number;
144
+ target?: number;
145
+ }
146
+ export interface GLTFAccessor extends GLTFProperty {
147
+ bufferView?: number;
148
+ byteOffset?: number;
149
+ componentType: number;
150
+ count: number;
151
+ type: string;
152
+ normalized?: boolean;
153
+ min?: number[];
154
+ max?: number[];
155
+ sparse?: {
156
+ count: number;
157
+ indices: { bufferView: number; byteOffset?: number; componentType: number };
158
+ values: { bufferView: number; byteOffset?: number };
159
+ };
160
+ }
161
+ export interface GLTFPrimitive extends GLTFProperty {
162
+ /** Absent for engine-owned prepared geometry whose vertices are supplied separately. */
163
+ attributes?: Record<string, number>;
164
+ indices?: number;
165
+ material?: number;
166
+ mode?: number;
167
+ targets?: Record<string, number>[];
168
+ }
169
+ export interface GLTFMesh extends GLTFProperty {
170
+ primitives: GLTFPrimitive[];
171
+ weights?: number[];
172
+ }
173
+ export interface GLTFNode extends GLTFProperty {
174
+ mesh?: number;
175
+ skin?: number;
176
+ camera?: number;
177
+ children?: number[];
178
+ matrix?: number[];
179
+ translation?: number[];
180
+ rotation?: number[];
181
+ scale?: number[];
182
+ weights?: number[];
183
+ }
184
+ export interface GLTFMaterial extends GLTFProperty {
185
+ pbrMetallicRoughness?: {
186
+ baseColorFactor?: number[];
187
+ metallicFactor?: number;
188
+ roughnessFactor?: number;
189
+ baseColorTexture?: GLTFTextureInfo;
190
+ metallicRoughnessTexture?: GLTFTextureInfo;
191
+ };
192
+ normalTexture?: GLTFTextureInfo;
193
+ occlusionTexture?: GLTFTextureInfo;
194
+ emissiveTexture?: GLTFTextureInfo;
195
+ emissiveFactor?: number[];
196
+ alphaMode?: string;
197
+ alphaCutoff?: number;
198
+ doubleSided?: boolean;
199
+ }
200
+ export interface GLTFTexture extends GLTFProperty {
201
+ source?: number;
202
+ sampler?: number;
203
+ }
204
+ export interface GLTFImageDefinition extends GLTFProperty {
205
+ uri?: string;
206
+ mimeType?: string;
207
+ bufferView?: number;
208
+ }
209
+ export interface GLTFSampler extends GLTFProperty {
210
+ wrapS?: number;
211
+ wrapT?: number;
212
+ magFilter?: number;
213
+ minFilter?: number;
214
+ }
215
+ export interface GLTFSkin extends GLTFProperty {
216
+ joints: number[];
217
+ inverseBindMatrices?: number;
218
+ skeleton?: number;
219
+ }
220
+ export interface GLTFAnimation extends GLTFProperty {
221
+ samplers: { input: number; output: number; interpolation?: string }[];
222
+ channels: { sampler: number; target: { node?: number; path: string; extensions?: Record<string, unknown> } }[];
223
+ }
224
+ export interface GLTFLightDefinition extends GLTFProperty {
225
+ type: 'directional' | 'point' | 'spot';
226
+ color?: number[];
227
+ intensity?: number;
228
+ range?: number;
229
+ spot?: { innerConeAngle?: number; outerConeAngle?: number };
230
+ }
231
+ export interface GLTFCameraDefinition extends GLTFProperty {
232
+ type: 'perspective' | 'orthographic';
233
+ perspective?: { yfov: number; znear: number; zfar?: number; aspectRatio?: number };
234
+ orthographic?: { xmag: number; ymag: number; znear: number; zfar: number };
235
+ }
236
+ /**
237
+ * A glTF 2.0 JSON document as the loaders read it: scenes, nodes, meshes, materials, animations and the other top-level arrays.
238
+ */
239
+ export interface GLTFDocument extends GLTFProperty {
240
+ asset?: { version: string; generator?: string; [key: string]: unknown };
241
+ buffers?: GLTFBuffer[];
242
+ bufferViews?: GLTFBufferView[];
243
+ accessors?: GLTFAccessor[];
244
+ meshes?: GLTFMesh[];
245
+ nodes?: GLTFNode[];
246
+ scenes?: (GLTFProperty & { nodes?: number[] })[];
247
+ scene?: number;
248
+ materials?: GLTFMaterial[];
249
+ textures?: GLTFTexture[];
250
+ images?: GLTFImageDefinition[];
251
+ samplers?: GLTFSampler[];
252
+ skins?: GLTFSkin[];
253
+ animations?: GLTFAnimation[];
254
+ cameras?: GLTFCameraDefinition[];
255
+ extensionsUsed?: string[];
256
+ extensionsRequired?: string[];
257
+ }
@@ -0,0 +1,2 @@
1
+ /** Shared clean-room thin-film Fresnel WGSL from Belcour and Barla (2017), with the Khronos Gaussian sensitivity fit. */
2
+ export const iridescenceWgsl: string;
@@ -0,0 +1,8 @@
1
+ /** Validate packed triangle geometry without loading its renderer. */
2
+ export function validatePreparedGeometry(data: {
3
+ vertices: Float32Array;
4
+ indices: Uint32Array;
5
+ interpolatedDirections?: boolean;
6
+ }): void;
7
+ /** Validate an already checked vertex range. */
8
+ export function checkPreparedVertices(vertices: Float32Array, from: number, to: number, interpolated?: boolean): void;
@@ -0,0 +1 @@
1
+ export declare function backSideShader(code: string): string;