@driftengine/core 4.9.0 → 4.10.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 (135) hide show
  1. package/CHANGELOG.json +62 -11
  2. package/README.md +43 -38
  3. package/dist/index.d.ts +3 -1
  4. package/dist/index.js +4 -3
  5. package/dist/render/ambientHarmonics.d.ts +1 -1
  6. package/dist/render/ambientHarmonics.js +1 -1
  7. package/dist/render/areaLights.d.ts +4 -4
  8. package/dist/render/areaLights.js +1 -1
  9. package/dist/render/backend/api.d.ts +10 -3
  10. package/dist/render/backend/select.js +11 -5
  11. package/dist/render/backend/webgl2/boneAnimations.d.ts +29 -0
  12. package/dist/render/backend/webgl2/boneAnimations.js +80 -0
  13. package/dist/render/backend/webgl2/instanced.d.ts +5 -1
  14. package/dist/render/backend/webgl2/instanced.js +13 -1
  15. package/dist/render/backend/webgl2/renderer.d.ts +90 -2
  16. package/dist/render/backend/webgl2/renderer.js +253 -24
  17. package/dist/render/backend/webgl2/skinPaletteTexture.d.ts +5 -3
  18. package/dist/render/backend/webgl2/skinPaletteTexture.js +6 -4
  19. package/dist/render/backend/webgpu/boneAnimations.d.ts +34 -0
  20. package/dist/render/backend/webgpu/boneAnimations.js +76 -0
  21. package/dist/render/backend/webgpu/buffers.d.ts +19 -4
  22. package/dist/render/backend/webgpu/buffers.js +18 -11
  23. package/dist/render/backend/webgpu/compressedUpload.d.ts +0 -1
  24. package/dist/render/backend/webgpu/compressedUpload.js +53 -8
  25. package/dist/render/backend/webgpu/depthPass.d.ts +59 -3
  26. package/dist/render/backend/webgpu/depthPass.js +49 -14
  27. package/dist/render/backend/webgpu/drawCommand.d.ts +18 -4
  28. package/dist/render/backend/webgpu/drawCommand.js +10 -3
  29. package/dist/render/backend/webgpu/flatPass.d.ts +85 -42
  30. package/dist/render/backend/webgpu/flatPass.js +136 -20
  31. package/dist/render/backend/webgpu/instanced.d.ts +14 -1
  32. package/dist/render/backend/webgpu/instanced.js +24 -1
  33. package/dist/render/backend/webgpu/materialStore.d.ts +101 -0
  34. package/dist/render/backend/webgpu/materialStore.js +265 -0
  35. package/dist/render/backend/webgpu/pipelineCache.d.ts +6 -0
  36. package/dist/render/backend/webgpu/pipelineCache.js +7 -0
  37. package/dist/render/backend/webgpu/renderer.d.ts +152 -35
  38. package/dist/render/backend/webgpu/renderer.js +787 -142
  39. package/dist/render/backend/webgpu/skinPaletteRing.d.ts +7 -3
  40. package/dist/render/backend/webgpu/skinPaletteRing.js +13 -7
  41. package/dist/render/backend/webgpu/skinPaletteTexture.d.ts +6 -0
  42. package/dist/render/backend/webgpu/skinPaletteTexture.js +7 -1
  43. package/dist/render/backend/webgpu/staticBundles.d.ts +125 -0
  44. package/dist/render/backend/webgpu/staticBundles.js +241 -0
  45. package/dist/render/backend/webgpu/surfaceTexturePass.d.ts +10 -3
  46. package/dist/render/backend/webgpu/surfaceTexturePass.js +20 -2
  47. package/dist/render/backend/webgpu/uniformRing.d.ts +21 -0
  48. package/dist/render/backend/webgpu/uniformRing.js +9 -1
  49. package/dist/render/bloomChain.d.ts +3 -3
  50. package/dist/render/boneAnimation.d.ts +92 -0
  51. package/dist/render/boneAnimation.js +133 -0
  52. package/dist/render/compressedSource.d.ts +33 -13
  53. package/dist/render/compressedSource.js +70 -25
  54. package/dist/render/glCompressed.js +83 -0
  55. package/dist/render/instances.d.ts +26 -0
  56. package/dist/render/lightBudget.d.ts +10 -0
  57. package/dist/render/lightBudget.js +10 -0
  58. package/dist/render/lightmap.d.ts +1 -1
  59. package/dist/render/mesh.d.ts +5 -0
  60. package/dist/render/mesh.js +6 -0
  61. package/dist/render/pointLightSelection.d.ts +4 -4
  62. package/dist/render/screenSpaceReflection.d.ts +2 -1
  63. package/dist/render/shaders/boneAnimation.d.ts +19 -0
  64. package/dist/render/shaders/boneAnimation.js +63 -0
  65. package/dist/render/shaders/depth.d.ts +7 -0
  66. package/dist/render/shaders/depth.js +35 -10
  67. package/dist/render/shaders/flat/index.d.ts +6 -0
  68. package/dist/render/shaders/flat/index.js +27 -5
  69. package/dist/render/shaders/flat/main.d.ts +1 -1
  70. package/dist/render/shaders/flat/main.js +15 -5
  71. package/dist/render/shaders/flat/models.js +1 -1
  72. package/dist/render/shaders/flat/overlay.js +1 -1
  73. package/dist/render/shaders/flat/pointShadow.js +2 -2
  74. package/dist/render/shaders/flat/preamble.js +38 -24
  75. package/dist/render/shaders/generated/depth.wgsl.d.ts +93 -0
  76. package/dist/render/shaders/generated/depth.wgsl.js +93 -0
  77. package/dist/render/shaders/generated/flat.wgsl.d.ts +3077 -2903
  78. package/dist/render/shaders/generated/flat.wgsl.js +3100 -2925
  79. package/dist/render/shaders/outputTransform.d.ts +7 -0
  80. package/dist/render/shaders/outputTransform.js +28 -14
  81. package/dist/render/shaders/vertexChannel.d.ts +7 -0
  82. package/dist/render/shaders/vertexChannel.js +26 -0
  83. package/dist/render/staticDraws.d.ts +47 -0
  84. package/dist/render/staticDraws.js +43 -0
  85. package/dist/render/surfaceTexture.d.ts +38 -7
  86. package/dist/render/surfaceTexture.js +56 -17
  87. package/package.json +6 -6
  88. package/src/index.ts +8 -2
  89. package/src/render/ambientHarmonics.ts +1 -1
  90. package/src/render/areaLights.ts +4 -4
  91. package/src/render/backend/api.ts +13 -3
  92. package/src/render/backend/select.ts +10 -5
  93. package/src/render/backend/webgl2/boneAnimations.ts +105 -0
  94. package/src/render/backend/webgl2/instanced.ts +20 -1
  95. package/src/render/backend/webgl2/renderer.ts +315 -24
  96. package/src/render/backend/webgl2/skinPaletteTexture.ts +6 -4
  97. package/src/render/backend/webgpu/boneAnimations.ts +97 -0
  98. package/src/render/backend/webgpu/buffers.ts +42 -16
  99. package/src/render/backend/webgpu/compressedUpload.ts +59 -9
  100. package/src/render/backend/webgpu/depthPass.ts +51 -10
  101. package/src/render/backend/webgpu/drawCommand.ts +22 -4
  102. package/src/render/backend/webgpu/flatPass.ts +187 -14
  103. package/src/render/backend/webgpu/instanced.ts +32 -1
  104. package/src/render/backend/webgpu/materialStore.ts +276 -0
  105. package/src/render/backend/webgpu/pipelineCache.ts +7 -0
  106. package/src/render/backend/webgpu/renderer.ts +928 -155
  107. package/src/render/backend/webgpu/skinPaletteRing.ts +13 -7
  108. package/src/render/backend/webgpu/skinPaletteTexture.ts +7 -1
  109. package/src/render/backend/webgpu/staticBundles.ts +363 -0
  110. package/src/render/backend/webgpu/surfaceTexturePass.ts +29 -3
  111. package/src/render/backend/webgpu/uniformRing.ts +10 -1
  112. package/src/render/bloomChain.ts +3 -3
  113. package/src/render/boneAnimation.ts +223 -0
  114. package/src/render/compressedSource.ts +121 -29
  115. package/src/render/glCompressed.ts +83 -0
  116. package/src/render/instances.ts +27 -0
  117. package/src/render/lightBudget.ts +11 -0
  118. package/src/render/lightmap.ts +1 -1
  119. package/src/render/mesh.ts +6 -0
  120. package/src/render/pointLightSelection.ts +4 -4
  121. package/src/render/screenSpaceReflection.ts +2 -1
  122. package/src/render/shaders/boneAnimation.ts +63 -0
  123. package/src/render/shaders/depth.ts +45 -10
  124. package/src/render/shaders/flat/index.ts +33 -5
  125. package/src/render/shaders/flat/main.ts +15 -5
  126. package/src/render/shaders/flat/models.ts +1 -1
  127. package/src/render/shaders/flat/overlay.ts +1 -1
  128. package/src/render/shaders/flat/pointShadow.ts +2 -2
  129. package/src/render/shaders/flat/preamble.ts +38 -24
  130. package/src/render/shaders/generated/depth.wgsl.ts +95 -0
  131. package/src/render/shaders/generated/flat.wgsl.ts +3100 -2925
  132. package/src/render/shaders/outputTransform.ts +30 -14
  133. package/src/render/shaders/vertexChannel.ts +27 -0
  134. package/src/render/staticDraws.ts +95 -0
  135. package/src/render/surfaceTexture.ts +94 -27
