@driftengine/core 4.10.0 → 4.11.1

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 (165) hide show
  1. package/CHANGELOG.json +107 -0
  2. package/README.md +1 -1
  3. package/dist/index.d.ts +6 -5
  4. package/dist/index.js +2 -2
  5. package/dist/render/ambientOcclusionPass.d.ts +3 -2
  6. package/dist/render/ambientOcclusionPass.js +4 -2
  7. package/dist/render/backend/api.d.ts +21 -1
  8. package/dist/render/backend/webgl2/renderer.d.ts +141 -3
  9. package/dist/render/backend/webgl2/renderer.js +454 -42
  10. package/dist/render/backend/webgpu/buffers.d.ts +5 -0
  11. package/dist/render/backend/webgpu/buffers.js +98 -48
  12. package/dist/render/backend/webgpu/clothKernels.d.ts +8 -0
  13. package/dist/render/backend/webgpu/clothKernels.js +76 -0
  14. package/dist/render/backend/webgpu/clothOps.d.ts +39 -0
  15. package/dist/render/backend/webgpu/clothOps.js +78 -0
  16. package/dist/render/backend/webgpu/clothSetLayout.d.ts +25 -0
  17. package/dist/render/backend/webgpu/clothSetLayout.js +84 -0
  18. package/dist/render/backend/webgpu/clothSetPack.d.ts +33 -0
  19. package/dist/render/backend/webgpu/clothSetPack.js +144 -0
  20. package/dist/render/backend/webgpu/drawCommand.d.ts +2 -0
  21. package/dist/render/backend/webgpu/drawCommand.js +1 -0
  22. package/dist/render/backend/webgpu/flatPass.d.ts +1 -1
  23. package/dist/render/backend/webgpu/flatPass.js +2 -1
  24. package/dist/render/backend/webgpu/gpuClothSet.d.ts +80 -0
  25. package/dist/render/backend/webgpu/gpuClothSet.js +462 -0
  26. package/dist/render/backend/webgpu/latePass.js +1 -0
  27. package/dist/render/backend/webgpu/motionPass.js +15 -6
  28. package/dist/render/backend/webgpu/pipelineCache.d.ts +22 -1
  29. package/dist/render/backend/webgpu/pipelineCache.js +39 -1
  30. package/dist/render/backend/webgpu/postPass.d.ts +1 -1
  31. package/dist/render/backend/webgpu/renderer.d.ts +100 -1
  32. package/dist/render/backend/webgpu/renderer.js +423 -95
  33. package/dist/render/backend/webgpu/shaders/clothSolve.wgsl.d.ts +9 -2
  34. package/dist/render/backend/webgpu/shaders/clothSolve.wgsl.js +121 -47
  35. package/dist/render/backend/webgpu/staticBundles.js +2 -1
  36. package/dist/render/backend/webgpu/vertexFormats.d.ts +22 -0
  37. package/dist/render/backend/webgpu/vertexFormats.js +97 -0
  38. package/dist/render/globalMediumPass.d.ts +2 -0
  39. package/dist/render/globalMediumPass.js +1 -0
  40. package/dist/render/indexWidth.d.ts +17 -0
  41. package/dist/render/indexWidth.js +23 -0
  42. package/dist/render/instances.d.ts +13 -1
  43. package/dist/render/instances.js +10 -0
  44. package/dist/render/lightMatrix.d.ts +11 -0
  45. package/dist/render/lightMatrix.js +14 -0
  46. package/dist/render/mesh.d.ts +9 -0
  47. package/dist/render/mesh.js +38 -14
  48. package/dist/render/occlusionFade.d.ts +21 -0
  49. package/dist/render/occlusionFade.js +27 -0
  50. package/dist/render/renderQuality.d.ts +30 -0
  51. package/dist/render/renderQuality.js +5 -0
  52. package/dist/render/rendererHarness.d.ts +7 -0
  53. package/dist/render/rendererHarness.js +12 -0
  54. package/dist/render/sceneTarget.d.ts +2 -0
  55. package/dist/render/sceneTarget.js +1 -1
  56. package/dist/render/shader.d.ts +15 -0
  57. package/dist/render/shader.js +41 -0
  58. package/dist/render/shaders/ambientOcclusion.js +12 -1
  59. package/dist/render/shaders/flat/directionalShadow.js +84 -10
  60. package/dist/render/shaders/flat/glassTint.d.ts +1 -1
  61. package/dist/render/shaders/flat/glassTint.js +3 -0
  62. package/dist/render/shaders/flat/index.d.ts +15 -0
  63. package/dist/render/shaders/flat/index.js +24 -4
  64. package/dist/render/shaders/flat/layered.d.ts +27 -0
  65. package/dist/render/shaders/flat/layered.js +198 -0
  66. package/dist/render/shaders/flat/main.d.ts +1 -1
  67. package/dist/render/shaders/flat/main.js +50 -16
  68. package/dist/render/shaders/flat/mapReads.d.ts +10 -0
  69. package/dist/render/shaders/flat/mapReads.js +38 -0
  70. package/dist/render/shaders/flat/movingSun.d.ts +21 -0
  71. package/dist/render/shaders/flat/movingSun.js +46 -0
  72. package/dist/render/shaders/flat/normalMap.d.ts +6 -2
  73. package/dist/render/shaders/flat/normalMap.js +23 -3
  74. package/dist/render/shaders/flat/overlay.d.ts +3 -2
  75. package/dist/render/shaders/flat/overlay.js +41 -19
  76. package/dist/render/shaders/flat/preamble.js +23 -5
  77. package/dist/render/shaders/flat/worldUv.d.ts +22 -0
  78. package/dist/render/shaders/flat/worldUv.js +113 -0
  79. package/dist/render/shaders/generated/ambientOcclusion.wgsl.d.ts +6 -1
  80. package/dist/render/shaders/generated/ambientOcclusion.wgsl.js +6 -1
  81. package/dist/render/shaders/generated/flat.wgsl.d.ts +768 -368
  82. package/dist/render/shaders/generated/flat.wgsl.js +791 -391
  83. package/dist/render/shaders/generated/globalMedium.wgsl.d.ts +8 -3
  84. package/dist/render/shaders/generated/globalMedium.wgsl.js +8 -3
  85. package/dist/render/shaders/generated/lightVolume.wgsl.d.ts +15 -10
  86. package/dist/render/shaders/generated/lightVolume.wgsl.js +16 -11
  87. package/dist/render/shaders/globalMedium.js +9 -1
  88. package/dist/render/shaders/lightVolume.js +9 -1
  89. package/dist/render/shaders/tangentFrame.d.ts +1 -1
  90. package/dist/render/shaders/tangentFrame.js +16 -3
  91. package/dist/render/skinnedClothRun.d.ts +28 -0
  92. package/dist/render/skinnedClothRun.js +103 -35
  93. package/dist/render/surfaceLayers.d.ts +107 -0
  94. package/dist/render/surfaceLayers.js +82 -0
  95. package/dist/render/surfaceOverlay.d.ts +16 -3
  96. package/dist/render/surfaceOverlay.js +11 -6
  97. package/dist/render/surfaceProjection.d.ts +34 -0
  98. package/dist/render/surfaceProjection.js +30 -0
  99. package/dist/render/surfaceTexture.d.ts +39 -0
  100. package/dist/render/transmission.d.ts +21 -0
  101. package/dist/render/transmission.js +21 -0
  102. package/dist/render/vertexPacking.d.ts +48 -0
  103. package/dist/render/vertexPacking.js +68 -0
  104. package/dist/ui/splash.d.ts +42 -2
  105. package/dist/ui/splash.js +78 -13
  106. package/package.json +6 -6
  107. package/src/index.ts +6 -2
  108. package/src/render/ambientOcclusionPass.ts +4 -1
  109. package/src/render/backend/api.ts +31 -0
  110. package/src/render/backend/webgl2/renderer.ts +519 -56
  111. package/src/render/backend/webgpu/buffers.ts +153 -54
  112. package/src/render/backend/webgpu/clothKernels.ts +86 -0
  113. package/src/render/backend/webgpu/clothOps.ts +86 -0
  114. package/src/render/backend/webgpu/clothSetLayout.ts +102 -0
  115. package/src/render/backend/webgpu/clothSetPack.ts +197 -0
  116. package/src/render/backend/webgpu/drawCommand.ts +3 -0
  117. package/src/render/backend/webgpu/flatPass.ts +26 -28
  118. package/src/render/backend/webgpu/gpuClothSet.ts +564 -0
  119. package/src/render/backend/webgpu/latePass.ts +1 -0
  120. package/src/render/backend/webgpu/motionPass.ts +18 -7
  121. package/src/render/backend/webgpu/pipelineCache.ts +46 -7
  122. package/src/render/backend/webgpu/renderer.ts +622 -164
  123. package/src/render/backend/webgpu/shaders/clothSolve.wgsl.ts +121 -47
  124. package/src/render/backend/webgpu/staticBundles.ts +2 -1
  125. package/src/render/backend/webgpu/vertexFormats.ts +113 -0
  126. package/src/render/globalMediumPass.ts +7 -0
  127. package/src/render/indexWidth.ts +27 -0
  128. package/src/render/instances.ts +18 -1
  129. package/src/render/lightMatrix.ts +15 -0
  130. package/src/render/mesh.ts +66 -14
  131. package/src/render/occlusionFade.ts +29 -0
  132. package/src/render/renderQuality.ts +38 -0
  133. package/src/render/rendererHarness.ts +15 -0
  134. package/src/render/sceneTarget.ts +3 -0
  135. package/src/render/shader.ts +59 -0
  136. package/src/render/shaders/ambientOcclusion.ts +12 -1
  137. package/src/render/shaders/flat/directionalShadow.ts +84 -10
  138. package/src/render/shaders/flat/glassTint.ts +7 -1
  139. package/src/render/shaders/flat/index.ts +39 -4
  140. package/src/render/shaders/flat/layered.ts +198 -0
  141. package/src/render/shaders/flat/main.ts +50 -16
  142. package/src/render/shaders/flat/mapReads.ts +38 -0
  143. package/src/render/shaders/flat/movingSun.ts +46 -0
  144. package/src/render/shaders/flat/normalMap.ts +23 -3
  145. package/src/render/shaders/flat/overlay.ts +41 -19
  146. package/src/render/shaders/flat/preamble.ts +23 -5
  147. package/src/render/shaders/flat/worldUv.ts +113 -0
  148. package/src/render/shaders/generated/ambientOcclusion.wgsl.ts +6 -1
  149. package/src/render/shaders/generated/flat.wgsl.ts +791 -391
  150. package/src/render/shaders/generated/globalMedium.wgsl.ts +8 -3
  151. package/src/render/shaders/generated/lightVolume.wgsl.ts +16 -11
  152. package/src/render/shaders/globalMedium.ts +9 -1
  153. package/src/render/shaders/lightVolume.ts +9 -1
  154. package/src/render/shaders/tangentFrame.ts +16 -3
  155. package/src/render/skinnedClothRun.ts +138 -38
  156. package/src/render/surfaceLayers.ts +176 -0
  157. package/src/render/surfaceOverlay.ts +24 -7
  158. package/src/render/surfaceProjection.ts +57 -0
  159. package/src/render/surfaceTexture.ts +39 -0
  160. package/src/render/transmission.ts +27 -0
  161. package/src/render/vertexPacking.ts +109 -0
  162. package/src/ui/splash.ts +83 -14
  163. package/dist/render/backend/webgpu/gpuSkinnedCloth.d.ts +0 -74
  164. package/dist/render/backend/webgpu/gpuSkinnedCloth.js +0 -452
  165. package/src/render/backend/webgpu/gpuSkinnedCloth.ts +0 -502
