@aethervtt/shard-render 0.0.1 → 0.2.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 (170) hide show
  1. package/dist/ablation.d.ts +74 -0
  2. package/dist/ablation.js +117 -0
  3. package/dist/assets.d.ts +3 -0
  4. package/dist/assets.js +43 -2
  5. package/dist/atmosphere-nodes.d.ts +9 -0
  6. package/dist/atmosphere-nodes.js +157 -30
  7. package/dist/atmosphere-plugin.js +8 -2
  8. package/dist/atmosphere-shaders.js +17 -5
  9. package/dist/baseline/atmosphere.d.ts +16 -0
  10. package/dist/baseline/atmosphere.js +301 -0
  11. package/dist/baseline/data-texture.d.ts +36 -0
  12. package/dist/baseline/data-texture.js +181 -0
  13. package/dist/baseline/environment.d.ts +14 -0
  14. package/dist/baseline/environment.js +368 -0
  15. package/dist/baseline/exposure.d.ts +25 -0
  16. package/dist/baseline/exposure.js +133 -0
  17. package/dist/baseline/lights.d.ts +33 -0
  18. package/dist/baseline/lights.js +133 -0
  19. package/dist/baseline/textures.d.ts +97 -0
  20. package/dist/baseline/textures.js +203 -0
  21. package/dist/camera.d.ts +2 -0
  22. package/dist/camera.js +4 -0
  23. package/dist/crowd.d.ts +21 -0
  24. package/dist/crowd.js +121 -0
  25. package/dist/culling-shaders.js +21 -2
  26. package/dist/culling.d.ts +11 -2
  27. package/dist/culling.js +44 -18
  28. package/dist/cutaway-plugin.d.ts +48 -0
  29. package/dist/cutaway-plugin.js +364 -0
  30. package/dist/cutaway.d.ts +27 -0
  31. package/dist/cutaway.js +49 -0
  32. package/dist/data-store.d.ts +69 -0
  33. package/dist/data-store.js +105 -0
  34. package/dist/debug-shaders.js +17 -3
  35. package/dist/debug-views.js +4 -2
  36. package/dist/decals-plugin.d.ts +5 -0
  37. package/dist/decals-plugin.js +54 -0
  38. package/dist/decals.d.ts +69 -0
  39. package/dist/decals.js +326 -0
  40. package/dist/deferred-shaders.js +2 -0
  41. package/dist/deferred.js +28 -4
  42. package/dist/deform.d.ts +5 -4
  43. package/dist/deform.js +4 -9
  44. package/dist/describe-plugin.d.ts +4 -2
  45. package/dist/describe-plugin.js +75 -3
  46. package/dist/display-nodes.js +37 -13
  47. package/dist/dynamic-resolution.d.ts +2 -0
  48. package/dist/dynamic-resolution.js +6 -1
  49. package/dist/environment-plugin.js +17 -2
  50. package/dist/environment-state.d.ts +7 -3
  51. package/dist/environment-state.js +20 -9
  52. package/dist/environment.js +7 -1
  53. package/dist/features.d.ts +49 -0
  54. package/dist/features.js +106 -0
  55. package/dist/foliage-budget.d.ts +64 -0
  56. package/dist/foliage-budget.js +108 -0
  57. package/dist/foliage-path.d.ts +19 -0
  58. package/dist/foliage-path.js +7 -0
  59. package/dist/foliage-shaders.d.ts +11 -0
  60. package/dist/foliage-shaders.js +504 -0
  61. package/dist/foliage.d.ts +194 -0
  62. package/dist/foliage.js +1027 -0
  63. package/dist/forward.d.ts +38 -2
  64. package/dist/forward.js +608 -186
  65. package/dist/fxaa.js +12 -2
  66. package/dist/gizmos-plugin.js +7 -0
  67. package/dist/gizmos.d.ts +3 -3
  68. package/dist/gizmos.js +11 -13
  69. package/dist/gpu-assets.d.ts +58 -4
  70. package/dist/gpu-assets.js +191 -8
  71. package/dist/graph.d.ts +45 -0
  72. package/dist/graph.js +169 -19
  73. package/dist/health.d.ts +58 -0
  74. package/dist/health.js +112 -0
  75. package/dist/index.d.ts +40 -11
  76. package/dist/index.js +343 -9
  77. package/dist/instances.d.ts +119 -8
  78. package/dist/instances.js +387 -78
  79. package/dist/interior-plugin.d.ts +121 -0
  80. package/dist/interior-plugin.js +465 -0
  81. package/dist/interior.d.ts +24 -0
  82. package/dist/interior.js +13 -0
  83. package/dist/layers.d.ts +35 -0
  84. package/dist/layers.js +49 -0
  85. package/dist/lens-plugin.d.ts +43 -0
  86. package/dist/lens-plugin.js +304 -0
  87. package/dist/lens.d.ts +41 -0
  88. package/dist/lens.js +99 -0
  89. package/dist/lights.d.ts +50 -5
  90. package/dist/lights.js +101 -22
  91. package/dist/material-pipelines.d.ts +37 -4
  92. package/dist/material-pipelines.js +102 -5
  93. package/dist/materials.d.ts +23 -0
  94. package/dist/materials.js +44 -1
  95. package/dist/outline-plugin.d.ts +48 -0
  96. package/dist/outline-plugin.js +529 -0
  97. package/dist/outline.d.ts +15 -0
  98. package/dist/outline.js +42 -0
  99. package/dist/overlay-registry.d.ts +3 -1
  100. package/dist/overlay-registry.js +3 -1
  101. package/dist/overlays.js +6 -2
  102. package/dist/perf-overlay.d.ts +9 -0
  103. package/dist/perf-overlay.js +125 -0
  104. package/dist/picking.d.ts +17 -0
  105. package/dist/picking.js +40 -11
  106. package/dist/pixel-perfect-plugin.js +10 -2
  107. package/dist/plugin.d.ts +69 -7
  108. package/dist/plugin.js +223 -25
  109. package/dist/post-common.d.ts +22 -2
  110. package/dist/post-common.js +82 -2
  111. package/dist/post-nodes.d.ts +7 -1
  112. package/dist/post-nodes.js +235 -111
  113. package/dist/post-plugin.js +5 -3
  114. package/dist/post-scene.d.ts +130 -0
  115. package/dist/post-scene.js +164 -0
  116. package/dist/post-shaders.js +85 -62
  117. package/dist/post.js +11 -1
  118. package/dist/projection.d.ts +24 -0
  119. package/dist/projection.js +87 -0
  120. package/dist/readback.d.ts +1 -0
  121. package/dist/readback.js +1 -0
  122. package/dist/render-scale.js +1 -0
  123. package/dist/ribbons-plugin.d.ts +5 -0
  124. package/dist/ribbons-plugin.js +59 -0
  125. package/dist/ribbons.d.ts +44 -0
  126. package/dist/ribbons.js +288 -0
  127. package/dist/scenario.d.ts +70 -0
  128. package/dist/scenario.js +125 -0
  129. package/dist/screen-effects.d.ts +97 -0
  130. package/dist/screen-effects.js +192 -0
  131. package/dist/shaders.d.ts +13 -0
  132. package/dist/shaders.js +189 -34
  133. package/dist/shadow-catcher.d.ts +9 -0
  134. package/dist/shadow-catcher.js +133 -0
  135. package/dist/shadows.d.ts +27 -2
  136. package/dist/shadows.js +100 -20
  137. package/dist/standard-fields.d.ts +1 -0
  138. package/dist/standard-fields.js +5 -0
  139. package/dist/standard.js +18 -0
  140. package/dist/stats.d.ts +45 -1
  141. package/dist/stats.js +91 -3
  142. package/dist/surface-model.d.ts +57 -0
  143. package/dist/surface-model.js +289 -0
  144. package/dist/surface-shaders.d.ts +3 -0
  145. package/dist/surface-shaders.js +160 -0
  146. package/dist/surface.d.ts +40 -0
  147. package/dist/surface.js +86 -0
  148. package/dist/target.d.ts +1 -13
  149. package/dist/target.js +1 -26
  150. package/dist/testing.d.ts +11 -0
  151. package/dist/testing.js +39 -1
  152. package/dist/tier.d.ts +13 -0
  153. package/dist/tier.js +14 -0
  154. package/dist/timer.d.ts +18 -1
  155. package/dist/timer.js +73 -20
  156. package/dist/variants.d.ts +37 -0
  157. package/dist/variants.js +104 -0
  158. package/dist/vfx-draw.d.ts +37 -0
  159. package/dist/vfx-draw.js +291 -0
  160. package/dist/vfx-state.d.ts +42 -0
  161. package/dist/vfx-state.js +81 -0
  162. package/dist/vfx.d.ts +69 -0
  163. package/dist/vfx.js +103 -0
  164. package/dist/view-visibility-plugin.d.ts +61 -0
  165. package/dist/view-visibility-plugin.js +267 -0
  166. package/dist/view-visibility.d.ts +28 -0
  167. package/dist/view-visibility.js +46 -0
  168. package/dist/view.d.ts +29 -1
  169. package/dist/view.js +57 -34
  170. package/package.json +23 -11