@@ -1,6 +1,7 @@
1
1
  import type { MeshInstances } from '../../instances.ts';
2
2
  import type { Mesh } from '../../mesh.ts';
3
3
  import type { FrustumPlanes } from '../../../math/frustum.ts';
4
+ import { GlInstanceClocks, type GlBoneAnimation } from './boneAnimations.ts';
4
5
  /**
5
6
  * One batch of a mesh: its per-instance buffer and a vertex array of its own.
6
7
  *
@@ -29,7 +30,10 @@ export declare class InstancedBatch {
29
30
  /** The survivors of a lightmapped batch's cull, made the first time one is culled. */
30
31
  private keptRegioned;
31
32
  private readonly kept;
32
- constructor(gl: WebGL2RenderingContext, mesh: Mesh, capacity: number, cull?: boolean);
33
+ /** The bone animation every instance plays, and its clocks; null for a batch that plays none. */
34
+ readonly animation: GlBoneAnimation | null;
35
+ readonly clocks: GlInstanceClocks | null;
36
+ constructor(gl: WebGL2RenderingContext, mesh: Mesh, capacity: number, cull?: boolean, animation?: GlBoneAnimation | null);
33
37
  upload(gl: WebGL2RenderingContext, data: MeshInstances): void;
34
38
  /** Draw the first `count` uploaded instances: every draw but a culling camera draw. */
