@woosh/meep-engine 3.81.0 → 3.83.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 (604) hide show
  1. package/CHANGELOG.md +121 -0
  2. package/build/bundle-worker-image-decoder.js +1 -1
  3. package/build/bundle-worker-terrain.js +1 -1
  4. package/editor/camera/camera_framing.js +2 -2
  5. package/editor/ecs/component/editors/common/BitFlagsEditor.d.ts.map +1 -1
  6. package/editor/ecs/component/editors/common/BitFlagsEditor.js +11 -0
  7. package/editor/ecs/component/editors/ecs/terrain/SplatMappingEditor.d.ts +0 -8
  8. package/editor/ecs/component/editors/ecs/terrain/SplatMappingEditor.d.ts.map +1 -1
  9. package/editor/ecs/component/editors/ecs/terrain/SplatMappingEditor.js +0 -8
  10. package/editor/prototypeEditorShell.d.ts.map +1 -1
  11. package/editor/prototypeEditorShell.js +4 -1
  12. package/editor/tools/paint/TerrainHeightPaintTool.d.ts.map +1 -1
  13. package/editor/tools/paint/TerrainHeightPaintTool.js +2 -1
  14. package/editor/view/ecs/EntityEditor.js +1 -1
  15. package/package.json +1 -1
  16. package/src/core/binary/BinaryBuffer.d.ts +0 -8
  17. package/src/core/binary/BinaryBuffer.d.ts.map +1 -1
  18. package/src/core/binary/BinaryBuffer.js +0 -14
  19. package/src/core/cache/Cache.d.ts +0 -4
  20. package/src/core/cache/Cache.d.ts.map +1 -1
  21. package/src/core/cache/Cache.js +0 -7
  22. package/src/core/collection/list/List.d.ts +0 -6
  23. package/src/core/collection/list/List.d.ts.map +1 -1
  24. package/src/core/collection/list/List.js +0 -9
  25. package/src/core/collection/table/RowFirstTable.d.ts +0 -6
  26. package/src/core/collection/table/RowFirstTable.d.ts.map +1 -1
  27. package/src/core/collection/table/RowFirstTable.js +0 -9
  28. package/src/core/events/signal/Signal.d.ts +0 -10
  29. package/src/core/events/signal/Signal.d.ts.map +1 -1
  30. package/src/core/events/signal/Signal.js +0 -13
  31. package/src/core/geom/2d/aabb/AABB2.d.ts +0 -23
  32. package/src/core/geom/2d/aabb/AABB2.d.ts.map +1 -1
  33. package/src/core/geom/2d/aabb/AABB2.js +0 -35
  34. package/src/core/geom/2d/quad-tree/QuadTreeNode.d.ts +0 -18
  35. package/src/core/geom/2d/quad-tree/QuadTreeNode.d.ts.map +1 -1
  36. package/src/core/geom/2d/quad-tree/QuadTreeNode.js +0 -24
  37. package/src/core/geom/3d/aabb/AABB3.d.ts +0 -42
  38. package/src/core/geom/3d/aabb/AABB3.d.ts.map +1 -1
  39. package/src/core/geom/3d/aabb/AABB3.js +0 -97
  40. package/src/core/geom/3d/tetrahedra/TetrahedralMesh.d.ts +0 -6
  41. package/src/core/geom/3d/tetrahedra/TetrahedralMesh.d.ts.map +1 -1
  42. package/src/core/geom/3d/tetrahedra/TetrahedralMesh.js +4 -15
  43. package/src/core/geom/Quaternion.d.ts +0 -34
  44. package/src/core/geom/Quaternion.d.ts.map +1 -1
  45. package/src/core/geom/Quaternion.js +0 -78
  46. package/src/core/geom/Vector2.d.ts +0 -8
  47. package/src/core/geom/Vector2.d.ts.map +1 -1
  48. package/src/core/geom/Vector2.js +0 -9
  49. package/src/core/geom/Vector3.d.ts +0 -15
  50. package/src/core/geom/Vector3.d.ts.map +1 -1
  51. package/src/core/geom/Vector3.js +0 -15
  52. package/src/core/geom/Vector4.d.ts +0 -8
  53. package/src/core/geom/Vector4.d.ts.map +1 -1
  54. package/src/core/geom/Vector4.js +0 -9
  55. package/src/core/graph/metis/native/metis_partition_kway.d.ts +3 -6
  56. package/src/core/graph/metis/native/metis_partition_kway.d.ts.map +1 -1
  57. package/src/core/graph/metis/native/metis_partition_kway.js +3 -6
  58. package/src/core/graph/v2/Graph.d.ts +0 -5
  59. package/src/core/graph/v2/Graph.d.ts.map +1 -1
  60. package/src/core/graph/v2/Graph.js +0 -8
  61. package/src/core/localization/Localization.d.ts +0 -6
  62. package/src/core/localization/Localization.d.ts.map +1 -1
  63. package/src/core/localization/Localization.js +1 -10
  64. package/src/core/math/interval/NumericInterval.d.ts +0 -5
  65. package/src/core/math/interval/NumericInterval.d.ts.map +1 -1
  66. package/src/core/math/interval/NumericInterval.js +0 -7
  67. package/src/core/model/ObservedBoolean.d.ts +0 -5
  68. package/src/core/model/ObservedBoolean.d.ts.map +1 -1
  69. package/src/core/model/ObservedBoolean.js +0 -6
  70. package/src/core/model/object/ObjectPoolFactory.d.ts +0 -5
  71. package/src/core/model/object/ObjectPoolFactory.d.ts.map +1 -1
  72. package/src/core/model/object/ObjectPoolFactory.js +0 -7
  73. package/src/core/path/uri_resolve.d.ts +27 -0
  74. package/src/core/path/uri_resolve.d.ts.map +1 -0
  75. package/src/core/path/uri_resolve.js +144 -0
  76. package/src/core/process/worker/WorkerBuilder.d.ts +0 -15
  77. package/src/core/process/worker/WorkerBuilder.d.ts.map +1 -1
  78. package/src/core/process/worker/WorkerBuilder.js +0 -33
  79. package/src/engine/Engine.d.ts +0 -4
  80. package/src/engine/Engine.d.ts.map +1 -1
  81. package/src/engine/Engine.js +0 -6
  82. package/src/engine/animation/curve/AnimationCurve.d.ts +0 -6
  83. package/src/engine/animation/curve/AnimationCurve.d.ts.map +1 -1
  84. package/src/engine/animation/curve/AnimationCurve.js +0 -9
  85. package/src/engine/control/first-person/FirstPersonPlayerControllerSystem.d.ts +0 -15
  86. package/src/engine/control/first-person/FirstPersonPlayerControllerSystem.d.ts.map +1 -1
  87. package/src/engine/control/first-person/FirstPersonPlayerControllerSystem.js +0 -16
  88. package/src/engine/ecs/EntityBlueprint.js +1 -1
  89. package/src/engine/ecs/EntityComponentDataset.d.ts +0 -8
  90. package/src/engine/ecs/EntityComponentDataset.d.ts.map +1 -1
  91. package/src/engine/ecs/EntityComponentDataset.js +3 -16
  92. package/src/engine/ecs/EntityManager.d.ts +1 -20
  93. package/src/engine/ecs/EntityManager.d.ts.map +1 -1
  94. package/src/engine/ecs/EntityManager.js +3 -40
  95. package/src/engine/ecs/async/WorkerSystem.js +1 -1
  96. package/src/engine/ecs/storage/populateEngineSerializationRegistry.d.ts.map +1 -1
  97. package/src/engine/ecs/storage/populateEngineSerializationRegistry.js +0 -2
  98. package/src/engine/ecs/system/AbstractContextSystem.js +1 -1
  99. package/src/engine/ecs/terrain/ecs/Terrain.d.ts +0 -12
  100. package/src/engine/ecs/terrain/ecs/Terrain.d.ts.map +1 -1
  101. package/src/engine/ecs/terrain/ecs/Terrain.js +785 -801
  102. package/src/engine/ecs/terrain/ecs/splat/SplatMapping.d.ts +0 -10
  103. package/src/engine/ecs/terrain/ecs/splat/SplatMapping.d.ts.map +1 -1
  104. package/src/engine/ecs/terrain/ecs/splat/SplatMapping.js +0 -16
  105. package/src/engine/ecs/transform/Transform.d.ts +0 -7
  106. package/src/engine/ecs/transform/Transform.d.ts.map +1 -1
  107. package/src/engine/ecs/transform/Transform.js +0 -20
  108. package/src/engine/ecs/transform/TransformFlags.d.ts +0 -1
  109. package/src/engine/ecs/transform/TransformFlags.js +0 -4
  110. package/src/engine/graphics/ecs/animation/animator/AnimationClip.d.ts.map +1 -1
  111. package/src/engine/graphics/ecs/animation/animator/AnimationClip.js +27 -37
  112. package/src/engine/graphics/ecs/animation/animator/graph/AnimationTransition.d.ts +19 -22
  113. package/src/engine/graphics/ecs/animation/animator/graph/AnimationTransition.d.ts.map +1 -1
  114. package/src/engine/graphics/ecs/animation/animator/graph/AnimationTransition.js +27 -52
  115. package/src/engine/graphics/ecs/highlight/Highlight.js +1 -1
  116. package/src/engine/graphics/ecs/highlight/HighlightDefinition.d.ts +0 -10
  117. package/src/engine/graphics/ecs/highlight/HighlightDefinition.d.ts.map +1 -1
  118. package/src/engine/graphics/ecs/highlight/HighlightDefinition.js +0 -16
  119. package/src/engine/graphics/ecs/highlight/HighlightSerializationAdapter.js +2 -2
  120. package/src/engine/graphics/ecs/mesh-v2/MESH_MORPH_EVENT_CHANGE.d.ts +13 -0
  121. package/src/engine/graphics/ecs/mesh-v2/MESH_MORPH_EVENT_CHANGE.d.ts.map +1 -0
  122. package/src/engine/graphics/ecs/mesh-v2/MESH_MORPH_EVENT_CHANGE.js +12 -0
  123. package/src/engine/graphics/ecs/mesh-v2/MeshMorph.d.ts +64 -0
  124. package/src/engine/graphics/ecs/mesh-v2/MeshMorph.d.ts.map +1 -0
  125. package/src/engine/graphics/ecs/mesh-v2/MeshMorph.js +89 -0
  126. package/src/engine/graphics/ecs/mesh-v2/MeshSkin.d.ts +1 -1
  127. package/src/engine/graphics/ecs/mesh-v2/MeshSkin.js +1 -1
  128. package/src/engine/graphics/ecs/mesh-v2/ShadedGeometryFlags.d.ts +1 -0
  129. package/src/engine/graphics/ecs/mesh-v2/ShadedGeometryFlags.js +10 -3
  130. package/src/engine/graphics/ecs/mesh-v2/mesh_morph_announce_change.d.ts +14 -0
  131. package/src/engine/graphics/ecs/mesh-v2/mesh_morph_announce_change.d.ts.map +1 -0
  132. package/src/engine/graphics/ecs/mesh-v2/mesh_morph_announce_change.js +21 -0
  133. package/src/engine/graphics/impostors/octahedral/ImpostorDescription.d.ts +0 -6
  134. package/src/engine/graphics/impostors/octahedral/ImpostorDescription.d.ts.map +1 -1
  135. package/src/engine/graphics/impostors/octahedral/ImpostorDescription.js +0 -6
  136. package/src/engine/graphics3/HairSystem.js +1 -1
  137. package/src/engine/graphics3/MeshMorphSystem.d.ts +48 -0
  138. package/src/engine/graphics3/MeshMorphSystem.d.ts.map +1 -0
  139. package/src/engine/graphics3/MeshMorphSystem.js +355 -0
  140. package/src/engine/graphics3/MeshSkinSystem.js +2 -2
  141. package/src/engine/graphics3/MeshSystem.d.ts +2 -1
  142. package/src/engine/graphics3/MeshSystem.d.ts.map +1 -1
  143. package/src/engine/graphics3/MeshSystem.js +2 -1
  144. package/src/engine/graphics3/ShadedGeometrySystem.d.ts +1 -1
  145. package/src/engine/graphics3/ShadedGeometrySystem.js +2 -2
  146. package/src/engine/graphics3/Trail3DSystem.d.ts +0 -14
  147. package/src/engine/graphics3/Trail3DSystem.d.ts.map +1 -1
  148. package/src/engine/graphics3/Trail3DSystem.js +0 -36
  149. package/src/engine/graphics3/animation/AnimationGraphController.d.ts +19 -4
  150. package/src/engine/graphics3/animation/AnimationGraphController.d.ts.map +1 -1
  151. package/src/engine/graphics3/animation/AnimationGraphController.js +561 -518
  152. package/src/engine/graphics3/prefab/Prefab.d.ts +14 -0
  153. package/src/engine/graphics3/prefab/Prefab.d.ts.map +1 -1
  154. package/src/engine/graphics3/prefab/Prefab.js +16 -0
  155. package/src/engine/graphics3/prefab/prefab_compile.d.ts.map +1 -1
  156. package/src/engine/graphics3/prefab/prefab_compile.js +8 -1
  157. package/src/engine/graphics3/prefab/prefab_instantiate.d.ts +3 -2
  158. package/src/engine/graphics3/prefab/prefab_instantiate.d.ts.map +1 -1
  159. package/src/engine/graphics3/prefab/prefab_instantiate.js +17 -4
  160. package/src/engine/graphics3/prefab/prefab_place.d.ts +27 -9
  161. package/src/engine/graphics3/prefab/prefab_place.d.ts.map +1 -1
  162. package/src/engine/graphics3/prefab/prefab_place.js +69 -13
  163. package/src/engine/graphics3/register_clips.d.ts.map +1 -1
  164. package/src/engine/graphics3/register_clips.js +8 -2
  165. package/src/engine/input/ecs/ism/map/InputBinding.d.ts +0 -3
  166. package/src/engine/input/ecs/ism/map/InputBinding.d.ts.map +1 -1
  167. package/src/engine/input/ecs/ism/map/InputBinding.js +0 -3
  168. package/src/engine/intelligence/behavior/composite/CompositeBehavior.d.ts +0 -5
  169. package/src/engine/intelligence/behavior/composite/CompositeBehavior.d.ts.map +1 -1
  170. package/src/engine/intelligence/behavior/composite/CompositeBehavior.js +0 -8
  171. package/src/engine/network/NetworkSession.d.ts +0 -34
  172. package/src/engine/network/NetworkSession.d.ts.map +1 -1
  173. package/src/engine/network/NetworkSession.js +10 -99
  174. package/src/engine/network/orchestrator/NetworkPeer.d.ts +1 -1
  175. package/src/engine/network/orchestrator/NetworkPeer.js +1 -1
  176. package/src/engine/physics/ecs/PhysicsSystem.d.ts +0 -19
  177. package/src/engine/physics/ecs/PhysicsSystem.d.ts.map +1 -1
  178. package/src/engine/physics/ecs/PhysicsSystem.js +0 -39
  179. package/src/engine/physics/fluid/ecs/FluidObstacleSystem.d.ts +4 -4
  180. package/src/engine/sound/ecs/SoundListenerSystem.d.ts.map +1 -1
  181. package/src/engine/sound/ecs/SoundListenerSystem.js +2 -1
  182. package/src/engine/sound/sopra/legacy/SoundEmitter.d.ts +0 -10
  183. package/src/engine/sound/sopra/legacy/SoundEmitter.d.ts.map +1 -1
  184. package/src/engine/sound/sopra/legacy/SoundEmitter.js +0 -16
  185. package/src/engine/sound/sopra/legacy/SoundTrack.d.ts +0 -30
  186. package/src/engine/sound/sopra/legacy/SoundTrack.d.ts.map +1 -1
  187. package/src/engine/sound/sopra/legacy/SoundTrack.js +0 -48
  188. package/src/generation/grid/generation/road/GridTaskGenerateRoads.d.ts.map +1 -1
  189. package/src/generation/grid/generation/road/GridTaskGenerateRoads.js +5 -4
  190. package/src/generation/grid/generation/road/RoadConnectionNetwork.d.ts.map +1 -1
  191. package/src/generation/grid/generation/road/RoadConnectionNetwork.js +3 -2
  192. package/src/generation/theme/ThemeEngine.d.ts.map +1 -1
  193. package/src/generation/theme/ThemeEngine.js +2 -1
  194. package/src/shade/playground/acoustics/main.js +1 -1
  195. package/src/shade/playground/hair_skinned/skinned_hair.js +2 -2
  196. package/src/shade/playground/point_shadows/README.md +58 -0
  197. package/src/shade/playground/point_shadows/index.html +151 -0
  198. package/src/shade/playground/point_shadows/main.d.ts +2 -0
  199. package/src/shade/playground/point_shadows/main.d.ts.map +1 -0
  200. package/src/shade/playground/point_shadows/main.js +532 -0
  201. package/src/shade/playground/point_shadows/scene.d.ts +131 -0
  202. package/src/shade/playground/point_shadows/scene.d.ts.map +1 -0
  203. package/src/shade/playground/point_shadows/scene.js +423 -0
  204. package/src/shade/playground/point_shadows/shadow_probe.d.ts +111 -0
  205. package/src/shade/playground/point_shadows/shadow_probe.d.ts.map +1 -0
  206. package/src/shade/playground/point_shadows/shadow_probe.js +382 -0
  207. package/src/shade/playground/skinned_blas_refit/verify_clone_leaves.js +1 -1
  208. package/src/shade/playground/skinned_blas_refit/verify_instance_bounds.js +1 -1
  209. package/src/shade/playground/skinned_blas_refit/verify_skinned_blas_refit.js +1 -1
  210. package/src/shade/playground/skinned_mesh_soup/main.js +1 -1
  211. package/src/shade/playground/skinned_mesh_soup/verify_clone_vertices.js +2 -2
  212. package/src/shade/renderer/Renderer.d.ts +2 -2
  213. package/src/shade/renderer/Renderer.js +16 -16
  214. package/src/shade/renderer/acoustics/GPUAcousticLattice.d.ts +1 -1
  215. package/src/shade/renderer/acoustics/GPUAcousticProbes.d.ts +1 -1
  216. package/src/shade/renderer/acoustics/GPUAcoustics.d.ts +1 -1
  217. package/src/shade/renderer/animation/ANIMATION_DATABASE_SPEC.d.ts +5 -0
  218. package/src/shade/renderer/animation/ANIMATION_DATABASE_SPEC.d.ts.map +1 -1
  219. package/src/shade/renderer/animation/ANIMATION_DATABASE_SPEC.js +19 -0
  220. package/src/shade/renderer/animation/ANIMATION_MORPH_STRUCT.d.ts +8 -0
  221. package/src/shade/renderer/animation/ANIMATION_MORPH_STRUCT.d.ts.map +1 -0
  222. package/src/shade/renderer/animation/ANIMATION_MORPH_STRUCT.js +19 -0
  223. package/src/shade/renderer/animation/ANIMATION_MORPH_WEIGHT_STRUCT.d.ts +6 -0
  224. package/src/shade/renderer/animation/ANIMATION_MORPH_WEIGHT_STRUCT.d.ts.map +1 -0
  225. package/src/shade/renderer/animation/ANIMATION_MORPH_WEIGHT_STRUCT.js +13 -0
  226. package/src/shade/renderer/animation/GPUAnimationManager.d.ts +71 -0
  227. package/src/shade/renderer/animation/GPUAnimationManager.d.ts.map +1 -1
  228. package/src/shade/renderer/animation/GPUAnimationManager.js +559 -9
  229. package/src/shade/renderer/animation/ShadeAnimationChannel.d.ts +23 -2
  230. package/src/shade/renderer/animation/ShadeAnimationChannel.d.ts.map +1 -1
  231. package/src/shade/renderer/animation/ShadeAnimationChannel.js +43 -2
  232. package/src/shade/renderer/animation/ShadeAnimationClip.d.ts +9 -3
  233. package/src/shade/renderer/animation/ShadeAnimationClip.d.ts.map +1 -1
  234. package/src/shade/renderer/animation/ShadeAnimationClip.js +67 -3
  235. package/src/shade/renderer/animation/ShadeAnimationClipSerializationAdapter.d.ts +3 -2
  236. package/src/shade/renderer/animation/ShadeAnimationClipSerializationAdapter.d.ts.map +1 -1
  237. package/src/shade/renderer/animation/ShadeAnimationClipSerializationAdapter.js +6 -3
  238. package/src/shade/renderer/animation/ShadeAnimationClipSerializationUpgrader_0_1.d.ts +14 -0
  239. package/src/shade/renderer/animation/ShadeAnimationClipSerializationUpgrader_0_1.d.ts.map +1 -0
  240. package/src/shade/renderer/animation/ShadeAnimationClipSerializationUpgrader_0_1.js +49 -0
  241. package/src/shade/renderer/animation/ShadeAnimationProperty.d.ts +12 -0
  242. package/src/shade/renderer/animation/ShadeAnimationProperty.d.ts.map +1 -0
  243. package/src/shade/renderer/animation/ShadeAnimationProperty.js +30 -0
  244. package/src/shade/renderer/animation/Skin.d.ts +1 -1
  245. package/src/shade/renderer/animation/Skin.js +1 -1
  246. package/src/shade/renderer/animation/deformation/DEFORMATION_BINDING_STRUCT.d.ts +26 -0
  247. package/src/shade/renderer/animation/deformation/DEFORMATION_BINDING_STRUCT.d.ts.map +1 -0
  248. package/src/shade/renderer/animation/{skinning/SKINNING_BINDING_STRUCT.js → deformation/DEFORMATION_BINDING_STRUCT.js} +33 -8
  249. package/src/shade/renderer/animation/{skinning/GPUMeshSkinningContext.d.ts → deformation/GPUMeshDeformationContext.d.ts} +60 -17
  250. package/src/shade/renderer/animation/deformation/GPUMeshDeformationContext.d.ts.map +1 -0
  251. package/src/shade/renderer/animation/{skinning/GPUMeshSkinningContext.js → deformation/GPUMeshDeformationContext.js} +458 -55
  252. package/src/shade/renderer/animation/{skinning/bounds_refresh/shader_skinned_mesh_bounds_refresh.d.ts → deformation/bounds_refresh/shader_deformed_mesh_bounds_refresh.d.ts} +2 -2
  253. package/src/shade/renderer/animation/deformation/bounds_refresh/shader_deformed_mesh_bounds_refresh.d.ts.map +1 -0
  254. package/src/shade/renderer/animation/{skinning/bounds_refresh/shader_skinned_mesh_bounds_refresh.js → deformation/bounds_refresh/shader_deformed_mesh_bounds_refresh.js} +3 -3
  255. package/src/shade/renderer/animation/deformation/bounds_refresh/shader_geometry_sphere_derive.d.ts.map +1 -0
  256. package/src/shade/renderer/animation/{skinning → deformation}/bounds_refresh/shader_geometry_sphere_derive.js +2 -2
  257. package/src/shade/renderer/animation/deformation/bounds_refresh/shader_meshlet_bounds_reduce.d.ts.map +1 -0
  258. package/src/shade/renderer/animation/{skinning → deformation}/bounds_refresh/shader_meshlet_bounds_reduce.js +2 -2
  259. package/src/shade/renderer/animation/deformation/bounds_refresh/shader_meshlet_bounds_scatter.d.ts.map +1 -0
  260. package/src/shade/renderer/animation/{skinning → deformation}/bounds_refresh/shader_meshlet_bounds_scatter.js +2 -2
  261. package/src/shade/renderer/animation/morph/shader_meshlet_apply_morph.d.ts +24 -0
  262. package/src/shade/renderer/animation/morph/shader_meshlet_apply_morph.d.ts.map +1 -0
  263. package/src/shade/renderer/animation/morph/shader_meshlet_apply_morph.js +257 -0
  264. package/src/shade/renderer/animation/morph/shader_morph_weights_resolve.d.ts +18 -0
  265. package/src/shade/renderer/animation/morph/shader_morph_weights_resolve.d.ts.map +1 -0
  266. package/src/shade/renderer/animation/morph/shader_morph_weights_resolve.js +75 -0
  267. package/src/shade/renderer/animation/shader_animation_apply.d.ts.map +1 -1
  268. package/src/shade/renderer/animation/shader_animation_apply.js +3 -1
  269. package/src/shade/renderer/animation/skinning/shader_meshlet_apply_skinning.d.ts.map +1 -1
  270. package/src/shade/renderer/animation/skinning/shader_meshlet_apply_skinning.js +31 -7
  271. package/src/shade/renderer/fluid/GPUFluidCascade.d.ts +3 -3
  272. package/src/shade/renderer/fluid/GPUFluidCascadeStack.d.ts +1 -1
  273. package/src/shade/renderer/fluid/forcing/GPUFluidForcing.d.ts +7 -7
  274. package/src/shade/renderer/fluid/pressure/GPUFluidPressureSolve.d.ts +1 -1
  275. package/src/shade/renderer/fluid/query/GPUFluidQueries.d.ts +1 -1
  276. package/src/shade/renderer/geometry/Attribute.d.ts +0 -10
  277. package/src/shade/renderer/geometry/Attribute.d.ts.map +1 -1
  278. package/src/shade/renderer/geometry/Attribute.js +0 -16
  279. package/src/shade/renderer/geometry/GPUGeometryManager.d.ts +8 -1
  280. package/src/shade/renderer/geometry/GPUGeometryManager.d.ts.map +1 -1
  281. package/src/shade/renderer/geometry/GPUGeometryManager.js +18 -1
  282. package/src/shade/renderer/geometry/bvh/GPUBLASRefitBatch.d.ts +1 -1
  283. package/src/shade/renderer/geometry/bvh/GPUBLASRefitBatch.js +1 -1
  284. package/src/shade/renderer/geometry/meshlet/GPUMeshletManager.d.ts +9 -0
  285. package/src/shade/renderer/geometry/meshlet/GPUMeshletManager.d.ts.map +1 -1
  286. package/src/shade/renderer/geometry/meshlet/GPUMeshletManager.js +30 -2
  287. package/src/shade/renderer/geometry/meshlet/MeshletBatch.d.ts +27 -0
  288. package/src/shade/renderer/geometry/meshlet/MeshletBatch.d.ts.map +1 -1
  289. package/src/shade/renderer/geometry/meshlet/MeshletBatch.js +85 -6
  290. package/src/shade/renderer/geometry/meshlet/meshlet_payload_collapse.d.ts +5 -1
  291. package/src/shade/renderer/geometry/meshlet/meshlet_payload_collapse.d.ts.map +1 -1
  292. package/src/shade/renderer/geometry/meshlet/meshlet_payload_collapse.js +8 -3
  293. package/src/shade/renderer/geometry/meshlet_geometry_build_from_geometry.d.ts +13 -0
  294. package/src/shade/renderer/geometry/meshlet_geometry_build_from_geometry.d.ts.map +1 -1
  295. package/src/shade/renderer/geometry/meshlet_geometry_build_from_geometry.js +47 -4
  296. package/src/shade/renderer/geometry/morph/MESHLET_MORPH_LAYOUT.d.ts +51 -0
  297. package/src/shade/renderer/geometry/morph/MESHLET_MORPH_LAYOUT.d.ts.map +1 -0
  298. package/src/shade/renderer/geometry/morph/MESHLET_MORPH_LAYOUT.js +60 -0
  299. package/src/shade/renderer/geometry/morph/MESHLET_MORPH_NORMAL_EXPONENT.d.ts +12 -0
  300. package/src/shade/renderer/geometry/morph/MESHLET_MORPH_NORMAL_EXPONENT.d.ts.map +1 -0
  301. package/src/shade/renderer/geometry/morph/MESHLET_MORPH_NORMAL_EXPONENT.js +11 -0
  302. package/src/shade/renderer/geometry/morph/MeshletMorphTargets.d.ts +73 -0
  303. package/src/shade/renderer/geometry/morph/MeshletMorphTargets.d.ts.map +1 -0
  304. package/src/shade/renderer/geometry/morph/MeshletMorphTargets.js +130 -0
  305. package/src/shade/renderer/geometry/morph/MeshletMorphTargetsSerializationAdapter.d.ts +34 -0
  306. package/src/shade/renderer/geometry/morph/MeshletMorphTargetsSerializationAdapter.d.ts.map +1 -0
  307. package/src/shade/renderer/geometry/morph/MeshletMorphTargetsSerializationAdapter.js +126 -0
  308. package/src/shade/renderer/geometry/morph/MorphedGeometry.d.ts +50 -0
  309. package/src/shade/renderer/geometry/morph/MorphedGeometry.d.ts.map +1 -0
  310. package/src/shade/renderer/geometry/morph/MorphedGeometry.js +81 -0
  311. package/src/shade/renderer/geometry/morph/meshlet_morph_targets_build.d.ts +22 -0
  312. package/src/shade/renderer/geometry/morph/meshlet_morph_targets_build.d.ts.map +1 -0
  313. package/src/shade/renderer/geometry/morph/meshlet_morph_targets_build.js +375 -0
  314. package/src/shade/renderer/geometry/morph/meshlet_morph_targets_read.d.ts +25 -0
  315. package/src/shade/renderer/geometry/morph/meshlet_morph_targets_read.d.ts.map +1 -0
  316. package/src/shade/renderer/geometry/morph/meshlet_morph_targets_read.js +134 -0
  317. package/src/shade/renderer/geometry/morph/meshlet_morph_targets_validate.d.ts +15 -0
  318. package/src/shade/renderer/geometry/morph/meshlet_morph_targets_validate.d.ts.map +1 -0
  319. package/src/shade/renderer/geometry/morph/meshlet_morph_targets_validate.js +110 -0
  320. package/src/shade/renderer/geometry/morph/morphed_geometry_build.d.ts +22 -0
  321. package/src/shade/renderer/geometry/morph/morphed_geometry_build.d.ts.map +1 -0
  322. package/src/shade/renderer/geometry/morph/morphed_geometry_build.js +32 -0
  323. package/src/shade/renderer/geometry/virtual/build/level/vgeo_build_cluster.d.ts.map +1 -1
  324. package/src/shade/renderer/geometry/virtual/build/level/vgeo_build_cluster.js +2 -1
  325. package/src/shade/renderer/geometry/virtual/runtime/VGeoViewCut.d.ts +8 -0
  326. package/src/shade/renderer/geometry/virtual/runtime/VGeoViewCut.d.ts.map +1 -1
  327. package/src/shade/renderer/geometry/virtual/runtime/VGeoViewCut.js +10 -1
  328. package/src/shade/renderer/geometry/virtual/runtime/graph_vgeo_expand_if_enabled.d.ts +9 -3
  329. package/src/shade/renderer/geometry/virtual/runtime/graph_vgeo_expand_if_enabled.d.ts.map +1 -1
  330. package/src/shade/renderer/geometry/virtual/runtime/graph_vgeo_expand_if_enabled.js +13 -4
  331. package/src/shade/renderer/geometry/virtual/runtime/graph_vgeo_expand_instances_to_meshlets.d.ts +9 -3
  332. package/src/shade/renderer/geometry/virtual/runtime/graph_vgeo_expand_instances_to_meshlets.d.ts.map +1 -1
  333. package/src/shade/renderer/geometry/virtual/runtime/graph_vgeo_expand_instances_to_meshlets.js +14 -9
  334. package/src/shade/renderer/global_illumination/probe_clipmap/GPUProbeClipmapGI.d.ts +1 -1
  335. package/src/shade/renderer/global_illumination/probe_clipmap/ProbeClipmapSceneHolds.js +3 -3
  336. package/src/shade/renderer/hair/GPUHairSystem.js +1 -1
  337. package/src/shade/renderer/loader/SceneNode.d.ts +20 -1
  338. package/src/shade/renderer/loader/SceneNode.d.ts.map +1 -1
  339. package/src/shade/renderer/loader/SceneNode.js +142 -114
  340. package/src/shade/renderer/loader/gltf/load_gltf.d.ts +1 -0
  341. package/src/shade/renderer/loader/gltf/load_gltf.d.ts.map +1 -1
  342. package/src/shade/renderer/loader/gltf/load_gltf.js +214 -30
  343. package/src/shade/renderer/loader/gltf/tiny-gltf.d.ts +5 -3
  344. package/src/shade/renderer/loader/gltf/tiny-gltf.d.ts.map +1 -1
  345. package/src/shade/renderer/loader/gltf/tiny-gltf.js +9 -33
  346. package/src/shade/renderer/loader/mtf/MTFMorphBinding.d.ts +41 -0
  347. package/src/shade/renderer/loader/mtf/MTFMorphBinding.d.ts.map +1 -0
  348. package/src/shade/renderer/loader/mtf/MTFMorphBinding.js +60 -0
  349. package/src/shade/renderer/loader/mtf/MTFMorphBindingSerializationAdapter.d.ts +31 -0
  350. package/src/shade/renderer/loader/mtf/MTFMorphBindingSerializationAdapter.d.ts.map +1 -0
  351. package/src/shade/renderer/loader/mtf/MTFMorphBindingSerializationAdapter.js +108 -0
  352. package/src/shade/renderer/loader/mtf/MTF_PACKAGE_VERSION.d.ts +3 -0
  353. package/src/shade/renderer/loader/mtf/MTF_PACKAGE_VERSION.d.ts.map +1 -1
  354. package/src/shade/renderer/loader/mtf/MTF_PACKAGE_VERSION.js +4 -1
  355. package/src/shade/renderer/loader/mtf/load_mtf.d.ts +1 -1
  356. package/src/shade/renderer/loader/mtf/load_mtf.d.ts.map +1 -1
  357. package/src/shade/renderer/loader/mtf/load_mtf.js +16 -4
  358. package/src/shade/renderer/loader/mtf/mtf_export.d.ts.map +1 -1
  359. package/src/shade/renderer/loader/mtf/mtf_export.js +7 -0
  360. package/src/shade/renderer/loader/mtf/mtf_read_scene.d.ts +6 -3
  361. package/src/shade/renderer/loader/mtf/mtf_read_scene.d.ts.map +1 -1
  362. package/src/shade/renderer/loader/mtf/mtf_read_scene.js +43 -3
  363. package/src/shade/renderer/loader/mtf/mtf_serialization_registry.d.ts +2 -0
  364. package/src/shade/renderer/loader/mtf/mtf_serialization_registry.d.ts.map +1 -1
  365. package/src/shade/renderer/loader/mtf/mtf_serialization_registry.js +9 -0
  366. package/src/shade/renderer/loader/mtf/mtf_write.d.ts +3 -1
  367. package/src/shade/renderer/loader/mtf/mtf_write.d.ts.map +1 -1
  368. package/src/shade/renderer/loader/mtf/mtf_write.js +20 -1
  369. package/src/shade/renderer/object_property/ObjectType.d.ts +1 -0
  370. package/src/shade/renderer/object_property/ObjectType.js +8 -0
  371. package/src/shade/renderer/object_property/chunk_write_object_property.d.ts +6 -7
  372. package/src/shade/renderer/object_property/chunk_write_object_property.d.ts.map +1 -1
  373. package/src/shade/renderer/object_property/chunk_write_object_property.js +13 -7
  374. package/src/shade/renderer/object_property/chunk_write_object_property_morph_weight.d.ts +17 -0
  375. package/src/shade/renderer/object_property/chunk_write_object_property_morph_weight.d.ts.map +1 -0
  376. package/src/shade/renderer/object_property/chunk_write_object_property_morph_weight.js +38 -0
  377. package/src/shade/renderer/postprocess/nss/NSS.d.ts +1 -1
  378. package/src/shade/renderer/rasterize/TemplatePassDescriptor.d.ts +3 -1
  379. package/src/shade/renderer/rasterize/TemplatePassDescriptor.d.ts.map +1 -1
  380. package/src/shade/renderer/rasterize/TemplatePassDescriptor.js +2 -0
  381. package/src/shade/renderer/rasterize/bucket/prepare_meshlet_draw_commands_by_material.d.ts +5 -3
  382. package/src/shade/renderer/rasterize/bucket/prepare_meshlet_draw_commands_by_material.d.ts.map +1 -1
  383. package/src/shade/renderer/rasterize/bucket/prepare_meshlet_draw_commands_by_material.js +14 -8
  384. package/src/shade/renderer/rasterize/expand/graph_meshlets_rasterize.d.ts +65 -0
  385. package/src/shade/renderer/rasterize/expand/graph_meshlets_rasterize.d.ts.map +1 -1
  386. package/src/shade/renderer/rasterize/expand/graph_meshlets_rasterize.js +189 -115
  387. package/src/shade/renderer/rasterize/fast/graph_draw_prepared_scene.d.ts +67 -0
  388. package/src/shade/renderer/rasterize/fast/graph_draw_prepared_scene.d.ts.map +1 -0
  389. package/src/shade/renderer/rasterize/fast/graph_draw_prepared_scene.js +175 -0
  390. package/src/shade/renderer/rasterize/fast/graph_prepare_scene_draw.d.ts +81 -0
  391. package/src/shade/renderer/rasterize/fast/graph_prepare_scene_draw.d.ts.map +1 -0
  392. package/src/shade/renderer/rasterize/fast/graph_prepare_scene_draw.js +147 -0
  393. package/src/shade/renderer/rasterize/fast/graph_rasterize_scene_fast.d.ts +37 -0
  394. package/src/shade/renderer/rasterize/fast/graph_rasterize_scene_fast.d.ts.map +1 -1
  395. package/src/shade/renderer/rasterize/fast/graph_rasterize_scene_fast.js +105 -59
  396. package/src/shade/renderer/rasterize/native/graph_rasterize_meshes_alpha_tested.d.ts +104 -0
  397. package/src/shade/renderer/rasterize/native/graph_rasterize_meshes_alpha_tested.d.ts.map +1 -1
  398. package/src/shade/renderer/rasterize/native/graph_rasterize_meshes_alpha_tested.js +237 -114
  399. package/src/shade/renderer/rasterize/standard/graph_rasterize_partial_opaque.d.ts.map +1 -1
  400. package/src/shade/renderer/rasterize/standard/graph_rasterize_partial_opaque.js +4 -1
  401. package/src/shade/renderer/rasterize/standard/graph_rasterize_remaining_opaque.d.ts.map +1 -1
  402. package/src/shade/renderer/rasterize/standard/graph_rasterize_remaining_opaque.js +4 -1
  403. package/src/shade/renderer/scene/GPUSceneContext.d.ts +5 -6
  404. package/src/shade/renderer/scene/GPUSceneContext.d.ts.map +1 -1
  405. package/src/shade/renderer/scene/GPUSceneContext.js +17 -20
  406. package/src/shade/renderer/scene/MESH_INSTANCE_METADATA_STRUCT.d.ts +1 -1
  407. package/src/shade/renderer/scene/MESH_INSTANCE_METADATA_STRUCT.d.ts.map +1 -1
  408. package/src/shade/renderer/scene/MESH_INSTANCE_METADATA_STRUCT.js +2 -2
  409. package/src/shade/renderer/scene/chunk_mesh_flags.js +3 -3
  410. package/src/shade/renderer/scene/movers/graph_scene_movers.d.ts +1 -1
  411. package/src/shade/renderer/scene/movers/graph_scene_movers.d.ts.map +1 -1
  412. package/src/shade/renderer/scene/movers/graph_scene_movers.js +20 -13
  413. package/src/shade/renderer/scene/movers/shader_scene_deformed_movers.d.ts +25 -0
  414. package/src/shade/renderer/scene/movers/shader_scene_deformed_movers.d.ts.map +1 -0
  415. package/src/shade/renderer/scene/movers/{shader_scene_skinned_movers.js → shader_scene_deformed_movers.js} +28 -18
  416. package/src/shade/renderer/scene/movers/shader_scene_movers.d.ts +1 -1
  417. package/src/shade/renderer/scene/movers/shader_scene_movers.js +2 -2
  418. package/src/shade/renderer/scene/rows/GPUSceneRows.d.ts +13 -13
  419. package/src/shade/renderer/scene/rows/GPUSceneRows.d.ts.map +1 -1
  420. package/src/shade/renderer/scene/rows/GPUSceneRows.js +30 -30
  421. package/src/shade/renderer/shader/ComputeShader.d.ts +0 -18
  422. package/src/shade/renderer/shader/ComputeShader.d.ts.map +1 -1
  423. package/src/shade/renderer/shader/ComputeShader.js +0 -34
  424. package/src/shade/renderer/shader/chunk/atmosphere/phase/jd/chunk_sample_draine.d.ts +3 -2
  425. package/src/shade/renderer/shader/chunk/atmosphere/phase/jd/chunk_sample_draine.d.ts.map +1 -1
  426. package/src/shade/renderer/shader/chunk/atmosphere/phase/jd/chunk_sample_draine.js +3 -2
  427. package/src/shade/renderer/shader/chunk/geometry/meshlet/chunk_read_lattice_position.d.ts +17 -0
  428. package/src/shade/renderer/shader/chunk/geometry/meshlet/chunk_read_lattice_position.d.ts.map +1 -0
  429. package/src/shade/renderer/shader/chunk/geometry/meshlet/chunk_read_lattice_position.js +78 -0
  430. package/src/shade/renderer/shader/chunk/geometry/meshlet/chunk_read_meshlet_position.d.ts +2 -1
  431. package/src/shade/renderer/shader/chunk/geometry/meshlet/chunk_read_meshlet_position.d.ts.map +1 -1
  432. package/src/shade/renderer/shader/chunk/geometry/meshlet/chunk_read_meshlet_position.js +10 -54
  433. package/src/shade/renderer/shader/chunk/texture/octahedral/chunk_texture_octahedral_wrap_texel_coordinates.d.ts.map +1 -1
  434. package/src/shade/renderer/shader/chunk/texture/octahedral/chunk_texture_octahedral_wrap_texel_coordinates.js +6 -0
  435. package/src/shade/renderer/shader/pass/RenderPassColorAttachmentDescriptor.d.ts +4 -0
  436. package/src/shade/renderer/shader/pass/RenderPassColorAttachmentDescriptor.d.ts.map +1 -1
  437. package/src/shade/renderer/shader/pass/RenderPassColorAttachmentDescriptor.js +4 -0
  438. package/src/shade/renderer/shader/pass/RenderPassDepthStencilAttachmentDescriptor.d.ts +4 -0
  439. package/src/shade/renderer/shader/pass/RenderPassDepthStencilAttachmentDescriptor.d.ts.map +1 -1
  440. package/src/shade/renderer/shader/pass/RenderPassDepthStencilAttachmentDescriptor.js +4 -0
  441. package/src/shade/renderer/shader/pass/RenderPassDescriptor.d.ts +18 -0
  442. package/src/shade/renderer/shader/pass/RenderPassDescriptor.d.ts.map +1 -1
  443. package/src/shade/renderer/shader/pass/RenderPassDescriptor.js +11 -0
  444. package/src/shade/renderer/shadow/map/DEFAULT_SHADOWMAP_LOCAL_RESOLUTION.d.ts +8 -0
  445. package/src/shade/renderer/shadow/map/DEFAULT_SHADOWMAP_LOCAL_RESOLUTION.d.ts.map +1 -0
  446. package/src/shade/renderer/shadow/map/DEFAULT_SHADOWMAP_LOCAL_RESOLUTION.js +7 -0
  447. package/src/shade/renderer/shadow/map/DEFAULT_SHADOWMAP_UPDATE_BUDGET.d.ts +1 -1
  448. package/src/shade/renderer/shadow/map/DEFAULT_SHADOWMAP_UPDATE_BUDGET.js +1 -1
  449. package/src/shade/renderer/shadow/map/DirectionalLightShadowmap.js +1 -1
  450. package/src/shade/renderer/shadow/map/GPUSceneShadowmapContext.d.ts +122 -141
  451. package/src/shade/renderer/shadow/map/GPUSceneShadowmapContext.d.ts.map +1 -1
  452. package/src/shade/renderer/shadow/map/GPUSceneShadowmapContext.js +213 -1719
  453. package/src/shade/renderer/shadow/map/POINT_SHADOW_CUBE_LAYOUT.d.ts +36 -0
  454. package/src/shade/renderer/shadow/map/POINT_SHADOW_CUBE_LAYOUT.d.ts.map +1 -1
  455. package/src/shade/renderer/shadow/map/POINT_SHADOW_CUBE_LAYOUT.js +55 -0
  456. package/src/shade/renderer/shadow/map/PointLightShadowmap.d.ts +35 -10
  457. package/src/shade/renderer/shadow/map/PointLightShadowmap.d.ts.map +1 -1
  458. package/src/shade/renderer/shadow/map/PointLightShadowmap.js +71 -56
  459. package/src/shade/renderer/shadow/map/SHADOW_CULL_POLICY.d.ts +10 -0
  460. package/src/shade/renderer/shadow/map/SHADOW_CULL_POLICY.d.ts.map +1 -0
  461. package/src/shade/renderer/shadow/map/SHADOW_CULL_POLICY.js +11 -0
  462. package/src/shade/renderer/shadow/map/ShadowViews.d.ts +67 -0
  463. package/src/shade/renderer/shadow/map/ShadowViews.d.ts.map +1 -0
  464. package/src/shade/renderer/shadow/map/ShadowViews.js +113 -0
  465. package/src/shade/renderer/shadow/map/Shadowmap.d.ts +6 -0
  466. package/src/shade/renderer/shadow/map/Shadowmap.d.ts.map +1 -1
  467. package/src/shade/renderer/shadow/map/Shadowmap.js +9 -0
  468. package/src/shade/renderer/shadow/map/ShadowmapAtlas.d.ts +60 -0
  469. package/src/shade/renderer/shadow/map/ShadowmapAtlas.d.ts.map +1 -0
  470. package/src/shade/renderer/shadow/map/ShadowmapAtlas.js +172 -0
  471. package/src/shade/renderer/shadow/map/ShadowmapDrawSelector.js +3 -3
  472. package/src/shade/renderer/shadow/map/ShadowmapRecords.d.ts +50 -0
  473. package/src/shade/renderer/shadow/map/ShadowmapRecords.d.ts.map +1 -0
  474. package/src/shade/renderer/shadow/map/ShadowmapRecords.js +145 -0
  475. package/src/shade/renderer/shadow/map/csm/CascadeShadows.d.ts +102 -0
  476. package/src/shade/renderer/shadow/map/csm/CascadeShadows.d.ts.map +1 -0
  477. package/src/shade/renderer/shadow/map/csm/CascadeShadows.js +446 -0
  478. package/src/shade/renderer/shadow/map/draw_shadow_views_into_atlas.d.ts +23 -0
  479. package/src/shade/renderer/shadow/map/draw_shadow_views_into_atlas.d.ts.map +1 -0
  480. package/src/shade/renderer/shadow/map/draw_shadow_views_into_atlas.js +69 -0
  481. package/src/shade/renderer/shadow/map/point/POINT_SHADOW_GENERATORS.d.ts +76 -0
  482. package/src/shade/renderer/shadow/map/point/POINT_SHADOW_GENERATORS.d.ts.map +1 -0
  483. package/src/shade/renderer/shadow/map/point/POINT_SHADOW_GENERATORS.js +154 -0
  484. package/src/shade/renderer/shadow/map/point/PointShadowFaces.d.ts +54 -0
  485. package/src/shade/renderer/shadow/map/point/PointShadowFaces.d.ts.map +1 -0
  486. package/src/shade/renderer/shadow/map/point/PointShadowFaces.js +144 -0
  487. package/src/shade/renderer/shadow/map/point/PointShadows.d.ts +94 -0
  488. package/src/shade/renderer/shadow/map/point/PointShadows.d.ts.map +1 -0
  489. package/src/shade/renderer/shadow/map/point/PointShadows.js +248 -0
  490. package/src/shade/renderer/shadow/map/spot/SpotShadows.d.ts +72 -0
  491. package/src/shade/renderer/shadow/map/spot/SpotShadows.d.ts.map +1 -0
  492. package/src/shade/renderer/shadow/map/spot/SpotShadows.js +148 -0
  493. package/src/shade/renderer/shadow/vsm/DEFAULT_VSM_FIRST_TEXEL_SIZE.d.ts +1 -1
  494. package/src/shade/renderer/shadow/vsm/DEFAULT_VSM_FIRST_TEXEL_SIZE.js +1 -1
  495. package/src/shade/renderer/shadow/vsm/DEFAULT_VSM_PAGE_BUDGET.d.ts +1 -1
  496. package/src/shade/renderer/shadow/vsm/DEFAULT_VSM_PAGE_BUDGET.js +1 -1
  497. package/src/shade/renderer/shadow/vsm/VSMPageManager.d.ts.map +1 -1
  498. package/src/shade/renderer/shadow/vsm/VSMPageManager.js +33 -163
  499. package/src/shade/renderer/shadow/vsm/VirtualShadowMap.d.ts +6 -10
  500. package/src/shade/renderer/shadow/vsm/VirtualShadowMap.d.ts.map +1 -1
  501. package/src/shade/renderer/shadow/vsm/VirtualShadowMap.js +423 -418
  502. package/src/shade/renderer/shadow/vsm/VirtualShadows.d.ts +178 -0
  503. package/src/shade/renderer/shadow/vsm/VirtualShadows.d.ts.map +1 -0
  504. package/src/shade/renderer/shadow/vsm/VirtualShadows.js +655 -0
  505. package/src/shade/renderer/texture/RenderTarget.d.ts +4 -0
  506. package/src/shade/renderer/texture/RenderTarget.d.ts.map +1 -1
  507. package/src/shade/renderer/texture/RenderTarget.js +4 -0
  508. package/src/shade/renderer/texture/virtual/README.md +12 -4
  509. package/src/shade/renderer/texture/virtual/VTLodBiasController.d.ts +116 -0
  510. package/src/shade/renderer/texture/virtual/VTLodBiasController.d.ts.map +1 -0
  511. package/src/shade/renderer/texture/virtual/VTLodBiasController.js +301 -0
  512. package/src/shade/renderer/texture/virtual/VirtualTextureManager.d.ts +8 -3
  513. package/src/shade/renderer/texture/virtual/VirtualTextureManager.d.ts.map +1 -1
  514. package/src/shade/renderer/texture/virtual/VirtualTextureManager.js +110 -20
  515. package/src/shade/renderer/view/GPUViewContext.d.ts.map +1 -1
  516. package/src/shade/renderer/view/GPUViewContext.js +8 -54
  517. package/src/shade/renderer/view/write_view_uniforms.d.ts +21 -0
  518. package/src/shade/renderer/view/write_view_uniforms.d.ts.map +1 -0
  519. package/src/shade/renderer/view/write_view_uniforms.js +83 -0
  520. package/src/shade/renderer/water/query/GPUWaterQueries.d.ts +1 -1
  521. package/src/shade/renderer/wind/GPUSceneWind.d.ts +1 -1
  522. package/src/view/elements/image/ImageView.js +2 -2
  523. package/src/view/elements/video/VideoView.js +2 -2
  524. package/src/view/interaction/InterfaceCommand.d.ts +0 -20
  525. package/src/view/interaction/InterfaceCommand.d.ts.map +1 -1
  526. package/src/view/interaction/InterfaceCommand.js +116 -148
  527. package/src/core/color/hsv/hsv2rgb_float.d.ts +0 -24
  528. package/src/core/color/hsv/hsv2rgb_float.d.ts.map +0 -1
  529. package/src/core/color/hsv/hsv2rgb_float.js +0 -36
  530. package/src/core/graph/metis/metis.d.ts +0 -38
  531. package/src/core/graph/metis/metis.d.ts.map +0 -1
  532. package/src/core/graph/metis/metis.js +0 -70
  533. package/src/core/graph/metis/metis_cluster_bs.d.ts +0 -23
  534. package/src/core/graph/metis/metis_cluster_bs.d.ts.map +0 -1
  535. package/src/core/graph/metis/metis_cluster_bs.js +0 -138
  536. package/src/core/graph/metis/metis_options.d.ts +0 -51
  537. package/src/core/graph/metis/metis_options.d.ts.map +0 -1
  538. package/src/core/graph/metis/metis_options.js +0 -51
  539. package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite_2d.d.ts +0 -35
  540. package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite_2d.d.ts.map +0 -1
  541. package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite_2d.js +0 -41
  542. package/src/engine/ecs/components/PropertySet.d.ts +0 -48
  543. package/src/engine/ecs/components/PropertySet.d.ts.map +0 -1
  544. package/src/engine/ecs/components/PropertySet.js +0 -115
  545. package/src/engine/ecs/components/PropertySetSerializationAdapter.d.ts +0 -19
  546. package/src/engine/ecs/components/PropertySetSerializationAdapter.d.ts.map +0 -1
  547. package/src/engine/ecs/components/PropertySetSerializationAdapter.js +0 -29
  548. package/src/engine/ecs/terrain/ecs/BuildLightTexture.d.ts +0 -21
  549. package/src/engine/ecs/terrain/ecs/BuildLightTexture.d.ts.map +0 -1
  550. package/src/engine/ecs/terrain/ecs/BuildLightTexture.js +0 -27
  551. package/src/engine/input/ecs/components/Input.d.ts +0 -61
  552. package/src/engine/input/ecs/components/Input.d.ts.map +0 -1
  553. package/src/engine/input/ecs/components/Input.js +0 -118
  554. package/src/engine/input/ecs/ism/InputBinding.d.ts +0 -46
  555. package/src/engine/input/ecs/ism/InputBinding.d.ts.map +0 -1
  556. package/src/engine/input/ecs/ism/InputBinding.js +0 -71
  557. package/src/engine/input/ecs/systems/InputSystem.d.ts +0 -65
  558. package/src/engine/input/ecs/systems/InputSystem.d.ts.map +0 -1
  559. package/src/engine/input/ecs/systems/InputSystem.js +0 -163
  560. package/src/shade/renderer/animation/skinning/GPUMeshSkinningContext.d.ts.map +0 -1
  561. package/src/shade/renderer/animation/skinning/SKINNING_BINDING_STRUCT.d.ts +0 -22
  562. package/src/shade/renderer/animation/skinning/SKINNING_BINDING_STRUCT.d.ts.map +0 -1
  563. package/src/shade/renderer/animation/skinning/bounds_refresh/shader_geometry_sphere_derive.d.ts.map +0 -1
  564. package/src/shade/renderer/animation/skinning/bounds_refresh/shader_meshlet_bounds_reduce.d.ts.map +0 -1
  565. package/src/shade/renderer/animation/skinning/bounds_refresh/shader_meshlet_bounds_scatter.d.ts.map +0 -1
  566. package/src/shade/renderer/animation/skinning/bounds_refresh/shader_skinned_mesh_bounds_refresh.d.ts.map +0 -1
  567. package/src/shade/renderer/loader/gltf/gltf_base_url.d.ts +0 -20
  568. package/src/shade/renderer/loader/gltf/gltf_base_url.d.ts.map +0 -1
  569. package/src/shade/renderer/loader/gltf/gltf_base_url.js +0 -27
  570. package/src/shade/renderer/loader/mtf/mtf_resolve_uri.d.ts +0 -21
  571. package/src/shade/renderer/loader/mtf/mtf_resolve_uri.d.ts.map +0 -1
  572. package/src/shade/renderer/loader/mtf/mtf_resolve_uri.js +0 -98
  573. package/src/shade/renderer/rasterize/expand/bucket/mesh/graph_scene_meshes_cull_and_classify_buckets.d.ts +0 -15
  574. package/src/shade/renderer/rasterize/expand/bucket/mesh/graph_scene_meshes_cull_and_classify_buckets.d.ts.map +0 -1
  575. package/src/shade/renderer/rasterize/expand/bucket/mesh/graph_scene_meshes_cull_and_classify_buckets.js +0 -152
  576. package/src/shade/renderer/scene/movers/shader_scene_skinned_movers.d.ts +0 -24
  577. package/src/shade/renderer/scene/movers/shader_scene_skinned_movers.d.ts.map +0 -1
  578. package/src/shade/renderer/shader/chunk/atmosphere/phase/jd/chunk_sample_draine_cos.d.ts +0 -31
  579. package/src/shade/renderer/shader/chunk/atmosphere/phase/jd/chunk_sample_draine_cos.d.ts.map +0 -1
  580. package/src/shade/renderer/shader/chunk/atmosphere/phase/jd/chunk_sample_draine_cos.js +0 -62
  581. package/src/shade/renderer/shader/chunk/brdf/chunk_sample_vndf_hemisphere_heitz.d.ts +0 -9
  582. package/src/shade/renderer/shader/chunk/brdf/chunk_sample_vndf_hemisphere_heitz.d.ts.map +0 -1
  583. package/src/shade/renderer/shader/chunk/brdf/chunk_sample_vndf_hemisphere_heitz.js +0 -36
  584. package/src/shade/renderer/shader/chunk/depth/chunk_linearize_depth.d.ts +0 -9
  585. package/src/shade/renderer/shader/chunk/depth/chunk_linearize_depth.d.ts.map +0 -1
  586. package/src/shade/renderer/shader/chunk/depth/chunk_linearize_depth.js +0 -28
  587. package/src/shade/renderer/shader/chunk/geometry/aabb3/chunk_aabb3_distance_to_ray.d.ts +0 -21
  588. package/src/shade/renderer/shader/chunk/geometry/aabb3/chunk_aabb3_distance_to_ray.d.ts.map +0 -1
  589. package/src/shade/renderer/shader/chunk/geometry/aabb3/chunk_aabb3_distance_to_ray.js +0 -37
  590. package/src/shade/renderer/shader/chunk/math/chunk_rsqrt.d.ts +0 -13
  591. package/src/shade/renderer/shader/chunk/math/chunk_rsqrt.d.ts.map +0 -1
  592. package/src/shade/renderer/shader/chunk/math/chunk_rsqrt.js +0 -29
  593. package/src/shade/renderer/shader/chunk/random/chunk_hash_jenkins.d.ts +0 -8
  594. package/src/shade/renderer/shader/chunk/random/chunk_hash_jenkins.d.ts.map +0 -1
  595. package/src/shade/renderer/shader/chunk/random/chunk_hash_jenkins.js +0 -22
  596. package/src/shade/renderer/shadow/map/TetrahedronPointLightShadowmap.d.ts +0 -33
  597. package/src/shade/renderer/shadow/map/TetrahedronPointLightShadowmap.d.ts.map +0 -1
  598. package/src/shade/renderer/shadow/map/TetrahedronPointLightShadowmap.js +0 -95
  599. package/src/view/elements/Group.d.ts +0 -31
  600. package/src/view/elements/Group.d.ts.map +0 -1
  601. package/src/view/elements/Group.js +0 -56
  602. /package/src/shade/renderer/animation/{skinning → deformation}/bounds_refresh/shader_geometry_sphere_derive.d.ts +0 -0
  603. /package/src/shade/renderer/animation/{skinning → deformation}/bounds_refresh/shader_meshlet_bounds_reduce.d.ts +0 -0
  604. /package/src/shade/renderer/animation/{skinning → deformation}/bounds_refresh/shader_meshlet_bounds_scatter.d.ts +0 -0
