@woosh/meep-engine 3.23.0 → 3.24.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 (522) hide show
  1. package/editor/entity_world_bounds.d.ts +9 -3
  2. package/editor/entity_world_bounds.d.ts.map +1 -1
  3. package/editor/entity_world_bounds.js +61 -4
  4. package/package.json +1 -1
  5. package/src/core/binary/allocator/OffsetAllocator.d.ts +40 -2
  6. package/src/core/binary/allocator/OffsetAllocator.d.ts.map +1 -1
  7. package/src/core/binary/allocator/OffsetAllocator.js +124 -29
  8. package/src/core/collection/map/u32_index.d.ts +83 -0
  9. package/src/core/collection/map/u32_index.d.ts.map +1 -0
  10. package/src/core/collection/map/u32_index.js +247 -0
  11. package/src/engine/asset/loaders/GLTFSceneBundleAssetLoader.d.ts +2 -2
  12. package/src/engine/asset/loaders/GLTFSceneBundleAssetLoader.js +2 -2
  13. package/src/engine/asset/loaders/USDSceneBundleAssetLoader.d.ts +1 -2
  14. package/src/engine/asset/loaders/USDSceneBundleAssetLoader.d.ts.map +1 -1
  15. package/src/engine/asset/loaders/USDSceneBundleAssetLoader.js +4 -12
  16. package/src/engine/ecs/gpu/GPUStateAuthority.d.ts +55 -0
  17. package/src/engine/ecs/gpu/GPUStateAuthority.d.ts.map +1 -0
  18. package/src/engine/ecs/gpu/GPUStateAuthority.js +72 -0
  19. package/src/engine/ecs/gpu/GPUStateAuthorityFlags.d.ts +40 -0
  20. package/src/engine/ecs/gpu/GPUStateAuthorityFlags.d.ts.map +1 -0
  21. package/src/engine/ecs/gpu/GPUStateAuthorityFlags.js +79 -0
  22. package/src/engine/ecs/gpu/gpu_authority_assert_cpu.d.ts +18 -0
  23. package/src/engine/ecs/gpu/gpu_authority_assert_cpu.d.ts.map +1 -0
  24. package/src/engine/ecs/gpu/gpu_authority_assert_cpu.js +27 -0
  25. package/src/engine/ecs/gpu/gpu_authority_declare.d.ts +23 -0
  26. package/src/engine/ecs/gpu/gpu_authority_declare.d.ts.map +1 -0
  27. package/src/engine/ecs/gpu/gpu_authority_declare.js +39 -0
  28. package/src/engine/ecs/gpu/gpu_authority_grant.d.ts +15 -0
  29. package/src/engine/ecs/gpu/gpu_authority_grant.d.ts.map +1 -0
  30. package/src/engine/ecs/gpu/gpu_authority_grant.js +38 -0
  31. package/src/engine/ecs/gpu/gpu_authority_has.d.ts +18 -0
  32. package/src/engine/ecs/gpu/gpu_authority_has.d.ts.map +1 -0
  33. package/src/engine/ecs/gpu/gpu_authority_has.js +28 -0
  34. package/src/engine/ecs/gpu/gpu_authority_revoke.d.ts +24 -0
  35. package/src/engine/ecs/gpu/gpu_authority_revoke.d.ts.map +1 -0
  36. package/src/engine/ecs/gpu/gpu_authority_revoke.js +49 -0
  37. package/src/engine/ecs/ik/IKProblem.d.ts +14 -0
  38. package/src/engine/ecs/ik/IKProblem.d.ts.map +1 -1
  39. package/src/engine/ecs/ik/IKProblem.js +16 -0
  40. package/src/engine/ecs/ik/InverseKinematicsSystem.d.ts.map +1 -1
  41. package/src/engine/ecs/ik/InverseKinematicsSystem.js +19 -0
  42. package/src/engine/ecs/ik/OneBoneSurfaceAlignmentSolver.js +2 -2
  43. package/src/engine/ecs/ik/TwoBoneInverseKinematicsSolver.js +2 -2
  44. package/src/engine/ecs/ik/ik_bone_chain.d.ts +11 -2
  45. package/src/engine/ecs/ik/ik_bone_chain.d.ts.map +1 -1
  46. package/src/engine/ecs/ik/ik_bone_chain.js +47 -2
  47. package/src/engine/ecs/ik/ik_write_local_rotation.d.ts.map +1 -1
  48. package/src/engine/ecs/ik/ik_write_local_rotation.js +6 -0
  49. package/src/engine/ecs/speaker/VoiceSystem.d.ts.map +1 -1
  50. package/src/engine/ecs/speaker/VoiceSystem.js +6 -0
  51. package/src/engine/ecs/transform/T64WorldCache.d.ts +50 -0
  52. package/src/engine/ecs/transform/T64WorldCache.d.ts.map +1 -0
  53. package/src/engine/ecs/transform/T64WorldCache.js +139 -0
  54. package/src/engine/ecs/transform/t64_evaluate_world.d.ts +31 -0
  55. package/src/engine/ecs/transform/t64_evaluate_world.d.ts.map +1 -0
  56. package/src/engine/ecs/transform/t64_evaluate_world.js +126 -0
  57. package/src/engine/ecs/transform-attachment/TransformAttachmentSystem.d.ts +8 -0
  58. package/src/engine/ecs/transform-attachment/TransformAttachmentSystem.d.ts.map +1 -1
  59. package/src/engine/ecs/transform-attachment/TransformAttachmentSystem.js +59 -30
  60. package/src/engine/graphics/ecs/highlight/system/ShadedGeometryHighlightSystem.d.ts.map +1 -1
  61. package/src/engine/graphics/ecs/highlight/system/ShadedGeometryHighlightSystem.js +4 -11
  62. package/src/engine/graphics/ecs/mesh-v2/SHADED_GEOMETRY_EVENT_CHANGE.d.ts +14 -0
  63. package/src/engine/graphics/ecs/mesh-v2/SHADED_GEOMETRY_EVENT_CHANGE.d.ts.map +1 -0
  64. package/src/engine/graphics/ecs/mesh-v2/SHADED_GEOMETRY_EVENT_CHANGE.js +13 -0
  65. package/src/engine/graphics/ecs/mesh-v2/ShadedGeometry.d.ts +2 -14
  66. package/src/engine/graphics/ecs/mesh-v2/ShadedGeometry.d.ts.map +1 -1
  67. package/src/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +11 -21
  68. package/src/engine/graphics/ecs/mesh-v2/ShadedGeometryFlags.d.ts +1 -0
  69. package/src/engine/graphics/ecs/mesh-v2/ShadedGeometryFlags.js +7 -0
  70. package/src/engine/graphics/ecs/mesh-v2/aggregate/SGMeshHighlightSystem.d.ts +5 -6
  71. package/src/engine/graphics/ecs/mesh-v2/aggregate/SGMeshHighlightSystem.d.ts.map +1 -1
  72. package/src/engine/graphics/ecs/mesh-v2/aggregate/SGMeshHighlightSystem.js +13 -11
  73. package/src/engine/graphics/ecs/mesh-v2/shaded_geometry_announce_change.d.ts +14 -0
  74. package/src/engine/graphics/ecs/mesh-v2/shaded_geometry_announce_change.d.ts.map +1 -0
  75. package/src/engine/graphics/ecs/mesh-v2/shaded_geometry_announce_change.js +21 -0
  76. package/src/engine/graphics/ecs/particles/ParticleEffect.d.ts +1 -1
  77. package/src/engine/graphics/ecs/particles/ParticleEffect.js +1 -1
  78. package/src/engine/graphics/sh3/path_tracer/populate_path_traced_scene_from_ecd.d.ts +1 -1
  79. package/src/engine/graphics/sh3/path_tracer/populate_path_traced_scene_from_ecd.js +1 -1
  80. package/src/engine/graphics3/AnimationGraphSystem.js +3 -3
  81. package/src/engine/graphics3/AnimationSystem.js +2 -2
  82. package/src/engine/graphics3/DebugDrawSystem.d.ts.map +1 -1
  83. package/src/engine/graphics3/DebugDrawSystem.js +2 -4
  84. package/src/engine/graphics3/GPUParticleEmitterSystem.d.ts +34 -27
  85. package/src/engine/graphics3/GPUParticleEmitterSystem.d.ts.map +1 -1
  86. package/src/engine/graphics3/GPUParticleEmitterSystem.js +185 -85
  87. package/src/engine/graphics3/HighlightOutlineSystem.d.ts +4 -3
  88. package/src/engine/graphics3/HighlightOutlineSystem.d.ts.map +1 -1
  89. package/src/engine/graphics3/HighlightOutlineSystem.js +7 -9
  90. package/src/engine/graphics3/LightSystem.d.ts +7 -5
  91. package/src/engine/graphics3/LightSystem.d.ts.map +1 -1
  92. package/src/engine/graphics3/LightSystem.js +36 -22
  93. package/src/engine/graphics3/MeshSystem.d.ts +43 -39
  94. package/src/engine/graphics3/MeshSystem.d.ts.map +1 -1
  95. package/src/engine/graphics3/MeshSystem.js +324 -331
  96. package/src/engine/graphics3/PathDisplaySystem.d.ts.map +1 -1
  97. package/src/engine/graphics3/PathDisplaySystem.js +2 -4
  98. package/src/engine/graphics3/PickingQuery.d.ts +15 -21
  99. package/src/engine/graphics3/PickingQuery.d.ts.map +1 -1
  100. package/src/engine/graphics3/PickingQuery.js +21 -25
  101. package/src/engine/graphics3/PickingSystem.d.ts +60 -31
  102. package/src/engine/graphics3/PickingSystem.d.ts.map +1 -1
  103. package/src/engine/graphics3/PickingSystem.js +416 -273
  104. package/src/engine/graphics3/ShadedGeometrySystem.d.ts +22 -12
  105. package/src/engine/graphics3/ShadedGeometrySystem.d.ts.map +1 -1
  106. package/src/engine/graphics3/ShadedGeometrySystem.js +309 -174
  107. package/src/engine/graphics3/TerrainSystem.d.ts +19 -11
  108. package/src/engine/graphics3/TerrainSystem.d.ts.map +1 -1
  109. package/src/engine/graphics3/TerrainSystem.js +102 -53
  110. package/src/engine/graphics3/TooltipComponentSystem.d.ts.map +1 -1
  111. package/src/engine/graphics3/TooltipComponentSystem.js +2 -14
  112. package/src/engine/graphics3/Trail3DSystem.d.ts.map +1 -1
  113. package/src/engine/graphics3/Trail3DSystem.js +2 -4
  114. package/src/engine/graphics3/animation/ClipListPlayer.d.ts +4 -4
  115. package/src/engine/graphics3/animation/ClipListPlayer.d.ts.map +1 -1
  116. package/src/engine/graphics3/animation/ClipListPlayer.js +2 -2
  117. package/src/engine/graphics3/highlight/pack_highlight_table.d.ts +9 -11
  118. package/src/engine/graphics3/highlight/pack_highlight_table.d.ts.map +1 -1
  119. package/src/engine/graphics3/highlight/pack_highlight_table.js +11 -18
  120. package/src/engine/graphics3/pose/query_entity_node_world_pose.d.ts +4 -3
  121. package/src/engine/graphics3/pose/query_entity_node_world_pose.d.ts.map +1 -1
  122. package/src/engine/graphics3/pose/query_entity_node_world_pose.js +75 -74
  123. package/src/engine/graphics3/prefab/Prefab.d.ts +130 -0
  124. package/src/engine/graphics3/prefab/Prefab.d.ts.map +1 -0
  125. package/src/engine/graphics3/prefab/Prefab.js +162 -0
  126. package/src/engine/graphics3/prefab/PrefabInstance.d.ts +72 -0
  127. package/src/engine/graphics3/prefab/PrefabInstance.d.ts.map +1 -0
  128. package/src/engine/graphics3/prefab/PrefabInstance.js +80 -0
  129. package/src/engine/graphics3/prefab/prefab_compile.d.ts +23 -0
  130. package/src/engine/graphics3/prefab/prefab_compile.d.ts.map +1 -0
  131. package/src/engine/graphics3/prefab/prefab_compile.js +334 -0
  132. package/src/engine/graphics3/prefab/prefab_instantiate.d.ts +46 -0
  133. package/src/engine/graphics3/prefab/prefab_instantiate.d.ts.map +1 -0
  134. package/src/engine/graphics3/prefab/prefab_instantiate.js +230 -0
  135. package/src/engine/graphics3/prefab/prefab_normalize_skin_frames.d.ts +70 -0
  136. package/src/engine/graphics3/prefab/prefab_normalize_skin_frames.d.ts.map +1 -0
  137. package/src/engine/graphics3/prefab/prefab_normalize_skin_frames.js +210 -0
  138. package/src/engine/graphics3/prefab/prefab_place.d.ts +60 -0
  139. package/src/engine/graphics3/prefab/prefab_place.d.ts.map +1 -0
  140. package/src/engine/graphics3/prefab/prefab_place.js +130 -0
  141. package/src/engine/graphics3/prefab/prefab_skin_clip_scale_conflicts.d.ts +60 -0
  142. package/src/engine/graphics3/prefab/prefab_skin_clip_scale_conflicts.d.ts.map +1 -0
  143. package/src/engine/graphics3/prefab/prefab_skin_clip_scale_conflicts.js +128 -0
  144. package/src/engine/graphics3/prefab/prefab_skin_frame.d.ts +40 -0
  145. package/src/engine/graphics3/prefab/prefab_skin_frame.d.ts.map +1 -0
  146. package/src/engine/graphics3/prefab/prefab_skin_frame.js +116 -0
  147. package/src/engine/graphics3/preview/make_model_preview_scene.d.ts +16 -14
  148. package/src/engine/graphics3/preview/make_model_preview_scene.d.ts.map +1 -1
  149. package/src/engine/graphics3/preview/make_model_preview_scene.js +126 -154
  150. package/src/engine/graphics3/preview/make_model_thumbnail.js +1 -1
  151. package/src/engine/graphics3/register_instance_animation.d.ts +6 -6
  152. package/src/engine/graphics3/register_instance_animation.d.ts.map +1 -1
  153. package/src/engine/graphics3/register_instance_animation.js +4 -4
  154. package/src/engine/graphics3/shade_bundle_bounds.d.ts +2 -6
  155. package/src/engine/graphics3/shade_bundle_bounds.d.ts.map +1 -1
  156. package/src/engine/graphics3/shade_bundle_bounds.js +47 -55
  157. package/src/engine/graphics3/terrain/pack_terrain_row_table.d.ts +11 -18
  158. package/src/engine/graphics3/terrain/pack_terrain_row_table.d.ts.map +1 -1
  159. package/src/engine/graphics3/terrain/pack_terrain_row_table.js +48 -53
  160. package/src/engine/physics/cloth/build/cloth_proxy_from_joints.d.ts +17 -2
  161. package/src/engine/physics/cloth/build/cloth_proxy_from_joints.d.ts.map +1 -1
  162. package/src/engine/physics/cloth/build/cloth_proxy_from_joints.js +284 -256
  163. package/src/engine/physics/cloth/ecs/ClothInstance.d.ts +13 -15
  164. package/src/engine/physics/cloth/ecs/ClothInstance.d.ts.map +1 -1
  165. package/src/engine/physics/cloth/ecs/ClothInstance.js +12 -14
  166. package/src/engine/physics/cloth/ecs/ClothRig.d.ts +7 -8
  167. package/src/engine/physics/cloth/ecs/ClothRig.d.ts.map +1 -1
  168. package/src/engine/physics/cloth/ecs/ClothRig.js +7 -8
  169. package/src/engine/physics/cloth/ecs/ClothSystem.d.ts +5 -4
  170. package/src/engine/physics/cloth/ecs/ClothSystem.d.ts.map +1 -1
  171. package/src/engine/physics/cloth/ecs/ClothSystem.js +11 -12
  172. package/src/engine/physics/cloth/ecs/cloth_seed_rig.d.ts +19 -23
  173. package/src/engine/physics/cloth/ecs/cloth_seed_rig.d.ts.map +1 -1
  174. package/src/engine/physics/cloth/ecs/cloth_seed_rig.js +201 -199
  175. package/src/engine/physics/cloth/ecs/cloth_seed_subtree.d.ts.map +1 -1
  176. package/src/engine/physics/cloth/ecs/cloth_seed_subtree.js +8 -0
  177. package/src/engine/physics/cloth/ecs/cloth_write_back_rig.d.ts +18 -34
  178. package/src/engine/physics/cloth/ecs/cloth_write_back_rig.d.ts.map +1 -1
  179. package/src/engine/physics/cloth/ecs/cloth_write_back_rig.js +58 -115
  180. package/src/engine/physics/cloth/playground/README.md +11 -11
  181. package/src/engine/physics/cloth/playground/garment_build.d.ts +0 -1
  182. package/src/engine/physics/cloth/playground/garment_build.d.ts.map +1 -1
  183. package/src/engine/physics/cloth/playground/garment_build.js +64 -58
  184. package/src/engine/physics/cloth/playground/garment_main.js +59 -33
  185. package/src/engine/physics/fluid/ecs/FluidObstacleSystem.d.ts +4 -4
  186. package/src/shade/RENDERER_CONTRACT.md +85 -53
  187. package/src/shade/device/ShadeGPUCommandContext.d.ts +23 -0
  188. package/src/shade/device/ShadeGPUCommandContext.d.ts.map +1 -1
  189. package/src/shade/device/ShadeGPUCommandContext.js +36 -0
  190. package/src/shade/playground/add_random_meshes.d.ts +4 -4
  191. package/src/shade/playground/add_random_meshes.d.ts.map +1 -1
  192. package/src/shade/playground/add_random_meshes.js +20 -16
  193. package/src/shade/playground/avboit/main.d.ts +1 -0
  194. package/src/shade/playground/avboit/main.d.ts.map +1 -1
  195. package/src/shade/playground/avboit/main.js +916 -875
  196. package/src/shade/playground/basis_textures/main.d.ts.map +1 -1
  197. package/src/shade/playground/basis_textures/main.js +22 -8
  198. package/src/shade/playground/basis_textures/texture_inventory.d.ts +2 -2
  199. package/src/shade/playground/basis_textures/texture_inventory.d.ts.map +1 -1
  200. package/src/shade/playground/basis_textures/texture_inventory.js +6 -7
  201. package/src/shade/playground/ground_seam/main.d.ts.map +1 -1
  202. package/src/shade/playground/ground_seam/main.js +13 -4
  203. package/src/shade/playground/ground_seam/make_ground.d.ts +13 -4
  204. package/src/shade/playground/ground_seam/make_ground.d.ts.map +1 -1
  205. package/src/shade/playground/ground_seam/make_ground.js +21 -16
  206. package/src/shade/playground/particle_ecs/bonfire_editor.js +3 -3
  207. package/src/shade/playground/particle_system/main.js +11 -10
  208. package/src/shade/playground/particle_system/particle_prototype.d.ts +15 -10
  209. package/src/shade/playground/particle_system/particle_prototype.d.ts.map +1 -1
  210. package/src/shade/playground/particle_system/particle_prototype.js +56 -15
  211. package/src/shade/playground/particle_system/particle_scene.d.ts +68 -28
  212. package/src/shade/playground/particle_system/particle_scene.d.ts.map +1 -1
  213. package/src/shade/playground/particle_system/particle_scene.js +149 -53
  214. package/src/shade/playground/readback_crossover/index.html +41 -0
  215. package/src/shade/playground/readback_crossover/main.d.ts +2 -0
  216. package/src/shade/playground/readback_crossover/main.d.ts.map +1 -0
  217. package/src/shade/playground/readback_crossover/main.js +372 -0
  218. package/src/shade/playground/skinned_blas_refit/README.md +11 -7
  219. package/src/shade/playground/skinned_blas_refit/add_floor.d.ts +13 -44
  220. package/src/shade/playground/skinned_blas_refit/add_floor.d.ts.map +1 -1
  221. package/src/shade/playground/skinned_blas_refit/add_floor.js +19 -59
  222. package/src/shade/playground/skinned_blas_refit/main.d.ts.map +1 -1
  223. package/src/shade/playground/skinned_blas_refit/main.js +67 -58
  224. package/src/shade/playground/skinned_blas_refit/place_character.d.ts +40 -54
  225. package/src/shade/playground/skinned_blas_refit/place_character.d.ts.map +1 -1
  226. package/src/shade/playground/skinned_blas_refit/place_character.js +47 -74
  227. package/src/shade/playground/skinned_blas_refit/sweep_views.d.ts +3 -3
  228. package/src/shade/playground/skinned_blas_refit/sweep_views.d.ts.map +1 -1
  229. package/src/shade/playground/skinned_blas_refit/sweep_views.js +4 -3
  230. package/src/shade/playground/skinned_blas_refit/verify_clone_leaves.d.ts +3 -3
  231. package/src/shade/playground/skinned_blas_refit/verify_clone_leaves.d.ts.map +1 -1
  232. package/src/shade/playground/skinned_blas_refit/verify_clone_leaves.js +11 -4
  233. package/src/shade/playground/skinned_blas_refit/verify_instance_bounds.d.ts.map +1 -1
  234. package/src/shade/playground/skinned_blas_refit/verify_instance_bounds.js +38 -9
  235. package/src/shade/playground/skinned_blas_refit/verify_skinned_blas_refit.d.ts +3 -3
  236. package/src/shade/playground/skinned_blas_refit/verify_skinned_blas_refit.d.ts.map +1 -1
  237. package/src/shade/playground/skinned_blas_refit/verify_skinned_blas_refit.js +9 -6
  238. package/src/shade/playground/skinned_blas_refit/verify_traversal_reachability.d.ts +3 -3
  239. package/src/shade/playground/skinned_blas_refit/verify_traversal_reachability.d.ts.map +1 -1
  240. package/src/shade/playground/skinned_blas_refit/verify_traversal_reachability.js +3 -3
  241. package/src/shade/playground/skinned_mesh_soup/README.md +6 -6
  242. package/src/shade/playground/skinned_mesh_soup/main.d.ts.map +1 -1
  243. package/src/shade/playground/skinned_mesh_soup/main.js +44 -102
  244. package/src/shade/playground/skinned_mesh_soup/verify_clone_vertices.d.ts +5 -5
  245. package/src/shade/playground/skinned_mesh_soup/verify_clone_vertices.d.ts.map +1 -1
  246. package/src/shade/playground/skinned_mesh_soup/verify_clone_vertices.js +42 -33
  247. package/src/shade/playground/sponza_path_trace/main.d.ts +1 -0
  248. package/src/shade/playground/sponza_path_trace/main.d.ts.map +1 -1
  249. package/src/shade/playground/sponza_path_trace/main.js +393 -363
  250. package/src/shade/playground/ssr_reprojection/main.js +11 -9
  251. package/src/shade/playground/ssr_reprojection/scene.d.ts +15 -4
  252. package/src/shade/playground/ssr_reprojection/scene.d.ts.map +1 -1
  253. package/src/shade/playground/ssr_reprojection/scene.js +32 -11
  254. package/src/shade/playground/ssr_variance/main.js +1 -1
  255. package/src/shade/playground/ssr_variance/scene.d.ts +10 -4
  256. package/src/shade/playground/ssr_variance/scene.d.ts.map +1 -1
  257. package/src/shade/playground/ssr_variance/scene.js +39 -15
  258. package/src/shade/playground/vgeo_viewer/main.js +6 -2
  259. package/src/shade/playground/volumetrics_froxel/main.d.ts.map +1 -1
  260. package/src/shade/playground/volumetrics_froxel/main.js +936 -922
  261. package/src/shade/renderer/GraphicsContext.d.ts +7 -0
  262. package/src/shade/renderer/GraphicsContext.d.ts.map +1 -1
  263. package/src/shade/renderer/GraphicsContext.js +11 -0
  264. package/src/shade/renderer/Renderer.d.ts +3 -2
  265. package/src/shade/renderer/Renderer.d.ts.map +1 -1
  266. package/src/shade/renderer/Renderer.js +3 -2
  267. package/src/shade/renderer/animation/GPUAnimationManager.d.ts +39 -47
  268. package/src/shade/renderer/animation/GPUAnimationManager.d.ts.map +1 -1
  269. package/src/shade/renderer/animation/GPUAnimationManager.js +319 -256
  270. package/src/shade/renderer/animation/ShadeAnimationChannel.d.ts +26 -22
  271. package/src/shade/renderer/animation/ShadeAnimationChannel.d.ts.map +1 -1
  272. package/src/shade/renderer/animation/ShadeAnimationChannel.js +28 -23
  273. package/src/shade/renderer/animation/ShadeAnimationClip.d.ts +14 -6
  274. package/src/shade/renderer/animation/ShadeAnimationClip.d.ts.map +1 -1
  275. package/src/shade/renderer/animation/ShadeAnimationClip.js +20 -8
  276. package/src/shade/renderer/animation/Skin.d.ts +19 -19
  277. package/src/shade/renderer/animation/Skin.d.ts.map +1 -1
  278. package/src/shade/renderer/animation/Skin.js +15 -13
  279. package/src/shade/renderer/animation/pose/pose_evaluate_local.d.ts +6 -5
  280. package/src/shade/renderer/animation/pose/pose_evaluate_local.d.ts.map +1 -1
  281. package/src/shade/renderer/animation/pose/pose_evaluate_local.js +9 -9
  282. package/src/shade/renderer/animation/skin_clip_scale_conflicts.d.ts +5 -59
  283. package/src/shade/renderer/animation/skin_clip_scale_conflicts.d.ts.map +1 -1
  284. package/src/shade/renderer/animation/skin_clip_scale_conflicts.js +8 -132
  285. package/src/shade/renderer/animation/skinning/GPUMeshSkinningContext.d.ts +65 -62
  286. package/src/shade/renderer/animation/skinning/GPUMeshSkinningContext.d.ts.map +1 -1
  287. package/src/shade/renderer/animation/skinning/GPUMeshSkinningContext.js +148 -194
  288. package/src/shade/renderer/animation/skinning/SKINNING_BINDING_STRUCT.d.ts.map +1 -1
  289. package/src/shade/renderer/animation/skinning/SKINNING_BINDING_STRUCT.js +4 -7
  290. package/src/shade/renderer/animation/skinning/chunk_skin_blend_mesh_local.d.ts +2 -2
  291. package/src/shade/renderer/animation/skinning/chunk_skin_blend_mesh_local.js +2 -2
  292. package/src/shade/renderer/buffer/GPUBufferReadbackAllocator.d.ts +74 -0
  293. package/src/shade/renderer/buffer/GPUBufferReadbackAllocator.d.ts.map +1 -0
  294. package/src/shade/renderer/buffer/GPUBufferReadbackAllocator.js +240 -0
  295. package/src/shade/renderer/buffer/table/GPUDatabase.d.ts +14 -0
  296. package/src/shade/renderer/buffer/table/GPUDatabase.d.ts.map +1 -1
  297. package/src/shade/renderer/buffer/table/GPUDatabase.js +64 -6
  298. package/src/shade/renderer/buffer/table/GPUDatabaseReadback.d.ts +190 -0
  299. package/src/shade/renderer/buffer/table/GPUDatabaseReadback.d.ts.map +1 -0
  300. package/src/shade/renderer/buffer/table/GPUDatabaseReadback.js +1323 -0
  301. package/src/shade/renderer/buffer/table/GPUPageMetadata.d.ts +10 -0
  302. package/src/shade/renderer/buffer/table/GPUPageMetadata.d.ts.map +1 -1
  303. package/src/shade/renderer/buffer/table/GPUPageMetadata.js +12 -0
  304. package/src/shade/renderer/buffer/table/GPUReadbackStagingRing.d.ts +96 -0
  305. package/src/shade/renderer/buffer/table/GPUReadbackStagingRing.d.ts.map +1 -0
  306. package/src/shade/renderer/buffer/table/GPUReadbackStatus.d.ts +15 -0
  307. package/src/shade/renderer/buffer/table/GPUReadbackStatus.d.ts.map +1 -0
  308. package/src/shade/renderer/buffer/table/GPUReadbackStatus.js +34 -0
  309. package/src/shade/renderer/buffer/table/GPUTypedTable.d.ts +75 -7
  310. package/src/shade/renderer/buffer/table/GPUTypedTable.d.ts.map +1 -1
  311. package/src/shade/renderer/buffer/table/GPUTypedTable.js +518 -135
  312. package/src/shade/renderer/buffer/table/GPU_TABLE_GATHER_DESCRIPTOR_WORDS.d.ts +19 -0
  313. package/src/shade/renderer/buffer/table/GPU_TABLE_GATHER_DESCRIPTOR_WORDS.d.ts.map +1 -0
  314. package/src/shade/renderer/buffer/table/GPU_TABLE_GATHER_DESCRIPTOR_WORDS.js +18 -0
  315. package/src/shade/renderer/buffer/table/WordViews.d.ts +39 -0
  316. package/src/shade/renderer/buffer/table/WordViews.d.ts.map +1 -0
  317. package/src/shade/renderer/buffer/table/WordViews.js +62 -0
  318. package/src/shade/renderer/buffer/table/gpu_table_gather_shader.d.ts +27 -0
  319. package/src/shade/renderer/buffer/table/gpu_table_gather_shader.d.ts.map +1 -0
  320. package/src/shade/renderer/buffer/table/gpu_table_gather_shader.js +117 -0
  321. package/src/shade/renderer/buffer/table/serde/generate_record_writer.d.ts +121 -0
  322. package/src/shade/renderer/buffer/table/serde/generate_record_writer.d.ts.map +1 -0
  323. package/src/shade/renderer/buffer/table/serde/generate_record_writer.js +395 -0
  324. package/src/shade/renderer/buffer/table/single/GPUSingleTypeTable.d.ts.map +1 -1
  325. package/src/shade/renderer/buffer/table/single/GPUSingleTypeTable.js +70 -20
  326. package/src/shade/renderer/dynamic/GPUDynamicMeshResidency.js +1 -1
  327. package/src/shade/renderer/geometry/bvh/GPUGeometryBVHManager.d.ts.map +1 -1
  328. package/src/shade/renderer/geometry/bvh/GPUGeometryBVHManager.js +6 -5
  329. package/src/shade/renderer/geometry/meshlet/GPUMeshletManager.d.ts +3 -3
  330. package/src/shade/renderer/geometry/meshlet/GPUMeshletManager.d.ts.map +1 -1
  331. package/src/shade/renderer/geometry/meshlet/GPUMeshletManager.js +15 -11
  332. package/src/shade/renderer/global_illumination/brick4/cpu/brick4_bake_for_scene.d.ts +1 -1
  333. package/src/shade/renderer/global_illumination/brick4/cpu/brick4_bake_for_scene.js +4 -4
  334. package/src/shade/renderer/global_illumination/brick4/cpu/brick4_generate_tree_from_scene.d.ts +1 -3
  335. package/src/shade/renderer/global_illumination/brick4/cpu/brick4_generate_tree_from_scene.d.ts.map +1 -1
  336. package/src/shade/renderer/global_illumination/brick4/cpu/brick4_generate_tree_from_scene.js +5 -4
  337. package/src/shade/renderer/global_illumination/brick4/gpu/bake/brick4_bake_basic.js +1 -1
  338. package/src/shade/renderer/global_illumination/lpv/bake/GPULightProbeVolumeRenderer.d.ts.map +1 -1
  339. package/src/shade/renderer/global_illumination/lpv/bake/GPULightProbeVolumeRenderer.js +1 -4
  340. package/src/shade/renderer/global_illumination/lpv/lpv_visualise_probes.d.ts +8 -3
  341. package/src/shade/renderer/global_illumination/lpv/lpv_visualise_probes.d.ts.map +1 -1
  342. package/src/shade/renderer/global_illumination/lpv/lpv_visualise_probes.js +19 -14
  343. package/src/shade/renderer/global_illumination/lpv/placement/graph_generate_probe_locations.d.ts.map +1 -1
  344. package/src/shade/renderer/global_illumination/lpv/placement/graph_generate_probe_locations.js +9 -1
  345. package/src/shade/renderer/global_illumination/lpv/placement/software/lpv_generate_probe_locations2.d.ts +3 -3
  346. package/src/shade/renderer/global_illumination/lpv/placement/software/lpv_generate_probe_locations2.d.ts.map +1 -1
  347. package/src/shade/renderer/global_illumination/lpv/placement/software/lpv_generate_probe_locations2.js +12 -5
  348. package/src/shade/renderer/global_illumination/probe/octahedral/GPUProbeAtlas.js +1 -1
  349. package/src/shade/renderer/light/GPULightCollection.d.ts +29 -0
  350. package/src/shade/renderer/light/GPULightCollection.d.ts.map +1 -1
  351. package/src/shade/renderer/light/GPULightCollection.js +444 -329
  352. package/src/shade/renderer/light/LIGHT_DATABASE_SPEC.d.ts.map +1 -1
  353. package/src/shade/renderer/light/LIGHT_DATABASE_SPEC.js +7 -1
  354. package/src/shade/renderer/light/LightCollection.d.ts +29 -1
  355. package/src/shade/renderer/light/LightCollection.d.ts.map +1 -1
  356. package/src/shade/renderer/light/LightCollection.js +50 -1
  357. package/src/shade/renderer/light/make_sunlight.js +2 -2
  358. package/src/shade/renderer/light/model/Light.d.ts +29 -2
  359. package/src/shade/renderer/light/model/Light.d.ts.map +1 -1
  360. package/src/shade/renderer/light/model/Light.js +30 -2
  361. package/src/shade/renderer/light/model/io/light_record_directional.d.ts +3 -1
  362. package/src/shade/renderer/light/model/io/light_record_directional.d.ts.map +1 -1
  363. package/src/shade/renderer/light/model/io/light_record_directional.js +8 -5
  364. package/src/shade/renderer/light/model/io/light_record_point.d.ts +3 -1
  365. package/src/shade/renderer/light/model/io/light_record_point.d.ts.map +1 -1
  366. package/src/shade/renderer/light/model/io/light_record_point.js +5 -2
  367. package/src/shade/renderer/light/model/io/light_record_spot.d.ts +4 -1
  368. package/src/shade/renderer/light/model/io/light_record_spot.d.ts.map +1 -1
  369. package/src/shade/renderer/light/model/io/light_record_spot.js +10 -6
  370. package/src/shade/renderer/light/place_light.d.ts +16 -0
  371. package/src/shade/renderer/light/place_light.d.ts.map +1 -0
  372. package/src/shade/renderer/light/place_light.js +36 -0
  373. package/src/shade/renderer/light/shader_refresh_light_poses.d.ts +44 -0
  374. package/src/shade/renderer/light/shader_refresh_light_poses.d.ts.map +1 -0
  375. package/src/shade/renderer/light/shader_refresh_light_poses.js +154 -0
  376. package/src/shade/renderer/lightmap/GPULightMap.js +1 -1
  377. package/src/shade/renderer/lightmap/bake/raster/graph_draw_lightmap_viz_buffer.d.ts.map +1 -1
  378. package/src/shade/renderer/lightmap/bake/raster/graph_draw_lightmap_viz_buffer.js +12 -14
  379. package/src/shade/renderer/loader/SceneBundle.d.ts +53 -28
  380. package/src/shade/renderer/loader/SceneBundle.d.ts.map +1 -1
  381. package/src/shade/renderer/loader/SceneBundle.js +111 -56
  382. package/src/shade/renderer/loader/SceneNode.d.ts +81 -0
  383. package/src/shade/renderer/loader/SceneNode.d.ts.map +1 -0
  384. package/src/shade/renderer/loader/SceneNode.js +114 -0
  385. package/src/shade/renderer/loader/gltf/load_gltf.d.ts +3 -2
  386. package/src/shade/renderer/loader/gltf/load_gltf.d.ts.map +1 -1
  387. package/src/shade/renderer/loader/gltf/load_gltf.js +110 -142
  388. package/src/shade/renderer/loader/gltf/tiny-gltf.d.ts +1 -1
  389. package/src/shade/renderer/loader/usd/UsdExtensionRegistry.d.ts +4 -4
  390. package/src/shade/renderer/loader/usd/UsdExtensionRegistry.d.ts.map +1 -1
  391. package/src/shade/renderer/loader/usd/UsdExtensionRegistry.js +2 -2
  392. package/src/shade/renderer/loader/usd/load_usd.d.ts +3 -2
  393. package/src/shade/renderer/loader/usd/load_usd.d.ts.map +1 -1
  394. package/src/shade/renderer/loader/usd/load_usd.js +4 -5
  395. package/src/shade/renderer/loader/usd/usd_build_scene.d.ts +3 -3
  396. package/src/shade/renderer/loader/usd/usd_build_scene.d.ts.map +1 -1
  397. package/src/shade/renderer/loader/usd/usd_build_scene.js +47 -55
  398. package/src/shade/renderer/material/GPUMaterialManager.js +1 -1
  399. package/src/shade/renderer/material/resident/GPUResidentMaterialContext.d.ts +5 -4
  400. package/src/shade/renderer/material/resident/GPUResidentMaterialContext.d.ts.map +1 -1
  401. package/src/shade/renderer/material/resident/GPUResidentMaterialContext.js +8 -15
  402. package/src/shade/renderer/object_property/shader_refresh_all_mesh_bounds.d.ts +15 -13
  403. package/src/shade/renderer/object_property/shader_refresh_all_mesh_bounds.d.ts.map +1 -1
  404. package/src/shade/renderer/object_property/shader_refresh_all_mesh_bounds.js +40 -21
  405. package/src/shade/renderer/particles/DESIGN.md +53 -50
  406. package/src/shade/renderer/particles/GPUParticleSystem.d.ts +31 -17
  407. package/src/shade/renderer/particles/GPUParticleSystem.d.ts.map +1 -1
  408. package/src/shade/renderer/particles/GPUParticleSystem.js +54 -91
  409. package/src/shade/renderer/particles/runtime/EmitterRegistry.d.ts +12 -11
  410. package/src/shade/renderer/particles/runtime/EmitterRegistry.d.ts.map +1 -1
  411. package/src/shade/renderer/particles/runtime/EmitterRegistry.js +12 -11
  412. package/src/shade/renderer/particles/runtime/GPUParticleEmitterContext.d.ts +13 -19
  413. package/src/shade/renderer/particles/runtime/GPUParticleEmitterContext.d.ts.map +1 -1
  414. package/src/shade/renderer/particles/runtime/GPUParticleEmitterContext.js +19 -25
  415. package/src/shade/renderer/particles/runtime/ParticleEmitter.d.ts +34 -24
  416. package/src/shade/renderer/particles/runtime/ParticleEmitter.d.ts.map +1 -1
  417. package/src/shade/renderer/particles/runtime/ParticleEmitter.js +53 -40
  418. package/src/shade/renderer/path_tracer/accumulating/AccumulatingPathTracer.js +1 -1
  419. package/src/shade/renderer/path_tracer/graph_path_trace_scene.js +1 -1
  420. package/src/shade/renderer/postprocess/nss/NSS.d.ts +1 -1
  421. package/src/shade/renderer/rasterize/expand/bucket/mesh/graph_meshes_classify_buckets.d.ts.map +1 -1
  422. package/src/shade/renderer/rasterize/expand/bucket/mesh/graph_meshes_classify_buckets.js +2 -1
  423. package/src/shade/renderer/rasterize/expand/bucket/mesh/graph_scene_meshes_cull_and_classify_buckets.d.ts.map +1 -1
  424. package/src/shade/renderer/rasterize/expand/bucket/mesh/graph_scene_meshes_cull_and_classify_buckets.js +5 -2
  425. package/src/shade/renderer/rasterize/fast/graph_rasterize_scene_fast.js +1 -1
  426. package/src/shade/renderer/rasterize/native/avboit/graph_rasterize_meshes_transparent_avboit.js +1 -1
  427. package/src/shade/renderer/rasterize/native/graph_rasterize_meshes_alpha_tested.js +1 -1
  428. package/src/shade/renderer/rasterize/native/oit/graph_rasterize_meshes_transparent_oit.js +1 -1
  429. package/src/shade/renderer/rasterize/standard/graph_rasterize_scene.js +1 -1
  430. package/src/shade/renderer/scene/DynamicMesh.d.ts +13 -4
  431. package/src/shade/renderer/scene/DynamicMesh.d.ts.map +1 -1
  432. package/src/shade/renderer/scene/DynamicMesh.js +14 -4
  433. package/src/shade/renderer/scene/GPUInstancesAccelerationStructure.d.ts +38 -18
  434. package/src/shade/renderer/scene/GPUInstancesAccelerationStructure.d.ts.map +1 -1
  435. package/src/shade/renderer/scene/GPUInstancesAccelerationStructure.js +112 -60
  436. package/src/shade/renderer/scene/GPUSceneContext.d.ts +55 -48
  437. package/src/shade/renderer/scene/GPUSceneContext.d.ts.map +1 -1
  438. package/src/shade/renderer/scene/GPUSceneContext.js +594 -928
  439. package/src/shade/renderer/scene/NODE3D_STRUCT.d.ts +5 -5
  440. package/src/shade/renderer/scene/NODE3D_STRUCT.js +5 -5
  441. package/src/shade/renderer/scene/Node3D.d.ts +27 -8
  442. package/src/shade/renderer/scene/Node3D.d.ts.map +1 -1
  443. package/src/shade/renderer/scene/Node3DDirtyList.d.ts +59 -0
  444. package/src/shade/renderer/scene/Node3DDirtyList.d.ts.map +1 -0
  445. package/src/shade/renderer/scene/Scene.d.ts +18 -60
  446. package/src/shade/renderer/scene/Scene.d.ts.map +1 -1
  447. package/src/shade/renderer/scene/Scene.js +53 -146
  448. package/src/shade/renderer/scene/SkinnedMesh.d.ts +10 -93
  449. package/src/shade/renderer/scene/SkinnedMesh.d.ts.map +1 -1
  450. package/src/shade/renderer/scene/bvh/StaticSceneBVH.d.ts +24 -3
  451. package/src/shade/renderer/scene/bvh/StaticSceneBVH.d.ts.map +1 -1
  452. package/src/shade/renderer/scene/bvh/StaticSceneBVH.js +53 -13
  453. package/src/shade/renderer/scene/hierarchy/graph_scene_update_transform_hierarchy.d.ts +5 -6
  454. package/src/shade/renderer/scene/hierarchy/graph_scene_update_transform_hierarchy.d.ts.map +1 -1
  455. package/src/shade/renderer/scene/hierarchy/graph_scene_update_transform_hierarchy.js +5 -6
  456. package/src/shade/renderer/scene/optimization/scene_optimize.d.ts +10 -2
  457. package/src/shade/renderer/scene/optimization/scene_optimize.d.ts.map +1 -1
  458. package/src/shade/renderer/scene/optimization/scene_optimize.js +266 -230
  459. package/src/shade/renderer/scene/rows/GPUEntityBoundsReadback.d.ts +53 -0
  460. package/src/shade/renderer/scene/rows/GPUEntityBoundsReadback.d.ts.map +1 -0
  461. package/src/shade/renderer/scene/rows/GPUEntityBoundsReadback.js +144 -0
  462. package/src/shade/renderer/scene/rows/GPUSceneRows.d.ts +227 -0
  463. package/src/shade/renderer/scene/rows/GPUSceneRows.d.ts.map +1 -0
  464. package/src/shade/renderer/scene/rows/GPUSceneRows.js +1136 -0
  465. package/src/shade/renderer/scene/rows/place_primitive.d.ts +48 -0
  466. package/src/shade/renderer/scene/rows/place_primitive.d.ts.map +1 -0
  467. package/src/shade/renderer/scene/rows/place_primitive.js +98 -0
  468. package/src/shade/renderer/scene/serialization/deserialize_scene.d.ts +10 -8
  469. package/src/shade/renderer/scene/serialization/deserialize_scene.d.ts.map +1 -1
  470. package/src/shade/renderer/scene/serialization/deserialize_scene.js +24 -27
  471. package/src/shade/renderer/scene/serialization/serialize_scene.d.ts +9 -2
  472. package/src/shade/renderer/scene/serialization/serialize_scene.d.ts.map +1 -1
  473. package/src/shade/renderer/scene/serialization/serialize_scene.js +25 -4
  474. package/src/shade/renderer/scene/verify_gpu_tlas_build.js +2 -2
  475. package/src/shade/renderer/shader/chunk/light/DIRECTIONAL_LIGHT_STRUCT.d.ts.map +1 -1
  476. package/src/shade/renderer/shader/chunk/light/DIRECTIONAL_LIGHT_STRUCT.js +5 -0
  477. package/src/shade/renderer/shader/chunk/light/POINT_LIGHT_STRUCT.d.ts.map +1 -1
  478. package/src/shade/renderer/shader/chunk/light/POINT_LIGHT_STRUCT.js +5 -0
  479. package/src/shade/renderer/shader/chunk/light/SPOT_LIGHT_STRUCT.d.ts.map +1 -1
  480. package/src/shade/renderer/shader/chunk/light/SPOT_LIGHT_STRUCT.js +5 -0
  481. package/src/shade/renderer/shadow/map/DirectionalLightShadowmap.d.ts +39 -0
  482. package/src/shade/renderer/shadow/map/DirectionalLightShadowmap.d.ts.map +1 -1
  483. package/src/shade/renderer/shadow/map/DirectionalLightShadowmap.js +112 -64
  484. package/src/shade/renderer/shadow/map/GPUSceneShadowmapContext.d.ts +7 -0
  485. package/src/shade/renderer/shadow/map/GPUSceneShadowmapContext.d.ts.map +1 -1
  486. package/src/shade/renderer/shadow/map/GPUSceneShadowmapContext.js +1541 -1352
  487. package/src/shade/renderer/shadow/map/PointLightShadowmap.js +1 -1
  488. package/src/shade/renderer/shadow/map/SpotLightShadowmap.js +1 -1
  489. package/src/shade/renderer/shadow/map/TetrahedronPointLightShadowmap.js +1 -1
  490. package/src/shade/renderer/shadow/map/csm/CSM_CASTER_RANGE_STRUCT.d.ts +29 -0
  491. package/src/shade/renderer/shadow/map/csm/CSM_CASTER_RANGE_STRUCT.d.ts.map +1 -0
  492. package/src/shade/renderer/shadow/map/csm/CSM_CASTER_RANGE_STRUCT.js +43 -0
  493. package/src/shade/renderer/shadow/map/csm/SHADOWMAP_CSM_CASTER_RANGE_MARGIN_FRACTION.d.ts +13 -0
  494. package/src/shade/renderer/shadow/map/csm/SHADOWMAP_CSM_CASTER_RANGE_MARGIN_FRACTION.d.ts.map +1 -0
  495. package/src/shade/renderer/shadow/map/csm/SHADOWMAP_CSM_CASTER_RANGE_MARGIN_FRACTION.js +12 -0
  496. package/src/shade/renderer/shadow/map/csm/shader/shader_csm_caster_range.d.ts +49 -0
  497. package/src/shade/renderer/shadow/map/csm/shader/shader_csm_caster_range.d.ts.map +1 -0
  498. package/src/shade/renderer/shadow/map/csm/shader/shader_csm_caster_range.js +194 -0
  499. package/src/shade/renderer/shadow/map/csm_debug_draw_preview.js +1 -1
  500. package/src/shade/renderer/shadow/map/shadowmap_update_score.js +1 -1
  501. package/src/shade/renderer/shadow/ray/RTXShadows.js +1 -1
  502. package/src/shade/renderer/shadow/ray/staged/trace/graph_trace_rays.js +1 -1
  503. package/src/shade/renderer/shadow/sdf/cascade/CascadedSceneSDF.d.ts.map +1 -1
  504. package/src/shade/renderer/shadow/sdf/cascade/CascadedSceneSDF.js +3 -1
  505. package/src/shade/renderer/texture/bindless/GPUBindlessTextureManager.js +8 -8
  506. package/src/shade/renderer/volumetrics/GPUViewVolumetrics.d.ts.map +1 -1
  507. package/src/shade/renderer/volumetrics/GPUViewVolumetrics.js +4 -3
  508. package/src/engine/graphics3/instantiate_scene_bundle.js +0 -164
  509. package/src/engine/graphics3/shade_node_to_entity_composition.js +0 -88
  510. package/src/shade/renderer/animation/compute_skin_world_bounds.js +0 -146
  511. package/src/shade/renderer/animation/compute_skinned_mesh_clip_bounding_sphere.js +0 -531
  512. package/src/shade/renderer/animation/pose/pose_evaluate_world.js +0 -76
  513. package/src/shade/renderer/animation/skin_bind_transform.js +0 -33
  514. package/src/shade/renderer/animation/skin_frame_defect.js +0 -132
  515. package/src/shade/renderer/animation/skin_joint_matrix.js +0 -46
  516. package/src/shade/renderer/animation/skin_normalize_mesh_frame.js +0 -216
  517. package/src/shade/renderer/scene/InstanceBatch.js +0 -235
  518. package/src/shade/renderer/scene/Mesh.js +0 -168
  519. package/src/shade/renderer/scene/Node3D.js +0 -263
  520. package/src/shade/renderer/scene/SceneNodeBinding.js +0 -56
  521. package/src/shade/renderer/scene/SkinnedMesh.js +0 -170
  522. package/src/shade/renderer/scene/TransformAuthority.js +0 -33