@@ -1,12 +1,18 @@
1
1
  import { type World } from '@aethervtt/shard-core';
2
- import { GpuBuffer, type GpuContext } from '@aethervtt/shard-gpu';
2
+ import type { GpuBuffer, GpuContext } from '@aethervtt/shard-gpu';
3
3
  import type { Mesh } from '@aethervtt/shard-mesh';
4
4
  import { MaterialAsset } from './assets.js';
5
+ import { DataStore } from './data-store.js';
5
6
  import { DeformStore } from './deform.js';
6
7
  export declare const InstanceSlot: import("@aethervtt/shard-core").ComponentDef<{
7
8
  readonly slot: import("@aethervtt/shard-core").FieldType<number, "u32">;
8
9
  }>;
9
10
  export declare const NotShadowCaster: import("@aethervtt/shard-core").ComponentDef<{}>;
11
+ /**
12
+ * Tag: while hidden (Visibility), this mesh still casts shadows. A hidden roof keeps its interior
13
+ * dark (0067): camera views skip it, shadow views draw it.
14
+ */
15
+ export declare const ShadowWhenHidden: import("@aethervtt/shard-core").ComponentDef<{}>;
10
16
  export declare const NotShadowReceiver: import("@aethervtt/shard-core").ComponentDef<{}>;