@@ -1,84 +1,38 @@
1
1
  import { assert } from "../../../../core/assert.js";
2
- import { shadowmap_budget_carry_over } from "./shadowmap_budget_carry_over.js";
3
- import { SHADOWMAP_VGEO_TAU_SCALE } from "./SHADOWMAP_VGEO_TAU_SCALE.js";
4
- import AABB2 from "../../../../core/geom/2d/aabb/AABB2.js";
5
- import { MaxRectanglesPacker } from "../../../../core/geom/packing/max-rect/MaxRectanglesPacker.js";
6
- import { FrameGraph } from "../../../../engine/graphics/render/frame_graph/FrameGraph.js";
7
- import { TextureResourceDescriptor } from "../../../device/graph/TextureResourceDescriptor.js";
8
- import { CameraManager } from "../../camera/CameraManager.js";
9
- import { OrthographicCamera } from "../../camera/OrthographicCamera.js";
10
- import { PerspectiveCamera } from "../../camera/PerspectiveCamera.js";
11
- import { CullPolicy } from "../../rasterize/bucket/construct_primitive_state.js";
12
- import { graph_mesh_sphere_cull } from "../../rasterize/compute/graph_mesh_sphere_cull.js";
13
- import { execute_rasterization_jobs } from "../../rasterize/execute_rasterization_jobs.js";
2
+ import { enquire_rasterize_scene_pipelines } from "../../rasterize/standard/graph_rasterize_scene.js";
14
3
  import {
15
- shadow_cascade_alpha_tested_pass_descriptor,
16
- shadow_rasterization_alpha_tested_pass_descriptor
17
- } from "../../rasterize/native/depth/shadow_rasterization_alpha_tested_pass_descriptor.js";
4
+ shadow_cascade_rasterization_pass_descriptor
5
+ } from "../../rasterize/native/depth/shadow_cascade_rasterization_pass_descriptor.js";
18
6
  import {
19
7
  shadow_rasterization_pass_descriptor
20
8
  } from "../../rasterize/native/depth/shadow_rasterization_pass_descriptor.js";
