@yali-engine/render 0.0.0-stage → 0.4.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/bvh.d.ts +66 -0
- package/dist/bvh.js +493 -0
- package/dist/bvh.js.map +1 -0
- package/dist/camera.d.ts +34 -0
- package/dist/camera.js +66 -0
- package/dist/camera.js.map +1 -0
- package/dist/cluster-build.d.ts +46 -0
- package/dist/cluster-build.js +179 -0
- package/dist/cluster-build.js.map +1 -0
- package/dist/cluster-pages.d.ts +70 -0
- package/dist/cluster-pages.js +203 -0
- package/dist/cluster-pages.js.map +1 -0
- package/dist/cluster-stream.d.ts +83 -0
- package/dist/cluster-stream.js +226 -0
- package/dist/cluster-stream.js.map +1 -0
- package/dist/culled-draws.d.ts +30 -0
- package/dist/culled-draws.js +103 -0
- package/dist/culled-draws.js.map +1 -0
- package/dist/debug-lines.d.ts +51 -0
- package/dist/debug-lines.js +158 -0
- package/dist/debug-lines.js.map +1 -0
- package/dist/device-profile.d.ts +100 -0
- package/dist/device-profile.js +131 -0
- package/dist/device-profile.js.map +1 -0
- package/dist/device.d.ts +39 -0
- package/dist/device.js +79 -0
- package/dist/device.js.map +1 -0
- package/dist/environment.d.ts +60 -0
- package/dist/environment.js +204 -0
- package/dist/environment.js.map +1 -0
- package/dist/extract.d.ts +74 -0
- package/dist/extract.js +194 -0
- package/dist/extract.js.map +1 -0
- package/dist/frame-graph.d.ts +112 -0
- package/dist/frame-graph.js +226 -0
- package/dist/frame-graph.js.map +1 -0
- package/dist/gpu-health.d.ts +74 -0
- package/dist/gpu-health.js +106 -0
- package/dist/gpu-health.js.map +1 -0
- package/dist/gpu-timer.d.ts +26 -0
- package/dist/gpu-timer.js +93 -0
- package/dist/gpu-timer.js.map +1 -0
- package/dist/headless.d.ts +28 -0
- package/dist/headless.js +91 -0
- package/dist/headless.js.map +1 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.js +36 -0
- package/dist/index.js.map +1 -0
- package/dist/lights.d.ts +81 -0
- package/dist/lights.js +247 -0
- package/dist/lights.js.map +1 -0
- package/dist/matrix.d.ts +6 -0
- package/dist/matrix.js +59 -0
- package/dist/matrix.js.map +1 -0
- package/dist/meshes.d.ts +411 -0
- package/dist/meshes.js +545 -0
- package/dist/meshes.js.map +1 -0
- package/dist/meshlets-decoder.d.ts +20 -0
- package/dist/meshlets-decoder.js +47 -0
- package/dist/meshlets-decoder.js.map +1 -0
- package/dist/meshlets.d.ts +186 -0
- package/dist/meshlets.js +1040 -0
- package/dist/meshlets.js.map +1 -0
- package/dist/occlusion.d.ts +51 -0
- package/dist/occlusion.js +188 -0
- package/dist/occlusion.js.map +1 -0
- package/dist/pick-decoder.d.ts +19 -0
- package/dist/pick-decoder.js +45 -0
- package/dist/pick-decoder.js.map +1 -0
- package/dist/pick.d.ts +86 -0
- package/dist/pick.js +452 -0
- package/dist/pick.js.map +1 -0
- package/dist/pipeline-cache.d.ts +53 -0
- package/dist/pipeline-cache.js +96 -0
- package/dist/pipeline-cache.js.map +1 -0
- package/dist/post-options.d.ts +109 -0
- package/dist/post-options.js +23 -0
- package/dist/post-options.js.map +1 -0
- package/dist/post-shaders.gen.d.ts +40 -0
- package/dist/post-shaders.gen.js +43 -0
- package/dist/post-shaders.gen.js.map +1 -0
- package/dist/post.d.ts +101 -0
- package/dist/post.js +555 -0
- package/dist/post.js.map +1 -0
- package/dist/render-plugin.d.ts +239 -0
- package/dist/render-plugin.js +633 -0
- package/dist/render-plugin.js.map +1 -0
- package/dist/scene.d.ts +406 -0
- package/dist/scene.js +2005 -0
- package/dist/scene.js.map +1 -0
- package/dist/shaders.gen.d.ts +40 -0
- package/dist/shaders.gen.js +43 -0
- package/dist/shaders.gen.js.map +1 -0
- package/dist/shadows.d.ts +104 -0
- package/dist/shadows.js +227 -0
- package/dist/shadows.js.map +1 -0
- package/dist/staging-ring.d.ts +41 -0
- package/dist/staging-ring.js +125 -0
- package/dist/staging-ring.js.map +1 -0
- package/dist/textures.d.ts +165 -0
- package/dist/textures.js +361 -0
- package/dist/textures.js.map +1 -0
- package/dist/tonemap.d.ts +45 -0
- package/dist/tonemap.js +141 -0
- package/dist/tonemap.js.map +1 -0
- package/dist/viewport.d.ts +78 -0
- package/dist/viewport.js +130 -0
- package/dist/viewport.js.map +1 -0
- package/dist/webgl2/plugin.d.ts +40 -0
- package/dist/webgl2/plugin.js +190 -0
- package/dist/webgl2/plugin.js.map +1 -0
- package/dist/webgl2/program.d.ts +27 -0
- package/dist/webgl2/program.js +74 -0
- package/dist/webgl2/program.js.map +1 -0
- package/dist/webgl2/renderer.d.ts +128 -0
- package/dist/webgl2/renderer.js +976 -0
- package/dist/webgl2/renderer.js.map +1 -0
- package/dist/webgl2/shaders.glsl.gen.d.ts +27 -0
- package/dist/webgl2/shaders.glsl.gen.js +20 -0
- package/dist/webgl2/shaders.glsl.gen.js.map +1 -0
- package/dist/webgl2/textures.d.ts +11 -0
- package/dist/webgl2/textures.js +82 -0
- package/dist/webgl2/textures.js.map +1 -0
- package/dist/webgl2/webgl2.d.ts +1 -0
- package/dist/webgl2/webgl2.js +4 -0
- package/dist/webgl2/webgl2.js.map +1 -0
- package/dist/worker-mode.d.ts +85 -0
- package/dist/worker-mode.js +204 -0
- package/dist/worker-mode.js.map +1 -0
- package/package.json +47 -3
- package/README.md +0 -3
package/dist/meshes.d.ts
ADDED
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
import { type Component, type World } from '@yali-engine/core';
|
|
2
|
+
import { TextureRef } from './textures.ts';
|
|
3
|
+
/** Floats per interleaved vertex in the geometry pool (position, normal, uv), for decode workers. */
|
|
4
|
+
export declare const MESH_VERTEX_FLOATS = 8;
|
|
5
|
+
/** Most LODs a mesh may have (LOD 0 included; `shaders/scene/instance.wesl` `MAX_LODS`). */
|
|
6
|
+
export declare const MAX_LODS = 8;
|
|
7
|
+
/** The mesh id of the unit cube every `MeshStore` starts with. */
|
|
8
|
+
export declare const CUBE_MESH = 0;
|
|
9
|
+
/** A coarser level of detail: indices into the same vertices, and its mesh-space error. */
|
|
10
|
+
export interface MeshLod {
|
|
11
|
+
readonly indices: Uint32Array;
|
|
12
|
+
/** How far, in mesh units, this LOD's surface may be from the full mesh's. */
|
|
13
|
+
readonly error: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* One mesh's geometry, as a loader hands it over: separate attributes (the glTF primitive
|
|
17
|
+
* shape), or already interleaved by a decode worker (8 floats per vertex: position,
|
|
18
|
+
* normal, uv), which keeps the main-thread step to storing a reference. `lods` are the
|
|
19
|
+
* coarser levels, finest first (LOD 0 is `indices`).
|
|
20
|
+
*/
|
|
21
|
+
export type MeshData = ({
|
|
22
|
+
readonly positions: Float32Array;
|
|
23
|
+
readonly normals: Float32Array;
|
|
24
|
+
readonly uvs?: Float32Array | null;
|
|
25
|
+
readonly indices: Uint32Array;
|
|
26
|
+
} | {
|
|
27
|
+
readonly vertices: Float32Array;
|
|
28
|
+
readonly indices: Uint32Array;
|
|
29
|
+
}) & {
|
|
30
|
+
readonly lods?: readonly MeshLod[];
|
|
31
|
+
readonly state?: MeshState;
|
|
32
|
+
/**
|
|
33
|
+
* A skinned mesh's skin stream (ADR-0088): per vertex 4 joint slots (u16) then 4 weights
|
|
34
|
+
* (unorm16, summing to 65535 or all 0 for a vertex drawn unskinned), `packSkin`'s layout. A
|
|
35
|
+
* skinned mesh lives in the skinned pool and draws with the skinned draw classes.
|
|
36
|
+
*/
|
|
37
|
+
readonly skin?: Uint16Array;
|
|
38
|
+
/** The culling radius about its bounds' centre, when the vertices move past them (GPU cloth, ADR-0101). */
|
|
39
|
+
readonly radius?: number;
|
|
40
|
+
/**
|
|
41
|
+
* Its clusters, packed ahead of time (`yali convert --clusters`, ADR-0121): `packClusters`' output
|
|
42
|
+
* over these vertices and whether it is a LOD hierarchy. `meshlets()` uses them instead of
|
|
43
|
+
* building (when `lod` matches its own).
|
|
44
|
+
*/
|
|
45
|
+
readonly clusters?: PrebuiltClusters;
|
|
46
|
+
/**
|
|
47
|
+
* Its cluster hierarchy in streaming pages (`yali convert --clusters --stream`, ADR-0134): these
|
|
48
|
+
* vertices and indices are its root pages' mesh; `meshlets({ lod: true })` streams the rest.
|
|
49
|
+
*/
|
|
50
|
+
readonly pages?: StreamedClusters;
|
|
51
|
+
/**
|
|
52
|
+
* Vertices to reserve in its block, at least its own (ADR-0134: room for streamed pages after its
|
|
53
|
+
* root vertices; `writeVertices` fills it). Its bounds are its own vertices'.
|
|
54
|
+
*/
|
|
55
|
+
readonly vertexCapacity?: number;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* A mesh's cluster hierarchy in streaming pages (ADR-0134), as `YALI_cluster_pages` carries it, and
|
|
59
|
+
* the absolute URL of the file with its pages past the roots.
|
|
60
|
+
*/
|
|
61
|
+
export interface StreamedClusters {
|
|
62
|
+
readonly words: Uint32Array;
|
|
63
|
+
readonly pages: Uint32Array;
|
|
64
|
+
readonly roots: number;
|
|
65
|
+
readonly localIds: number;
|
|
66
|
+
readonly triangleBytes: number;
|
|
67
|
+
readonly corners: number;
|
|
68
|
+
readonly slotVertices: number;
|
|
69
|
+
readonly rootData: Uint8Array;
|
|
70
|
+
/** The pages file; a page at table offset `o` is at `base + o - rootData.length` in it. */
|
|
71
|
+
readonly url: string;
|
|
72
|
+
readonly base: number;
|
|
73
|
+
}
|
|
74
|
+
/** A mesh's clusters packed ahead of time (ADR-0121): `PackedClusters` and whether they are a LOD hierarchy. */
|
|
75
|
+
export interface PrebuiltClusters {
|
|
76
|
+
readonly lod: boolean;
|
|
77
|
+
readonly words: Uint32Array;
|
|
78
|
+
readonly vertices: Uint32Array;
|
|
79
|
+
readonly triangles: Uint8Array;
|
|
80
|
+
readonly corners: number;
|
|
81
|
+
}
|
|
82
|
+
/** Bytes per vertex of the skin stream: 4 × u16 joints, 4 × unorm16 weights. */
|
|
83
|
+
export declare const SKIN_STREAM_BYTES = 16;
|
|
84
|
+
/**
|
|
85
|
+
* Packs 4 joints and 4 weights per vertex (glTF `JOINTS_0` / `WEIGHTS_0`, weights summing to 1)
|
|
86
|
+
* into the skin stream's layout: u16 joints, then the weights as unorm16 rounded so they sum to
|
|
87
|
+
* exactly 65535 (the largest absorbs the rounding).
|
|
88
|
+
*/
|
|
89
|
+
export declare function packSkin(joints: ArrayLike<number>, weights: ArrayLike<number>, count: number): Uint16Array;
|
|
90
|
+
/**
|
|
91
|
+
* How a mesh draws (ADR-0081): its material's alpha mode (glTF `alphaMode`; the cutoff is the
|
|
92
|
+
* material's `alphaCutoff`) and whether its back faces draw (glTF `doubleSided`). Per mesh, not
|
|
93
|
+
* per instance: draws are grouped per mesh, and a glTF primitive has one material.
|
|
94
|
+
*/
|
|
95
|
+
export interface MeshState {
|
|
96
|
+
readonly alpha?: 'opaque' | 'mask' | 'blend';
|
|
97
|
+
readonly doubleSided?: boolean;
|
|
98
|
+
}
|
|
99
|
+
/** The rigid draw classes: opaque, mask, blend (last), each single then double-sided. */
|
|
100
|
+
export declare const RIGID_CLASSES = 6;
|
|
101
|
+
/**
|
|
102
|
+
* Draw classes: the six rigid ones, then the same six skinned (ADR-0088: `+ SKINNED_CLASS`),
|
|
103
|
+
* which read the skinned pool and the palette.
|
|
104
|
+
*/
|
|
105
|
+
export declare const DRAW_CLASSES = 12;
|
|
106
|
+
/** What a skinned mesh's class adds to its rigid class. */
|
|
107
|
+
export declare const SKINNED_CLASS = 6;
|
|
108
|
+
/** A mesh state's draw class: alpha mode × 2 + double-sided, + `SKINNED_CLASS` when skinned. Class 0 is opaque single-sided rigid. */
|
|
109
|
+
export declare function drawClassOf(state?: MeshState, skinned?: boolean): number;
|
|
110
|
+
/** Whether a draw class blends (no depth writes, no shadow casting, drawn last). */
|
|
111
|
+
export declare const isBlendClass: (c: number) => boolean;
|
|
112
|
+
/** Whether a draw class is skinned (reads the skinned pool and the palette). */
|
|
113
|
+
export declare const isSkinnedClass: (c: number) => boolean;
|
|
114
|
+
/** One LOD's placement in the index pool. */
|
|
115
|
+
export interface LodRange {
|
|
116
|
+
readonly firstIndex: number;
|
|
117
|
+
readonly count: number;
|
|
118
|
+
readonly error: number;
|
|
119
|
+
}
|
|
120
|
+
/** A stored mesh. */
|
|
121
|
+
export interface MeshEntry {
|
|
122
|
+
/** First vertex of this mesh in its vertex pool (the skinned pool for a skinned mesh). */
|
|
123
|
+
readonly baseVertex: number;
|
|
124
|
+
/** Whether it is skinned (its vertices are in the skinned pool, with a skin stream). */
|
|
125
|
+
readonly skinned: boolean;
|
|
126
|
+
/** LOD 0 first. */
|
|
127
|
+
lods: LodRange[];
|
|
128
|
+
/** Bounding sphere in mesh space. */
|
|
129
|
+
readonly center: readonly [number, number, number];
|
|
130
|
+
readonly radius: number;
|
|
131
|
+
/** `drawClassOf(state)` (ADR-0081). */
|
|
132
|
+
readonly drawClass: number;
|
|
133
|
+
}
|
|
134
|
+
/** A block of data waiting for (or already in) a GPU pool. */
|
|
135
|
+
interface Block<T> {
|
|
136
|
+
readonly data: T;
|
|
137
|
+
/** Offset in the pool, in elements (vertices or indices). */
|
|
138
|
+
readonly at: number;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Every mesh the app has loaded, kept on the CPU too (ADR-0047): the GPU geometry pool is
|
|
142
|
+
* rebuilt from it after device loss (DESIGN.md §3). A mesh id is its index here, and what
|
|
143
|
+
* the `render.Mesh` component stores. Mesh 0 is a unit cube (`CUBE_MESH`).
|
|
144
|
+
*
|
|
145
|
+
* Geometry is append-only: vertex and index blocks are placed one after another, so a
|
|
146
|
+
* renderer uploads only what was added since it last looked (`vertexBlocks`,
|
|
147
|
+
* `indexBlocks`). LODs added later (`addLods`) are new index blocks over the same vertices.
|
|
148
|
+
*/
|
|
149
|
+
export declare class MeshStore {
|
|
150
|
+
#private;
|
|
151
|
+
readonly entries: MeshEntry[];
|
|
152
|
+
readonly vertexBlocks: Block<Float32Array>[];
|
|
153
|
+
readonly indexBlocks: Block<Uint32Array>[];
|
|
154
|
+
/** The skinned pool (ADR-0088): vertices in the same layout, and the skin stream beside them. */
|
|
155
|
+
readonly skinnedVertexBlocks: Block<Float32Array>[];
|
|
156
|
+
readonly skinBlocks: Block<Uint16Array>[];
|
|
157
|
+
/** Bumped on every change, so a renderer knows it has something to upload. */
|
|
158
|
+
version: number;
|
|
159
|
+
/**
|
|
160
|
+
* Meshes whose vertices were rewritten (`updateVertices`), by id: the serial of the latest
|
|
161
|
+
* write, the pool and where in it. A renderer uploads those newer than the last it saw.
|
|
162
|
+
*/
|
|
163
|
+
readonly vertexWrites: Map<number, {
|
|
164
|
+
serial: number;
|
|
165
|
+
skinned: boolean;
|
|
166
|
+
at: number;
|
|
167
|
+
data: Float32Array;
|
|
168
|
+
}>;
|
|
169
|
+
/**
|
|
170
|
+
* Vertex ranges written into reserved room (`writeVertices`, streamed pages, ADR-0134): not motion,
|
|
171
|
+
* so they do not make the pool dynamic. The renderer uploads those newer than the last it saw and
|
|
172
|
+
* sets `rangesSeen`; older ones are dropped on the next write.
|
|
173
|
+
*/
|
|
174
|
+
readonly rangeWrites: {
|
|
175
|
+
serial: number;
|
|
176
|
+
at: number;
|
|
177
|
+
data: Float32Array;
|
|
178
|
+
}[];
|
|
179
|
+
rangesSeen: number;
|
|
180
|
+
/**
|
|
181
|
+
* Meshes whose finest LOD's indices were rewritten (`updateIndices`, ADR-0117), by id: the serial
|
|
182
|
+
* of the latest write (shared with the vertex writes), where in the index pool, and the indices.
|
|
183
|
+
*/
|
|
184
|
+
readonly indexWrites: Map<number, {
|
|
185
|
+
serial: number;
|
|
186
|
+
at: number;
|
|
187
|
+
data: Uint32Array;
|
|
188
|
+
}>;
|
|
189
|
+
constructor();
|
|
190
|
+
/** Interleaves (if needed) and stores a mesh; returns its id. Main thread, inside the upload budget. */
|
|
191
|
+
add(m: MeshData): number;
|
|
192
|
+
/**
|
|
193
|
+
* Rewrites mesh `id`'s vertices (the same count, `MESH_VERTEX_FLOATS` each): a morphed pose
|
|
194
|
+
* (ADR-0088). The stored copy changes too, so a pool rebuilt after device loss has it. Its
|
|
195
|
+
* bounds stay those it was added with.
|
|
196
|
+
*/
|
|
197
|
+
updateVertices(id: number, vertices: Float32Array): void;
|
|
198
|
+
/**
|
|
199
|
+
* Writes `vertices` (`MESH_VERTEX_FLOATS` each) into mesh `id`'s block from its vertex `first`: room
|
|
200
|
+
* it reserved (`vertexCapacity`), for streamed cluster pages (ADR-0134). Not motion: the pool stays
|
|
201
|
+
* static. The stored copy changes too.
|
|
202
|
+
*/
|
|
203
|
+
writeVertices(id: number, first: number, vertices: Float32Array): void;
|
|
204
|
+
/**
|
|
205
|
+
* Rewrites mesh `id`'s finest LOD's indices (the same count): a CPU cloth's triangles after a tear
|
|
206
|
+
* split them (ADR-0117). The stored copy changes too (a pool rebuilt after device loss has it, and
|
|
207
|
+
* picking sees it). Its coarser LODs stay as they were.
|
|
208
|
+
*/
|
|
209
|
+
updateIndices(id: number, indices: Uint32Array): void;
|
|
210
|
+
/**
|
|
211
|
+
* Mesh `id`'s CPU geometry: interleaved vertices (`MESH_VERTEX_FLOATS` each, position first),
|
|
212
|
+
* its finest LOD's indices, its skin stream (null when rigid) and its prebuilt clusters (or null). Null for an unknown id.
|
|
213
|
+
*/
|
|
214
|
+
geometry(id: number): {
|
|
215
|
+
readonly vertices: Float32Array;
|
|
216
|
+
readonly indices: Uint32Array;
|
|
217
|
+
readonly skin: Uint16Array | null;
|
|
218
|
+
readonly clusters: PrebuiltClusters | null;
|
|
219
|
+
readonly pages: StreamedClusters | null;
|
|
220
|
+
} | null;
|
|
221
|
+
/** The serial of the latest `updateVertices` or `updateIndices` (0: none yet). */
|
|
222
|
+
get writeSerial(): number;
|
|
223
|
+
/**
|
|
224
|
+
* Adds coarser LODs to mesh `id` (finest first, after the ones it has): for a model
|
|
225
|
+
* whose file carried none, simplified on a decode worker after LOD 0 was already drawn.
|
|
226
|
+
*/
|
|
227
|
+
addLods(id: number, lods: readonly MeshLod[]): void;
|
|
228
|
+
get vertexCount(): number;
|
|
229
|
+
/** Vertices in the skinned pool. */
|
|
230
|
+
get skinnedVertexCount(): number;
|
|
231
|
+
get indexCount(): number;
|
|
232
|
+
/** CPU bytes held (vertices + indices). */
|
|
233
|
+
get bytes(): number;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Where a material's texture comes from: a texture already in the store, or anything with
|
|
237
|
+
* `get()` returning one (an asset `Handle` from a `.ktx2` loader, read again whenever the
|
|
238
|
+
* textures change, so a loading texture appears when it is ready). A handle whose state is
|
|
239
|
+
* `Failed` draws the magenta checker of DESIGN.md §9.
|
|
240
|
+
*/
|
|
241
|
+
export type TextureSource = TextureRef | {
|
|
242
|
+
get(): TextureRef | null;
|
|
243
|
+
readonly state?: string;
|
|
244
|
+
};
|
|
245
|
+
/**
|
|
246
|
+
* A compiled node material's shader (`@yali-engine/tsl`'s `CompiledMaterial`, from the `materials`
|
|
247
|
+
* build step; ADR-0064): a WGSL surface function and where its parameters sit.
|
|
248
|
+
*/
|
|
249
|
+
export interface MaterialShader {
|
|
250
|
+
readonly name: string;
|
|
251
|
+
readonly entry: string;
|
|
252
|
+
readonly wgsl: string;
|
|
253
|
+
readonly hash: string;
|
|
254
|
+
readonly params: readonly {
|
|
255
|
+
readonly name: string;
|
|
256
|
+
readonly lanes: number;
|
|
257
|
+
readonly offset: number;
|
|
258
|
+
readonly default: readonly number[];
|
|
259
|
+
}[];
|
|
260
|
+
}
|
|
261
|
+
/** One material: the standard one (shader 0), or a node material's shader with its parameters. */
|
|
262
|
+
export interface MaterialData {
|
|
263
|
+
/** Linear RGBA (the standard material multiplies it in; a node material may ignore it). */
|
|
264
|
+
readonly baseColor: readonly [number, number, number, number];
|
|
265
|
+
/** An sRGB colour texture, multiplied with `baseColor` (sampled at the mesh's first UV set). */
|
|
266
|
+
readonly baseColorMap?: TextureSource;
|
|
267
|
+
/** A linear tangent-space normal map (used by PBR lighting, M2.5). */
|
|
268
|
+
readonly normalMap?: TextureSource;
|
|
269
|
+
/** A linear ORM map: occlusion (R), roughness (G), metalness (B), as glTF packs them. */
|
|
270
|
+
readonly ormMap?: TextureSource;
|
|
271
|
+
/** An sRGB emissive texture, multiplied with `emissive`. */
|
|
272
|
+
readonly emissiveMap?: TextureSource;
|
|
273
|
+
/** Standard material: 0–1 (default 0). */
|
|
274
|
+
readonly metalness?: number;
|
|
275
|
+
/** Standard material: 0–1 (default 1). */
|
|
276
|
+
readonly roughness?: number;
|
|
277
|
+
/** Standard material: linear emitted colour (default black). */
|
|
278
|
+
readonly emissive?: readonly [number, number, number];
|
|
279
|
+
/** Standard material: scale of the normal map's X and Y (glTF `normalTexture.scale`, default 1). */
|
|
280
|
+
readonly normalScale?: number;
|
|
281
|
+
/** Standard material: how much the ORM map's occlusion applies (glTF `occlusionTexture.strength`, default 1). */
|
|
282
|
+
readonly occlusionStrength?: number;
|
|
283
|
+
/**
|
|
284
|
+
* Standard material: the alpha below which a MASK mesh discards a fragment (glTF
|
|
285
|
+
* `alphaCutoff`, default 0.5). Whether a mesh masks or blends is its `MeshState` (ADR-0081).
|
|
286
|
+
*/
|
|
287
|
+
readonly alphaCutoff?: number;
|
|
288
|
+
/** Standard material, KHR_materials_clearcoat: the coat's strength, 0–1 (default 0: none). */
|
|
289
|
+
readonly clearcoat?: number;
|
|
290
|
+
/** The coat's roughness, 0–1 (default 0). */
|
|
291
|
+
readonly clearcoatRoughness?: number;
|
|
292
|
+
/** Linear maps: the coat's strength in R, its roughness in G (glTF's channels). */
|
|
293
|
+
readonly clearcoatMap?: TextureSource;
|
|
294
|
+
readonly clearcoatRoughnessMap?: TextureSource;
|
|
295
|
+
/**
|
|
296
|
+
* Standard material, KHR_materials_transmission: the share of light passing through, 0–1
|
|
297
|
+
* (default 0). Drawn as a blended mesh (its `MeshState`), achromatic and unrefracted (ADR-0093).
|
|
298
|
+
*/
|
|
299
|
+
readonly transmission?: number;
|
|
300
|
+
/** A linear map of it in R. */
|
|
301
|
+
readonly transmissionMap?: TextureSource;
|
|
302
|
+
/** Standard material, KHR_materials_sheen: the sheen's linear colour (default black: none) and roughness. */
|
|
303
|
+
readonly sheenColor?: readonly [number, number, number];
|
|
304
|
+
readonly sheenRoughness?: number;
|
|
305
|
+
/** An sRGB map of the sheen colour. */
|
|
306
|
+
readonly sheenColorMap?: TextureSource;
|
|
307
|
+
/** Index of refraction (KHR_materials_ior, default 1.5): how a transmissive surface bends what is behind it. */
|
|
308
|
+
readonly ior?: number;
|
|
309
|
+
/** KHR_materials_volume (ADR-0099): the thickness the light travels through (mesh units; 0: thin-walled, no bend). */
|
|
310
|
+
readonly thickness?: number;
|
|
311
|
+
/** The volume's thickness map: its G channel times `thickness` (glTF `thicknessTexture`, ADR-0125). */
|
|
312
|
+
readonly thicknessMap?: TextureSource;
|
|
313
|
+
/** KHR_materials_dispersion (ADR-0125): how far the colours part when refracted (20 / the Abbe number; 0: none). */
|
|
314
|
+
readonly dispersion?: number;
|
|
315
|
+
/**
|
|
316
|
+
* Which transparent layer the surface draws in (ADR-0125, default 0). Layer 1 is drawn after a second
|
|
317
|
+
* copy of the scene, so its transmission sees layer 0's glass: give it to glass that is in front of other
|
|
318
|
+
* glass. Only on devices with the opaque copy (the GPU cull's storage path); elsewhere one pass draws both.
|
|
319
|
+
*/
|
|
320
|
+
readonly transmissionLayer?: 0 | 1;
|
|
321
|
+
/**
|
|
322
|
+
* A blended surface's motion (ADR-0133, default false): TAA and motion blur see it move where it is at
|
|
323
|
+
* least as opaque as its `alphaCutoff` (0.5 unless set), instead of seeing what is behind it. For
|
|
324
|
+
* mostly opaque blended surfaces (a fading character, a solid-looking leaf card drawn blended); smoke and
|
|
325
|
+
* glass should keep what is behind them, as by default.
|
|
326
|
+
*/
|
|
327
|
+
readonly blendMotion?: boolean;
|
|
328
|
+
/** The colour white light becomes after `attenuationDistance` inside (default white, Infinity: none). */
|
|
329
|
+
readonly attenuationColor?: readonly [number, number, number];
|
|
330
|
+
readonly attenuationDistance?: number;
|
|
331
|
+
/** A node material's shader (`materials.registerShader`); 0 or absent is the standard material. */
|
|
332
|
+
readonly shader?: number;
|
|
333
|
+
/** A node material's uniforms by name; unset ones take the shader's defaults. */
|
|
334
|
+
readonly params?: Readonly<Record<string, number | readonly number[]>>;
|
|
335
|
+
}
|
|
336
|
+
/** Most materials in the uniform table (`shaders/scene/draw.wesl` `MAX_MATERIALS`). */
|
|
337
|
+
export declare const MAX_MATERIALS = 256;
|
|
338
|
+
/** Words per material: base colour (4 f32), texture slots (4 u32), parameters (8 f32). 64 bytes, so 256 fit compatibility mode's 16 KiB uniform binding. */
|
|
339
|
+
export declare const MATERIAL_WORDS = 16;
|
|
340
|
+
/** Most node-material shaders (the shader id has 6 bits; 0 is the standard material). */
|
|
341
|
+
export declare const MAX_SHADERS = 63;
|
|
342
|
+
/**
|
|
343
|
+
* Words per material in the extension table: four parameters, four texture slots, the volume (ior,
|
|
344
|
+
* thickness, attenuation distance and colour), then dispersion, the thickness map's slot and the
|
|
345
|
+
* transmission layer (ADR-0125).
|
|
346
|
+
*/
|
|
347
|
+
export declare const MATERIAL_EXT_WORDS = 16;
|
|
348
|
+
/**
|
|
349
|
+
* The app's materials (M2 increments 2–4): a material id is its index, stored in
|
|
350
|
+
* `render.Mesh.material`. Material 0 is white, so a `render.Mesh` that sets only `color`
|
|
351
|
+
* draws that colour. Texture slots are packed from the texture store (`sync`), so a texture
|
|
352
|
+
* that streams in mip by mip is sampled from its first resident level. Node materials
|
|
353
|
+
* (`registerShader`) become functions of the draw shader, chosen per material by a switch
|
|
354
|
+
* (ADR-0064): one pipeline and one bind group for every material.
|
|
355
|
+
*/
|
|
356
|
+
export declare class MaterialStore {
|
|
357
|
+
#private;
|
|
358
|
+
/** `MATERIAL_WORDS` per material (the uniform table's layout). */
|
|
359
|
+
readonly data: Float32Array<ArrayBuffer>;
|
|
360
|
+
/**
|
|
361
|
+
* The standard material's glTF extensions (`material_ext`, ADR-0093), `MATERIAL_EXT_WORDS`
|
|
362
|
+
* per material: clearcoat, clearcoat roughness, transmission, the sheen packed RGBA8
|
|
363
|
+
* (colour, roughness); then four texture slots. All zero: no extension.
|
|
364
|
+
*/
|
|
365
|
+
readonly ext: Float32Array<ArrayBuffer>;
|
|
366
|
+
/** Bumped on every change. */
|
|
367
|
+
version: number;
|
|
368
|
+
/** Bumped when a shader is registered (the draw pipeline is rebuilt). */
|
|
369
|
+
shadersVersion: number;
|
|
370
|
+
constructor();
|
|
371
|
+
/**
|
|
372
|
+
* Registers a node material's shader; returns its id for `MaterialData.shader`. The same
|
|
373
|
+
* shader (by hash) registered twice returns the first id.
|
|
374
|
+
*/
|
|
375
|
+
registerShader(s: MaterialShader): number;
|
|
376
|
+
/**
|
|
377
|
+
* The draw shader's material block (between its `@yali:materials` markers): every
|
|
378
|
+
* registered shader's function and the switch that picks one per material.
|
|
379
|
+
*/
|
|
380
|
+
shaderBlock(): string;
|
|
381
|
+
/** Stores a material; returns its id. */
|
|
382
|
+
add(m: MaterialData): number;
|
|
383
|
+
/**
|
|
384
|
+
* Re-packs the texture slots (and each material's shader bits) when `texturesVersion`
|
|
385
|
+
* (the texture store's `version`) moved or a material was added. Returns true when the
|
|
386
|
+
* table changed.
|
|
387
|
+
*/
|
|
388
|
+
sync(texturesVersion: number): boolean;
|
|
389
|
+
get count(): number;
|
|
390
|
+
/** Materials in the second transparent layer (ADR-0125): the scene adds its second copy and pass only while there are any. */
|
|
391
|
+
layered: number;
|
|
392
|
+
/** Materials whose blended surfaces draw motion (ADR-0133): the motion pass draws the blended classes only while there are any. */
|
|
393
|
+
blendMotion: number;
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* The `render.Mesh` component: which mesh an entity draws, with which material, and a colour
|
|
397
|
+
* that tints it, packed RGBA8 (`rgba8`; zero is black). Packed because converting a float
|
|
398
|
+
* colour every frame cost 1.1 ms of the extract at 20k instances on a Galaxy F04 (ADR-0052).
|
|
399
|
+
*/
|
|
400
|
+
export declare function registerMeshComponent(world: World): Component;
|
|
401
|
+
/**
|
|
402
|
+
* Packs a linear RGBA colour (components 0–1) for `render.Mesh.color`, red in the lowest byte
|
|
403
|
+
* (what the shader's `unpack4x8unorm` reads).
|
|
404
|
+
*
|
|
405
|
+
* @example
|
|
406
|
+
* world.insert(e, render.Mesh!, { mesh: CUBE_MESH, material: 0, color: rgba8(1, 0.5, 0.2) });
|
|
407
|
+
*/
|
|
408
|
+
export declare function rgba8(r: number, g: number, b: number, a?: number): number;
|
|
409
|
+
/** The inverse of `rgba8`: [r, g, b, a], each 0–1. */
|
|
410
|
+
export declare function unpackRgba8(packed: number): [number, number, number, number];
|
|
411
|
+
export {};
|