@@ -7,7 +7,7 @@ import type { PickHit, PickableSource } from '../../pickable.ts';
7
7
  import type { RendererApi } from '../api.ts';
8
8
  import { GpuTimestamps } from './gpuTimestamps.ts';
9
9
  import type { Environment, FilmOptions, InsetRect, LightVolumeDrawOptions, SkyColors, TranslucentMeshOptions } from '../webgl2/renderer.ts';
10
- import type { IncrementalMeshHandle, MeshOptions } from '../api.ts';
10
+ import type { IncrementalMeshHandle, MeshOptions, PrepareOptions } from '../api.ts';
11
11
  import type { LightmapPage } from '../../lightmap.ts';
12
12
  import { type BloomResponse } from '../../bloomChain.ts';
13
13
  import type { WaterBody } from '../../waterRenderer.ts';
@@ -133,6 +133,10 @@ export declare class WebGPURenderer implements RendererApi {
133
133
  * flight at the time, so a consumer that builds more meshes later can wait again.
134
134
  */
135
135
  ready(): Promise<void>;
136
+ /** Every distinct cache a lit draw reaches: the frame's, the canvas's, the late pass's, skin's. */
137
+ private pipelineCaches;
138
+ /** Whether a lit draw whose pipeline is not built is left out while it compiles. */
139
+ private skipCompiling;
136
140
  private presentedFrameCount;
137
141
  /**
138
142
  * The joint palettes this frame has set, one slot each. The WebGL2 field of this name is a
@@ -847,6 +851,8 @@ export declare class WebGPURenderer implements RendererApi {
847
851
  private temporalHistoryUsable;
848
852
  private readonly aoStaging;
849
853
  private readonly aoFloats;
854
+ /** Where occlusion fades out with distance, `uFade`: none until a caller sets one. */
855
+ private readonly aoFade;
850
856
  private aoBindGroup;
851
857
  private readonly aoBlurLayout;
852
858
  /**
@@ -1179,6 +1185,17 @@ export declare class WebGPURenderer implements RendererApi {
1179
1185
  private modelMap;
1180
1186
  /** The material's shading model, which picks the lit pipeline: null the standard. */
1181
1187
  private materialModel;
1188
+ /** `uWorldUv`, the material's projection packed by `packSurfaceProjection`. */
1189
+ private readonly projection;
1190
+ /** `uLayers`, the material's layers packed by `packSurfaceLayers`. */
1191
+ private readonly layerFloats;
1192
+ /**
1193
+ * `uGlassTint` as the material leaves it, its light from behind and that light's colour, which a
1194
+ * pane overwrites for its own draw and `releaseSeeThrough` puts back. See `transmission.ts`.
1195
+ */
1196
+ private readonly transmission;
1197
+ private warnedLayersModelMap;
1198
+ private warnedLayersTriplanar;
1182
1199
  /** Its numbers, `uModelParams`, packed by `packModel`. */
1183
1200
  private readonly modelParams;
1184
1201
  /**
@@ -1398,6 +1415,8 @@ export declare class WebGPURenderer implements RendererApi {
1398
1415
  * this one is called per crossfading region per frame and a closure per call is an allocation.
1399
1416
  */
1400
1417
  setDitherFade(amount: number): void;
1418
+ /** Whether the draws that follow spend their own opacity on that screen door. See `renderer.ts`. */
1419
+ setDitherOpacity(on: boolean): void;
1401
1420
  /**
1402
1421
  * How strong the microscopic relief on the surfaces drawn next is, and how coarse.
1403
1422
  *
@@ -2013,6 +2032,22 @@ export declare class WebGPURenderer implements RendererApi {
2013
2032
  * the texel-for-texel comparison that settled it.
2014
2033
  */
2015
2034
  private readonly correctedLightViewProj;
2035
+ /**
2036
+ * What a receiver projects through to read the sun's static layers: the environment's
2037
+ * `lightViewProj`, taken at `bindMeshPass` as WebGL2 takes it there.
2038
+ *
2039
+ * **It was the last shadow pass's matrix**, which is the environment's wherever both layers are
2040
+ * drawn with one and the moving layer's wherever they are not: the static layer was then read
2041
+ * through the moving layer's tight square, and a distant pillar lost its shadow on WebGPU and kept
2042
+ * it on WebGL2, measured on demo/dev/sunLayers.html?moving=tight.
2043
+ */
2044
+ private readonly receiverLightViewProj;
2045
+ /**
2046
+ * The matrix the sun's dynamic shadow pass was last drawn with, uncorrected as the lit stage
2047
+ * projects with, and whether one has been. See `movingLightFor`.
2048
+ */
2049
+ private readonly movingLightViewProj;
2050
+ private movingLightKnown;
2016
2051
  /**
2017
2052
  * The same matrix *uncorrected*, which is what the flat shader must project with.
2018
2053
  *
@@ -2061,6 +2096,21 @@ export declare class WebGPURenderer implements RendererApi {
2061
2096
  * the lit pass on every surface whether they find anything or not.
2062
2097
  */
2063
2098
  private noteGlassCaster;
2099
+ /**
2100
+ * A material's layers where they can be drawn: none asked, or a model's map in the mask's place,
2101
+ * said once, leave one layer.
2102
+ */
2103
+ private layersOf;
2104
+ /** Says once that a layered material's triplanar projection is laid on the horizontal plane. */
2105
+ private warnLayersTriplanar;
2106
+ /**
2107
+ * What the sun's moving layer is read through: the matrix its shadow pass was last drawn with,
2108
+ * where the lit pipelines carry one (`MOVING_SUN`); the environment's otherwise, which every caller
2109
+ * drawing both layers with one matrix hands it anyway.
2110
+ */
2111
+ private movingLightFor;
2112
+ /** The moving layer's own matrix on, the first time a frame draws that layer with one. */
2113
+ private enableMovingSun;
2064
2114
  /** One of the lit stage's switches on, in every cache a lit pipeline can come from. */
2065
2115
  private enableLit;
2066
2116
  /** One resolution every glass caster is read through, so recording one allocates nothing. */
@@ -2438,6 +2488,35 @@ export declare class WebGPURenderer implements RendererApi {
2438
2488
  */
2439
2489
  private refuseOitMultisampled;
2440
2490
  drawTranslucentMesh(mesh: GpuMesh, model: ReadonlyMat4, opacity: number, options?: TranslucentMeshOptions): void;
2491
+ /**
2492
+ * Compile off the main thread every pipeline a draw of `mesh` in `material` takes. **The other
2493
+ * backend's `prepareMesh` carries the contract**; here a draw's key is `meshShape`'s, so a prepared
2494
+ * key is exactly the one the draw asks for, and the compiles are started as a skipping draw starts
2495
+ * them (`PipelineCache.lit`) whatever `pipelineCompile` says, into the frame's own caches.
2496
+ */
2497
+ prepareMesh(mesh: GpuMesh, material: SurfaceMaterial<GpuSurfaceTexture> | null, options?: PrepareOptions): void;
2498
+ /** `prepareMesh` for an instanced batch. See the other backend's `prepareInstanced`. */
2499
+ prepareInstanced(batch: GpuInstancedBatch, material: SurfaceMaterial<GpuSurfaceTexture> | null, options?: PrepareOptions): void;
2500
+ /**
2501
+ * `material` set, every cache a draw in it may build into passed to `start` with whether that draw
2502
+ * blends, compiles started rather than built (`PipelineCache.lit`), and then no material set and
2503
+ * each cache back to what `pipelineCompile` says.
2504
+ */
2505
+ private preparing;
2506
+ /** What `meshShape` worked out for the mesh draw at hand. Reused, so a draw allocates no record. */
2507
+ private readonly drawShape;
2508
+ /**
2509
+ * The key a mesh draw's pipeline is cached under, and the pipeline state that key encodes, under
2510
+ * the current material and these options, into `drawShape`. **The one statement of it**:
2511
+ * `submitMesh` draws by it and `prepareMesh` compiles by it, so the two cannot disagree about a key.
2512
+ */
2513
+ private meshShape;
2514
+ /**
2515
+ * The pipeline `drawShape` names: the one built, one built here, or none where draws skip a
2516
+ * compile and this one has not landed (`PipelineCache.lit`) — and none for a split skin until all
2517
+ * of its halves have.
2518
+ */
2519
+ private meshPipeline;
2441
2520
  /**
2442
2521
  * @param blend Which of the two entry points above this came through, and **not** something to
2443
2522
  * infer from `opacity`.
@@ -2528,6 +2607,13 @@ export declare class WebGPURenderer implements RendererApi {
2528
2607
  * **What it gives up** against `drawMesh` is skinning and morphing, refused where the variant
2529
2608
  * is built, and a per-instance opacity: `opacity` here dims the whole batch.
2530
2609
  */
2610
+ /**
2611
+ * An instanced draw's pipeline under the current material and these options: the one built, one
2612
+ * built here, or none while it compiles (`PipelineCache.lit`), its key, base and model left in
2613
+ * `drawShape`. **The one statement of an instanced key**: `submitInstanced` draws by it and
2614
+ * `prepareInstanced` compiles by it.
2615
+ */
2616
+ private instancedPipeline;
2531
2617
  /**
2532
2618
  * The next of a batch's cull slots this frame, with its cull queued against the current view; null
2533
2619
  * when the batch has drawn from `MAX_CULL_SLOTS` views already or the frame's job ring is full,
@@ -3202,6 +3288,14 @@ export declare class WebGPURenderer implements RendererApi {
3202
3288
  * light alone and its colour alone into the blur's targets and test for the depth its frame half
3203
3289
  * wrote.
3204
3290
  */
3291
+ /**
3292
+ * Whether a split skin draw's two kept halves have pipelines, starting the compile of either that
3293
+ * has not: a skin drawn without them would lose its diffuse light for the frames they take, so a
3294
+ * split skin draws all three halves or none. See `PipelineCache.lit`.
3295
+ */
3296
+ private skinHalvesReady;
3297
+ /** One kept half's pipeline, or none where it is still compiling: see `PipelineCache.lit`. */
3298
+ private skinHalfPipeline;
3205
3299
  private keepSkinDiffuse;
3206
3300
  /**
3207
3301
  * Spread the frame's skin and add it back: once, at the first blended draw or before the frame's
@@ -3946,6 +4040,11 @@ export declare class WebGPURenderer implements RendererApi {
3946
4040
  setLocalExposure(strength: number): void;
3947
4041
  /** The exposure pass, built once; the composite's group holds placeholders until it exists. */
3948
4042
  private ensureExposurePass;
4043
+ /**
4044
+ * Where ambient occlusion fades out with distance. **The other backend's
4045
+ * `setAmbientOcclusionFade` carries the reasoning**; this is the same setter over the same state.
4046
+ */
4047
+ setAmbientOcclusionFade(distance: number, radius: number): void;
3949
4048
  /**
3950
4049
  * Where this frame's lens is focused, how deep the sharp zone is, and how much of the ceiling
3951
4050
  * to take. **The other backend's `setDepthOfField` carries the reasoning**, whole: the