21
- import {
22
- shadow_cascade_rasterization_pass_descriptor
23
- } from "../../rasterize/native/depth/shadow_cascade_rasterization_pass_descriptor.js";
24
- import { RasterizationJob, RasterizationPipelineType } from "../../rasterize/RasterizationJob.js";
25
- import { enquire_rasterize_scene_pipelines } from "../../rasterize/standard/graph_rasterize_scene.js";
26
- import { graph_rasterize_scene_fast_raw } from "../../rasterize/fast/graph_rasterize_scene_fast.js";
27
- import { graph_create_texture, graph_import_texture } from "../../shader/graph/graph_import_texture.js";
28
- import { GPUTextureContext } from "../../texture/GPUTextureContext.js";
29
- import { RenderTarget } from "../../texture/RenderTarget.js";
30
9
  import { enquire_texture_fill_rectangle_depth_pipeline } from "../../texture/util/texture_fill_rectangle.js";
31
- import { View } from "../../view/View.js";
32
- import { ViewManager } from "../../view/ViewManager.js";
33
- import { generate_record_writer } from "../../buffer/table/serde/generate_record_writer.js";
34
- import {
35
- CSM_CASCADE_STRUCT,
36
- CSM_CASTER_RANGE_UNKNOWN,
37
- CSM_CASTER_RANGE_UNKNOWN_BITS
38
- } from "./csm/CSM_CASCADE_STRUCT.js";
39
- import { SHADOWMAP_CSM_DEFAULT_CASCADE_COUNT } from "./csm/SHADOWMAP_CSM_DEFAULT_CASCADE_COUNT.js";
40
- import {
41
- CSM_CASTER_RANGE_SETTINGS_STRUCT,
42
- CSM_CASTER_RANGE_WORKGROUP_SIZE,
43
- shader_csm_caster_range_accumulate,
44
- shader_csm_caster_range_publish,
45
- } from "./csm/shader/shader_csm_caster_range.js";
10
+ import { enquire_vsm_feedback_pipelines } from "../vsm/graph_vsm_feedback.js";
11
+ import { VirtualShadows } from "../vsm/VirtualShadows.js";
12
+ import { CascadeShadows } from "./csm/CascadeShadows.js";
13
+ import { shader_csm_caster_range_accumulate, shader_csm_caster_range_publish, } from "./csm/shader/shader_csm_caster_range.js";
46
14
  import { DEFAULT_SHADOWMAP_UPDATE_BUDGET } from "./DEFAULT_SHADOWMAP_UPDATE_BUDGET.js";