@@ -1,922 +1,936 @@
1
- import package_json from "../../../../package.json";
2
- import Quaternion from "../../../core/geom/Quaternion.js";
3
- import Vector3 from "../../../core/geom/Vector3.js";
4
- import { DEG_TO_RAD } from "../../../core/math/DEG_TO_RAD.js";
5
- import { MIE_PARTICLES_STANDARD_PRECOMPUTED } from "../../../core/math/physics/mie/MIE_PARTICLES_STANDARD_PRECOMPUTED.js";
6
- import { t64_set_rotation_axis_angle } from "../../../engine/ecs/transform/t64_set_rotation_axis_angle.js";
7
- import { GPUProfileLevel } from "../../device/timing/profile/GPUProfileLevel.js";
8
- import { GPUProfileSession } from "../../device/timing/profile/GPUProfileSession.js";
9
- import { OrbitalCameraController } from "../../renderer/camera/OrbitalCameraController.js";
10
- import { PerspectiveCamera } from "../../renderer/camera/PerspectiveCamera.js";
11
- import { create_frame_loop } from "../../renderer/create_frame_loop.js";
12
- import { make_sunlight } from "../../renderer/light/make_sunlight.js";
13
- import { load_gltf } from "../../renderer/loader/gltf/load_gltf.js";
14
- import { Renderer } from "../../renderer/Renderer.js";
15
- import { Scene } from "../../renderer/scene/Scene.js";
16
- import {
17
- ParticipatingMediaVolume,
18
- VolumetricsParticleSpec
19
- } from "../../renderer/volumetrics/ParticipatingMediaVolume.js";
20
- import { load_default_environment } from "../load_default_environment.js";
21
- import { make_playground_asset_manager } from "../make_playground_asset_manager.js";
22
-
23
- /**
24
- * The froxel volumetrics pass, with the controls that make its known defects visible.
25
- *
26
- * `shader_volumetrics_build_lighting` and the passes around it were reviewed statically and five
27
- * correctness findings came out of it (C-01 … C-05). Four are geometric, and geometry is the one
28
- * class of defect a unit test can prove but not show: an emulator can assert that a sample lands at
29
- * the wrong depth, and it still cannot tell you whether that reads as a smear, a seam, or nothing
30
- * at all. This page exists so each fix can be looked at before and after.
31
- *
32
- * Every control below is aimed at one finding. The panel says which.
33
- *
34
- * Runs under the dev server (`npm run dev`), which serves `test_assets/` and resolves the one bare
35
- * specifier the renderer reaches for. The panel is hand-rolled for the same reason the Sponza page
36
- * hand-rolls its own — a dozen inputs are not worth a dependency the library does not otherwise
37
- * have.
38
- *
39
- * @see src/shade/renderer/volumetrics/NOTES.md
40
- */
41
-
42
- /**
43
- * Served out of `test_assets/`, which is gitignored and unpublished — `test_assets/README.md` has
44
- * how it gets there.
45
- *
46
- * glTF rather than the `.shade` scene sitting next to it: that export's header reads format
47
- * version 1 and `deserialize_scene` accepts version 2 only, deliberately and with no backward
48
- * compatibility. Re-exporting it is the fix if the `.shade` is ever wanted.
49
- *
50
- * @type {string}
51
- */
52
- const SCENE_URL = '/test_assets/flying_world_-_battle_of_the_trash_god/v2/scene.gltf';
53
-
54
- /**
55
- * A low sun, which is what the volumetrics want: it rakes the scene, so the shafts have something
56
- * to be cast by, and it sits near the horizon where the sun can be swung in and out of the frustum
57
- * without also swinging it behind the terrain.
58
- *
59
- * @type {string}
60
- */
61
- const ENVIRONMENT_URL = '/test_assets/environments/octahedral/venice_sunset_2k.hdr';
62
-
63
- /**
64
- * Camera placements carried over from the sibling repo's playground, where they were found by
65
- * hand while looking at this exact scene. Keeping the numbers rather than re-deriving them means a
66
- * before/after pair is taken from the same place to the pixel.
67
- *
68
- * The `c` field names the finding each one is good for; the panel groups by it.
69
- */
70
- const VIEWS = [
71
- {
72
- id: 'overview',
73
- label: 'Dead overview',
74
- c: 'orientation',
75
- hint: 'the whole island — start here',
76
- position: { x: -44.23572420730413, y: 16.787419516572818, z: -0.3908097424888902 },
77
- rotation: { x: -0.10289617976426199, y: 0.8965686124184902, z: -0.32052909150868936, w: -0.2878162624184363 }
78
- },
79
- {
80
- id: 'vol_0',
81
- label: 'Fog bank, wide',
82
- c: 'C-01',
83
- hint: 'fog fills the frame corners, where the depth error is largest',
84
- position: { x: -39.165083083628595, y: 9.002002938463146, z: -12.822321096883556 },
85
- rotation: { x: 0.0461501744849993, y: 0.9414711984407541, z: -0.14428237367052793, w: 0.3011390717750397 }
86
- },
87
- {
88
- id: 'vol_1',
89
- label: 'Inside the fog',
90
- c: 'C-01',
91
- hint: 'camera inside the medium — radial thinning shows against a flat wall of fog',
92
- position: { x: -57.19543561067503, y: 4.497368033549733, z: -5.431935542965578 },
93
- rotation: {
94
- x: 0.0012158994167123557,
95
- y: 0.9584376528911036,
96
- z: -0.0040851224490818586,
97
- w: 0.28527022081489145
98
- }
99
- },
100
- {
101
- id: 'broadside',
102
- label: 'Island broadside',
103
- c: 'C-03',
104
- hint: 'the island against open sky — the clearest place to swing the sun in and out of frame',
105
- position: { x: -30, y: 11, z: -5 },
106
- rotation: {
107
- x: 0.08308534470573395,
108
- y: -0.7022085341941733,
109
- z: 0.08308534470573395,
110
- w: 0.7022085341941732
111
- }
112
- },
113
- {
114
- id: 'above',
115
- label: 'Island from above',
116
- c: 'C-03',
117
- hint: 'all six volumes at once, with sky behind them',
118
- position: { x: -18, y: 26, z: 26 },
119
- rotation: {
120
- x: -0.09605984305376475,
121
- y: 0.8751796663464206,
122
- z: -0.19438519850844194,
123
- w: -0.43248982966896177
124
- }
125
- },
126
- {
127
- id: 'cloud_deck',
128
- label: 'Inside the cloud deck',
129
- c: 'C-01',
130
- hint: 'uniform medium filling the frame — radial thinning reads as a vignette here',
131
- position: { x: -57, y: -10, z: 20 },
132
- rotation: { x: 0, y: 0.9999652844073138, z: 0.008332465433472727, w: 0 }
133
- },
134
- {
135
- id: 'aliasing_0',
136
- label: 'Volume edge',
137
- c: 'C-02',
138
- hint: 'a fog volume boundary against geometry — a half-froxel shift moves this edge',
139
- position: { x: -44.358600521646366, y: 8.13976892720825, z: 2.6707745658793725 },
140
- rotation: { x: -0.07197787209539422, y: 0.9277035010259875, z: -0.24609398688026018, w: -0.2713358614966388 }
141
- },
142
- {
143
- id: 'aliasing_1',
144
- label: 'Volume edge, above',
145
- c: 'C-02',
146
- hint: 'the same boundary from above, where the slab stack is edge-on',
147
- position: { x: -36.56903863396318, y: 19.1017887067011, z: 13.881382214134083 },
148
- rotation: { x: -0.0961072760435774, y: 0.9036695806244697, z: -0.3054532939528032, w: -0.28432897453277794 }
149
- },
150
- {
151
- id: 'fog_box_0',
152
- label: 'Beside the fog box',
153
- c: 'Q-04',
154
- hint: 'the sun crosses three units of medium here — where sixteen march steps read +58',
155
- position: { x: -49.64917207609583, y: 3.9195318273572317, z: -4.211048766762115 },
156
- rotation: {
157
- x: -0.037898077937503966,
158
- y: 0.6176094542736352,
159
- z: 0.029816629610983452,
160
- w: 0.7850052651282708
161
- }
162
- },
163
- {
164
- id: 'fog_box_1',
165
- label: 'Beside the fog box, deeper',
166
- c: 'Q-04',
167
- hint: 'the same medium a little further in; +70 for the march, and where the volume strobed',
168
- position: { x: -50.28590468756837, y: 4.239170044321892, z: -3.9966900541348767 },
169
- rotation: {
170
- x: -0.03789807793750395,
171
- y: 0.6176094542736352,
172
- z: 0.02981662961098345,
173
- w: 0.7850052651282708
174
- }
175
- },
176
- {
177
- id: 'inside_out',
178
- label: 'Under the island',
179
- c: 'C-05',
180
- hint: 'thin haze over a dark ground — per-froxel noise is most legible here',
181
- position: { x: -61.55864473831582, y: 23.7158848700074, z: -19.634434309820563 },
182
- rotation: { x: 0.27745576215003553, y: 0.0922110339369582, z: -0.026764015593898134, w: 0.9559284035634205 }
183
- },
184
- ];
185
-
186
- /**
187
- * The participating media, carried over from the sibling repo's setup for this scene. Positions are
188
- * tuned to the model, so they move with it and not with anything here.
189
- *
190
- * `target_extinction` rather than `density`: it normalizes across particle specs, so swapping a
191
- * preset changes how the medium *looks* without changing how much light it stops.
192
- *
193
- * @param {Scene} scene
194
- */
195
- function add_participating_media(scene) {
196
-
197
- /**
198
- * @param {object} spec
199
- * @param {number[]} spec.position
200
- * @param {number[]} spec.scale
201
- * @param {object} spec.particle from MIE_PARTICLES_STANDARD_PRECOMPUTED
202
- * @param {number} spec.extinction
203
- * @param {number} spec.fade
204
- * @param {number} [spec.yaw_degrees]
205
- */
206
- function volume({ position, scale, particle, extinction, fade, yaw_degrees = 0 }) {
207
- const v = new ParticipatingMediaVolume();
208
-
209
- v.transform.setTranslation(...position);
210
- v.transform.setScale(...scale);
211
-
212
- if (yaw_degrees !== 0) {
213
- t64_set_rotation_axis_angle(v.transform, 0, 1, 0, yaw_degrees * DEG_TO_RAD);
214
- }
215
-
216
- // the GPU is handed `transform.matrix`, and a Transform64 does not maintain one - the
217
- // scale and the yaw above are components and nothing more until this call folds them in
218
- v.transform.updateMatrix();
219
-
220
- v.fade_distance = fade;
221
- v.particle_spec = VolumetricsParticleSpec.fromMeep(particle);
222
- v.target_extinction = extinction;
223
-
224
- scene.volumetrics.add(v);
225
-
226
- return v;
227
- }
228
-
229
- const P = MIE_PARTICLES_STANDARD_PRECOMPUTED;
230
-
231
- // the dense bank along the western edge — the thickest medium in the scene, and the one that
232
- // fills the frame corners from the `vol_0` view
233
- volume({
234
- position: [-55, 4, -5.116],
235
- scale: [10, 3, 20],
236
- yaw_degrees: 83,
237
- particle: P.CLOUD_DROPLET_LARGE,
238
- extinction: 1,
239
- fade: 0.5,
240
- });
241
-
242
- // graveyard
243
- volume({
244
- position: [-51.98019820725889, 7.899311905935347, -15.3228393616169],
245
- scale: [7, 5, 7],
246
- particle: P.FOG_DROPLET_SMALL,
247
- extinction: 0.4,
248
- fade: 1,
249
- });
250
-
251
- // mine
252
- volume({
253
- position: [-50.846390607312934, 0.3159949821015605, 17.89429433940319],
254
- scale: [10, 7, 10],
255
- particle: P.COARSE_DUST_MEDIUM,
256
- extinction: 0.4,
257
- fade: 4,
258
- });
259
-
260
- // large crystal
261
- volume({
262
- position: [-53.41918585295826, 17.333878151116526, 29.90844167706601],
263
- scale: [18, 10, 18],
264
- particle: P.MARITIME_HAZE_MEDIUM,
265
- extinction: 0.1,
266
- fade: 4,
267
- });
268
-
269
- // the low cloud deck the island sits above — big and thin, so it is what a wide FOV sees at the
270
- // frame edges
271
- volume({
272
- position: [-57.36387203979457, -15, 2.607232848593789],
273
- scale: [400, 20, 400],
274
- particle: P.CLOUD_DROPLET_LARGE,
275
- extinction: 0.1,
276
- fade: 4,
277
- });
278
-
279
- // ball cloud overhead
280
- volume({
281
- position: [-51.137423384559284, 33, 5.593067265589105],
282
- scale: [15, 15, 15],
283
- particle: P.CLOUD_DROPLET_LARGE,
284
- extinction: 1,
285
- fade: 7,
286
- });
287
- }
288
-
289
- /**
290
- * A rolling mean frame time, so the readout is legible rather than jittering.
291
- */
292
- class FrameTimer {
293
- #samples = new Float64Array(60);
294
- #count = 0;
295
- #cursor = 0;
296
-
297
- add(seconds) {
298
- this.#samples[this.#cursor] = seconds * 1000;
299
- this.#cursor = (this.#cursor + 1) % this.#samples.length;
300
- this.#count = Math.min(this.#count + 1, this.#samples.length);
301
- }
302
-
303
- reset() {
304
- this.#count = 0;
305
- this.#cursor = 0;
306
- }
307
-
308
- get mean_ms() {
309
- if (this.#count === 0) {
310
- return 0;
311
- }
312
-
313
- let total = 0;
314
- for (let i = 0; i < this.#count; i++) {
315
- total += this.#samples[i];
316
- }
317
- return total / this.#count;
318
- }
319
- }
320
-
321
- /**
322
- * Point a directional light along a heading, in place.
323
- *
324
- * The sun's azimuth is the control C-03 turns on: the shadow ray is clipped against a frustum whose
325
- * far plane is degenerate, so a sun direction that lies inside the view cone never exits it. Swing
326
- * the sun through the frame and the media self-shadowing should be steady; if it switches on as the
327
- * sun leaves the frustum, that is the finding.
328
- *
329
- * @param {DirectionalLight} light
330
- * @param {number} azimuth_degrees 0 points along +X
331
- * @param {number} elevation_degrees above the horizon
332
- */
333
- function aim_light(light, azimuth_degrees, elevation_degrees) {
334
- const azimuth = azimuth_degrees * DEG_TO_RAD;
335
- const elevation = elevation_degrees * DEG_TO_RAD;
336
-
337
- const horizontal = Math.cos(elevation);
338
-
339
- // direction the light travels — downward for a sun above the horizon
340
- const direction = new Vector3(
341
- Math.cos(azimuth) * horizontal,
342
- -Math.sin(elevation),
343
- Math.sin(azimuth) * horizontal
344
- ).normalize();
345
-
346
- const q = new Quaternion();
347
- q.fromUnitVectors(Vector3.forward, direction);
348
- q.normalize();
349
-
350
- light.transform_local.setRotation(q.x, q.y, q.z, q.w);
351
- light.updateMatrices();
352
- }
353
-
354
- /**
355
- * How much each profile capture records. `WORKLOAD` is the highest of the three levels the proposal
356
- * calls shippable: pass spans, the frame graph, and dispatch/draw counts.
357
- *
358
- * Measured on this page it runs ~11 KB a frame over ~393 spans, so ~660 KB/s at 60 Hz — the
359
- * proposal's estimate of 6 KB assumed ~200 passes and this graph is about twice that. Still small
360
- * enough that a hand-driven recording will not notice. `VERBOSE` above it adds bind group contents
361
- * at roughly seven times the rate and wants a frame limit set, not a key you can lean on.
362
- *
363
- * @type {number}
364
- */
365
- const PROFILE_LEVEL = GPUProfileLevel.WORKLOAD;
366
-
367
- /**
368
- * Hand an ArrayBuffer to the browser as a file.
369
- *
370
- * @param {ArrayBuffer} bytes
371
- * @param {string} filename
372
- */
373
- function download_bytes(bytes, filename) {
374
- const url = URL.createObjectURL(new Blob([bytes], { type: 'application/octet-stream' }));
375
-
376
- const anchor = document.createElement('a');
377
-
378
- anchor.href = url;
379
- anchor.download = filename;
380
-
381
- document.body.appendChild(anchor);
382
- anchor.click();
383
- anchor.remove();
384
-
385
- // Revoking in the same task cancels the download in some browsers — the click only schedules it.
386
- setTimeout(() => URL.revokeObjectURL(url), 60000);
387
- }
388
-
389
- /**
390
- * `YYYYMMDD-HHMMSS` in local time, matching the naming the other `.sgpt` captures on this machine
391
- * already use — same sort order, and it reads as the clock you took it by rather than as UTC.
392
- *
393
- * @returns {string}
394
- */
395
- function file_timestamp() {
396
- const now = new Date();
397
-
398
- const pad = value => String(value).padStart(2, '0');
399
-
400
- return `${now.getFullYear()}${pad(now.getMonth() + 1)}${pad(now.getDate())}`
401
- + `-${pad(now.getHours())}${pad(now.getMinutes())}${pad(now.getSeconds())}`;
402
- }
403
-
404
- /**
405
- * @param {number} bytes
406
- * @returns {string}
407
- */
408
- function format_bytes(bytes) {
409
- if (bytes < 1024) {
410
- return `${bytes} B`;
411
- }
412
-
413
- if (bytes < 1024 * 1024) {
414
- return `${(bytes / 1024).toFixed(1)} KiB`;
415
- }
416
-
417
- return `${(bytes / (1024 * 1024)).toFixed(1)} MiB`;
418
- }
419
-
420
- export async function start() {
421
-
422
- const element = id => document.getElementById(id);
423
-
424
- const status_element = element('status');
425
- const stats_element = element('stats');
426
-
427
- function set_status(text, kind = '') {
428
- status_element.textContent = text;
429
- status_element.className = kind;
430
- }
431
-
432
- const canvas = element('view');
433
-
434
- const context = canvas.getContext('webgpu');
435
-
436
- if (context === null) {
437
- set_status('no WebGPU context — this browser has none, or the page is not a secure context', 'fail');
438
- return;
439
- }
440
-
441
- const renderer = new Renderer();
442
-
443
- set_status('acquiring a device…');
444
-
445
- await renderer.initialize({ context });
446
-
447
- const camera = new PerspectiveCamera();
448
-
449
- camera.near = 0.1;
450
- camera.far = 120;
451
- camera.fov = 60 * DEG_TO_RAD;
452
- // aspect is set by the frame loop, which is the first place the viewport has a size
453
-
454
- const scene = new Scene();
455
-
456
- const controller = new OrbitalCameraController(camera, document.body);
457
-
458
- // handy from the console
459
- globalThis.renderer = renderer;
460
- globalThis.scene = scene;
461
- globalThis.camera = camera;
462
- globalThis.controller = controller;
463
-
464
- // ---- scene ----------------------------------------------------------------------------
465
-
466
- set_status(`loading ${SCENE_URL} …`);
467
-
468
- try {
469
- const bundle = await load_gltf(SCENE_URL, { assetManager: await make_playground_asset_manager() });
470
-
471
- scene.add(bundle.scenes);
472
- } catch (error) {
473
- set_status(
474
- `could not load the scene (${error.message}). Put the assets under test_assets/ — `
475
- + `see test_assets/README.md.`,
476
- 'fail'
477
- );
478
- console.error(error);
479
- return;
480
- }
481
-
482
- const sun = make_sunlight({ intensity: 0.6, temperature: 5500 });
483
-
484
- scene.lights.add(sun);
485
-
486
- add_participating_media(scene);
487
-
488
- load_default_environment(scene, ENVIRONMENT_URL).then(applied => {
489
- if (applied) {
490
- renderer.indicate_view_change();
491
- }
492
- });
493
-
494
- // ---- controls -------------------------------------------------------------------------
495
-
496
- const frame_timer = new FrameTimer();
497
-
498
- let paused = false;
499
-
500
- /** Re-render and drop the frame-time history, since a setting change invalidates it. */
501
- function repaint() {
502
- renderer.indicate_view_change();
503
- frame_timer.reset();
504
- }
505
-
506
- // -- views
507
-
508
- const views_element = element('views');
509
-
510
- /**
511
- * Which placement the camera was last sent to, for the profile capture's note — a capture that
512
- * cannot say where it was taken is much less use a week later.
513
- * @type {object|null}
514
- */
515
- let current_view = null;
516
-
517
- /** @param {object} view */
518
- function go_to(view) {
519
- current_view = view;
520
-
521
- camera.transform.fromJSON({ translation: view.position, rotation: view.rotation });
522
-
523
- // the controller holds its own spherical state and would otherwise snap the camera back on
524
- // the next update
525
- controller.from_transform(camera.transform);
526
-
527
- repaint();
528
- }
529
-
530
- for (const view of VIEWS) {
531
- const button = document.createElement('button');
532
-
533
- button.className = 'view';
534
- button.title = view.hint;
535
- button.innerHTML = `<span class="tag">${view.c}</span>${view.label}`;
536
- button.addEventListener('click', () => {
537
- go_to(view);
538
- set_status(view.hint);
539
- });
540
-
541
- views_element.appendChild(button);
542
- }
543
-
544
- // -- sun
545
-
546
- let sun_azimuth = 200;
547
- let sun_elevation = 12;
548
-
549
- function update_sun() {
550
- aim_light(sun, sun_azimuth, sun_elevation);
551
-
552
- element('sun_azimuth_value').textContent = `${sun_azimuth}°`;
553
- element('sun_elevation_value').textContent = `${sun_elevation}°`;
554
-
555
- repaint();
556
- }
557
-
558
- element('sun_azimuth').addEventListener('input', event => {
559
- sun_azimuth = Number(event.target.value);
560
- update_sun();
561
- });
562
-
563
- element('sun_elevation').addEventListener('input', event => {
564
- sun_elevation = Number(event.target.value);
565
- update_sun();
566
- });
567
-
568
- /**
569
- * Put the sun directly in front of the camera, or directly behind it, at the current elevation.
570
- *
571
- * This is the C-03 A/B reduced to two clicks. "Into view" places the sun's direction inside the
572
- * frustum's direction cone, which is the condition under which `frustum_clip_ray` returns its
573
- * 1e20 sentinel.
574
- *
575
- * @param {boolean} in_front
576
- */
577
- function aim_sun_relative_to_camera(in_front) {
578
- // Straight off the view matrix rather than by rotating a basis vector through the camera's
579
- // quaternion by hand: the third row of a view matrix is the camera's backward axis, so this
580
- // is the renderer's own answer and cannot disagree with what is on screen. The hand-rolled
581
- // version this replaces had a sign error that put the sun behind the camera on both
582
- // branches, which is invisible in a screenshot and made the C-03 A/B read as a null result.
583
- // The matrices are rebuilt during render, so a placement made this tick is not in them yet
584
- // — reading straight after `go_to` would aim the sun at wherever the camera used to be.
585
- camera.update();
586
-
587
- const vm = camera.view_matrix;
588
-
589
- const forward_x = -vm[2];
590
- const forward_z = -vm[10];
591
-
592
- // `aim_light` takes the direction light *travels*, so the sun sits opposite it. Placing the
593
- // sun on the camera's forward axis therefore means aiming its travel back along that axis.
594
- const toward_sun_x = in_front ? forward_x : -forward_x;
595
- const toward_sun_z = in_front ? forward_z : -forward_z;
596
-
597
- const azimuth = Math.atan2(-toward_sun_z, -toward_sun_x) / DEG_TO_RAD;
598
-
599
- sun_azimuth = Math.round((azimuth % 360 + 360) % 360);
600
-
601
- element('sun_azimuth').value = String(sun_azimuth);
602
-
603
- update_sun();
604
- }
605
-
606
- element('sun_into_view').addEventListener('click', () => {
607
- aim_sun_relative_to_camera(true);
608
- set_status('sun placed in front of the camera — C-03 predicts media self-shadowing vanishes here', 'warn');
609
- });
610
-
611
- element('sun_behind').addEventListener('click', () => {
612
- aim_sun_relative_to_camera(false);
613
- set_status('sun placed behind the camera — C-03 predicts media self-shadowing returns here', 'pass');
614
- });
615
-
616
- // -- camera
617
-
618
- element('fov').addEventListener('input', event => {
619
- const degrees = Number(event.target.value);
620
-
621
- camera.fov = degrees * DEG_TO_RAD;
622
-
623
- element('fov_value').textContent = `${degrees}°`;
624
-
625
- repaint();
626
- });
627
-
628
- // -- volumetrics knobs, read by GPUViewVolumetrics on every metadata update
629
-
630
- element('vol_taa').addEventListener('change', event => {
631
- globalThis.__VOL_TAA_ENABLED = event.target.checked;
632
- repaint();
633
- });
634
-
635
- element('taa').addEventListener('change', event => {
636
- renderer.feature_taa_enabled = event.target.checked;
637
- repaint();
638
- });
639
-
640
- // Off by default on this page. Auto exposure keeps adapting for seconds after anything changes,
641
- // which makes a before/after pair differ by more than most of the fixes being judged here do —
642
- // it read as a large effect with the wrong sign more than once while this page was being built.
643
- renderer.feature_automatic_exposure_enabled = false;
644
-
645
- element('auto_exposure').addEventListener('change', event => {
646
- renderer.feature_automatic_exposure_enabled = event.target.checked;
647
- repaint();
648
- });
649
-
650
- element('froxel_far').addEventListener('input', event => {
651
- const value = Number(event.target.value);
652
-
653
- // the slider's top notch means "no split", which is the engine default
654
- globalThis.__VOL_FROXEL_FAR = value >= 120 ? Infinity : value;
655
-
656
- element('froxel_far_value').textContent = value >= 120 ? 'off' : `${value} m`;
657
-
658
- repaint();
659
- });
660
-
661
- element('ms_octaves').addEventListener('input', event => {
662
- const value = Number(event.target.value);
663
-
664
- globalThis.__VOL_MS_OCTAVES = value;
665
-
666
- element('ms_octaves_value').textContent = String(value);
667
-
668
- repaint();
669
- });
670
-
671
- // -- profiling: T starts a recording, T again stops it and downloads the capture
672
-
673
- const profile_status = element('profile_status');
674
-
675
- /**
676
- * The recording in progress, or null.
677
- *
678
- * The engine never constructs one of these — `Renderer.profile_session` is a nullable field and
679
- * the null checks around it are the entire integration, which is what keeps the profiler out of
680
- * a bundle that does not ask for it. The two imports at the top of this file are the whole
681
- * opt-in.
682
- *
683
- * @type {GPUProfileSession|null}
684
- */
685
- let profile_session = null;
686
-
687
- /** Guards against T being leaned on while a stop is still draining. */
688
- let profile_busy = false;
689
-
690
- function set_profile_status(text, recording = false) {
691
- profile_status.textContent = text;
692
- profile_status.className = recording ? 'recording' : '';
693
- }
694
-
695
- function start_profile() {
696
- const device = renderer.device;
697
-
698
- const settings = [
699
- current_view === null ? 'free camera' : current_view.label,
700
- `fov ${Math.round(camera.fov / DEG_TO_RAD)}°`,
701
- `volumetric TAA ${(globalThis.__VOL_TAA_ENABLED ?? true) ? 'on' : 'off'}`,
702
- `${renderer.pixel_ratio.toFixed(2)}x`,
703
- ];
704
-
705
- const session = new GPUProfileSession({
706
- level: PROFILE_LEVEL,
707
- note: `volumetrics_froxel — ${settings.join(' · ')}`,
708
- });
709
-
710
- // Populate before start(): the meta record is written into the stream there and not read
711
- // again. Without it the capture is unreadable in the sense that matters — a pass taking
712
- // 0.4 ms says nothing until you know which GPU and at what resolution.
713
- const meta = session.meta;
714
-
715
- // `GPUDevice.adapterInfo` is recent enough that a browser running this page may not have it,
716
- // and several browsers withhold the fields even when they do. Empty is what the format
717
- // expects in that case.
718
- const info = device.adapterInfo;
719
-
720
- if (info !== undefined && info !== null) {
721
- meta.adapter_vendor = info.vendor ?? "";
722
- meta.adapter_architecture = info.architecture ?? "";
723
- meta.adapter_device = info.device ?? "";
724
- meta.adapter_description = info.description ?? "";
725
- }
726
-
727
- meta.features = [...device.features];
728
- meta.engine_version = package_json.version;
729
-
730
- session.onBytesWritten.add(bytes => {
731
- set_profile_status(
732
- `● recording — ${session.frames_recorded} frames, ${format_bytes(bytes)} · T to stop`,
733
- true
734
- );
735
- });
736
-
737
- renderer.profile_session = session;
738
- session.start();
739
-
740
- profile_session = session;
741
-
742
- // The timers go quiet without this rather than failing, so the capture still carries the
743
- // frame graph and the workload — it just has no durations in it. Worth knowing before you
744
- // record for a minute and then look.
745
- const timed = device.features.has('timestamp-query');
746
-
747
- set_profile_status(
748
- timed
749
- ? '● recording — 0 frames · T to stop'
750
- : '● recording without timestamp-query — structure only, no durations · T to stop',
751
- true
752
- );
753
- }
754
-
755
- /**
756
- * Wait for frames already submitted to finish landing in the session.
757
- *
758
- * A frame is committed when its timestamp readback resolves — a `mapAsync` a frame or two behind
759
- * submit, see `ShadeGPUCommandContext.profiling_absorbed` — and `record_frame` silently ignores
760
- * anything arriving after `stop()`. Stopping the instant the key goes down therefore discards
761
- * the last few frames, which are the ones you were most likely looking at.
762
- *
763
- * Drains the queue, then waits for the frame count to stop moving. Capped, because a recording
764
- * taken while the page is paused never moves at all.
765
- *
766
- * @param {GPUProfileSession} session
767
- */
768
- async function drain_profile(session) {
769
- const DEADLINE_MS = 1000;
770
- const QUIET_MS = 60;
771
-
772
- await renderer.device.queue.onSubmittedWorkDone();
773
-
774
- const deadline = performance.now() + DEADLINE_MS;
775
-
776
- let previous = session.frames_recorded;
777
-
778
- while (performance.now() < deadline) {
779
- await new Promise(resolve => setTimeout(resolve, QUIET_MS));
780
-
781
- if (session.frames_recorded === previous) {
782
- return;
783
- }
784
-
785
- previous = session.frames_recorded;
786
- }
787
- }
788
-
789
- async function stop_profile() {
790
- const session = profile_session;
791
-
792
- profile_session = null;
793
-
794
- // Detach first, so nothing encoded during the drain below joins the recording. Frames
795
- // already encoded are unaffected: Renderer captures the session into a local before it
796
- // subscribes to the readback.
797
- renderer.profile_session = null;
798
-
799
- set_profile_status('stopping — draining in-flight frames…');
800
-
801
- await drain_profile(session);
802
-
803
- const bytes = session.stop();
804
-
805
- const filename = `volumetrics_froxel-${file_timestamp()}.sgpt`;
806
-
807
- download_bytes(bytes, filename);
808
-
809
- // Also to the console, because the status line is the only other place the name appears and
810
- // a browser that declines the save says nothing about which capture it declined.
811
- console.log(
812
- `profile: ${session.frames_recorded} frames, ${format_bytes(bytes.byteLength)}, `
813
- + `${session.topology_count} topolog${session.topology_count === 1 ? 'y' : 'ies'} -> ${filename}`
814
- );
815
-
816
- set_profile_status(
817
- `${session.frames_recorded} frames, ${format_bytes(bytes.byteLength)}`
818
- + `, ${session.topology_count} topolog${session.topology_count === 1 ? 'y' : 'ies'}`
819
- + ` · ${filename}`
820
- );
821
- }
822
-
823
- window.addEventListener('keydown', event => {
824
- if (event.ctrlKey || event.metaKey || event.altKey || event.repeat) {
825
- return;
826
- }
827
-
828
- // `key` first, because it is the letter actually printed on the key the user pressed —
829
- // `code` is physical position, so on AZERTY it names the key where T sits on QWERTY. `code`
830
- // is the fallback for layouts whose `key` is not Latin at all (Cyrillic gives "е" here).
831
- if (event.key.toLowerCase() !== 't' && event.code !== 'KeyT') {
832
- return;
833
- }
834
-
835
- // the panel's sliders and buttons are focusable; do not steal a key from a field
836
- const target = event.target;
837
-
838
- if (target instanceof HTMLInputElement || target instanceof HTMLTextAreaElement || target instanceof HTMLSelectElement) {
839
- return;
840
- }
841
-
842
- if (profile_busy) {
843
- return;
844
- }
845
-
846
- event.preventDefault();
847
-
848
- profile_busy = true;
849
-
850
- const done = profile_session === null
851
- ? Promise.resolve(start_profile())
852
- : stop_profile();
853
-
854
- done.catch(error => {
855
- set_profile_status(`profiling failed: ${error?.message ?? error}`);
856
- console.error(error);
857
-
858
- profile_session = null;
859
- renderer.profile_session = null;
860
- }).finally(() => {
861
- profile_busy = false;
862
- });
863
- });
864
-
865
- element('pause').addEventListener('click', () => {
866
- paused = !paused;
867
- element('pause').textContent = paused ? 'Resume' : 'Pause';
868
- });
869
-
870
- element('log_camera').addEventListener('click', () => {
871
- const t = camera.transform;
872
-
873
- const json = {
874
- position: { x: t.translation_x, y: t.translation_y, z: t.translation_z },
875
- rotation: { x: t.rotation_x, y: t.rotation_y, z: t.rotation_z, w: t.rotation_w }
876
- };
877
-
878
- console.log(JSON.stringify(json, null, 4));
879
- set_status('camera written to the console', 'pass');
880
- });
881
-
882
- // ---- start ----------------------------------------------------------------------------
883
-
884
- update_sun();
885
- go_to(VIEWS[0]);
886
-
887
- controller.movement_speed_scale = 4;
888
-
889
- // the controller's keyboard device listens on body, and only a focused element gets key events
890
- document.body.focus();
891
-
892
- set_status(`loaded — ${scene.instances.instances.length} instances, ${scene.volumetrics.volumes.length} media volumes`, 'pass');
893
-
894
- // ---- frame loop -----------------------------------------------------------------------
895
-
896
- const FRAME_RATE_LIMIT = 60;
897
-
898
- create_frame_loop(time_delta_s => {
899
- const width = window.innerWidth;
900
- const height = window.innerHeight;
901
-
902
- renderer.resize(width, height);
903
- renderer.pixel_ratio = window.devicePixelRatio;
904
- camera.aspect = width / height;
905
-
906
- controller.update();
907
-
908
- if (paused) {
909
- return;
910
- }
911
-
912
- renderer.render(camera, scene, time_delta_s);
913
-
914
- frame_timer.add(time_delta_s);
915
-
916
- const mean = frame_timer.mean_ms;
917
-
918
- stats_element.textContent =
919
- `${mean.toFixed(1)} ms · ${mean > 0 ? (1000 / mean).toFixed(0) : '0'} fps`
920
- + ` · fov ${Math.round(camera.fov / DEG_TO_RAD)}°`;
921
- }, FRAME_RATE_LIMIT);
922
- }
1
+ import package_json from "../../../../package.json";
2
+ import Quaternion from "../../../core/geom/Quaternion.js";
3
+ import Vector3 from "../../../core/geom/Vector3.js";
4
+ import { DEG_TO_RAD } from "../../../core/math/DEG_TO_RAD.js";
5
+ import { MIE_PARTICLES_STANDARD_PRECOMPUTED } from "../../../core/math/physics/mie/MIE_PARTICLES_STANDARD_PRECOMPUTED.js";
6
+ import { t64_set_rotation_axis_angle } from "../../../engine/ecs/transform/t64_set_rotation_axis_angle.js";
7
+ import { GPUProfileLevel } from "../../device/timing/profile/GPUProfileLevel.js";
8
+ import { GPUProfileSession } from "../../device/timing/profile/GPUProfileSession.js";
9
+ import { OrbitalCameraController } from "../../renderer/camera/OrbitalCameraController.js";
10
+ import { PerspectiveCamera } from "../../renderer/camera/PerspectiveCamera.js";
11
+ import { create_frame_loop } from "../../renderer/create_frame_loop.js";
12
+ import { make_sunlight } from "../../renderer/light/make_sunlight.js";
13
+ import { place_light } from "../../renderer/light/place_light.js";
14
+ import { EntityComponentDataset } from "../../../engine/ecs/EntityComponentDataset.js";
15
+ import { load_gltf } from "../../renderer/loader/gltf/load_gltf.js";
16
+ import { Renderer } from "../../renderer/Renderer.js";
17
+ import { Scene } from "../../renderer/scene/Scene.js";
18
+ import {
19
+ ParticipatingMediaVolume,
20
+ VolumetricsParticleSpec
21
+ } from "../../renderer/volumetrics/ParticipatingMediaVolume.js";
22
+ import { load_default_environment } from "../load_default_environment.js";
23
+ import { make_playground_asset_manager } from "../make_playground_asset_manager.js";
24
+ import { Transform64 } from "../../../engine/ecs/transform/Transform64.js";
25
+ import { prefab_compile } from "../../../engine/graphics3/prefab/prefab_compile.js";
26
+ import { prefab_place } from "../../../engine/graphics3/prefab/prefab_place.js";
27
+
28
+ /** how many primitives the loaded scene placed */
29
+ let drawn = 0;
30
+
31
+ /**
32
+ * The froxel volumetrics pass, with the controls that make its known defects visible.
33
+ *
34
+ * `shader_volumetrics_build_lighting` and the passes around it were reviewed statically and five
35
+ * correctness findings came out of it (C-01 … C-05). Four are geometric, and geometry is the one
36
+ * class of defect a unit test can prove but not show: an emulator can assert that a sample lands at
37
+ * the wrong depth, and it still cannot tell you whether that reads as a smear, a seam, or nothing
38
+ * at all. This page exists so each fix can be looked at before and after.
39
+ *
40
+ * Every control below is aimed at one finding. The panel says which.
41
+ *
42
+ * Runs under the dev server (`npm run dev`), which serves `test_assets/` and resolves the one bare
43
+ * specifier the renderer reaches for. The panel is hand-rolled for the same reason the Sponza page
44
+ * hand-rolls its own — a dozen inputs are not worth a dependency the library does not otherwise
45
+ * have.
46
+ *
47
+ * @see src/shade/renderer/volumetrics/NOTES.md
48
+ */
49
+
50
+ /**
51
+ * Served out of `test_assets/`, which is gitignored and unpublished — `test_assets/README.md` has
52
+ * how it gets there.
53
+ *
54
+ * glTF rather than the `.shade` scene sitting next to it: that export's header reads format
55
+ * version 1 and `deserialize_scene` accepts version 2 only, deliberately and with no backward
56
+ * compatibility. Re-exporting it is the fix if the `.shade` is ever wanted.
57
+ *
58
+ * @type {string}
59
+ */
60
+ const SCENE_URL = '/test_assets/flying_world_-_battle_of_the_trash_god/v2/scene.gltf';
61
+
62
+ /**
63
+ * A low sun, which is what the volumetrics want: it rakes the scene, so the shafts have something
64
+ * to be cast by, and it sits near the horizon where the sun can be swung in and out of the frustum
65
+ * without also swinging it behind the terrain.
66
+ *
67
+ * @type {string}
68
+ */
69
+ const ENVIRONMENT_URL = '/test_assets/environments/octahedral/venice_sunset_2k.hdr';
70
+
71
+ /**
72
+ * Camera placements carried over from the sibling repo's playground, where they were found by
73
+ * hand while looking at this exact scene. Keeping the numbers rather than re-deriving them means a
74
+ * before/after pair is taken from the same place to the pixel.
75
+ *
76
+ * The `c` field names the finding each one is good for; the panel groups by it.
77
+ */
78
+ const VIEWS = [
79
+ {
80
+ id: 'overview',
81
+ label: 'Dead overview',
82
+ c: 'orientation',
83
+ hint: 'the whole island — start here',
84
+ position: { x: -44.23572420730413, y: 16.787419516572818, z: -0.3908097424888902 },
85
+ rotation: { x: -0.10289617976426199, y: 0.8965686124184902, z: -0.32052909150868936, w: -0.2878162624184363 }
86
+ },
87
+ {
88
+ id: 'vol_0',
89
+ label: 'Fog bank, wide',
90
+ c: 'C-01',
91
+ hint: 'fog fills the frame corners, where the depth error is largest',
92
+ position: { x: -39.165083083628595, y: 9.002002938463146, z: -12.822321096883556 },
93
+ rotation: { x: 0.0461501744849993, y: 0.9414711984407541, z: -0.14428237367052793, w: 0.3011390717750397 }
94
+ },
95
+ {
96
+ id: 'vol_1',
97
+ label: 'Inside the fog',
98
+ c: 'C-01',
99
+ hint: 'camera inside the medium — radial thinning shows against a flat wall of fog',
100
+ position: { x: -57.19543561067503, y: 4.497368033549733, z: -5.431935542965578 },
101
+ rotation: {
102
+ x: 0.0012158994167123557,
103
+ y: 0.9584376528911036,
104
+ z: -0.0040851224490818586,
105
+ w: 0.28527022081489145
106
+ }
107
+ },
108
+ {
109
+ id: 'broadside',
110
+ label: 'Island broadside',
111
+ c: 'C-03',
112
+ hint: 'the island against open sky — the clearest place to swing the sun in and out of frame',
113
+ position: { x: -30, y: 11, z: -5 },
114
+ rotation: {
115
+ x: 0.08308534470573395,
116
+ y: -0.7022085341941733,
117
+ z: 0.08308534470573395,
118
+ w: 0.7022085341941732
119
+ }
120
+ },
121
+ {
122
+ id: 'above',
123
+ label: 'Island from above',
124
+ c: 'C-03',
125
+ hint: 'all six volumes at once, with sky behind them',
126
+ position: { x: -18, y: 26, z: 26 },
127
+ rotation: {
128
+ x: -0.09605984305376475,
129
+ y: 0.8751796663464206,
130
+ z: -0.19438519850844194,
131
+ w: -0.43248982966896177
132
+ }
133
+ },
134
+ {
135
+ id: 'cloud_deck',
136
+ label: 'Inside the cloud deck',
137
+ c: 'C-01',
138
+ hint: 'uniform medium filling the frame — radial thinning reads as a vignette here',
139
+ position: { x: -57, y: -10, z: 20 },
140
+ rotation: { x: 0, y: 0.9999652844073138, z: 0.008332465433472727, w: 0 }
141
+ },
142
+ {
143
+ id: 'aliasing_0',
144
+ label: 'Volume edge',
145
+ c: 'C-02',
146
+ hint: 'a fog volume boundary against geometry — a half-froxel shift moves this edge',
147
+ position: { x: -44.358600521646366, y: 8.13976892720825, z: 2.6707745658793725 },
148
+ rotation: { x: -0.07197787209539422, y: 0.9277035010259875, z: -0.24609398688026018, w: -0.2713358614966388 }
149
+ },
150
+ {
151
+ id: 'aliasing_1',
152
+ label: 'Volume edge, above',
153
+ c: 'C-02',
154
+ hint: 'the same boundary from above, where the slab stack is edge-on',
155
+ position: { x: -36.56903863396318, y: 19.1017887067011, z: 13.881382214134083 },
156
+ rotation: { x: -0.0961072760435774, y: 0.9036695806244697, z: -0.3054532939528032, w: -0.28432897453277794 }
157
+ },
158
+ {
159
+ id: 'fog_box_0',
160
+ label: 'Beside the fog box',
161
+ c: 'Q-04',
162
+ hint: 'the sun crosses three units of medium here — where sixteen march steps read +58',
163
+ position: { x: -49.64917207609583, y: 3.9195318273572317, z: -4.211048766762115 },
164
+ rotation: {
165
+ x: -0.037898077937503966,
166
+ y: 0.6176094542736352,
167
+ z: 0.029816629610983452,
168
+ w: 0.7850052651282708
169
+ }
170
+ },
171
+ {
172
+ id: 'fog_box_1',
173
+ label: 'Beside the fog box, deeper',
174
+ c: 'Q-04',
175
+ hint: 'the same medium a little further in; +70 for the march, and where the volume strobed',
176
+ position: { x: -50.28590468756837, y: 4.239170044321892, z: -3.9966900541348767 },
177
+ rotation: {
178
+ x: -0.03789807793750395,
179
+ y: 0.6176094542736352,
180
+ z: 0.02981662961098345,
181
+ w: 0.7850052651282708
182
+ }
183
+ },
184
+ {
185
+ id: 'inside_out',
186
+ label: 'Under the island',
187
+ c: 'C-05',
188
+ hint: 'thin haze over a dark ground — per-froxel noise is most legible here',
189
+ position: { x: -61.55864473831582, y: 23.7158848700074, z: -19.634434309820563 },
190
+ rotation: { x: 0.27745576215003553, y: 0.0922110339369582, z: -0.026764015593898134, w: 0.9559284035634205 }
191
+ },
192
+ ];
193
+
194
+ /**
195
+ * The participating media, carried over from the sibling repo's setup for this scene. Positions are
196
+ * tuned to the model, so they move with it and not with anything here.
197
+ *
198
+ * `target_extinction` rather than `density`: it normalizes across particle specs, so swapping a
199
+ * preset changes how the medium *looks* without changing how much light it stops.
200
+ *
201
+ * @param {Scene} scene
202
+ */
203
+ function add_participating_media(scene) {
204
+
205
+ /**
206
+ * @param {object} spec
207
+ * @param {number[]} spec.position
208
+ * @param {number[]} spec.scale
209
+ * @param {object} spec.particle from MIE_PARTICLES_STANDARD_PRECOMPUTED
210
+ * @param {number} spec.extinction
211
+ * @param {number} spec.fade
212
+ * @param {number} [spec.yaw_degrees]
213
+ */
214
+ function volume({ position, scale, particle, extinction, fade, yaw_degrees = 0 }) {
215
+ const v = new ParticipatingMediaVolume();
216
+
217
+ v.transform.setTranslation(...position);
218
+ v.transform.setScale(...scale);
219
+
220
+ if (yaw_degrees !== 0) {
221
+ t64_set_rotation_axis_angle(v.transform, 0, 1, 0, yaw_degrees * DEG_TO_RAD);
222
+ }
223
+
224
+ // the GPU is handed `transform.matrix`, and a Transform64 does not maintain one - the
225
+ // scale and the yaw above are components and nothing more until this call folds them in
226
+ v.transform.updateMatrix();
227
+
228
+ v.fade_distance = fade;
229
+ v.particle_spec = VolumetricsParticleSpec.fromMeep(particle);
230
+ v.target_extinction = extinction;
231
+
232
+ scene.volumetrics.add(v);
233
+
234
+ return v;
235
+ }
236
+
237
+ const P = MIE_PARTICLES_STANDARD_PRECOMPUTED;
238
+
239
+ // the dense bank along the western edge — the thickest medium in the scene, and the one that
240
+ // fills the frame corners from the `vol_0` view
241
+ volume({
242
+ position: [-55, 4, -5.116],
243
+ scale: [10, 3, 20],
244
+ yaw_degrees: 83,
245
+ particle: P.CLOUD_DROPLET_LARGE,
246
+ extinction: 1,
247
+ fade: 0.5,
248
+ });
249
+
250
+ // graveyard
251
+ volume({
252
+ position: [-51.98019820725889, 7.899311905935347, -15.3228393616169],
253
+ scale: [7, 5, 7],
254
+ particle: P.FOG_DROPLET_SMALL,
255
+ extinction: 0.4,
256
+ fade: 1,
257
+ });
258
+
259
+ // mine
260
+ volume({
261
+ position: [-50.846390607312934, 0.3159949821015605, 17.89429433940319],
262
+ scale: [10, 7, 10],
263
+ particle: P.COARSE_DUST_MEDIUM,
264
+ extinction: 0.4,
265
+ fade: 4,
266
+ });
267
+
268
+ // large crystal
269
+ volume({
270
+ position: [-53.41918585295826, 17.333878151116526, 29.90844167706601],
271
+ scale: [18, 10, 18],
272
+ particle: P.MARITIME_HAZE_MEDIUM,
273
+ extinction: 0.1,
274
+ fade: 4,
275
+ });
276
+
277
+ // the low cloud deck the island sits above — big and thin, so it is what a wide FOV sees at the
278
+ // frame edges
279
+ volume({
280
+ position: [-57.36387203979457, -15, 2.607232848593789],
281
+ scale: [400, 20, 400],
282
+ particle: P.CLOUD_DROPLET_LARGE,
283
+ extinction: 0.1,
284
+ fade: 4,
285
+ });
286
+
287
+ // ball cloud overhead
288
+ volume({
289
+ position: [-51.137423384559284, 33, 5.593067265589105],
290
+ scale: [15, 15, 15],
291
+ particle: P.CLOUD_DROPLET_LARGE,
292
+ extinction: 1,
293
+ fade: 7,
294
+ });
295
+ }
296
+
297
+ /**
298
+ * A rolling mean frame time, so the readout is legible rather than jittering.
299
+ */
300
+ class FrameTimer {
301
+ #samples = new Float64Array(60);
302
+ #count = 0;
303
+ #cursor = 0;
304
+
305
+ add(seconds) {
306
+ this.#samples[this.#cursor] = seconds * 1000;
307
+ this.#cursor = (this.#cursor + 1) % this.#samples.length;
308
+ this.#count = Math.min(this.#count + 1, this.#samples.length);
309
+ }
310
+
311
+ reset() {
312
+ this.#count = 0;
313
+ this.#cursor = 0;
314
+ }
315
+
316
+ get mean_ms() {
317
+ if (this.#count === 0) {
318
+ return 0;
319
+ }
320
+
321
+ let total = 0;
322
+ for (let i = 0; i < this.#count; i++) {
323
+ total += this.#samples[i];
324
+ }
325
+ return total / this.#count;
326
+ }
327
+ }
328
+
329
+ /**
330
+ * Point a directional light along a heading, in place.
331
+ *
332
+ * The sun's azimuth is the control C-03 turns on: the shadow ray is clipped against a frustum whose
333
+ * far plane is degenerate, so a sun direction that lies inside the view cone never exits it. Swing
334
+ * the sun through the frame and the media self-shadowing should be steady; if it switches on as the
335
+ * sun leaves the frustum, that is the finding.
336
+ *
337
+ * @param {DirectionalLight} light
338
+ * @param {number} azimuth_degrees 0 points along +X
339
+ * @param {number} elevation_degrees above the horizon
340
+ */
341
+ function aim_light(light, azimuth_degrees, elevation_degrees) {
342
+ const azimuth = azimuth_degrees * DEG_TO_RAD;
343
+ const elevation = elevation_degrees * DEG_TO_RAD;
344
+
345
+ const horizontal = Math.cos(elevation);
346
+
347
+ // direction the light travels — downward for a sun above the horizon
348
+ const direction = new Vector3(
349
+ Math.cos(azimuth) * horizontal,
350
+ -Math.sin(elevation),
351
+ Math.sin(azimuth) * horizontal
352
+ ).normalize();
353
+
354
+ const q = new Quaternion();
355
+ q.fromUnitVectors(Vector3.forward, direction);
356
+ q.normalize();
357
+
358
+ light.transform.setRotation(q.x, q.y, q.z, q.w);
359
+ light.transform.updateMatrix();
360
+ }
361
+
362
+ /**
363
+ * How much each profile capture records. `WORKLOAD` is the highest of the three levels the proposal
364
+ * calls shippable: pass spans, the frame graph, and dispatch/draw counts.
365
+ *
366
+ * Measured on this page it runs ~11 KB a frame over ~393 spans, so ~660 KB/s at 60 Hz — the
367
+ * proposal's estimate of 6 KB assumed ~200 passes and this graph is about twice that. Still small
368
+ * enough that a hand-driven recording will not notice. `VERBOSE` above it adds bind group contents
369
+ * at roughly seven times the rate and wants a frame limit set, not a key you can lean on.
370
+ *
371
+ * @type {number}
372
+ */
373
+ const PROFILE_LEVEL = GPUProfileLevel.WORKLOAD;
374
+
375
+ /**
376
+ * Hand an ArrayBuffer to the browser as a file.
377
+ *
378
+ * @param {ArrayBuffer} bytes
379
+ * @param {string} filename
380
+ */
381
+ function download_bytes(bytes, filename) {
382
+ const url = URL.createObjectURL(new Blob([bytes], { type: 'application/octet-stream' }));
383
+
384
+ const anchor = document.createElement('a');
385
+
386
+ anchor.href = url;
387
+ anchor.download = filename;
388
+
389
+ document.body.appendChild(anchor);
390
+ anchor.click();
391
+ anchor.remove();
392
+
393
+ // Revoking in the same task cancels the download in some browsers — the click only schedules it.
394
+ setTimeout(() => URL.revokeObjectURL(url), 60000);
395
+ }
396
+
397
+ /**
398
+ * `YYYYMMDD-HHMMSS` in local time, matching the naming the other `.sgpt` captures on this machine
399
+ * already use — same sort order, and it reads as the clock you took it by rather than as UTC.
400
+ *
401
+ * @returns {string}
402
+ */
403
+ function file_timestamp() {
404
+ const now = new Date();
405
+
406
+ const pad = value => String(value).padStart(2, '0');
407
+
408
+ return `${now.getFullYear()}${pad(now.getMonth() + 1)}${pad(now.getDate())}`
409
+ + `-${pad(now.getHours())}${pad(now.getMinutes())}${pad(now.getSeconds())}`;
410
+ }
411
+
412
+ /**
413
+ * @param {number} bytes
414
+ * @returns {string}
415
+ */
416
+ function format_bytes(bytes) {
417
+ if (bytes < 1024) {
418
+ return `${bytes} B`;
419
+ }
420
+
421
+ if (bytes < 1024 * 1024) {
422
+ return `${(bytes / 1024).toFixed(1)} KiB`;
423
+ }
424
+
425
+ return `${(bytes / (1024 * 1024)).toFixed(1)} MiB`;
426
+ }
427
+
428
+ export async function start() {
429
+
430
+ const element = id => document.getElementById(id);
431
+
432
+ const status_element = element('status');
433
+ const stats_element = element('stats');
434
+
435
+ function set_status(text, kind = '') {
436
+ status_element.textContent = text;
437
+ status_element.className = kind;
438
+ }
439
+
440
+ const canvas = element('view');
441
+
442
+ const context = canvas.getContext('webgpu');
443
+
444
+ if (context === null) {
445
+ set_status('no WebGPU context — this browser has none, or the page is not a secure context', 'fail');
446
+ return;
447
+ }
448
+
449
+ const renderer = new Renderer();
450
+
451
+ set_status('acquiring a device…');
452
+
453
+ await renderer.initialize({ context });
454
+
455
+ const camera = new PerspectiveCamera();
456
+
457
+ camera.near = 0.1;
458
+ camera.far = 120;
459
+ camera.fov = 60 * DEG_TO_RAD;
460
+ // aspect is set by the frame loop, which is the first place the viewport has a size
461
+
462
+ const scene = new Scene();
463
+
464
+ // the sun stands at an entity, so the scene names a dataset for it
465
+ scene.dataset = new EntityComponentDataset();
466
+
467
+ const controller = new OrbitalCameraController(camera, document.body);
468
+
469
+ // handy from the console
470
+ globalThis.renderer = renderer;
471
+ globalThis.scene = scene;
472
+ globalThis.camera = camera;
473
+ globalThis.controller = controller;
474
+
475
+ // ---- scene ----------------------------------------------------------------------------
476
+
477
+ set_status(`loading ${SCENE_URL} …`);
478
+
479
+ try {
480
+ const bundle = await load_gltf(SCENE_URL, { assetManager: await make_playground_asset_manager() });
481
+
482
+ drawn = prefab_place(renderer.scenes.obtain(scene), scene.dataset, prefab_compile(bundle), new Transform64()).drawn;
483
+ } catch (error) {
484
+ set_status(
485
+ `could not load the scene (${error.message}). Put the assets under test_assets/ — `
486
+ + `see test_assets/README.md.`,
487
+ 'fail'
488
+ );
489
+ console.error(error);
490
+ return;
491
+ }
492
+
493
+ const sun = make_sunlight({ intensity: 0.6, temperature: 5500 });
494
+
495
+ place_light(scene, sun);
496
+
497
+ add_participating_media(scene);
498
+
499
+ load_default_environment(scene, ENVIRONMENT_URL).then(applied => {
500
+ if (applied) {
501
+ renderer.indicate_view_change();
502
+ }
503
+ });
504
+
505
+ // ---- controls -------------------------------------------------------------------------
506
+
507
+ const frame_timer = new FrameTimer();
508
+
509
+ let paused = false;
510
+
511
+ /** Re-render and drop the frame-time history, since a setting change invalidates it. */
512
+ function repaint() {
513
+ renderer.indicate_view_change();
514
+ frame_timer.reset();
515
+ }
516
+
517
+ // -- views
518
+
519
+ const views_element = element('views');
520
+
521
+ /**
522
+ * Which placement the camera was last sent to, for the profile capture's note — a capture that
523
+ * cannot say where it was taken is much less use a week later.
524
+ * @type {object|null}
525
+ */
526
+ let current_view = null;
527
+
528
+ /** @param {object} view */
529
+ function go_to(view) {
530
+ current_view = view;
531
+
532
+ camera.transform.fromJSON({ translation: view.position, rotation: view.rotation });
533
+
534
+ // the controller holds its own spherical state and would otherwise snap the camera back on
535
+ // the next update
536
+ controller.from_transform(camera.transform);
537
+
538
+ repaint();
539
+ }
540
+
541
+ for (const view of VIEWS) {
542
+ const button = document.createElement('button');
543
+
544
+ button.className = 'view';
545
+ button.title = view.hint;
546
+ button.innerHTML = `<span class="tag">${view.c}</span>${view.label}`;
547
+ button.addEventListener('click', () => {
548
+ go_to(view);
549
+ set_status(view.hint);
550
+ });
551
+
552
+ views_element.appendChild(button);
553
+ }
554
+
555
+ // -- sun
556
+
557
+ let sun_azimuth = 200;
558
+ let sun_elevation = 12;
559
+
560
+ function update_sun() {
561
+ aim_light(sun, sun_azimuth, sun_elevation);
562
+
563
+ // re-aimed in place: the collection's version is what rebuilds the record and rewrites the row
564
+ scene.lights.needsUpdate = true;
565
+
566
+ element('sun_azimuth_value').textContent = `${sun_azimuth}°`;
567
+ element('sun_elevation_value').textContent = `${sun_elevation}°`;
568
+
569
+ repaint();
570
+ }
571
+
572
+ element('sun_azimuth').addEventListener('input', event => {
573
+ sun_azimuth = Number(event.target.value);
574
+ update_sun();
575
+ });
576
+
577
+ element('sun_elevation').addEventListener('input', event => {
578
+ sun_elevation = Number(event.target.value);
579
+ update_sun();
580
+ });
581
+
582
+ /**
583
+ * Put the sun directly in front of the camera, or directly behind it, at the current elevation.
584
+ *
585
+ * This is the C-03 A/B reduced to two clicks. "Into view" places the sun's direction inside the
586
+ * frustum's direction cone, which is the condition under which `frustum_clip_ray` returns its
587
+ * 1e20 sentinel.
588
+ *
589
+ * @param {boolean} in_front
590
+ */
591
+ function aim_sun_relative_to_camera(in_front) {
592
+ // Straight off the view matrix rather than by rotating a basis vector through the camera's
593
+ // quaternion by hand: the third row of a view matrix is the camera's backward axis, so this
594
+ // is the renderer's own answer and cannot disagree with what is on screen. The hand-rolled
595
+ // version this replaces had a sign error that put the sun behind the camera on both
596
+ // branches, which is invisible in a screenshot and made the C-03 A/B read as a null result.
597
+ // The matrices are rebuilt during render, so a placement made this tick is not in them yet
598
+ // — reading straight after `go_to` would aim the sun at wherever the camera used to be.
599
+ camera.update();
600
+
601
+ const vm = camera.view_matrix;
602
+
603
+ const forward_x = -vm[2];
604
+ const forward_z = -vm[10];
605
+
606
+ // `aim_light` takes the direction light *travels*, so the sun sits opposite it. Placing the
607
+ // sun on the camera's forward axis therefore means aiming its travel back along that axis.
608
+ const toward_sun_x = in_front ? forward_x : -forward_x;
609
+ const toward_sun_z = in_front ? forward_z : -forward_z;
610
+
611
+ const azimuth = Math.atan2(-toward_sun_z, -toward_sun_x) / DEG_TO_RAD;
612
+
613
+ sun_azimuth = Math.round((azimuth % 360 + 360) % 360);
614
+
615
+ element('sun_azimuth').value = String(sun_azimuth);
616
+
617
+ update_sun();
618
+ }
619
+
620
+ element('sun_into_view').addEventListener('click', () => {
621
+ aim_sun_relative_to_camera(true);
622
+ set_status('sun placed in front of the camera — C-03 predicts media self-shadowing vanishes here', 'warn');
623
+ });
624
+
625
+ element('sun_behind').addEventListener('click', () => {
626
+ aim_sun_relative_to_camera(false);
627
+ set_status('sun placed behind the camera — C-03 predicts media self-shadowing returns here', 'pass');
628
+ });
629
+
630
+ // -- camera
631
+
632
+ element('fov').addEventListener('input', event => {
633
+ const degrees = Number(event.target.value);
634
+
635
+ camera.fov = degrees * DEG_TO_RAD;
636
+
637
+ element('fov_value').textContent = `${degrees}°`;
638
+
639
+ repaint();
640
+ });
641
+
642
+ // -- volumetrics knobs, read by GPUViewVolumetrics on every metadata update
643
+
644
+ element('vol_taa').addEventListener('change', event => {
645
+ globalThis.__VOL_TAA_ENABLED = event.target.checked;
646
+ repaint();
647
+ });
648
+
649
+ element('taa').addEventListener('change', event => {
650
+ renderer.feature_taa_enabled = event.target.checked;
651
+ repaint();
652
+ });
653
+
654
+ // Off by default on this page. Auto exposure keeps adapting for seconds after anything changes,
655
+ // which makes a before/after pair differ by more than most of the fixes being judged here do —
656
+ // it read as a large effect with the wrong sign more than once while this page was being built.
657
+ renderer.feature_automatic_exposure_enabled = false;
658
+
659
+ element('auto_exposure').addEventListener('change', event => {
660
+ renderer.feature_automatic_exposure_enabled = event.target.checked;
661
+ repaint();
662
+ });
663
+
664
+ element('froxel_far').addEventListener('input', event => {
665
+ const value = Number(event.target.value);
666
+
667
+ // the slider's top notch means "no split", which is the engine default
668
+ globalThis.__VOL_FROXEL_FAR = value >= 120 ? Infinity : value;
669
+
670
+ element('froxel_far_value').textContent = value >= 120 ? 'off' : `${value} m`;
671
+
672
+ repaint();
673
+ });
674
+
675
+ element('ms_octaves').addEventListener('input', event => {
676
+ const value = Number(event.target.value);
677
+
678
+ globalThis.__VOL_MS_OCTAVES = value;
679
+
680
+ element('ms_octaves_value').textContent = String(value);
681
+
682
+ repaint();
683
+ });
684
+
685
+ // -- profiling: T starts a recording, T again stops it and downloads the capture
686
+
687
+ const profile_status = element('profile_status');
688
+
689
+ /**
690
+ * The recording in progress, or null.
691
+ *
692
+ * The engine never constructs one of these — `Renderer.profile_session` is a nullable field and
693
+ * the null checks around it are the entire integration, which is what keeps the profiler out of
694
+ * a bundle that does not ask for it. The two imports at the top of this file are the whole
695
+ * opt-in.
696
+ *
697
+ * @type {GPUProfileSession|null}
698
+ */
699
+ let profile_session = null;
700
+
701
+ /** Guards against T being leaned on while a stop is still draining. */
702
+ let profile_busy = false;
703
+
704
+ function set_profile_status(text, recording = false) {
705
+ profile_status.textContent = text;
706
+ profile_status.className = recording ? 'recording' : '';
707
+ }
708
+
709
+ function start_profile() {
710
+ const device = renderer.device;
711
+
712
+ const settings = [
713
+ current_view === null ? 'free camera' : current_view.label,
714
+ `fov ${Math.round(camera.fov / DEG_TO_RAD)}°`,
715
+ `volumetric TAA ${(globalThis.__VOL_TAA_ENABLED ?? true) ? 'on' : 'off'}`,
716
+ `${renderer.pixel_ratio.toFixed(2)}x`,
717
+ ];
718
+
719
+ const session = new GPUProfileSession({
720
+ level: PROFILE_LEVEL,
721
+ note: `volumetrics_froxel — ${settings.join(' · ')}`,
722
+ });
723
+
724
+ // Populate before start(): the meta record is written into the stream there and not read
725
+ // again. Without it the capture is unreadable in the sense that matters — a pass taking
726
+ // 0.4 ms says nothing until you know which GPU and at what resolution.
727
+ const meta = session.meta;
728
+
729
+ // `GPUDevice.adapterInfo` is recent enough that a browser running this page may not have it,
730
+ // and several browsers withhold the fields even when they do. Empty is what the format
731
+ // expects in that case.
732
+ const info = device.adapterInfo;
733
+
734
+ if (info !== undefined && info !== null) {
735
+ meta.adapter_vendor = info.vendor ?? "";
736
+ meta.adapter_architecture = info.architecture ?? "";
737
+ meta.adapter_device = info.device ?? "";
738
+ meta.adapter_description = info.description ?? "";
739
+ }
740
+
741
+ meta.features = [...device.features];
742
+ meta.engine_version = package_json.version;
743
+
744
+ session.onBytesWritten.add(bytes => {
745
+ set_profile_status(
746
+ `● recording — ${session.frames_recorded} frames, ${format_bytes(bytes)} · T to stop`,
747
+ true
748
+ );
749
+ });
750
+
751
+ renderer.profile_session = session;
752
+ session.start();
753
+
754
+ profile_session = session;
755
+
756
+ // The timers go quiet without this rather than failing, so the capture still carries the
757
+ // frame graph and the workload — it just has no durations in it. Worth knowing before you
758
+ // record for a minute and then look.
759
+ const timed = device.features.has('timestamp-query');
760
+
761
+ set_profile_status(
762
+ timed
763
+ ? '● recording — 0 frames · T to stop'
764
+ : '● recording without timestamp-query — structure only, no durations · T to stop',
765
+ true
766
+ );
767
+ }
768
+
769
+ /**
770
+ * Wait for frames already submitted to finish landing in the session.
771
+ *
772
+ * A frame is committed when its timestamp readback resolves — a `mapAsync` a frame or two behind
773
+ * submit, see `ShadeGPUCommandContext.profiling_absorbed` — and `record_frame` silently ignores
774
+ * anything arriving after `stop()`. Stopping the instant the key goes down therefore discards
775
+ * the last few frames, which are the ones you were most likely looking at.
776
+ *
777
+ * Drains the queue, then waits for the frame count to stop moving. Capped, because a recording
778
+ * taken while the page is paused never moves at all.
779
+ *
780
+ * @param {GPUProfileSession} session
781
+ */
782
+ async function drain_profile(session) {
783
+ const DEADLINE_MS = 1000;
784
+ const QUIET_MS = 60;
785
+
786
+ await renderer.device.queue.onSubmittedWorkDone();
787
+
788
+ const deadline = performance.now() + DEADLINE_MS;
789
+
790
+ let previous = session.frames_recorded;
791
+
792
+ while (performance.now() < deadline) {
793
+ await new Promise(resolve => setTimeout(resolve, QUIET_MS));
794
+
795
+ if (session.frames_recorded === previous) {
796
+ return;
797
+ }
798
+
799
+ previous = session.frames_recorded;
800
+ }
801
+ }
802
+
803
+ async function stop_profile() {
804
+ const session = profile_session;
805
+
806
+ profile_session = null;
807
+
808
+ // Detach first, so nothing encoded during the drain below joins the recording. Frames
809
+ // already encoded are unaffected: Renderer captures the session into a local before it
810
+ // subscribes to the readback.
811
+ renderer.profile_session = null;
812
+
813
+ set_profile_status('stopping — draining in-flight frames…');
814
+
815
+ await drain_profile(session);
816
+
817
+ const bytes = session.stop();
818
+
819
+ const filename = `volumetrics_froxel-${file_timestamp()}.sgpt`;
820
+
821
+ download_bytes(bytes, filename);
822
+
823
+ // Also to the console, because the status line is the only other place the name appears and
824
+ // a browser that declines the save says nothing about which capture it declined.
825
+ console.log(
826
+ `profile: ${session.frames_recorded} frames, ${format_bytes(bytes.byteLength)}, `
827
+ + `${session.topology_count} topolog${session.topology_count === 1 ? 'y' : 'ies'} -> ${filename}`
828
+ );
829
+
830
+ set_profile_status(
831
+ `${session.frames_recorded} frames, ${format_bytes(bytes.byteLength)}`
832
+ + `, ${session.topology_count} topolog${session.topology_count === 1 ? 'y' : 'ies'}`
833
+ + ` · ${filename}`
834
+ );
835
+ }
836
+
837
+ window.addEventListener('keydown', event => {
838
+ if (event.ctrlKey || event.metaKey || event.altKey || event.repeat) {
839
+ return;
840
+ }
841
+
842
+ // `key` first, because it is the letter actually printed on the key the user pressed —
843
+ // `code` is physical position, so on AZERTY it names the key where T sits on QWERTY. `code`
844
+ // is the fallback for layouts whose `key` is not Latin at all (Cyrillic gives "е" here).
845
+ if (event.key.toLowerCase() !== 't' && event.code !== 'KeyT') {
846
+ return;
847
+ }
848
+
849
+ // the panel's sliders and buttons are focusable; do not steal a key from a field
850
+ const target = event.target;
851
+
852
+ if (target instanceof HTMLInputElement || target instanceof HTMLTextAreaElement || target instanceof HTMLSelectElement) {
853
+ return;
854
+ }
855
+
856
+ if (profile_busy) {
857
+ return;
858
+ }
859
+
860
+ event.preventDefault();
861
+
862
+ profile_busy = true;
863
+
864
+ const done = profile_session === null
865
+ ? Promise.resolve(start_profile())
866
+ : stop_profile();
867
+
868
+ done.catch(error => {
869
+ set_profile_status(`profiling failed: ${error?.message ?? error}`);
870
+ console.error(error);
871
+
872
+ profile_session = null;
873
+ renderer.profile_session = null;
874
+ }).finally(() => {
875
+ profile_busy = false;
876
+ });
877
+ });
878
+
879
+ element('pause').addEventListener('click', () => {
880
+ paused = !paused;
881
+ element('pause').textContent = paused ? 'Resume' : 'Pause';
882
+ });
883
+
884
+ element('log_camera').addEventListener('click', () => {
885
+ const t = camera.transform;
886
+
887
+ const json = {
888
+ position: { x: t.translation_x, y: t.translation_y, z: t.translation_z },
889
+ rotation: { x: t.rotation_x, y: t.rotation_y, z: t.rotation_z, w: t.rotation_w }
890
+ };
891
+
892
+ console.log(JSON.stringify(json, null, 4));
893
+ set_status('camera written to the console', 'pass');
894
+ });
895
+
896
+ // ---- start ----------------------------------------------------------------------------
897
+
898
+ update_sun();
899
+ go_to(VIEWS[0]);
900
+
901
+ controller.movement_speed_scale = 4;
902
+
903
+ // the controller's keyboard device listens on body, and only a focused element gets key events
904
+ document.body.focus();
905
+
906
+ set_status(`loaded — ${drawn} instances, ${scene.volumetrics.volumes.length} media volumes`, 'pass');
907
+
908
+ // ---- frame loop -----------------------------------------------------------------------
909
+
910
+ const FRAME_RATE_LIMIT = 60;
911
+
912
+ create_frame_loop(time_delta_s => {
913
+ const width = window.innerWidth;
914
+ const height = window.innerHeight;
915
+
916
+ renderer.resize(width, height);
917
+ renderer.pixel_ratio = window.devicePixelRatio;
918
+ camera.aspect = width / height;
919
+
920
+ controller.update();
921
+
922
+ if (paused) {
923
+ return;
924
+ }
925
+
926
+ renderer.render(camera, scene, time_delta_s);
927
+
928
+ frame_timer.add(time_delta_s);
929
+
930
+ const mean = frame_timer.mean_ms;
931
+
932
+ stats_element.textContent =
933
+ `${mean.toFixed(1)} ms · ${mean > 0 ? (1000 / mean).toFixed(0) : '0'} fps`
934
+ + ` · fov ${Math.round(camera.fov / DEG_TO_RAD)}°`;
935
+ }, FRAME_RATE_LIMIT);
936
+ }