11
17
  export declare const Mesh3d: import("@aethervtt/shard-core").ComponentDef<{
12
18
  readonly mesh: import("@aethervtt/shard-core").FieldType<import("@aethervtt/shard-core").AssetRef<"Mesh"> | null, "object">;
@@ -51,8 +57,22 @@ export declare const InstanceFlags: {
51
57
  readonly Skinned: 32;
52
58
  /** Morphed: the vertex stage adds morph target deltas. */
53
59
  readonly Morph: 64;
60
+ /** Hidden, but drawn in shadow views (ShadowWhenHidden); Visible is off. */
61
+ readonly ShadowOnly: 128;
62
+ /**
63
+ * May be cut away around a camera's reveal points (Cutaway, 0070). In the record's flags word
64
+ * it rides in bit 28 (`CUTAWAY_BIT`), above the layers and the LOD.
65
+ */
66
+ readonly Cutaway: 256;
54
67
  };
68
+ /** Where `InstanceFlags.Cutaway` sits in the record's flags word (0070). */
69
+ export declare const CUTAWAY_BIT: number;
70
+ /** A slot's flags word: its flags (bits 0–7, Cutaway in 28) and render layers (8–23). */
71
+ export declare function recordFlags(flags: number, layers: number): number;
55
72
  /** Record value for "no batch". LOD slots store `LOD_BIT | lodSet`. */
73
+ /** The render layer mask's place in the flags word (bits 8–23; LOD rides in 24–27 when read). */
74
+ export declare const LAYER_SHIFT = 8;
75
+ export declare const LAYER_BITS: number;
56
76
  export declare const NO_BATCH = 4294967295;
57
77
  export declare const LOD_BIT = 2147483648;
58
78
  /** Visible-list entries: slot in the low 28 bits, LOD level in the top 4. */
@@ -85,6 +105,19 @@ export interface Batch {
85
105
  /** Per-cull scratch for forward-only slots in deferred views. */
86
106
  forwardScratch: Uint32Array;
87
107
  forwardCount: number;
108
+ /** The mesh version shadows last saw (cached shadows redraw when it changes, 0055). */
109
+ meshVersion: number;
110
+ /**
111
+ * Instances that can land in this batch and are Cutaway (0070). While any are, a view whose
112
+ * reveal points can cut one this frame draws it with the cutaway variant of its pipeline.
113
+ */
114
+ cutaway: number;
115
+ /**
116
+ * Drawn in the ground phase (0057): its slots have a GroundLayer, draw in (band, order) order
117
+ * after opaque geometry, and cast no shadows. Kept apart from the same mesh and material off
118
+ * the ground.
119
+ */
120
+ ground: boolean;
88
121
  }
89
122
  /** A Lod component's levels resolved to batches, shared by every entity with the same values. */
90
123
  export interface LodSet {
@@ -128,6 +161,12 @@ export interface CullParams {
128
161
  /** LOD state per slot for this view's camera; updated when `updateLod`. */
129
162
  lodState: Uint8Array | undefined;
130
163
  updateLod: boolean;
164
+ /** Render layers the view draws (0057): slots sharing no bit are culled first. Default: all. */
165
+ layers?: number;
166
+ /** Slots this view doesn't draw (ViewVisibility, 0070): a bit per slot. */
167
+ hidden?: Uint32Array | undefined;
168
+ /** Where those bits start in the GPU's hidden-set buffer, or NO_HIDDEN. */
169
+ hiddenBase?: number;
131
170
  }
132
171
  /**
133
172
  * World bounding sphere of a slot: the mesh's local sphere (from its bounds) through the slot's
@@ -167,7 +206,7 @@ export declare class InstanceStore {
167
206
  * Each slot's InstanceFlags, mirrored from its record: prepare compares against these every
168
207
  * frame, and reading them from the 64-byte records would touch a cache line per instance.
169
208
  */
170
- flags: Uint8Array<ArrayBuffer>;
209
+ flags: Uint16Array<ArrayBuffer>;
171
210
  /** Hidden instances per ECS table id, from the last time prepare visited the table. */
172
211
  readonly tableHidden: number[];
173
212
  /** Batch index (>= 0), LOD set (-2 - index), or -1 (none), per slot. */
@@ -201,7 +240,7 @@ export declare class InstanceStore {
201
240
  private lastMoved;
202
241
  private lastMovedCount;
203
242
  private frame;
204
- readonly prevBuffer: GpuBuffer;
243
+ readonly prevBuffer: DataStore;
205
244
  private readonly free;
206
245
  /** Slots waiting for their mesh or material to load. */
207
246
  readonly pending: Set<number>;
@@ -209,9 +248,24 @@ export declare class InstanceStore {
209
248
  /** Batches in draw order (sorted by pipeline, then material, then mesh). */
210
249
  readonly sorted: Batch[];
211
250
  private readonly byMesh;
251
+ private readonly byMeshGround;
252
+ /**
253
+ * Render layer mask per slot (0057); 1 for slots without RenderLayers. It also rides in bits
254
+ * 8–23 of the record's flags word, where the GPU culler reads it.
255
+ */
256
+ layers: Uint16Array<ArrayBuffer>;
257
+ /** Ground key per slot, (level, band, order) packed; NaN off the ground (0057, 0067). */
258
+ groundKeys: Float64Array<ArrayBuffer>;
212
259
  readonly lodSets: LodSet[];
213
260
  private readonly lodByKey;
214
261
  readonly defaultMaterial: MaterialAsset;
262
+ /**
263
+ * What stand-ins for failed meshes are drawn with (0061): matte gray, or magenta in a dev build
264
+ * (`DevMode`, read by prepareInstances).
265
+ */
266
+ readonly missingMaterial: MaterialAsset;
267
+ /** A development build: the missing material turns magenta. */
268
+ dev: boolean;
215
269
  /** Bytes of instance data uploaded this frame. */
216
270
  uploadedBytes: number;
217
271
  /** Slots with a batch and not hidden, and hidden ones: stats for GPU-culled views. */
@@ -219,11 +273,18 @@ export declare class InstanceStore {
219
273
  hiddenCount: number;
220
274
  /** Bumps when batches or LOD sets change shape (the GPU tables re-upload). */
221
275
  structureVersion: number;
276
+ /** Bumps when a slot is allocated or freed (hidden sets resolve again, 0070). */
277
+ slotEpoch: number;
278
+ /**
279
+ * Bumps when what casts shadows changes other than by moving: a slot's batch, its caster or
280
+ * visible flag, or a batch's mesh data. Cached shadow maps (0055) redraw when it moves.
281
+ */
282
+ shadowEpoch: number;
222
283
  /** Visible slot lists of every CPU-culled view this frame, concatenated. */
223
284
  visible: Uint32Array<ArrayBuffer>;
224
285
  visibleCount: number;
225
- readonly instanceBuffer: GpuBuffer;
226
- readonly visibleBuffer: GpuBuffer;
286
+ readonly instanceBuffer: DataStore;
287
+ readonly visibleBuffer: DataStore;
227
288
  private generation;
228
289
  private readonly gpu;
229
290
  bindGroup: GPUBindGroup | undefined;
@@ -240,6 +301,13 @@ export declare class InstanceStore {
240
301
  get live(): number;
241
302
  private grow;
242
303
  alloc(entity: number): number;
304
+ /** A slot's render layer mask (0057). What casts shadows in a view may change: cached maps redraw. */
305
+ setLayers(slot: number, mask: number): void;
306
+ /**
307
+ * A slot's ground key (0057): `groundKey(band, order, level)`, or NaN off the ground. Returns whether
308
+ * it moved on or off the ground (its batch must be resolved again).
309
+ */
310
+ setGround(slot: number, key: number): boolean;
243
311
  release(slot: number): void;
244
312
  private boundsDirty;
245
313
  private readonly cachedBounds;
@@ -265,11 +333,26 @@ export declare class InstanceStore {
265
333
  settleMoved(): void;
266
334
  /** Assigns a slot to a batch (>= 0), a LOD set (-2 - index), or nothing (-1). */
267
335
  assign(slot: number, assignment: number): void;
336
+ /** Adds `delta` to the cutaway count of every batch the slot can land in (0070). */
337
+ countCutaway(slot: number, delta: number): void;
338
+ /**
339
+ * Bumps `shadowEpoch` if any batch's mesh data changed since the last call (a structure chunk
340
+ * rebuilt in place). One compare per batch.
341
+ */
342
+ checkMeshVersions(): void;
343
+ /**
344
+ * Whether a visible caster that moved this frame touches the half-spaces `planes`, where it
345
+ * was or where it is now. Call after prepare. Skinned and morphed poses aren't moves; see
346
+ * `deforming`.
347
+ */
348
+ movedCasterIn(planes: Float32Array): boolean;
349
+ /** Whether skinned or morphed poses are being written this frame (their shadows move). */
350
+ get deforming(): boolean;
268
351
  /** A plain batch assignment. */
269
352
  setBatch(slot: number, index: number): void;
270
353
  private addMember;
271
354
  private removeMember;
272
- batchFor(mesh: Mesh, material: MaterialAsset, meshGuid: string | undefined, materialGuid: string | undefined): Batch;
355
+ batchFor(mesh: Mesh, material: MaterialAsset, meshGuid: string | undefined, materialGuid: string | undefined, ground?: boolean): Batch;
273
356
  /** The LOD set for a Lod value and material (created on first use). Undefined if a mesh is missing. */
274
357
  lodSetFor(lod: LodValue, material: MaterialAsset, materialGuid: string | undefined, meshes: import('@aethervtt/shard-assets').AssetStore<Mesh, 'Mesh'>): LodSet | undefined;
275
358
  /** Orders batches by pipeline (set by the renderer: material type and variant). */
@@ -291,15 +374,37 @@ export declare class InstanceStore {
291
374
  private tBatches;
292
375
  private tDepths;
293
376
  private readonly tOrder;
377
+ private groundCount;
378
+ private gSlots;
379
+ private gBatches;
380
+ private gKeys;
381
+ private readonly gOrder;
294
382
  /**
295
383
  * CPU culling of every slot into `list` (and, for camera views, `transparent` back to front and
296
384
  * deferred `forwardOnly`). Same tests as the GPU culler: bounding sphere against the frustum,
297
385
  * visibility range, LOD level. `bounds` gets the union of what passed (cascade fitting). With
298
386
  * `transparentOnly`, only blended batches are culled (the GPU culls the rest).
299
387
  */
300
- cullCpu(list: DrawList, params: CullParams, bounds?: Float32Array, transparent?: DrawList, forward?: Float32Array, forwardOnly?: DrawList, transparentOnly?: boolean): void;
388
+ cullCpu(list: DrawList, params: CullParams, bounds?: Float32Array, transparent?: DrawList, forward?: Float32Array, forwardOnly?: DrawList, transparentOnly?: boolean, ground?: DrawList, overlay?: DrawList): void;
301
389
  /** Transparent-only CPU cull over blended batches' members (LOD slots aren't members). */
302
390
  cullTransparentMembers(list: DrawList, params: CullParams, forward: Float32Array): void;
391
+ /**
392
+ * Ground-only CPU cull over ground batches' members (0057), for views the GPU culls: the ground
393
+ * list is always built on the CPU, in (band, order) order.
394
+ */
395
+ cullGroundMembers(list: DrawList, params: CullParams, overlay?: DrawList): void;
396
+ private pushGround;
397
+ /**
398
+ * Packs visible-list entries (a slot in the low 28 bits, 4 spare bits a pass may use, like an
399
+ * outline style) into `list`, one draw per batch: for passes that draw chosen slots (0057's
400
+ * outline mask). `batches` holds each entry's batch index. Skips entries whose batch isn't ready.
401
+ */
402
+ packEntries(list: DrawList, entries: Uint32Array, batches: Int32Array, count: number): void;
403
+ /**
404
+ * Sorts this cull's ground instances by (level, band, order), then batch; runs of a batch share a
405
+ * draw. With `overlay`, bands from OVERLAY_BAND up go there instead (0058).
406
+ */
407
+ private packGround;
303
408
  /**
304
409
  * CPU culling with positional arguments: planes, flag mask, bounds, transparent list, eye, view
305
410
  * direction, and the deferred forward-only list. LOD selects fresh (no hysteresis state).
@@ -335,8 +440,14 @@ export declare class InstanceStore {
335
440
  }
336
441
  /** Projected diameter of a sphere as a fraction of viewport height. Mirrors the cull shader. */
337
442
  export declare function lodSize(radius: number, distance: number, params: CullParams): number;
338
- export declare function createInstanceLayout(gpu: GpuContext): GPUBindGroupLayout;
443
+ /** The instances bind group's layout: storage on the full tier, data textures on baseline. */
444
+ export declare function createInstanceLayout(gpu: GpuContext, store: InstanceStore): GPUBindGroupLayout;
339
445
  export declare const Instances: import("@aethervtt/shard-core").ResourceDef<InstanceStore>;
446
+ /**
447
+ * Ground draw order: level (−16..15, 0067), then band, then order. Exact in a double: 5 + 16 + 32
448
+ * bits.
449
+ */
450
+ export declare function groundKey(band: number, order: number, level?: number): number;
340
451
  /** Present when skinningPlugin is installed: SkinnedMesh and MorphWeights deform what they draw. */
341
452
  export declare const DeformPath: import("@aethervtt/shard-core").ResourceDef<{
342
453
  installed: true;