47
- import { VGEO_CUT_STAT } from "../../geometry/virtual/runtime/layout/VGEO_CUT_STAT.js";
15
+ import { PointShadows } from "./point/PointShadows.js";
16
+ import { SHADOW_CULL_POLICY } from "./SHADOW_CULL_POLICY.js";
17
+ import { shadowmap_budget_carry_over } from "./shadowmap_budget_carry_over.js";
48
18
  import { shadowmap_caster_detail_pending } from "./shadowmap_caster_detail_pending.js";
49
- import { DirectionalLightShadowmap } from "./DirectionalLightShadowmap.js";
50
- import { POINT_SHADOW_CUBE_COLS, POINT_SHADOW_CUBE_ROWS } from "./POINT_SHADOW_CUBE_LAYOUT.js";
51
- import {
52
- POINT_SHADOW_TETRA_COLS,
53
- POINT_SHADOW_TETRA_FACE_COUNT,
54
- POINT_SHADOW_TETRA_MAPPING_RESOLUTION_SCALE,
55
- POINT_SHADOW_TETRA_ROWS,
56
- } from "./POINT_SHADOW_TETRAHEDRON_LAYOUT.js";
57
- import { PointLightShadowmap } from "./PointLightShadowmap.js";
58
- import {
59
- shader_shadowmap_remap_cube_to_octahedral
60
- } from "./shader/shader_shadowmap_remap_cube_to_octahedral.js";
61
- import {
62
- POINT_SHADOW_TETRA_REMAP_SETTINGS,
63
- shader_shadowmap_remap_tetrahedron_to_octahedral
64
- } from "./shader/shader_shadowmap_remap_tetrahedron_to_octahedral.js";
65
- import { SHADOWMAP_ATLAS_BORDER } from "./SHADOWMAP_ATLAS_BORDER.js";
66
- import { SHADOWMAP_PATCH_MIN_SIDE } from "./SHADOWMAP_PATCH_MIN_SIDE.js";
67
- import { TetrahedronPointLightShadowmap } from "./TetrahedronPointLightShadowmap.js";
68
19
  import { compute_light_projected_area_px } from "./shadowmap_update_score.js";
20
+ import { ShadowmapAtlas } from "./ShadowmapAtlas.js";
69
21
  import { ShadowmapDrawSelector } from "./ShadowmapDrawSelector.js";
22
+ import { ShadowmapRecords } from "./ShadowmapRecords.js";
70
23
  import { ShadowmapRegistry } from "./ShadowmapRegistry.js";
71
24
  import { ShadowmapResolutionPolicy } from "./ShadowmapResolutionPolicy.js";
72
- import { SpotLightShadowmap } from "./SpotLightShadowmap.js";
73
- import { DEFAULT_VSM_FIRST_TEXEL_SIZE } from "../vsm/DEFAULT_VSM_FIRST_TEXEL_SIZE.js";
74
- import { DEFAULT_VSM_PAGE_BUDGET } from "../vsm/DEFAULT_VSM_PAGE_BUDGET.js";
75
- import { DEFAULT_VSM_LOW_LOAD_FACTOR } from "../vsm/DEFAULT_VSM_LOW_LOAD_FACTOR.js";
76
- import { DEFAULT_VSM_MAX_DYNAMIC_LOD_BIAS } from "../vsm/DEFAULT_VSM_MAX_DYNAMIC_LOD_BIAS.js";
77
- import { DEFAULT_VSM_MAX_LOAD_FACTOR } from "../vsm/DEFAULT_VSM_MAX_LOAD_FACTOR.js";
78
- import { enquire_vsm_feedback_pipelines, graph_vsm_feedback } from "../vsm/graph_vsm_feedback.js";
79
- import { VirtualShadowMap } from "../vsm/VirtualShadowMap.js";
80
- import { VSM_DEFAULT_REQUEST_CAPACITY } from "../vsm/VSM_FEEDBACK_LAYOUT.js";
81
- import { VSM_SLOT_EMPTY } from "../vsm/VSM_SLOT_STRUCT.js";
25
+ import { ShadowViews } from "./ShadowViews.js";
26
+ import { shader_shadowmap_remap_cube_to_octahedral } from "./shader/shader_shadowmap_remap_cube_to_octahedral.js";
27
+ import {
28
+ shader_shadowmap_remap_tetrahedron_to_octahedral
29
+ } from "./shader/shader_shadowmap_remap_tetrahedron_to_octahedral.js";
30
+ import { SpotShadows } from "./spot/SpotShadows.js";
31
+
32
+ /**
33
+ * @typedef {import("../../../../engine/graphics/render/frame_graph/FrameGraph.js").FrameGraph} FrameGraph
34
+ * @typedef {import("../../buffer/table/GPUDatabase.js").GPUDatabase} GPUDatabase
35
+ */
82
36
 
83
37
  /**
84
38
  * @typedef {import("../../../device/ShadeGPUCommandContext.js").ShadeGPUCommandContext} ShadeGPUCommandContext
@@ -88,81 +42,27 @@ import { VSM_SLOT_EMPTY } from "../vsm/VSM_SLOT_STRUCT.js";
88
42
  * @typedef {import("../../light/model/Light.js").Light} Light
89
43
  * @typedef {import("../../scene/GPUSceneContext.js").GPUSceneContext} GPUSceneContext
90
44
  * @typedef {import("./Shadowmap.js").Shadowmap} Shadowmap
91
- * @typedef {import("../../buffer/table/serde/generate_record_writer.js").GPURecordWriter} GPURecordWriter
92
- */
93
-
94
- /**
95
- * Side the shadow atlas starts at, or the device's largest texture when that is smaller. A patch
96
- * that does not fit grows it, up to that largest texture ({@link GPUSceneShadowmapContext.bind}).
97
- * @type {number}
98
45
  */
99
- const DEFAULT_SHADOWMAP_ATLAS_RESOLUTION = 4096;
100
46
 
101
47
  /**
102
- * Resolution by cascade.
103
- * If the number of cascades is greater than the array length, the last resolution is used.
104
- *
105
- * 1536 is chosen for the cascade's HZB: half of it, 768 = 3·2⁸, is a mip 0 the HZB takes as it is, with
106
- * no padding, so mip 0 halves the cascade exactly (a 2x2 footprint) and the rest of the pyramid is two
107
- * 4-mip SPD passes and one single-mip pass. 1740 and 1440 padded mip 0 to 880 and 736, a 3x3 footprint
108
- * and five single-mip passes each. Three cascades at 1536² hold about the texels 1740² + 2·1440² did.
48
+ * What the context asks of the kind of map a light has — {@link PointShadows}, {@link SpotShadows},
49
+ * {@link CascadeShadows} or {@link VirtualShadows}. The context schedules, places and publishes
50
+ * maps; a kind builds, draws and releases its own.
109
51
  *
110
- * @type {number[]}
111
- */
112
- const DEFAULT_SHADOWMAP_DIRECTIONAL_RESOLUTION = [
113
- 1536,
114
- ];
115
-
116
- /**
117
- * Placeholder resolution for local-light shadowmaps (spot/point).
118
- * A proper implementation will project the light's bounding volume into screen space to derive this at runtime.
119
- * @type {number}
120
- */
121
- const DEFAULT_SHADOWMAP_LOCAL_RESOLUTION = 128;
122
-
123
- /**
124
- * How every shadow caster is culled: as the main view culls it, so a caster's front faces are what
125
- * reach the shadow map and acne is the caster bias's to prevent — the rasterizer's slope bias
126
- * ({@link DEPTH_STENCIL_STATE_SHADOW}), or for a directional light's cascades the vertex-stage push of
127
- * `shadow_cascade_rasterization_pass_descriptor`. Casting back faces on top of the rasterizer's bias
128
- * pushed a caster's steep far face past the ground at its base, a gap of 1–1.5 shadow texels at every contact.
129
- * @type {Readonly<Record<number, GPUCullMode>>}
52
+ * @typedef {Object} ShadowmapKind
53
+ * @property {function(Light): Shadowmap} create a map for the light, its atlas patches bound; nothing
54
+ * is left held when it throws
55
+ * @property {function(Shadowmap): boolean} is_outdated whether the map was built under settings of
56
+ * the kind's that no longer hold, and must be rebuilt
57
+ * @property {function(Shadowmap, ShadeGPUCommandContext): void} draw rasterize the map into its patches
58
+ * @property {function(Shadowmap, ShadeGPUCommandContext): void} finish close the frame for a map drawn in it
59
+ * @property {function(Shadowmap, GPUDatabase): void} publish write the map's rows beyond its record, every frame
60
+ * @property {function(Shadowmap): number} clamped_clusters what the map's last cut of virtual geometry
61
+ * clamped, for a cached map to be drawn finer when pages arrive; 0 for one that never asks
62
+ * @property {function(Shadowmap): void} release give back everything the map holds but its patches
63
+ * @property {function(Shadowmap): void} dispose give back the map's GPU contexts, leaving the light
64
+ * database alone, as the context is destroyed
130
65
  */
131
- const SHADOW_CULL_POLICY = CullPolicy.Standard;
132
-
133
- /**
134
- * Writes the CPU's half of a `shadow_cascade` row and leaves `caster_near`, the GPU's, alone.
135
- * @type {GPURecordWriter}
136
- */
137
- const CASCADE_VIEW_WRITER = generate_record_writer(CSM_CASCADE_STRUCT, ['atlas', 'projection']);
138
-
139
- /**
140
- * A virtual shadow map's clipmap: levels, and pages on a side of each level's window. Twelve levels
141
- * of 64² pages at the default 1 cm first texel reach from 41 m windows at level 0 to 168 km at the
142
- * coarsest; see {@link VirtualShadowMap}.
143
- */
144
- const VSM_LEVEL_COUNT = 12;
145
- const VSM_PAGES_PER_LEVEL = 64;
146
-
147
- /**
148
- * Texels on a side of a virtual shadow map page — the reference's 128 — and of the pool
149
- * the map claims in the atlas for them, 30 × 30 slots of 128 plus {@link SHADOWMAP_ATLAS_BORDER}
150
- * each side. A device whose atlas is smaller gets a pool of what fits.
151
- */
152
- const VSM_PAGE_SIZE = 128;
153
- const VSM_POOL_SIZE = 30 * (VSM_PAGE_SIZE + 2 * SHADOWMAP_ATLAS_BORDER);
154
-
155
- /**
156
- * How far either side of the camera's snapped depth along the light a virtual shadow map's depth
157
- * range reaches, in metres. Casters further toward the light than this are clipped.
158
- */
159
- const VSM_DEPTH_EXTENT = 1000;
160
-
161
- /**
162
- * Frames a page something looked at is safe from eviction for: longer than a reading takes to come
163
- * back with three readbacks in flight.
164
- */
165
- const VSM_PROTECT_FRAMES = 6;
166
66
 
167
67
  /**
168
68
  * Shadows for a single scene
@@ -189,7 +89,7 @@ export class GPUSceneShadowmapContext {
189
89
  * {@link enquirePipelines}, which offers what every setting shares.
190
90
  *
191
91
  * @param {import("../../../device/pipeline/PipelineEnquiry.js").PipelineEnquiry} enquiry
192
- * @param {boolean} use_tetrahedron_point_shadows as {@link use_tetrahedron_point_shadows} will be set
92
+ * @param {boolean} use_tetrahedron_point_shadows as {@link PointShadows.use_tetrahedron} will be set
193
93
  * @param {boolean} use_virtual_shadow_maps as {@link use_virtual_shadow_maps} will be set
194
94
  */
195
95
  static enquireSettingPipelines(enquiry, use_tetrahedron_point_shadows, use_virtual_shadow_maps) {
@@ -207,44 +107,46 @@ export class GPUSceneShadowmapContext {
207
107
  }
208
108
  }
209
109
 
210
- atlas = new MaxRectanglesPacker(DEFAULT_SHADOWMAP_ATLAS_RESOLUTION, DEFAULT_SHADOWMAP_ATLAS_RESOLUTION);
211
-
212
110
  /**
213
- * Depth texture atlas used for shadowmaps.
214
- * @type {GPUTextureContext}
111
+ * The atlas every map of the scene draws into.
112
+ * @type {ShadowmapAtlas}
215
113
  */
216
- texture;
217
-
114
+ #atlas;
218
115
 
219
116
  /**
220
- * @type {GraphicsContext}
117
+ * The packer that hands out the atlas's patches.
118
+ * @returns {import("../../../../core/geom/packing/max-rect/MaxRectanglesPacker.js").MaxRectanglesPacker}
221
119
  */
222
- #graphics;
120
+ get atlas() {
121
+ return this.#atlas.packer;
122
+ }
223
123
 
224
124
  /**
225
- * Dedicated ViewManager for the cube/cascade/perspective shadow views this context
226
- * creates and rasterizes into the atlas. Decoupled from the renderer-level ViewManager
227
- * so the ownership chain stays self-contained — the shadow context creates the views,
228
- * caches their GPU contexts, and disposes them with itself. The shared SceneManager
229
- * lookup is short-circuited with a tiny object that always returns our owning
230
- * GPUSceneContext (every shadow view here is for the same scene by construction).
231
- * @type {ViewManager}
125
+ * Depth texture atlas used for shadowmaps.
126
+ * @returns {import("../../texture/GPUTextureContext.js").GPUTextureContext}
232
127
  */
233
- shadow_view_manager;
128
+ get texture() {
129
+ return this.#atlas.texture;
130
+ }
234
131
 
235
132
  /**
236
- * Internal CameraManager backing {@link shadow_view_manager}. Shadow cameras are
237
- * created locally in {@link process_lights} and only referenced by this context, so
238
- * they don't need to share the renderer-level CameraManager.
239
- * @type {CameraManager}
133
+ * @type {GraphicsContext}
240
134
  */
241
- #cameras;
135
+ #graphics;
242
136
 
243
137
  /**
244
- * @type {RenderTarget}
138
+ * The views the scene's maps draw through, and their GPU contexts.
139
+ * @type {ShadowViews}
245
140
  */
246
- #render_target;
141
+ #views;
247
142
 
143
+ /**
144
+ * The ViewManager behind the shadow views — see {@link ShadowViews}.
145
+ * @returns {import("../../view/ViewManager.js").ViewManager}
146
+ */
147
+ get shadow_view_manager() {
148
+ return this.#views.manager;
149
+ }
248
150
 
249
151
  /**
250
152
  * Every shadowmap this scene holds, plus the light -> map index and the reconciliation marks
@@ -260,6 +162,12 @@ export class GPUSceneShadowmapContext {
260
162
  */
261
163
  #selector = new ShadowmapDrawSelector();
262
164
 