35
39
  draw(gl: WebGL2RenderingContext, count: number): void;
@@ -1,5 +1,7 @@
1
1
  import { cullInstances, instancesBox } from '../../instanceCull.js';
2
2
  import { INSTANCE_FLOATS, INSTANCE_STRIDE, createMeshInstances, packInstances, } from '../../instances.js';
3
+ import { packInstanceClocks } from '../../boneAnimation.js';
4
+ import { GlInstanceClocks } from './boneAnimations.js';
3
5
  /**
4
6
  * One batch of a mesh: its per-instance buffer and a vertex array of its own.
5
7
  *
@@ -28,10 +30,15 @@ export class InstancedBatch {
28
30
  /** The survivors of a lightmapped batch's cull, made the first time one is culled. */
29
31
  keptRegioned = null;
30
32
  kept;
31
- constructor(gl, mesh, capacity, cull = false) {
33
+ /** The bone animation every instance plays, and its clocks; null for a batch that plays none. */
34
+ animation;
35
+ clocks;
36
+ constructor(gl, mesh, capacity, cull = false, animation = null) {
32
37
  this.mesh = mesh;
33
38
  this.capacity = capacity;
34
39
  this.cull = cull;
40
+ this.animation = animation;
41
+ this.clocks = animation === null ? null : new GlInstanceClocks(gl, capacity);
35
42
  this.staging = new Float32Array(capacity * INSTANCE_FLOATS);
36
43
  this.buffer = allocate(gl, capacity);
37
44
  this.vao = mesh.createInstanceArray(gl, this.buffer, INSTANCE_STRIDE);
@@ -56,6 +63,10 @@ export class InstancedBatch {
56
63
  packInstances(data, this.staging);
57
64
  gl.bindBuffer(gl.ARRAY_BUFFER, this.buffer);
58
65
  gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.staging, 0, count * INSTANCE_FLOATS);
66
+ if (this.clocks !== null) {
67
+ packInstanceClocks(data, this.clocks.staging);
68
+ this.clocks.upload(gl, count);
69
+ }
59
70
  }
60
71
  /** Draw the first `count` uploaded instances: every draw but a culling camera draw. */
61
72
  draw(gl, count) {
@@ -88,6 +99,7 @@ export class InstancedBatch {
88
99
  dispose(gl) {
89
100
  gl.deleteVertexArray(this.vao);
90
101
  gl.deleteBuffer(this.buffer);
102
+ this.clocks?.dispose(gl);
91
103
  if (this.kept !== null) {
92
104
  gl.deleteVertexArray(this.kept.vao);
93
105
  gl.deleteBuffer(this.kept.buffer);
@@ -44,13 +44,14 @@ import type { AreaLightBuffer, AreaLightSource } from '../../areaLights.ts';
44
44
  import type { PhotometricProfile } from '../../iesProfile.ts';
45
45
  import type { ShadowLight } from '../../pointShadowSystem.ts';
46
46
  import type { ShadowCasters } from '../../shadowCasters.ts';
47
+ import type { StaticDrawsHandle } from '../../staticDraws.ts';
47
48
  import type { RenderQuality, RenderQualityOptions } from '../../renderQuality.ts';
48
49
  import { Mesh } from '../../mesh.ts';
49
50
  import type { IncrementalMesh } from '../../mesh.ts';
50
51
  import type { MeshData } from '../../mesh.ts';
51
52
  import type { MeshOptions } from '../api.ts';
52
53
  import { SurfaceTexture } from '../../surfaceTexture.ts';
53
- import type { CompressedTextureFormat, SurfaceSource } from '../../compressedSource.ts';
54
+ import type { CompressedTextureFormat, CompressedTextureSource, SurfaceSource } from '../../compressedSource.ts';
54
55
  import type { SurfaceMaterial, SurfaceTextureOptions } from '../../surfaceTexture.ts';
55
56
  import { PlumeRenderer } from '../../plumeRenderer.ts';
56
57
  import type { PlumeOptions, PlumePlacement } from '../../plumeRenderer.ts';
@@ -82,6 +83,7 @@ import type { WindStreakOptions } from '../../windStreakRenderer.ts';
82
83
  import type { WindField } from '../../windField.ts';
83
84
  import type { FlockParams } from '../../flockRenderer.ts';
84
85
  import { InstancedBatch } from './instanced.ts';
86
+ import type { BoneAnimationClip, BoneAnimationHandle } from '../../boneAnimation.ts';
85
87
  import type { InstancedOptions, MeshInstances } from '../../instances.ts';
86
88
  /** Reused each frame: which shader light slot each bound cubemap serves. */
87
89
  export type { ShadowCasterSink, ShadowCasters } from '../../shadowCasters.ts';
@@ -1156,6 +1158,11 @@ export declare class WebGL2Renderer implements RendererApi {
1156
1158
  private readonly depthCutoutUniforms;
1157
1159
  private readonly depthInstancedCutoutProgram;
1158
1160
  private readonly depthInstancedCutoutUniforms;
1161
+ /** A crowd's casters: the instanced depth programs that play a bone animation. */
1162
+ private readonly depthAnimatedProgram;
1163
+ private readonly depthAnimatedUniforms;
1164
+ private readonly depthAnimatedCutoutProgram;
1165
+ private readonly depthAnimatedCutoutUniforms;
1159
1166
  private readonly scatterDepthProgram;
1160
1167
  private readonly scatterDepthUniforms;
1161
1168
  /** The sun's static, moving and peeled maps, as layers of one array. See `shadowMap.ts`. */
@@ -1894,7 +1901,7 @@ export declare class WebGL2Renderer implements RendererApi {
1894
1901
  *
1895
1902
  * Not a hot path — it re-uploads the whole image and regenerates the mip chain.
1896
1903
  */
1897
- updateSurfaceTexture(texture: SurfaceTexture, source: TexImageSource): void;
1904
+ updateSurfaceTexture(texture: SurfaceTexture, source: TexImageSource | CompressedTextureSource): void;
1898
1905
  disposeSurfaceTexture(texture: SurfaceTexture): void;
1899
1906
  /**
1900
1907
  * Choose the surface texture the following `drawMesh` calls sample, or `null` for none.
@@ -2035,6 +2042,16 @@ export declare class WebGL2Renderer implements RendererApi {
2035
2042
  * exactly as it did.
2036
2043
  */
2037
2044
  setSurfaceReflectivity(amount: number): void;
2045
+ /**
2046
+ * The reflectivity and environment gain the setters gave the pass, and the ones the material
2047
+ * set now states, or null where it states none (`SurfaceMaterial.reflectivity`). A draw wears the
2048
+ * material's where it has one and the pass's otherwise.
2049
+ */
2050
+ private passReflectivity;
2051
+ private passEnvironmentGain;
2052
+ private materialReflectivity;
2053
+ private materialEnvironmentGain;
2054
+ private writeEnvironmentDials;
2038
2055
  /**
2039
2056
  * The overlay the following draws wear — a rim of light, a dissolve, wrinkles by region — or null
2040
2057
  * for none. Pass state, as the material is: `bindMeshPass` puts it back to none. See
@@ -2231,6 +2248,40 @@ export declare class WebGL2Renderer implements RendererApi {
2231
2248
  * one. `Mesh.attachInstances` is what refuses a second, and says why.
2232
2249
  */
2233
2250
  createInstanced(mesh: Mesh, capacity: number, options?: InstancedOptions): InstancedBatch;
2251
+ /**
2252
+ * A bone animation an instanced batch can play (`InstancedOptions.animation`): per frame, a turn
2253
+ * and a place for each bone, which every vertex of the batch's mesh follows — the bone its second
2254
+ * coordinates' u names, times `boneScale` — at each instance's own moment of the clip. What a
2255
+ * crowd is made of: every instance moves at the frame's rate on its own clock, in the colour pass
2256
+ * and in every shadow, with nothing on the processor after this. See `boneAnimation.ts` for the
2257
+ * clip's layout and the arithmetic, which both backends run.
2258
+ *
2259
+ * What it gives up against skinning is the blend: a vertex follows one bone. Refused, with what
2260
+ * was wrong, for a clip whose numbers are not its size, or past 2,048 bones or frames.
2261
+ */
2262
+ createBoneAnimation(clip: BoneAnimationClip): BoneAnimationHandle;
2263
+ /** Release a clip. A batch still playing it draws nothing, and casts nothing, after. */
2264
+ disposeBoneAnimation(animation: BoneAnimationHandle): void;
2265
+ /**
2266
+ * The clock a bone animation plays by this frame, in seconds on the caller's clock: an instance's
2267
+ * moment is this times its rate plus its phase (`MeshInstances.clocks`). **Set it before the
2268
+ * shadows are drawn**, once a frame, as the wind is set: a shadow drawn under one clock and its
2269
+ * caster under another come apart at the frame's rate. 0 until set, which holds every crowd at
2270
+ * the moment its phases name.
2271
+ */
2272
+ setAnimationTime(seconds: number): void;
2273
+ /** The clock `setAnimationTime` set. */
2274
+ private animationTime;
2275
+ /**
2276
+ * An animated batch's clip, clocks and numbers into whichever program is bound: the three vertex
2277
+ * textures on units of their own (`lightBudget.ts`), the clip's speed and bone scale, the clock.
2278
+ */
2279
+ private bindAnimation;
2280
+ /** The animated instanced program, compiled on first use. See `ensureInstancedProgram`. */
2281
+ private flatAnimatedProgram;
2282
+ private flatAnimatedUniforms;
2283
+ /** Compile the animated variant, once, and feed it this frame's pass state. */
2284
+ private ensureAnimatedProgram;
2234
2285
  /** Push placement and colour. Only the live prefix. */
2235
2286
  uploadInstanced(batch: InstancedBatch, data: MeshInstances): void;
2236
2287
  /** Draw every live instance, opaque. */
@@ -2765,6 +2816,43 @@ export declare class WebGL2Renderer implements RendererApi {
2765
2816
  */
2766
2817
  drawSceneCasters(casters: ShadowCasters): void;
2767
2818
  drawShadowCasters(casters: ShadowCasters): void;
2819
+ /**
2820
+ * Draws that do not change between frames, enumerated once and kept: what a stage, a set or any
2821
+ * world that stands still draws, recorded so a frame replays it rather than issuing it.
2822
+ *
2823
+ * **The same enumeration `drawSceneCasters` takes**, called once, here: rigid meshes and instanced
2824
+ * batches, each with its material. A skinned mesh or a scatter batch is refused by name, since
2825
+ * both change every frame. What it captures is what the enumeration said at the time — the
2826
+ * matrices and the instance counts are copied, so a caller's scratch is free to move on — while
2827
+ * the meshes, batches, textures and materials stay the caller's: a list must be disposed, or made
2828
+ * again, before anything it holds is, and made again when a material it holds is changed.
2829
+ *
2830
+ * **What it is for is the frame's processor time.** WebGPU records the list into a render bundle
2831
+ * per view and replays it with one call, where a draw issued a frame at a time costs its encoding
2832
+ * every frame and again for every view that draws it. This backend has no bundles and replays the
2833
+ * entries through the scene-caster path every frame, at the cost a frame drawing them itself pays;
2834
+ * the picture is the same.
2835
+ *
2836
+ * What a list gives up against drawing each frame is culling: every entry is drawn in every view,
2837
+ * because a bundle cannot leave one out. A world split into lists by region culls by list.
2838
+ */
2839
+ createStaticDraws(casters: ShadowCasters): StaticDrawsHandle;
2840
+ /**
2841
+ * Draw a list into the open mesh pass, under the camera, the lights and the fog `bindMeshPass`
2842
+ * set — the frame's, a mirror's, a capture's. Opaque draws, through each entry's material.
2843
+ *
2844
+ * **Its draws are rigid and wear no overlay**, so a skin palette, morph weights, cloth or a surface
2845
+ * overlay set before it is put back to none, as `bindMeshPass` puts an overlay back; and no
2846
+ * material is left set after it, which is what `setMaterial(null)` leaves. The state a pass set —
2847
+ * the grain, the relief, the fog, the grade — is the list's to draw with, as it is any draw's, and
2848
+ * a list drawn under a different one is recorded again for it on WebGPU.
2849
+ */
2850
+ drawStaticDraws(draws: StaticDrawsHandle): void;
2851
+ /** Release a list. Its meshes, batches and materials are the caller's and are not released. */
2852
+ disposeStaticDraws(draws: StaticDrawsHandle): void;
2853
+ /** A disposed list drawn, said once: the frame loop does not throw. */
2854
+ private warnStaticDisposed;
2855
+ private warnedStaticDisposed;
2768
2856
  /**
2769
2857
  * Draw the pass's glass twice: where the nearest pane is, and what the panes let through.
2770
2858
  *