165
+ /**
166
+ * The maps' slots in the light database's shadow tables, and their writes.
167
+ * @type {ShadowmapRecords}
168
+ */
169
+ #records = new ShadowmapRecords();
170
+
263
171
  /**
264
172
  * Scratch list of lights that need a shadowmap allocated, handed from pass 1 of
265
173
  * {@link process_lights} to pass 3. Held across frames rather than allocated per call — it is
@@ -269,205 +177,50 @@ export class GPUSceneShadowmapContext {
269
177
  #reconcile_newcomers = [];
270
178
 
271
179
  /**
272
- * Master kill switch for shadows on this scene. Defaults true; the renderer sets it from
273
- * its own `feature_shadows_enabled` flag before each frame's light update. When false,
274
- * {@link process_lights} evicts all maps so the next light-record build clears
275
- * CASTS_SHADOW_BIT on every light. {@link select_for_draw} and {@link draw} are still
276
- * gated externally by the renderer; this flag exists to keep the GPU light records in
277
- * sync with that gating without needing to thread the renderer's flag down further.
278
- * @type {boolean}
279
- */
280
- enabled = true;
281
-
282
- /**
283
- * Selects the tetrahedral point-light shadow generator (4 face frusta) over the default
284
- * cube generator (6 faces). The renderer pushes this from its
285
- * `feature_tetrahedron_point_shadows` flag before each light update, alongside {@link enabled}.
286
- *
287
- * Only affects how a point light's shadow is GENERATED — both paths remap into the same
288
- * octahedral atlas encoding, so the sampler is identical and this can be toggled at runtime.
289
- * A flip is picked up in {@link process_lights}: existing point maps whose generator no longer
290
- * matches this flag are evicted and rebuilt with the correct face count on the same pass.
291
- * @type {boolean}
292
- */
293
- use_tetrahedron_point_shadows = false;
294
-
295
- /**
296
- * Gives directional lights virtual shadow maps instead of cascades. The renderer pushes this
297
- * from its `feature_virtual_shadow_maps` flag before each light update, alongside
298
- * {@link enabled}; a flip is picked up in {@link process_lights}, which rebuilds every
299
- * directional map of the other kind on the same pass, as it does for the point-light generator.
300
- * @type {boolean}
301
- */
302
- use_virtual_shadow_maps = false;
303
-
304
- /**
305
- * Pages the scene's virtual shadow maps may render per frame. See {@link virtual_page_budget}.
306
- * @type {number}
307
- */
308
- #virtual_page_budget = DEFAULT_VSM_PAGE_BUDGET;
309
-
310
- /**
311
- * @returns {number} pages per frame, across the scene's virtual shadow maps
312
- */
313
- get virtual_page_budget() {
314
- return this.#virtual_page_budget;
315
- }
316
-
317
- /**
318
- * The renderer pushes this from {@link Renderer.shadow_virtual_page_budget} every frame. Pages a
319
- * frame wants beyond it wait, best first, for the next.
320
- *
321
- * @param {number} v pages per frame; zero draws none and leaves every page as it is
322
- */
323
- set virtual_page_budget(v) {
324
- assert.isNonNegativeInteger(v, 'virtual_page_budget');
325
-
326
- this.#virtual_page_budget = v;
327
- }
328
-
329
- /**
330
- * Added to the level every point of a virtual shadow map selects; positive is coarser. Pushed by
331
- * the renderer every frame and written into each map's record, so a change takes effect on the
332
- * next frame's demand and sampling alike.
333
- * @type {number}
334
- */
335
- virtual_lod_bias = 0;
336
-
337
- /**
338
- * High-watermark pool demand ratio `(wants + requests_dropped) / slots.capacity` above which a
339
- * virtual shadow map steps its dynamic LOD bias up (`0` disables dynamic throttling). See
340
- * {@link DEFAULT_VSM_MAX_LOAD_FACTOR}.
341
- * @type {number}
342
- */
343
- #virtual_max_load_factor = DEFAULT_VSM_MAX_LOAD_FACTOR;
344
-
345
- /**
346
- * @returns {number}
347
- */
348
- get virtual_max_load_factor() {
349
- return this.#virtual_max_load_factor;
350
- }
351
-
352
- /**
353
- * Pushed from {@link Renderer.shadow_virtual_max_load_factor} each frame.
354
- *
355
- * @param {number} v in `[0, 1]`; `0` disables dynamic throttling
356
- */
357
- set virtual_max_load_factor(v) {
358
- assert.isNumber(v, 'virtual_max_load_factor');
359
- assert.greaterThanOrEqual(v, 0, 'virtual_max_load_factor');
360
- assert.lessThanOrEqual(v, 1, 'virtual_max_load_factor');
361
-
362
- this.#virtual_max_load_factor = v;
363
- }
364
-
365
- /**
366
- * Low-watermark pool demand ratio below which a virtual shadow map's dynamic LOD bias steps
367
- * back down toward zero. See {@link DEFAULT_VSM_LOW_LOAD_FACTOR}.
368
- * @type {number}
369
- */
370
- #virtual_low_load_factor = DEFAULT_VSM_LOW_LOAD_FACTOR;
371
-
372
- /**
373
- * @returns {number}
374
- */
375
- get virtual_low_load_factor() {
376
- return this.#virtual_low_load_factor;
377
- }
378
-
379
- /**
380
- * Pushed from {@link Renderer.shadow_virtual_low_load_factor} each frame.
381
- *
382
- * @param {number} v in `[0, 1]`
383
- */
384
- set virtual_low_load_factor(v) {
385
- assert.isNumber(v, 'virtual_low_load_factor');
386
- assert.greaterThanOrEqual(v, 0, 'virtual_low_load_factor');
387
- assert.lessThanOrEqual(v, 1, 'virtual_low_load_factor');
388
-
389
- this.#virtual_low_load_factor = v;
390
- }
391
-
392
- /**
393
- * Maximum dynamic LOD bias a virtual shadow map may add under pool pressure (`0` disables
394
- * dynamic throttling). See {@link DEFAULT_VSM_MAX_DYNAMIC_LOD_BIAS}.
395
- * @type {number}
396
- */
397
- #virtual_max_dynamic_lod_bias = DEFAULT_VSM_MAX_DYNAMIC_LOD_BIAS;
398
-
399
- /**
400
- * @returns {number}
401
- */
402
- get virtual_max_dynamic_lod_bias() {
403
- return this.#virtual_max_dynamic_lod_bias;
404
- }
405
-
406
- /**
407
- * Pushed from {@link Renderer.shadow_virtual_max_dynamic_lod_bias} each frame.
408
- *
409
- * @param {number} v non-negative; `0` disables dynamic throttling
410
- */
411
- set virtual_max_dynamic_lod_bias(v) {
412
- assert.isNumber(v, 'virtual_max_dynamic_lod_bias');
413
- assert.greaterThanOrEqual(v, 0, 'virtual_max_dynamic_lod_bias');
414
-
415
- this.#virtual_max_dynamic_lod_bias = v;
416
- }
417
-
418
- /**
419
- * World size of a virtual shadow map's level-0 texel. See {@link virtual_first_texel_size}.
420
- * @type {number}
180
+ * The scene's point-light maps, and the settings they are built with.
181
+ * @type {PointShadows}
421
182
  */
422
- #virtual_first_texel_size = DEFAULT_VSM_FIRST_TEXEL_SIZE;
183
+ point;
423
184
 
424
185
  /**
425
- * @returns {number}
186
+ * The scene's spot-light maps.
187
+ * @type {SpotShadows}
426
188
  */
427
- get virtual_first_texel_size() {
428
- return this.#virtual_first_texel_size;
429
- }
189
+ spot;
430
190
 
431
191
  /**
432
- * Pushed from {@link Renderer.shadow_virtual_first_texel_size}. A change rebuilds every virtual
433
- * shadow map in {@link process_lights}: every page of the clipmap changes size.
434
- *
435
- * @param {number} v metres, positive
192
+ * The scene's directional maps when they are cascades ({@link use_virtual_shadow_maps} off), and
193
+ * the settings they are built with.
194
+ * @type {CascadeShadows}
436
195
  */
437
- set virtual_first_texel_size(v) {
438
- assert.isNumber(v, 'virtual_first_texel_size');
439
- assert.greaterThan(v, 0, 'virtual_first_texel_size');
440
-
441
- this.#virtual_first_texel_size = v;
442
- }
196
+ cascades;
443
197
 
444
198
  /**
445
- * How many cascades a directional shadow map is built with. See {@link cascade_count}.
446
- * @type {number}
199
+ * The scene's directional maps when they are virtual ({@link use_virtual_shadow_maps} on), and
200
+ * the settings they are built with.
201
+ * @type {VirtualShadows}
447
202
  */
448
- #cascade_count = SHADOWMAP_CSM_DEFAULT_CASCADE_COUNT;
203
+ virtual;
449
204
 
450
205
  /**
451
- * @returns {number} cascades per directional shadow map
206
+ * Master kill switch for shadows on this scene. Defaults true; the renderer sets it from
207
+ * its own `feature_shadows_enabled` flag before each frame's light update. When false,
208
+ * {@link process_lights} evicts all maps so the next light-record build clears
209
+ * CASTS_SHADOW_BIT on every light. {@link select_for_draw} and {@link draw} are still
210
+ * gated externally by the renderer; this flag exists to keep the GPU light records in
211
+ * sync with that gating without needing to thread the renderer's flag down further.
212
+ * @type {boolean}
452
213
  */
453
- get cascade_count() {
454
- return this.#cascade_count;
455
- }
214
+ enabled = true;
456
215
 
457
216
  /**
458
- * The renderer pushes this from {@link Renderer.shadow_cascade_count} before each light update,
459
- * alongside {@link enabled}. A change is picked up in {@link process_lights}: every directional
460
- * map built with another count is evicted and rebuilt with this one in the same pass, which
461
- * gives its atlas rects back first. A rebuilt map has no caster range until its first readback
462
- * lands, two frames on, so its near planes are its slices' own until then.
463
- *
464
- * @param {number} v at least one
217
+ * Gives directional lights virtual shadow maps ({@link virtual}) instead of cascades
218
+ * ({@link cascades}). The renderer pushes this from its `feature_virtual_shadow_maps` flag
219
+ * before each light update, alongside {@link enabled}; a flip is picked up in
220
+ * {@link process_lights}, which rebuilds every directional map of the other kind on the same pass.
221
+ * @type {boolean}
465
222
  */
466
- set cascade_count(v) {
467
- assert.isPositiveInteger(v, 'cascade_count');
468
-
469
- this.#cascade_count = v;
470
- }
223
+ use_virtual_shadow_maps = false;
471
224
 
472
225
  /**
473
226
  * Frame index of the most recent {@link select_for_draw} call. Passed to {@link draw} via
@@ -538,51 +291,6 @@ export class GPUSceneShadowmapContext {
538
291
  */
539
292
  #scene_ctx;
540
293
 
541
- /**
542
- * One word per row of the light database's `shadow_cascade` table, the accumulate pass's
543
- * scratch, holding plain f32 bit patterns seeded to {@link CSM_CASTER_RANGE_UNKNOWN} and reset
544
- * to it by each publish.
545
- * @type {GPUBuffer|null}
546
- */
547
- #caster_scratch = null;
548
-
549
- /**
550
- * Cascade rows {@link #caster_scratch} has words for.
551
- * @type {number}
552
- */
553
- #caster_scratch_rows = 0;
554
-
555
- /**
556
- * The readback service's handle for the `shadow_cascade` table, taken on first use.
557
- * @type {number}
558
- */
559
- #cascade_table = -1;
560
-
561
- /**
562
- * Scratch for {@link #write_shadow_records}: the CPU's half of one cascade row.
563
- * @type {{atlas: number[], projection: ArrayLike<number>}}
564
- */
565
- #cascade_record = { atlas: [0, 0, 0, 0], projection: null };
566
-
567
- /**
568
- * Scratch for {@link #write_virtual_rows}: one `shadow_virtual_slot` row, and one window corner.
569
- */
570
- #virtual_slot_record = { level: 0, x: 0, y: 0 };
571
- #virtual_level_record = [0, 0];
572
-
573
- /**
574
- * Which virtual map's turn it is to take the first of the page budget's remainder; advanced by
575
- * every {@link select_for_draw}.
576
- * @type {number}
577
- */
578
- #virtual_budget_turn = 0;
579
-
580
- /**
581
- * Scratch for {@link graph_virtual_feedback}: the scene's virtual maps this frame.
582
- * @type {VirtualShadowMap[]}
583
- */
584
- #vsm_feedback_maps = [];
585
-
586
294
  /**
587
295
  * @returns {number} number of shadowmaps rasterized in the most recent draw pass
588
296
  */
@@ -611,17 +319,6 @@ export class GPUSceneShadowmapContext {
611
319
  return this.#resolution_policy.drop_size_scale;
612
320
  }
613
321
 
614
-
615
- /**
616
- * Per-type counts of shadow records written to the GPU database in the previous
617
- * {@link draw} pass. Used to identify trailing slots that must be zeroed when the
618
- * map count for a given type shrinks (e.g. a shadow-casting light is removed),
619
- * mirroring the bookkeeping in {@link GPULightCollection.#build}.
620
- */
621
- #prev_point_count = 0;
622
- #prev_spot_count = 0;
623
- #prev_directional_count = 0;
624
-
625
322
  /**
626
323
  * The Scene this context manages shadows for. Captured at construction so
627
324
  * {@link process_lights} doesn't need it threaded back through every frame.
@@ -640,8 +337,7 @@ export class GPUSceneShadowmapContext {
640
337
  *
641
338
  * @param {GraphicsContext} graphics
642
339
  * @param {GPUSceneContext} scene_ctx the GPU-side context for the Scene we manage
643
- * shadows for. Used as the (single) destination of {@link shadow_view_manager}'s
644
- * scene lookup — every shadow view is for this scene, so the lookup short-circuits.
340
+ * shadows for — every shadow view is for this scene.
645
341
  * @param {GPULightCollection} owner the parent light collection — gives us back-access
646
342
  * to the GPU database we publish records into during {@link draw}.
647
343
  */
@@ -655,454 +351,110 @@ export class GPUSceneShadowmapContext {
655
351
  assert.equal(scene_ctx.isGPUSceneContext, true, 'scene_ctx.isGPUSceneContext !== true');
656
352
  assert.defined(owner, 'owner');
657
353
 
658
-
659
- const initial_atlas_resolution = Math.min(
660
- graphics.device.limits.maxTextureDimension2D,
661
- DEFAULT_SHADOWMAP_ATLAS_RESOLUTION,
662
- );
663
-
664
- {
665
- const t = this.texture = new GPUTextureContext(graphics.device);
666
-
667
-
668
- const descriptor = t.descriptor;
669
-
670
- descriptor.format = "depth32float";
671
- descriptor.dimension = "2d";
672
- descriptor.label = "Shadowmap atlas";
673
- descriptor.usage = GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_SRC;
674
-
675
- t.resize(
676
- initial_atlas_resolution,
677
- initial_atlas_resolution
678
- );
679
-
680
- // ensure atlas size matches
681
- this.atlas.resize(
682
- initial_atlas_resolution,
683
- initial_atlas_resolution
684
- );
685
- }
686
-
687
354
  this.#graphics = graphics;
688
355
  this.#scene = scene_ctx.scene;
356
+ this.#scene_ctx = scene_ctx;
689
357
  this.#owner = owner;
690
358
 
691
- // Local CameraManager + ViewManager dedicated to shadow rasterization. We don't
692
- // share with the renderer-level managers because the cameras and views here are
693
- // owned by this context and only referenced from inside it. The "scenes" lookup
694
- // is a stub that always returns the owning scene context — every shadow view is
695
- // for `this.#scene` by construction.
696
- this.#cameras = new CameraManager(graphics.device);
697
- this.shadow_view_manager = new ViewManager(graphics, this.#cameras, {
698
- obtain: () => scene_ctx,
699
- }, {
700
- virtual_geometry_tau_scale: SHADOWMAP_VGEO_TAU_SCALE,
359
+ this.#atlas = new ShadowmapAtlas(graphics.device, {
360
+ // nothing samples a pending reservation, so its room is the first to go back
361
+ release_pending: () => this.#resolution_policy.release_all_pending(this.#registry.maps),
362
+ on_grow: () => this.#atlas_lost(),
701
363
  });
702
364
 
703
- this.#render_target = RenderTarget.from({
704
- depth: this.texture,
705
- });
365
+ this.#resolution_policy = new ShadowmapResolutionPolicy(this.#atlas.packer);
706
366
 
707
- this.#resolution_policy = new ShadowmapResolutionPolicy(this.atlas);
367
+ const views = this.#views = new ShadowViews(graphics, scene_ctx);
368
+ const scene = this.#scene;
369
+ const atlas = this.#atlas;
708
370
 
709
- this.#scene_ctx = scene_ctx;
371
+ this.point = new PointShadows({ graphics, scene_ctx, atlas });
372
+ this.spot = new SpotShadows({ graphics, scene, atlas, views });
373
+ this.cascades = new CascadeShadows({ graphics, scene, scene_ctx, owner, atlas, views });
374
+ this.virtual = new VirtualShadows({ graphics, scene, owner, atlas, views });
710
375
  }
711
376
 
712
377
  /**
713
- * The readback service's handle for the light database's `shadow_cascade` table — what a
714
- * directional map asks its caster range through.
378
+ * The kind a light's map is made by now, as the settings stand; undefined for a light no kind
379
+ * shadows.
715
380
  *
716
- * @returns {number}
381
+ * @param {Light} light
382
+ * @returns {ShadowmapKind|undefined}
717
383
  */
718
- get cascade_table() {
719
- if (this.#cascade_table === -1) {
720
- this.#cascade_table = this.#owner.readback.table('shadow_cascade');
384
+ #kind_for(light) {
385
+ if (light.isPointLight) {
386
+ return this.point;
387
+ } else if (light.isSpotLight) {
388
+ return this.spot;
389
+ } else if (light.isDirectionalLight) {
390
+ return this.use_virtual_shadow_maps ? this.virtual : this.cascades;
721
391
  }
722
392
 
723
- return this.#cascade_table;
393
+ return undefined;
724
394
  }
725
395
 
726
396
  /**
727
- * Give a directional map a run of `shadow_cascade` rows, one per cascade, and their words of
728
- * the scratch.
397
+ * The kind that made `map`.
729
398
  *
730
- * @param {DirectionalLightShadowmap} map
399
+ * @param {Shadowmap} map
400
+ * @returns {ShadowmapKind|undefined}
731
401
  */
732
- #claim_cascades(map) {
733
- const count = map.cascade_count;
734
- const records = new Array(count);
735
-
736
- for (let i = 0; i < count; i++) {
737
- // The CPU writes the whole row once, its range unknown; from here on it writes only its
738
- // own fields and the GPU writes the range. The atlas and projection are written by the
739
- // map's first draw, before anything samples them.
740
- records[i] = {
741
- atlas: [0, 0, 0, 0],
742
- projection: new Float32Array(16),
743
- caster_near: CSM_CASTER_RANGE_UNKNOWN,
744
- };
402
+ #kind_of(map) {
403
+ if (map.isVirtualShadowMap === true) {
404
+ return this.virtual;
745
405
  }
746
406
 
747
- const first = this.#owner.database.get('shadow_cascade').add_run(records);
748
-
749
- map.first_cascade = first;
750
- map.caster_settings.base = first;
751
- map.caster_range_valid = false;
752
- map.caster_range.fill(NaN);
753
-
754
- const rows_needed = first + count;
755
-
756
- if (rows_needed > this.#caster_scratch_rows) {
757
- // Grown by replacement rather than copied: every claimed row's words are unknown
758
- // between frames — the publish resets them — so a fresh seed loses nothing.
759
- const rows = Math.max(rows_needed, this.#caster_scratch_rows * 2, 4);
760
- const words = new Uint32Array(rows).fill(CSM_CASTER_RANGE_UNKNOWN_BITS);
761
- const device = this.#graphics.device;
762
-
763
- if (this.#caster_scratch !== null) {
764
- this.#caster_scratch.destroy();
765
- }
766
-
767
- this.#caster_scratch = device.createBuffer({
768
- label: 'shadows/csm caster range scratch',
769
- size: words.byteLength,
770
- usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_DST,
771
- });
772
-
773
- device.queue.writeBuffer(this.#caster_scratch, 0, words);
407
+ const light = map.light;
774
408
 
775
- this.#caster_scratch_rows = rows;
409
+ if (light.isDirectionalLight) {
410
+ return this.cascades;
411
+ } else if (light.isSpotLight) {
412
+ return this.spot;
413
+ } else if (light.isPointLight) {
414
+ return this.point;
776
415
  }
416
+
417
+ return undefined;
777
418
  }
778
419
 
779
420
  /**
780
- * Take a directional map's cascade rows back. A readback still in flight for one of them is
781
- * dropped, its row's generation having moved.
782
- *
783
- * @param {DirectionalLightShadowmap} map
421
+ * The atlas texture was replaced: every patch keeps its place, but the new texture holds no
422
+ * depth, so every map is drawn again before it is sampled and every virtual map gives its pages
423
+ * back.
784
424
  */
785
- #release_cascades(map) {
786
- const first = map.first_cascade;
425
+ #atlas_lost() {
426
+ const maps = this.#registry.maps;
787
427
 
788
- if (first === -1) {
789
- return;
790
- }
428
+ for (let i = 0; i < maps.length; i++) {
429
+ const map = maps[i];
791
430
 
792
- const table = this.#owner.database.get('shadow_cascade');
431
+ map.is_invalid = true;
793
432
 
794
- for (let i = 0; i < map.cascade_count; i++) {
795
- table.remove(first + i);
433
+ if (map.isVirtualShadowMap === true) {
434
+ map.manager.evict_all();
435
+ }
796
436
  }
797
-
798
- map.first_cascade = -1;
799
- map.caster_range_valid = false;
800
437
  }
801
438
 
802
439
  /**
803
- * Give a virtual shadow map its rows of the light database: its `shadow_virtual` record, and its
804
- * runs of window corners, page-table entries — every cell empty — and slots — every slot empty.
805
- * The record is written for real by the map's first draw, before anything samples it.
440
+ * Record this frame's virtual shadow map feedback into the frame's `Shading` graph — see
441
+ * {@link VirtualShadows.graph_feedback}. Does nothing in a scene without virtual shadow maps.
806
442
  *
807
- * @param {VirtualShadowMap} map
443
+ * @param {Object} options
444
+ * @param {FrameGraph} options.graph
445
+ * @param {import("../../view/GPUViewContext.js").GPUViewContext} options.view the main view
446
+ * @param {number} options.depth graph handle of the main view's depth
447
+ * @param {number} options.movers graph handle of the scene's mover list this frame
448
+ * ({@link GPUSceneContext#graph_movers})
808
449
  */
809
- #claim_virtual(map) {
810
- const database = this.#owner.database;
811
- const manager = map.manager;
812
-
813
- const levels = new Array(manager.level_count);
814
-
815
- for (let i = 0; i < levels.length; i++) {
816
- levels[i] = [0, 0];
817
- }
818
-
819
- const pages = new Array(manager.cell_count).fill(0);
820
- const slots = new Array(manager.slots.capacity);
821
-
822
- for (let i = 0; i < slots.length; i++) {
823
- slots[i] = { level: VSM_SLOT_EMPTY, x: 0, y: 0 };
824
- }
825
-
826
- map.first_level = database.get('shadow_virtual_level').add_run(levels);
827
- map.first_page = database.get('shadow_virtual_page').add_run(pages);
828
- map.first_slot = database.get('shadow_virtual_slot').add_run(slots);
829
- map.record_row = database.get('shadow_virtual').add(map.make_virtual_record());
830
-
831
- // zeroed at creation: no slot has a mover over it yet
832
- map.stale_flags = this.#graphics.device.createBuffer({
833
- label: 'VSM / stale flags',
834
- size: manager.slots.capacity * Uint32Array.BYTES_PER_ELEMENT,
835
- usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_DST,
836
- });
450
+ graph_virtual_feedback({ graph, view, depth, movers }) {
451
+ this.virtual.graph_feedback({ graph, view, depth, movers, maps: this.#registry.maps });
837
452
  }
838
453
 
839
454
  /**
840
- * Take a virtual shadow map's rows back. The page and slot rows the GPU reads go with the
841
- * record that names them.
455
+ * Pages the scene's virtual geometry has installed so far, or 0 for a scene without any.
842
456
  *
843
- * @param {VirtualShadowMap} map
844
- */
845
- #release_virtual(map) {
846
- if (map.record_row === -1) {
847
- return;
848
- }
849
-
850
- const database = this.#owner.database;
851
- const manager = map.manager;
852
-
853
- const t_levels = database.get('shadow_virtual_level');
854
- const t_pages = database.get('shadow_virtual_page');
855
- const t_slots = database.get('shadow_virtual_slot');
856
-
857
- for (let i = 0; i < manager.level_count; i++) {
858
- t_levels.remove(map.first_level + i);
859
- }
860
-
861
- for (let i = 0; i < manager.cell_count; i++) {
862
- t_pages.remove(map.first_page + i);
863
- }
864
-
865
- for (let i = 0; i < manager.slots.capacity; i++) {
866
- t_slots.remove(map.first_slot + i);
867
- }
868
-
869
- database.get('shadow_virtual').remove(map.record_row);
870
-
871
- map.record_row = -1;
872
- map.first_level = -1;
873
- map.first_page = -1;
874
- map.first_slot = -1;
875
- }
876
-
877
- /**
878
- * Write the rows of a virtual shadow map that changed since the last frame — page-table entries
879
- * of cells installed, evicted or scrolled away, slots that changed hands, and window corners —
880
- * and then its record.
881
- *
882
- * @param {VirtualShadowMap} map
883
- * @param {GPUDatabase} database
884
- */
885
- #write_virtual_rows(map, database) {
886
- const manager = map.manager;
887
-
888
- const t_pages = database.get('shadow_virtual_page');
889
- const t_slots = database.get('shadow_virtual_slot');
890
-
891
- for (let i = 0; i < manager.dirty_cell_count; i++) {
892
- const cell = manager.dirty_cell(i);
893
-
894
- t_pages.set(map.first_page + cell, manager.cell_entry(cell));
895
- }
896
-
897
- const slot_record = this.#virtual_slot_record;
898
-
899
- for (let i = 0; i < manager.dirty_slot_count; i++) {
900
- const slot = manager.dirty_slot(i);
901
- const level = manager.slot_level(slot);
902
-
903
- slot_record.level = level === -1 ? VSM_SLOT_EMPTY : level;
904
- slot_record.x = manager.slot_x(slot);
905
- slot_record.y = manager.slot_y(slot);
906
-
907
- t_slots.set(map.first_slot + slot, slot_record);
908
- }
909
-
910
- if (manager.levels_dirty) {
911
- const t_levels = database.get('shadow_virtual_level');
912
- const corner = this.#virtual_level_record;
913
-
914
- for (let level = 0; level < manager.level_count; level++) {
915
- corner[0] = manager.origin_x(level);
916
- corner[1] = manager.origin_y(level);
917
-
918
- t_levels.set(map.first_level + level, corner);
919
- }
920
- }
921
-
922
- manager.clear_dirty();
923
-
924
- database.get('shadow_virtual').set(map.record_row, map.make_virtual_record());
925
- }
926
-
927
- /**
928
- * Record this frame's virtual shadow map feedback — the pages the scene's movers made stale, the
929
- * pages the view's pixels ask for — into the frame's `Shading` graph once the main view's depth
930
- * exists, and read it back for the maps' next frames. Does nothing in a scene without virtual
931
- * shadow maps, and then reads nothing of `movers`. See {@link graph_vsm_feedback}.
932
- *
933
- * @param {Object} options
934
- * @param {FrameGraph} options.graph
935
- * @param {import("../../view/GPUViewContext.js").GPUViewContext} options.view the main view
936
- * @param {number} options.depth graph handle of the main view's depth
937
- * @param {number} options.movers graph handle of the scene's mover list this frame
938
- * ({@link GPUSceneContext#graph_movers})
939
- */
940
- graph_virtual_feedback({ graph, view, depth, movers }) {
941
- const maps = this.#vsm_feedback_maps;
942
- const all = this.#registry.maps;
943
-
944
- maps.length = 0;
945
-
946
- for (let i = 0; i < all.length; i++) {
947
- if (all[i].isVirtualShadowMap === true) {
948
- maps.push(all[i]);
949
- }
950
- }
951
-
952
- if (maps.length === 0) {
953
- // no virtual map to feed
954
- return;
955
- }
956
-
957
- graph_vsm_feedback({
958
- graph,
959
- view,
960
- depth,
961
- maps,
962
- movers,
963
- light_database: this.#owner.database,
964
- });
965
-
966
- // the graph holds what it needs; don't keep the maps reachable from here until next frame
967
- maps.length = 0;
968
- }
969
-
970
- /**
971
- * Rasterize the pages a virtual shadow map chose this frame, each into its slot of the pool
972
- * through a pooled view aimed at the page — the {@link #draw_direct} path, with the Fast
973
- * pipeline: a pooled view's last depth belongs to some other page, and occlusion buys nothing on
974
- * a slot.
975
- *
976
- * @param {VirtualShadowMap} map
977
- * @param {ShadeGPUCommandContext} command_ctx
978
- */
979
- #draw_virtual(map, command_ctx) {
980
- const manager = map.manager;
981
- const count = manager.job_count;
982
-
983
- if (count === 0) {
984
- return;
985
- }
986
-
987
- const views = map.views;
988
-
989
- while (views.length < count) {
990
- const camera = new OrthographicCamera();
991
- camera.update();
992
-
993
- const view = new View(camera, this.#scene);
994
- view.label = `Virtual Shadow Page ${views.length}`;
995
-
996
- views.push(view);
997
- }
998
-
999
- const graph = new FrameGraph("virtual shadow pages");
1000
- const jobs = new Array(count);
1001
-
1002
- const pool = map.layout[0];
1003
- const slot_size = map.slot_size;
1004
- const per_axis = manager.slots.slots_per_axis;
1005
-
1006
- for (let i = 0; i < count; i++) {
1007
- const view = views[i];
1008
-
1009
- map.aim_page_camera(view.camera, manager.job_level(i), manager.job_x(i), manager.job_y(i));
1010
-
1011
- const view_ctx = this.shadow_view_manager.obtain(view);
1012
-
1013
- view_ctx.setViewportSize(slot_size, slot_size);
1014
- view_ctx.update();
1015
-
1016
- const slot = manager.job_slot(i);
1017
-
1018
- const job = new RasterizationJob();
1019
- job.pipeline_type = RasterizationPipelineType.Fast;
1020
- job.opaque_pass = shadow_rasterization_pass_descriptor;
1021
- job.alpha_tested_pass = shadow_rasterization_alpha_tested_pass_descriptor;
1022
- job.cull_policy = SHADOW_CULL_POLICY;
1023
- job.render_target = this.#render_target;
1024
- job.view_ctx = view_ctx;
1025
- job.viewport = [
1026
- pool.x0 + (slot % per_axis) * slot_size,
1027
- pool.y0 + ((slot / per_axis) | 0) * slot_size,
1028
- slot_size,
1029
- slot_size,
1030
- ];
1031
-
1032
- jobs[i] = job;
1033
- }
1034
-
1035
- execute_rasterization_jobs({
1036
- jobs,
1037
- limits: this.#graphics.collection_limits,
1038
- command_ctx,
1039
- graph,
1040
- });
1041
-
1042
- command_ctx.encodeGraph(graph);
1043
- }
1044
-
1045
- /**
1046
- * Measure this frame's casters against the map's cascades and publish the result to their
1047
- * rows, for the readback to carry to the next frame's fit.
1048
- *
1049
- * @param {DirectionalLightShadowmap} map
1050
- * @param {ShadeGPUCommandContext} command_ctx
1051
- */
1052
- #measure_caster_range(map, command_ctx) {
1053
- const scene_ctx = this.#scene_ctx;
1054
- const meshes = scene_ctx.scene_database.get('meshes');
1055
- const group_count = meshes.dispatch_group_count(CSM_CASTER_RANGE_WORKGROUP_SIZE);
1056
-
1057
- if (group_count === 0) {
1058
- // nothing to measure: the rows keep the last range published into them — unknown if
1059
- // there never was one, and otherwise stale, which pushes the near planes back further
1060
- // than they need to go and costs nothing but depth precision
1061
- return;
1062
- }
1063
-
1064
- const ranges = this.#caster_scratch;
1065
- const caster_settings = map.caster_settings;
1066
- const planes_words = caster_settings.planes_words;
1067
-
1068
- // transient: the frusta differ every frame, so there is nothing worth keeping between them
1069
- const settings = command_ctx.allocateTransientValueBuffer(CSM_CASTER_RANGE_SETTINGS_STRUCT, caster_settings);
1070
- const planes = command_ctx.allocateTransientBufferAndLoad(
1071
- planes_words.buffer,
1072
- GPUBufferUsage.STORAGE,
1073
- planes_words.byteOffset,
1074
- planes_words.byteLength
1075
- );
1076
-
1077
- shader_csm_caster_range_accumulate.dispatch({
1078
- encoder: command_ctx,
1079
- group_count_x: group_count,
1080
- bindings: {
1081
- scene_database: scene_ctx.scene_database_buffer,
1082
- settings,
1083
- planes,
1084
- ranges,
1085
- },
1086
- });
1087
-
1088
- shader_csm_caster_range_publish.dispatch({
1089
- encoder: command_ctx,
1090
- group_count_x: 1,
1091
- bindings: {
1092
- ranges,
1093
- light_database: this.#owner.database.buffer,
1094
- publish: {
1095
- first_cascade: map.first_cascade,
1096
- cascade_count: map.cascade_count,
1097
- },
1098
- },
1099
- });
1100
- }
1101
-
1102
- /**
1103
- * Pages the scene's virtual geometry has installed so far, or 0 for a scene without any.
1104
- *
1105
- * @returns {number}
457
+ * @returns {number}
1106
458
  */
1107
459
  #installed_page_count() {
1108
460
  return this.#scene_ctx.virtual_geometry?.pool.installed_page_count ?? 0;
@@ -1116,10 +468,9 @@ export class GPUSceneShadowmapContext {
1116
468
  * installs/evictions — VGEO streams pages almost every frame under normal usage, so purging
1117
469
  * cached VSM pages on streaming events would constantly thrash top-level coarse clipmap tiles.
1118
470
  *
1119
- * A local map's views are its own view contexts, each of which holds what the last reading of
1120
- * its cut said — so the question is answered from the map's own readings, and a map that cut
1121
- * nothing clamped is left alone however many pages arrive for other views
1122
- * (SHADOW_PLAN_2026_09_28 §2.5).
471
+ * A local map's cuts are its own, each holding what the last reading of it said — so the
472
+ * question is answered from the map's own readings, and a map that cut nothing clamped is left
473
+ * alone however many pages arrive for other views (SHADOW_PLAN_2026_09_28 §2.5).
1123
474
  *
1124
475
  * @param {Shadowmap[]} shadowmaps
1125
476
  */
@@ -1129,29 +480,16 @@ export class GPUSceneShadowmapContext {
1129
480
  }
1130
481
 
1131
482
  const installs_now = this.#installed_page_count();
1132
- const views = this.shadow_view_manager;
1133
483
 
1134
484
  for (let i = 0; i < shadowmaps.length; i++) {
1135
485
  const map = shadowmaps[i];
1136
486
 
1137
- // Directional maps (both per-frame CSM and cached VSM) intentionally skip VGEO streaming
1138
- // invalidation to avoid thrashing coarse VSM clipmap tiles on routine per-frame page churn.
1139
487
  if (map.light.isDirectionalLight || map.is_invalid) {
1140
488
  continue;
1141
489
  }
1142
490
 
1143
- let clamped = 0;
1144
-
1145
- for (let j = 0; j < map.views.length; j++) {
1146
- const view = map.views[j];
1147
-
1148
- if (views.exists(view)) {
1149
- clamped += views.obtain(view).virtual_geometry_cut.stats[VGEO_CUT_STAT.CLAMPED];
1150
- }
1151
- }
1152
-
1153
491
  map.caster_detail_pending = shadowmap_caster_detail_pending({
1154
- clamped,
492
+ clamped: this.#kind_of(map).clamped_clusters(map),
1155
493
  installs_at_draw: map.installs_at_draw,
1156
494
  installs_now,
1157
495
  });
@@ -1196,7 +534,7 @@ export class GPUSceneShadowmapContext {
1196
534
  const rect = map.layout[v];
1197
535
 
1198
536
  entry.camera = map.views[v].camera;
1199
- entry.camera_buffer = this.shadow_view_manager.obtain(map.views[v]).camera.gpu_buffer;
537
+ entry.camera_buffer = this.#views.obtain(map.views[v]).camera.gpu_buffer;
1200
538
  entry.viewport[0] = rect.x0;
1201
539
  entry.viewport[1] = rect.y0;
1202
540
  entry.viewport[2] = rect.width;
@@ -1302,48 +640,13 @@ export class GPUSceneShadowmapContext {
1302
640
 
1303
641
  // Step 2: recompute projected areas. Writing onto the map so the policy + scorer can
1304
642
  // just read `map.projected_area_px` without threading a parallel array through.
1305
- let virtual_maps = 0;
1306
-
1307
643
  for (let i = 0; i < n; i++) {
1308
644
  const m = shadowmaps[i];
1309
645
  m.projected_area_px = compute_light_projected_area_px(m.light, main_camera, view_resolution);
1310
-
1311
- if (m.isVirtualShadowMap === true) {
1312
- virtual_maps++;
1313
- }
1314
646
  }
1315
647
 
1316
- if (virtual_maps > 0) {
1317
- // the scene's page budget, shared out between its virtual maps: all of it to the one
1318
- // map of a scene with one sun; with several, the pages that do not divide evenly go
1319
- // round them a frame at a time, so a budget below the suns' count starves none
1320
- const budget = this.#virtual_page_budget;
1321
- const share = Math.floor(budget / virtual_maps);
1322
- const remainder = budget - share * virtual_maps;
1323
- const first_extra = this.#virtual_budget_turn++ % virtual_maps;
1324
-
1325
- let k = 0;
1326
-
1327
- for (let i = 0; i < n; i++) {
1328
- const m = shadowmaps[i];
1329
-
1330
- if (m.isVirtualShadowMap !== true) {
1331
- continue;
1332
- }
1333
-
1334
- const turn = (k - first_extra + virtual_maps) % virtual_maps;
1335
-
1336
- // what its update works with this frame
1337
- m.page_budget = share + (turn < remainder ? 1 : 0);
1338
- m.lod_bias = this.virtual_lod_bias;
1339
- m.max_load_factor = this.#virtual_max_load_factor;
1340
- m.low_load_factor = this.#virtual_low_load_factor;
1341
- m.max_lod_bias = this.#virtual_max_dynamic_lod_bias;
1342
- m.view_height = view_resolution[1];
1343
-
1344
- k++;
1345
- }
1346
- }
648
+ // the scene's page budget, shared out between its virtual maps
649
+ this.virtual.prepare_frame(shadowmaps, view_resolution);
1347
650
 
1348
651
  // Step 2b: a cached map whose last cut of virtual geometry was clamped, and under which pages
1349
652
  // have installed since, would now draw finer — score it as if it had never been drawn.
@@ -1386,111 +689,6 @@ export class GPUSceneShadowmapContext {
1386
689
  );
1387
690
  }
1388
691
 
1389
- /**
1390
- * Publish per-shadowmap records into the scene's GPU database. Each map writes its record
1391
- * into the type-specific shadow_* table at the slot identified by `light._gpu_shadowmap_id`
1392
- * (which is itself the per-type index, set by {@link process_lights}). Trailing slots from
1393
- * previous frames are zeroed when the map count for a type shrinks, so stale entries don't
1394
- * linger.
1395
- *
1396
- * Only maps with `metadata_changed === true` are re-uploaded; the flag is cleared after
1397
- * the slot is queued so unchanged maps don't pay for an upload they don't need. Trim writes
1398
- * always run regardless of the flag — they zero slots that no longer correspond to any map.
1399
- *
1400
- * The type-bucket order here MUST match the per-type id assignment in {@link process_lights}
1401
- * (Point → Spot → Directional) so the shadow_id stamped onto each light record points at the
1402
- * slot we write here.
1403
- *
1404
- * Caller must invoke `database.update(cmd)` afterwards to upload the writes — that is done
1405
- * by {@link draw} once for both the new records and any zeroed trailing slots.
1406
- *
1407
- * @param {GPUDatabase} database
1408
- */
1409
- #write_shadow_records(database) {
1410
- const t_point = database.get('shadow_point');
1411
- const t_spot = database.get('shadow_spot');
1412
- const t_directional = database.get('shadow_directional');
1413
- const t_cascade = database.get('shadow_cascade');
1414
-
1415
- const cascade_record = this.#cascade_record;
1416
-
1417
- const maps = this.#registry.maps;
1418
- let pc = 0;
1419
- let sc = 0;
1420
- let dc = 0;
1421
-
1422
- for (let i = 0; i < maps.length; i++) {
1423
- const map = maps[i];
1424
- const light = map.light;
1425
-
1426
- let table;
1427
- let slot;
1428
- if (light.isPointLight) {
1429
- table = t_point;
1430
- slot = pc++;
1431
- } else if (light.isSpotLight) {
1432
- table = t_spot;
1433
- slot = sc++;
1434
- } else if (light.isDirectionalLight) {
1435
- table = t_directional;
1436
- slot = dc++;
1437
- } else {
1438
- continue;
1439
- }
1440
-
1441
- if (map.isVirtualShadowMap === true) {
1442
- // its rows change with its pages, whether or not anything else about it did
1443
- this.#write_virtual_rows(map, database);
1444
- }
1445
-
1446
- if (map.metadata_changed) {
1447
- table.set(slot, map.make_record());
1448
-
1449
- if (light.isDirectionalLight && map.isVirtualShadowMap !== true) {
1450
- // the record names the cascades; their rows hold what to sample — written a
1451
- // field at a time, since the GPU owns the rest of the row
1452
- for (let j = 0; j < map.cascade_count; j++) {
1453
- t_cascade.set_fields(map.first_cascade + j, map.make_cascade_record(j, cascade_record), CASCADE_VIEW_WRITER);
1454
- }
1455
- }
1456
-
1457
- map.metadata_changed = false;
1458
- }
1459
- }
1460
-
1461
- this.#trim_shadow_records(database, pc, sc, dc);
1462
- }
1463
-
1464
- /**
1465
- * Free the shadow_* slots past the counts given — slots a previous write filled that no map
1466
- * holds any more — so disused entries don't leak. A `shadow_directional` slot left standing
1467
- * would go on naming cascade rows its map gave back.
1468
- *
1469
- * @param {GPUDatabase} database
1470
- * @param {number} point_count slots of `shadow_point` still in use
1471
- * @param {number} spot_count slots of `shadow_spot` still in use
1472
- * @param {number} directional_count slots of `shadow_directional` still in use
1473
- */
1474
- #trim_shadow_records(database, point_count, spot_count, directional_count) {
1475
- const t_point = database.get('shadow_point');
1476
- const t_spot = database.get('shadow_spot');
1477
- const t_directional = database.get('shadow_directional');
1478
-
1479
- for (let i = point_count; i < this.#prev_point_count; i++) {
1480
- t_point.remove(i);
1481
- }
1482
- for (let i = spot_count; i < this.#prev_spot_count; i++) {
1483
- t_spot.remove(i);
1484
- }
1485
- for (let i = directional_count; i < this.#prev_directional_count; i++) {
1486
- t_directional.remove(i);
1487
- }
1488
-
1489
- this.#prev_point_count = point_count;
1490
- this.#prev_spot_count = spot_count;
1491
- this.#prev_directional_count = directional_count;
1492
- }
1493
-
1494
692
  /**
1495
693
  * Rasterize every shadowmap flagged by {@link select_for_draw} for a refresh this frame,
1496
694
  * committing any pending resize reservations in the process, then publish per-shadow
@@ -1501,12 +699,7 @@ export class GPUSceneShadowmapContext {
1501
699
  * 1. If the map has a {@link Shadowmap.pending_layout} reservation, swap it into place
1502
700
  * BEFORE rasterization so the draw targets the new region. The old committed rects
1503
701
  * are remembered for step 3.
1504
- * 2. Dispatch to the type-specific raster path:
1505
- * - **Directional / spot**: direct raster into the atlas's sub-rects (one job per
1506
- * cascade for directionals, one job per spot).
1507
- * - **Point**: 6 cube-face depth passes into a shared intermediate texture, then
1508
- * cube→octahedral remap into the atlas. Point lights are serialised so they can
1509
- * reuse the intermediate texture.
702
+ * 2. Its kind draws it.
1510
703
  * 3. If a commit happened in step 1, release the old committed rects from the atlas now
1511
704
  * that the new region holds valid depth.
1512
705
  * 4. Clear per-frame flags (`should_draw`, `is_invalid`) and stamp
@@ -1518,9 +711,6 @@ export class GPUSceneShadowmapContext {
1518
711
  * swaps become visible to the lighting shader. `#debug_render_count` is reset at entry
1519
712
  * and incremented per map to expose scheduling behaviour to the debug overlay.
1520
713
  *
1521
- * No external job list: every path batches its own work internally via
1522
- * {@link execute_rasterization_jobs}. Callers just pass a command context.
1523
- *
1524
714
  * @param {ShadeGPUCommandContext} command_ctx
1525
715
  */
1526
716
  draw(command_ctx) {
@@ -1552,28 +742,20 @@ export class GPUSceneShadowmapContext {
1552
742
  map.metadata_changed = true;
1553
743
  }
1554
744
 
1555
- const light = map.light;
745
+ const kind = this.#kind_of(map);
1556
746
 
1557
- if (map.isVirtualShadowMap === true) {
1558
- this.#draw_virtual(map, command_ctx);
1559
- } else if (light.isDirectionalLight || light.isSpotLight) {
1560
- this.#draw_direct(map, command_ctx);
1561
- } else if (light.isPointLight) {
1562
- if (map.isTetrahedron) {
1563
- this.#draw_point_tetrahedron(map, command_ctx);
1564
- } else {
1565
- this.#draw_point(map, command_ctx);
1566
- }
1567
- } else {
1568
- throw new Error(`Unsupported light type ${light.constructor.name}`);
747
+ if (kind === undefined) {
748
+ throw new Error(`Unsupported light type ${map.light.constructor.name}`);
1569
749
  }
1570
750
 
751
+ kind.draw(map, command_ctx);
752
+
1571
753
  // Step 3: release the retired rects from the atlas. Must happen AFTER the raster
1572
754
  // helpers finish reading map.layout (they may close over retired_rects as scratch
1573
755
  // memory or view references in some paths; safest order is raster-first).
1574
756
  if (retired_rects !== null) {
1575
757
  for (let j = 0; j < retired_rects.length; j++) {
1576
- this.atlas.remove(retired_rects[j]);
758
+ this.#atlas.remove(retired_rects[j]);
1577
759
  }
1578
760
  }
1579
761
 
@@ -1595,460 +777,33 @@ export class GPUSceneShadowmapContext {
1595
777
  // frame — their caster ranges, as the passes above published them — is copied out here,
1596
778
  // after the passes, and delivered at the head of a later frame.
1597
779
  const database = this.#owner.database;
1598
- this.#write_shadow_records(database);
780
+ this.#records.write(maps, database, (map, db) => this.#kind_of(map).publish(map, db));
1599
781
  database.update(command_ctx);
1600
782
 
1601
783
 
1602
- // finalize rendered views
1603
- for (const map of this.#registry.maps) {
1604
- if (map.last_updated_frame_index !== frame_index) {
1605
- // skip
1606
- continue;
1607
- }
1608
-
1609
- for (const view of map.views) {
1610
- const view_ctx = this.shadow_view_manager.obtain(view);
1611
- view_ctx.finish_frame(command_ctx);
1612
- }
1613
- }
1614
- }
1615
-
1616
- /**
1617
- * Rasterize a directional or spot shadowmap directly into its atlas rects. One job per
1618
- * `map.views[i]` / `map.layout[i]` pair — directionals have N cascades, spots have one.
1619
- *
1620
- * @param {Shadowmap} map
1621
- * @param {ShadeGPUCommandContext} command_ctx
1622
- */
1623
- #draw_direct(map, command_ctx) {
1624
- if (map.light.isDirectionalLight === true && map.first_cascade !== -1) {
1625
- // this frame's casters against this frame's cascades, for next frame's fit
1626
- this.#measure_caster_range(map, command_ctx);
1627
- }
1628
-
1629
- // TODO pre-cull mesh set by sphere-casting the light volume against the main View Frustum
1630
- // see ref: https://www.reddit.com/r/Unity3D/comments/1foe8qi/added_a_way_to_perform_frustum_culling_and_take
1631
-
1632
- const graph = new FrameGraph("shadows");
1633
-
1634
- const shadow_views = map.views;
1635
- const jobs = new Array(shadow_views.length);
1636
-
1637
- for (let i = 0; i < shadow_views.length; i++) {
1638
- const view = shadow_views[i];
1639
- const view_ctx = this.shadow_view_manager.obtain(view);
1640
-
1641
- const atlas_aabb = map.layout[i];
1642
- view_ctx.setViewportSize(atlas_aabb.width, atlas_aabb.height);
1643
- view_ctx.update();
1644
-
1645
- const job = new RasterizationJob();
1646
- // a directional light's cascades are biased in the vertex stage of an orthographic view; a spot
1647
- // light keeps the rasterizer's bias
1648
- const cascade = map.light.isDirectionalLight === true;
1649
- job.opaque_pass = cascade ? shadow_cascade_rasterization_pass_descriptor : shadow_rasterization_pass_descriptor;
1650
- job.alpha_tested_pass = cascade ? shadow_cascade_alpha_tested_pass_descriptor : shadow_rasterization_alpha_tested_pass_descriptor;
1651
- job.cull_policy = SHADOW_CULL_POLICY;
1652
- job.render_target = this.#render_target;
1653
- job.view_ctx = view_ctx;
1654
- job.viewport = [atlas_aabb.x0, atlas_aabb.y0, atlas_aabb.width, atlas_aabb.height];
1655
-
1656
-
1657
- jobs[i] = job;
1658
-
1659
- // TODO reproject current scene view into shadow map for better occlusion culling,
1660
- // see Assassin's Creed Unity talk on GPU-driven rendering,
1661
- // see "RE ENGINE Meshlet Rendering Pipeline" https://youtu.be/nWgPtCDXlPc?t=2055
1662
-
1663
- // TODO need to linearize depth(?)
1664
- // can linearize together with reprojection (TAA)
1665
- }
1666
-
1667
- execute_rasterization_jobs({
1668
- jobs,
1669
- limits: this.#graphics.collection_limits,
1670
- command_ctx,
1671
- graph,
1672
- });
1673
-
1674
- command_ctx.encodeGraph(graph);
1675
- }
1676
-
1677
- /**
1678
- * Rasterize a point light's 6 cube faces into the shared intermediate texture, then run the
1679
- * cube→octahedral remap shader to write the encoded depth into this light's atlas rect.
1680
- *
1681
- * Sequencing matters: each point light fully completes (6 cube rasters + remap) before the
1682
- * next one starts, so the intermediate texture can be reused across point lights without
1683
- * cross-contamination.
1684
- *
1685
- * @param {PointLightShadowmap} map
1686
- * @param {ShadeGPUCommandContext} command_ctx
1687
- */
1688
- #draw_point(
1689
- map,
1690
- command_ctx,
1691
- ) {
1692
-
1693
- const graph = new FrameGraph("shadows");
1694
-
1695
- const gr_atlas_texture = graph_import_texture(graph, this.texture);
1696
-
1697
- const atlas_rect = map.layout[0];
1698
-
1699
- const octahedral_resolution = atlas_rect.width;
1700
-
1701
- /**
1702
- * Controls the relationship between octahedral resolution and the cube map used during rendering
1703
- * If this is larger - we get better quality at the cost of rendering more pixels.
1704
- *
1705
- * Solving for solid angle coverage, using the formula `N=POW(1 - SQRT(E/3), 3/2)` we get:
1706
- *
1707
- * 0% error -> 1
1708
- * 1% error -> 0.915
1709
- * 2% error -> 0.880
1710
- * 3% error -> 0.854
1711
- * 5% error -> 0.813
1712
- * 10% error -> 0.739
1713
- * 20% error -> 0.639
1714
- * 30% error -> 0.565
1715
- * 40% error -> 0.506
1716
- * 50% error -> 0.455
1717
- *
1718
- * @type {number}
1719
- */
1720
- const CUBE_MAPPING_RESOLUTION_SCALE = 0.880;
1721
-
1722
- const cube_face_resolution = Math.ceil(octahedral_resolution * CUBE_MAPPING_RESOLUTION_SCALE);
1723
-
1724
- // reserve texture
1725
- let cube_packed_texture = graph_create_texture(graph, TextureResourceDescriptor.from({
1726
- resolution: [
1727
- cube_face_resolution * POINT_SHADOW_CUBE_COLS,
1728
- cube_face_resolution * POINT_SHADOW_CUBE_ROWS,
1729
- ],
1730
- usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.TEXTURE_BINDING,
1731
- format: 'depth32float',
1732
- enableMips: false,
1733
- }));
1734
-
1735
- /**
1736
- *
1737
- * @type {PointLight}
1738
- */
1739
- const light = map.light;
1740
-
1741
- const scene_ctx = this.shadow_view_manager.obtain(map.views[0]).scene;
1742
-
1743
- /**
1744
- * Sphere-culled meshes from the scene.
1745
- * We could do per-face culling, but most point lights are local, and there's already meshlet culling happening later in the pipeline.
1746
- * Good enough.
1747
- * @type {number}
1748
- */
1749
- const input_meshes = graph_mesh_sphere_cull({
1750
- graph,
1751
- sphere: [light.transform.translation_x, light.transform.translation_y, light.transform.translation_z, light.distance],
1752
- scene: scene_ctx,
1753
- limits: this.#graphics.collection_limits,
1754
- });
1755
-
1756
- for (let face = 0; face < 6; face++) {
1757
- const view = map.views[face];
1758
- const view_ctx = this.shadow_view_manager.obtain(view);
1759
-
1760
- view_ctx.setViewportSize(cube_face_resolution, cube_face_resolution);
1761
- view_ctx.update();
1762
-
1763
- const col = face % POINT_SHADOW_CUBE_COLS;
1764
- const row = Math.floor(face / POINT_SHADOW_CUBE_COLS);
1765
-
1766
- const job = new RasterizationJob();
1767
-
1768
- job.pipeline_type = RasterizationPipelineType.Fast;
1769
- job.opaque_pass = shadow_rasterization_pass_descriptor;
1770
- job.alpha_tested_pass = shadow_rasterization_alpha_tested_pass_descriptor;
1771
- job.cull_policy = SHADOW_CULL_POLICY;
1772
- job.render_target = null;
1773
- job.view_ctx = view_ctx;
1774
- job.viewport = [
1775
- col * cube_face_resolution,
1776
- row * cube_face_resolution,
1777
- cube_face_resolution,
1778
- cube_face_resolution,
1779
- ];
1780
-
1781
- cube_packed_texture = graph_rasterize_scene_fast_raw({
1782
- graph,
1783
- meshes: input_meshes,
1784
- limits: this.#graphics.collection_limits,
1785
- target_depth: cube_packed_texture,
1786
- job,
1787
- }).target_depth;
1788
- }
1789
-
1790
- /**
1791
- *
1792
- * @param data
1793
- * @param {FramePassResources} resources
1794
- * @param {GraphicsExecutionContext} context
1795
- */
1796
- function remap_to_atlas(data, resources, context) {
1797
- const atlas = resources.get(data.atlas);
1798
- const cube_texture = resources.get(data.cube_texture);
1799
-
1800
- const settings = {
1801
- atlas_offset: [
1802
- atlas_rect.x0 + SHADOWMAP_ATLAS_BORDER,
1803
- atlas_rect.y0 + SHADOWMAP_ATLAS_BORDER,
1804
- atlas_rect.width - 2 * SHADOWMAP_ATLAS_BORDER,
1805
- atlas_rect.height - 2 * SHADOWMAP_ATLAS_BORDER,
1806
- ],
1807
- light_params: [
1808
- map.light.distance,
1809
- map.cube_near,
1810
- 0,
1811
- 0,
1812
- ]
1813
- };
1814
-
1815
- shader_shadowmap_remap_cube_to_octahedral.draw({
1816
- encoder: context.encoder,
1817
- bindings: {
1818
- settings: settings,
1819
- cube_faces: cube_texture.obtainView(),
1820
- },
1821
- depthStencilAttachment: {
1822
- view: atlas.obtainView(),
1823
- depthLoadOp: "load",
1824
- depthStoreOp: "store",
1825
- },
1826
- viewport: [
1827
- atlas_rect.x0,
1828
- atlas_rect.y0,
1829
- atlas_rect.width,
1830
- atlas_rect.height,
1831
- ]
1832
- })
1833
- }
1834
-
1835
- const remap_data = {};
1836
-
1837
- const remap_pass = graph.add("remap to atals", remap_data, remap_to_atlas);
1838
-
1839
- remap_data.atlas = remap_pass.write(gr_atlas_texture);
1840
- remap_data.cube_texture = remap_pass.read(cube_packed_texture);
1841
-
1842
-
1843
- command_ctx.encodeGraph(graph);
1844
- }
1845
-
1846
- /**
1847
- * Rasterize a point light's 4 tetrahedron faces into a shared intermediate texture, then run
1848
- * the tetrahedron→octahedral remap to write the encoded depth into this light's atlas rect.
1849
- * The tetrahedral parallel to {@link #draw_point} — same shape, 4 faces in a 2x2 grid instead
1850
- * of 6 in a 3x2 grid, and the remap is handed each face's view-projection matrix so it can
1851
- * select faces and project directions in exact agreement with how the depth was rasterized.
1852
- *
1853
- * @param {TetrahedronPointLightShadowmap} map
1854
- * @param {ShadeGPUCommandContext} command_ctx
1855
- */
1856
- #draw_point_tetrahedron(
1857
- map,
1858
- command_ctx,
1859
- ) {
1860
-
1861
- const graph = new FrameGraph("shadows");
1862
-
1863
- const gr_atlas_texture = graph_import_texture(graph, this.texture);
1864
-
1865
- const atlas_rect = map.layout[0];
1866
-
1867
- const octahedral_resolution = atlas_rect.width;
1868
-
1869
- // Wider face fov than the cube path (see POINT_SHADOW_TETRA_FOV_DEGREES) needs a larger
1870
- // per-face resolution to hold comparable on-axis density — the analogue of the cube
1871
- // path's CUBE_MAPPING_RESOLUTION_SCALE.
1872
- const face_resolution = Math.ceil(octahedral_resolution * POINT_SHADOW_TETRA_MAPPING_RESOLUTION_SCALE);
1873
-
1874
- // reserve intermediate depth texture — 2x2 grid of faces
1875
- let tetra_packed_texture = graph_create_texture(graph, TextureResourceDescriptor.from({
1876
- resolution: [
1877
- face_resolution * POINT_SHADOW_TETRA_COLS,
1878
- face_resolution * POINT_SHADOW_TETRA_ROWS,
1879
- ],
1880
- usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.TEXTURE_BINDING,
1881
- format: 'depth32float',
1882
- enableMips: false,
1883
- }));
1884
-
1885
- /**
1886
- *
1887
- * @type {PointLight}
1888
- */
1889
- const light = map.light;
1890
-
1891
- const scene_ctx = this.shadow_view_manager.obtain(map.views[0]).scene;
1892
-
1893
- // One sphere cull for all 4 faces — most point lights are local and meshlet culling
1894
- // refines later; per-face culling isn't worth it. Same trade as the cube path.
1895
- const input_meshes = graph_mesh_sphere_cull({
1896
- graph,
1897
- sphere: [light.transform.translation_x, light.transform.translation_y, light.transform.translation_z, light.distance],
1898
- scene: scene_ctx,
1899
- limits: this.#graphics.collection_limits,
1900
- });
1901
-
1902
- for (let face = 0; face < POINT_SHADOW_TETRA_FACE_COUNT; face++) {
1903
- const view = map.views[face];
1904
- const view_ctx = this.shadow_view_manager.obtain(view);
1905
-
1906
- view_ctx.setViewportSize(face_resolution, face_resolution);
1907
- view_ctx.update();
1908
-
1909
- const col = face % POINT_SHADOW_TETRA_COLS;
1910
- const row = Math.floor(face / POINT_SHADOW_TETRA_COLS);
1911
-
1912
- const job = new RasterizationJob();
1913
-
1914
- job.pipeline_type = RasterizationPipelineType.Fast;
1915
- job.opaque_pass = shadow_rasterization_pass_descriptor;
1916
- job.alpha_tested_pass = shadow_rasterization_alpha_tested_pass_descriptor;
1917
- job.cull_policy = SHADOW_CULL_POLICY;
1918
- job.render_target = null;
1919
- job.view_ctx = view_ctx;
1920
- job.viewport = [
1921
- col * face_resolution,
1922
- row * face_resolution,
1923
- face_resolution,
1924
- face_resolution,
1925
- ];
1926
-
1927
- tetra_packed_texture = graph_rasterize_scene_fast_raw({
1928
- graph,
1929
- meshes: input_meshes,
1930
- limits: this.#graphics.collection_limits,
1931
- target_depth: tetra_packed_texture,
1932
- job,
1933
- }).target_depth;
1934
- }
1935
-
1936
- const views = map.views;
1937
- const tetra_near = map.tetra_near;
1938
- const light_max_distance = map.light.distance;
784
+ // finalize rendered maps
785
+ for (let i = 0; i < maps.length; i++) {
786
+ const map = maps[i];
1939
787
 
1940
- /**
1941
- *
1942
- * @param data
1943
- * @param {FramePassResources} resources
1944
- * @param {GraphicsExecutionContext} context
1945
- */
1946
- function remap_to_atlas(data, resources, context) {
1947
- const atlas = resources.get(data.atlas);
1948
- const tetra_texture = resources.get(data.tetra_texture);
1949
-
1950
- // Read each face camera's view-projection at encode time — set in map.update() and
1951
- // untouched since, and it is exactly the matrix the rasterizer used above.
1952
- const face_view_proj = new Array(POINT_SHADOW_TETRA_FACE_COUNT);
1953
- for (let f = 0; f < POINT_SHADOW_TETRA_FACE_COUNT; f++) {
1954
- face_view_proj[f] = views[f].camera.view_projection_matrix;
788
+ if (map.last_updated_frame_index === frame_index) {
789
+ this.#kind_of(map).finish(map, command_ctx);
1955
790
  }
1956
-
1957
- const settings = context.encoder.allocateTransientValueBuffer(
1958
- POINT_SHADOW_TETRA_REMAP_SETTINGS,
1959
- {
1960
- atlas_offset: [
1961
- atlas_rect.x0 + SHADOWMAP_ATLAS_BORDER,
1962
- atlas_rect.y0 + SHADOWMAP_ATLAS_BORDER,
1963
- atlas_rect.width - 2 * SHADOWMAP_ATLAS_BORDER,
1964
- atlas_rect.height - 2 * SHADOWMAP_ATLAS_BORDER,
1965
- ],
1966
- light_params: [
1967
- light_max_distance,
1968
- tetra_near,
1969
- 0,
1970
- 0,
1971
- ],
1972
- face_view_proj,
1973
- }
1974
- );
1975
-
1976
- shader_shadowmap_remap_tetrahedron_to_octahedral.draw({
1977
- encoder: context.encoder,
1978
- bindings: {
1979
- settings: settings,
1980
- tetra_faces: tetra_texture.obtainView(),
1981
- },
1982
- depthStencilAttachment: {
1983
- view: atlas.obtainView(),
1984
- depthLoadOp: "load",
1985
- depthStoreOp: "store",
1986
- },
1987
- viewport: [
1988
- atlas_rect.x0,
1989
- atlas_rect.y0,
1990
- atlas_rect.width,
1991
- atlas_rect.height,
1992
- ]
1993
- })
1994
- }
1995
-
1996
- const remap_data = {};
1997
-
1998
- const remap_pass = graph.add("remap tetra to atlas", remap_data, remap_to_atlas);
1999
-
2000
- remap_data.atlas = remap_pass.write(gr_atlas_texture);
2001
- remap_data.tetra_texture = remap_pass.read(tetra_packed_texture);
2002
-
2003
-
2004
- command_ctx.encodeGraph(graph);
2005
- }
2006
-
2007
- /**
2008
- * Release the per-face GPU contexts (each view's uniform/HZB/volumetrics buffers + its camera
2009
- * uniform) backing a map. The dedicated {@link shadow_view_manager} / {@link #cameras} caches
2010
- * key on the View/Camera objects and have no GC path, so a map's contexts must be released
2011
- * explicitly here or their GPU buffers leak for the context's lifetime. Most visible when the
2012
- * point-shadow generator toggle rebuilds every point map (fresh Views each time), but it also
2013
- * closes the ordinary eviction leak (light removed / stops casting / shadows disabled).
2014
- *
2015
- * In this context Views and Cameras are 1:1 per map (each map creates its own), so releasing a
2016
- * view's camera alongside it can't strand a still-referenced camera.
2017
- *
2018
- * @param {Shadowmap} map
2019
- */
2020
- #release_map_gpu_contexts(map) {
2021
- const views = map.views;
2022
- for (let j = 0; j < views.length; j++) {
2023
- const view = views[j];
2024
- this.shadow_view_manager.release(view);
2025
- this.#cameras.release(view.camera);
2026
791
  }
2027
792
  }
2028
793
 
2029
794
  /**
2030
- * Release a map's atlas rects + GPU side-resources. Caller is responsible for splicing it
2031
- * out of {@link #registry}.
795
+ * Release a map's atlas rects and everything else it holds. Caller is responsible for
796
+ * splicing it out of {@link #registry}.
2032
797
  *
2033
798
  * @param {Shadowmap} map
2034
799
  */
2035
800
  #evict_map(map) {
2036
801
  for (let j = 0; j < map.layout.length; j++) {
2037
- this.atlas.remove(map.layout[j]);
802
+ this.#atlas.remove(map.layout[j]);
2038
803
  }
2039
804
  this.#resolution_policy.release_pending(map);
2040
805
 
2041
- // free the per-view/-camera GPU contexts — without this an evicted map's buffers leak
2042
- this.#release_map_gpu_contexts(map);
2043
-
2044
- if (map.isVirtualShadowMap === true) {
2045
- this.#release_virtual(map);
2046
-
2047
- // a reading of its feedback still on its way back finds the map gone and drops itself
2048
- map.destroy();
2049
- } else if (map.light.isDirectionalLight === true) {
2050
- this.#release_cascades(map);
2051
- }
806
+ this.#kind_of(map).release(map);
2052
807
 
2053
808
  map.light._gpu_shadowmap_id = -1;
2054
809
  }
@@ -2092,50 +847,31 @@ export class GPUSceneShadowmapContext {
2092
847
  // No draw runs while shadows are off, and the draw is what frees disused slots — so
2093
848
  // they are freed here, or a directional slot would name the cascade rows just given
2094
849
  // back for as long as shadows stay off.
2095
- this.#trim_shadow_records(this.#owner.database, 0, 0, 0);
850
+ this.#records.trim(this.#owner.database, 0, 0, 0);
2096
851
 
2097
852
  return had_maps;
2098
853
  }
2099
854
 
2100
- const scene = this.#scene;
2101
- const lights = scene.lights.elements;
855
+ const lights = this.#scene.lights.elements;
2102
856
  let changed = false;
2103
857
 
2104
- const use_tetra = this.use_tetrahedron_point_shadows;
2105
858
  const use_virtual = this.use_virtual_shadow_maps;
2106
- const cascade_count = this.#cascade_count;
2107
- const first_texel_size = this.#virtual_first_texel_size;
2108
859
  const newcomers = this.#reconcile_newcomers;
2109
860
 
2110
861
  /**
2111
- * Whether a map was built under settings that no longer hold — a point map by the other
2112
- * generator (cube vs tetra), whose face count and draw path no longer match, a directional
2113
- * map of the other kind (cascades vs virtual), one with another number of cascades, or a
2114
- * virtual one with another first texel — and so must be rebuilt.
862
+ * Whether a map was built under settings that no longer hold — a directional map of the
863
+ * other kind (cascades vs virtual), or one its own kind no longer builds that way — and so
864
+ * must be rebuilt.
2115
865
  *
2116
866
  * @param {Shadowmap} map
2117
867
  * @returns {boolean}
2118
868
  */
2119
869
  const is_outdated = (map) => {
2120
- const light = map.light;
2121
-
2122
- if (light.isPointLight) {
2123
- return Boolean(map.isTetrahedron) !== use_tetra;
2124
- }
2125
-
2126
- if (light.isDirectionalLight) {
2127
- const is_virtual = map.isVirtualShadowMap === true;
2128
-
2129
- if (is_virtual !== use_virtual) {
2130
- return true;
2131
- }
2132
-
2133
- return is_virtual
2134
- ? map.manager.first_texel_size !== first_texel_size
2135
- : map.cascade_count !== cascade_count;
870
+ if (map.light.isDirectionalLight && (map.isVirtualShadowMap === true) !== use_virtual) {
871
+ return true;
2136
872
  }
2137
873
 
2138
- return false;
874
+ return this.#kind_of(map).is_outdated(map);
2139
875
  };
2140
876
 
2141
877
  registry.begin_reconcile();
@@ -2183,159 +919,29 @@ export class GPUSceneShadowmapContext {
2183
919
  changed = true;
2184
920
  }
2185
921
 
2186
- const add_directional = (light) => {
2187
- const map = new DirectionalLightShadowmap(cascade_count);
2188
- map.light = light;
2189
-
2190
- const bound = [];
2191
- try {
2192
- for (let j = 0; j < cascade_count; j++) {
2193
- const resolution_index = Math.min(j, DEFAULT_SHADOWMAP_DIRECTIONAL_RESOLUTION.length - 1);
2194
- const resolution = DEFAULT_SHADOWMAP_DIRECTIONAL_RESOLUTION[resolution_index];
2195
-
2196
- const rect = this.bind(resolution);
2197
- bound.push(rect);
2198
- map.layout[j] = rect;
2199
-
2200
- const camera = new OrthographicCamera();
2201
- camera.update();
2202
-
2203
- const view = new View(camera, scene);
2204
- view.label = `Shadow Cascade ${j}`;
2205
-
2206
- map.views[j] = view;
2207
- }
2208
- } catch (e) {
2209
- // Partial bind: roll back any cascade rects already inserted so the atlas isn't
2210
- // left holding orphans for a map that never got registered.
2211
- for (let j = 0; j < bound.length; j++) {
2212
- this.atlas.remove(bound[j]);
2213
- }
2214
- throw e;
2215
- }
2216
-
2217
- this.#claim_cascades(map);
2218
- registry.add(map);
2219
- };
2220
-
2221
- const add_virtual = (light) => {
2222
- // the pool: as many whole slots as fit the default pool, or the largest atlas the device
2223
- // can hold when that is smaller; bind grows the atlas for it, or shrinks it by whole slots
2224
- const slot_size = VSM_PAGE_SIZE + 2 * SHADOWMAP_ATLAS_BORDER;
2225
- const pool_side = Math.floor(Math.min(VSM_POOL_SIZE, this.#graphics.device.limits.maxTextureDimension2D) / slot_size) * slot_size;
2226
-
2227
- // the pool first: an atlas without room for it throws here, every frame the sun is
2228
- // retried, and the map's page bookkeeping — megabytes — is not built for nothing
2229
- const pool = this.bind(pool_side, slot_size);
2230
-
2231
- let map;
2232
-
2233
- try {
2234
- map = new VirtualShadowMap({
2235
- level_count: VSM_LEVEL_COUNT,
2236
- pages_per_level: VSM_PAGES_PER_LEVEL,
2237
- first_texel_size,
2238
- page_size: VSM_PAGE_SIZE,
2239
- border: SHADOWMAP_ATLAS_BORDER,
2240
- pool_size: pool.width,
2241
- request_capacity: VSM_DEFAULT_REQUEST_CAPACITY,
2242
- protect_frames: VSM_PROTECT_FRAMES,
2243
- depth_extent: VSM_DEPTH_EXTENT,
2244
- });
2245
-
2246
- map.light = light;
2247
- map.layout[0] = pool;
2248
-
2249
- this.#claim_virtual(map);
2250
- } catch (e) {
2251
- // nothing registered the map: give its pool back rather than leave an orphan rect
2252
- this.atlas.remove(pool);
2253
- throw e;
2254
- }
2255
-
2256
- registry.add(map);
2257
- };
2258
-
2259
- const add_spot = (light) => {
2260
- const map = new SpotLightShadowmap();
2261
- map.light = light;
2262
-
2263
- const rect = this.bind(DEFAULT_SHADOWMAP_LOCAL_RESOLUTION);
2264
- map.layout[0] = rect;
2265
-
2266
- try {
2267
- const camera = new PerspectiveCamera();
2268
- camera.update();
2269
-
2270
- const view = new View(camera, scene);
2271
- view.label = `Spot Shadow`;
2272
-
2273
- map.views[0] = view;
2274
- } catch (e) {
2275
- this.atlas.remove(rect);
2276
- throw e;
2277
- }
2278
-
2279
- registry.add(map);
2280
- };
2281
-
2282
- const add_point = (light) => {
2283
-
2284
- // Generator picked by `use_tetra` above; both remap into one octahedral slot, they
2285
- // only differ in how many face frusta feed that remap (tetra 4, cube 6).
2286
- const map = use_tetra ? new TetrahedronPointLightShadowmap() : new PointLightShadowmap();
2287
- map.light = light;
2288
-
2289
- // single atlas rect holds the octahedral-encoded depth for all faces
2290
- const rect = this.bind(DEFAULT_SHADOWMAP_LOCAL_RESOLUTION);
2291
- map.layout[0] = rect;
2292
-
2293
- const face_count = use_tetra ? POINT_SHADOW_TETRA_FACE_COUNT : 6;
2294
-
2295
- for (let j = 0; j < face_count; j++) {
2296
- const camera = new PerspectiveCamera();
2297
- camera.update();
2298
-
2299
- const view = new View(camera, scene);
2300
- view.label = use_tetra ? `Point Shadow (tetra) face ${j}` : `Point Shadow face ${j}`;
2301
-
2302
- map.views[j] = view;
2303
- }
2304
-
2305
- registry.add(map);
2306
- };
922
+ // Pass 3 — allocate. Only the lights pass 1 flagged, so on the overwhelming majority of
923
+ // frames (nothing arrived, nothing left) this loop does not run at all. The old version
924
+ // walked every light here and re-tested casts_shadow on each; pass 1 already answered that.
925
+ for (let i = 0; i < newcomers.length; i++) {
926
+ const light = newcomers[i];
2307
927
 
2308
- const add_light = (light) => {
2309
928
  // A light present twice in the scene's light array gets queued twice by pass 1, since
2310
929
  // neither occurrence finds a map. LightCollection.add doesn't dedupe, so re-check here
2311
930
  // rather than letting the registry's one-map-per-light assert fire every frame. Free
2312
931
  // in the normal case — this loop only runs over lights that actually need a map.
2313
932
  if (registry.get(light) !== undefined) {
2314
- return;
933
+ continue;
2315
934
  }
2316
935
 
2317
- if (light.isDirectionalLight) {
2318
- if (use_virtual) {
2319
- add_virtual(light);
2320
- } else {
2321
- add_directional(light);
2322
- }
2323
- changed = true;
2324
- } else if (light.isSpotLight) {
2325
- add_spot(light);
2326
- changed = true;
2327
- } else if (light.isPointLight) {
2328
- add_point(light);
2329
- changed = true;
936
+ const kind = this.#kind_for(light);
937
+
938
+ if (kind === undefined) {
939
+ continue;
2330
940
  }
2331
- };
2332
941
 
2333
- // Pass 3 — allocate. Only the lights pass 1 flagged, so on the overwhelming majority of
2334
- // frames (nothing arrived, nothing left) this loop does not run at all. The old version
2335
- // walked every light here and re-tested casts_shadow on each; pass 1 already answered that.
2336
- for (let i = 0; i < newcomers.length; i++) {
2337
942
  try {
2338
- add_light(newcomers[i]);
943
+ registry.add(kind.create(light));
944
+ changed = true;
2339
945
  } catch (e) {
2340
946
  console.error(e);
2341
947
  }
@@ -2346,137 +952,25 @@ export class GPUSceneShadowmapContext {
2346
952
  // this scratch array for a frame.
2347
953
  newcomers.length = 0;
2348
954
 
2349
- // Publish per-type shadowmap ids back onto the lights. Each shadow_* table is indexed
2350
- // independently, so a point light's shadow_id points into shadow_point, a spot's into
2351
- // shadow_spot, etc. Type-bucket order MUST match {@link #write_shadow_records} so each
2352
- // light record's stored shadow_id lines up with the slot we'll write into the table.
2353
- // When a map's slot index actually changes (eviction shifted neighbours up the array),
2354
- // mark its record dirty so the next #write_shadow_records re-publishes it into the new
2355
- // slot, and report `changed` so the caller re-publishes the light records too.
2356
- let pc = 0;
2357
- let sc = 0;
2358
- let dc = 0;
2359
- for (let i = 0; i < shadowmaps.length; i++) {
2360
- const map = shadowmaps[i];
2361
- const light = map.light;
2362
-
2363
- let new_id;
2364
- if (light.isPointLight) {
2365
- new_id = pc++;
2366
- } else if (light.isSpotLight) {
2367
- new_id = sc++;
2368
- } else if (light.isDirectionalLight) {
2369
- new_id = dc++;
2370
- } else {
2371
- continue;
2372
- }
2373
-
2374
- if (light._gpu_shadowmap_id !== new_id) {
2375
- light._gpu_shadowmap_id = new_id;
2376
- map.metadata_changed = true;
2377
- changed = true;
2378
- }
955
+ // Publish per-type shadowmap ids back onto the lights.
956
+ if (this.#records.assign_ids(shadowmaps)) {
957
+ changed = true;
2379
958
  }
2380
959
 
2381
960
  return changed;
2382
961
  }
2383
962
 
2384
- /**
2385
- * Place a square patch of `resolution` texels in the atlas. When it does not fit: first the
2386
- * room pending resizes hold is given back, then the atlas grows, and only when it is as large
2387
- * as the device allows is the patch shrunk, halving and kept to whole multiples of `step`,
2388
- * down to {@link SHADOWMAP_PATCH_MIN_SIDE}.
2389
- *
2390
- * @param {number} resolution side the patch asks for
2391
- * @param {number} [step] texels the side must be a multiple of
2392
- * @returns {AABB2} the patch placed, `resolution` or smaller on a side
2393
- * @throws {Error} when not even the smallest patch fits
2394
- */
2395
- bind(resolution, step = 1) {
2396
- const floor = Math.max(step, SHADOWMAP_PATCH_MIN_SIDE);
2397
-
2398
- for (let side = resolution; side >= floor; side = Math.floor(side / (2 * step)) * step) {
2399
- const rect = new AABB2(0, 0, side, side);
2400
-
2401
- if (this.#make_room(rect)) {
2402
- return rect;
2403
- }
2404
- }
2405
-
2406
- throw new Error(`Failed to add shadowmap to atlas`);
2407
- }
2408
-
2409
- /**
2410
- * Add `rect` to the atlas, making room for it if it does not fit: the pending resizes'
2411
- * reservations go back first, as nothing samples them, then the atlas doubles, up to the
2412
- * device's largest texture.
2413
- *
2414
- * @param {AABB2} rect
2415
- * @returns {boolean} whether it was placed
2416
- */
2417
- #make_room(rect) {
2418
- const atlas = this.atlas;
2419
-
2420
- if (atlas.add(rect)) {
2421
- return true;
2422
- }
2423
-
2424
- if (this.#resolution_policy.release_all_pending(this.#registry.maps) && atlas.add(rect)) {
2425
- return true;
2426
- }
2427
-
2428
- // the atlas is square, packer and texture alike
2429
- const limit = this.#graphics.device.limits.maxTextureDimension2D;
2430
-
2431
- while (atlas.size.x < limit) {
2432
- this.#grow_atlas(Math.min(limit, atlas.size.x * 2));
2433
-
2434
- if (atlas.add(rect)) {
2435
- return true;
2436
- }
2437
- }
2438
-
2439
- return false;
2440
- }
2441
-
2442
- /**
2443
- * Make the atlas `side` texels square, packer and texture. Every patch keeps its place, but the
2444
- * new texture holds no depth, so every map is drawn again before it is sampled and every
2445
- * virtual map gives its pages back.
2446
- *
2447
- * @param {number} side
2448
- */
2449
- #grow_atlas(side) {
2450
- this.atlas.resize(side, side);
2451
- this.texture.resize(side, side);
2452
-
2453
- const maps = this.#registry.maps;
2454
-
2455
- for (let i = 0; i < maps.length; i++) {
2456
- const map = maps[i];
2457
-
2458
- map.is_invalid = true;
2459
-
2460
- if (map.isVirtualShadowMap === true) {
2461
- map.manager.evict_all();
2462
- }
2463
- }
2464
- }
2465
-
2466
963
  destroy() {
2467
- if (this.#caster_scratch !== null) {
2468
- this.#caster_scratch.destroy();
2469
- this.#caster_scratch = null;
2470
- }
964
+ this.cascades.destroy();
2471
965
 
2472
- this.texture.destroy();
966
+ this.#atlas.destroy();
2473
967
 
2474
968
  const maps = this.#registry.maps;
2475
969
  for (let i = 0; i < maps.length; i++) {
2476
970
  const map = maps[i];
2477
971
  // release the per-view/-camera GPU contexts too — map.destroy() alone doesn't (the
2478
972
  // buffers live in the view/camera manager caches, not on the map)
2479
- this.#release_map_gpu_contexts(map);
973
+ this.#kind_of(map).dispose(map);
2480
974
  map.destroy();
2481
975
  }
2482
976
  this.#registry.clear();