@woosh/meep-engine 3.43.0 → 3.45.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 (466) hide show
  1. package/build/bundle-worker-terrain.js +1 -1
  2. package/editor/prototypeEditorShell.d.ts.map +1 -1
  3. package/editor/prototypeEditorShell.js +4 -2
  4. package/package.json +1 -1
  5. package/src/core/collection/array/array_sort_insertion_ascending.d.ts +19 -0
  6. package/src/core/collection/array/array_sort_insertion_ascending.d.ts.map +1 -0
  7. package/src/core/collection/array/array_sort_insertion_ascending.js +31 -0
  8. package/src/core/geom/3d/aabb/aabb3_array_round_outward_f32.d.ts +27 -0
  9. package/src/core/geom/3d/aabb/aabb3_array_round_outward_f32.d.ts.map +1 -0
  10. package/src/core/geom/3d/aabb/aabb3_array_round_outward_f32.js +39 -0
  11. package/src/core/geom/3d/aabb/aabb3_from_v3_array.d.ts.map +1 -1
  12. package/src/core/geom/3d/aabb/aabb3_from_v3_array.js +4 -1
  13. package/src/core/geom/3d/aabb/aabb3_transform_oriented.d.ts +2 -2
  14. package/src/core/geom/3d/aabb/aabb3_transform_oriented.d.ts.map +1 -1
  15. package/src/core/geom/3d/aabb/aabb3_transform_oriented.js +1 -1
  16. package/src/core/geom/3d/pose/pose3_apply_inverse_point_array.d.ts +21 -0
  17. package/src/core/geom/3d/pose/pose3_apply_inverse_point_array.d.ts.map +1 -0
  18. package/src/core/geom/3d/pose/pose3_apply_inverse_point_array.js +36 -0
  19. package/src/core/geom/3d/pose/pose3_apply_point_array.d.ts +25 -0
  20. package/src/core/geom/3d/pose/pose3_apply_point_array.d.ts.map +1 -0
  21. package/src/core/geom/3d/pose/pose3_apply_point_array.js +40 -0
  22. package/src/core/geom/3d/pose/pose3_compose_array.d.ts +28 -0
  23. package/src/core/geom/3d/pose/pose3_compose_array.d.ts.map +1 -0
  24. package/src/core/geom/3d/pose/pose3_compose_array.js +41 -0
  25. package/src/core/geom/3d/pose/pose3_to_local_array.d.ts +29 -0
  26. package/src/core/geom/3d/pose/pose3_to_local_array.d.ts.map +1 -0
  27. package/src/core/geom/3d/pose/pose3_to_local_array.js +42 -0
  28. package/src/core/geom/3d/quaternion/quat3_clamp_angle_array.d.ts +28 -0
  29. package/src/core/geom/3d/quaternion/quat3_clamp_angle_array.d.ts.map +1 -0
  30. package/src/core/geom/3d/quaternion/quat3_clamp_angle_array.js +66 -0
  31. package/src/core/geom/3d/quaternion/quat3_multiply_conjugate_left_array.d.ts +22 -0
  32. package/src/core/geom/3d/quaternion/quat3_multiply_conjugate_left_array.d.ts.map +1 -0
  33. package/src/core/geom/3d/quaternion/quat3_multiply_conjugate_left_array.js +30 -0
  34. package/src/core/geom/3d/quaternion/quat3_multiply_conjugate_right_array.d.ts +23 -0
  35. package/src/core/geom/3d/quaternion/quat3_multiply_conjugate_right_array.d.ts.map +1 -0
  36. package/src/core/geom/3d/quaternion/quat3_multiply_conjugate_right_array.js +31 -0
  37. package/src/core/geom/3d/triangle/tri3_compute_normal_area_weighted_array.d.ts +26 -0
  38. package/src/core/geom/3d/triangle/tri3_compute_normal_area_weighted_array.d.ts.map +1 -0
  39. package/src/core/geom/3d/triangle/tri3_compute_normal_area_weighted_array.js +46 -0
  40. package/src/core/geom/vec3/v3_distance_array.d.ts +11 -0
  41. package/src/core/geom/vec3/v3_distance_array.d.ts.map +1 -0
  42. package/src/core/geom/vec3/v3_distance_array.js +19 -0
  43. package/src/core/geom/vec3/v3_normalize_array_checked.d.ts +23 -0
  44. package/src/core/geom/vec3/v3_normalize_array_checked.d.ts.map +1 -0
  45. package/src/core/geom/vec3/v3_normalize_array_checked.js +49 -0
  46. package/src/core/geom/vec3/v3_reject_array.d.ts +15 -0
  47. package/src/core/geom/vec3/v3_reject_array.d.ts.map +1 -0
  48. package/src/core/geom/vec3/v3_reject_array.js +32 -0
  49. package/src/core/graph/csr/csr_build_incidence.d.ts +26 -0
  50. package/src/core/graph/csr/csr_build_incidence.d.ts.map +1 -0
  51. package/src/core/graph/csr/csr_build_incidence.js +71 -0
  52. package/src/core/graph/csr/csr_graph_color_greedy.d.ts +25 -0
  53. package/src/core/graph/csr/csr_graph_color_greedy.d.ts.map +1 -0
  54. package/src/core/graph/csr/csr_graph_color_greedy.js +83 -0
  55. package/src/core/graph/csr/csr_graph_validate_coloring.d.ts +15 -0
  56. package/src/core/graph/csr/csr_graph_validate_coloring.d.ts.map +1 -0
  57. package/src/core/graph/csr/csr_graph_validate_coloring.js +33 -0
  58. package/src/core/math/linalg/matrix_symmetric_3x3_solve_ldlt.d.ts +26 -0
  59. package/src/core/math/linalg/matrix_symmetric_3x3_solve_ldlt.d.ts.map +1 -0
  60. package/src/core/math/linalg/matrix_symmetric_3x3_solve_ldlt.js +71 -0
  61. package/src/core/math/max2_exact.d.ts +15 -0
  62. package/src/core/math/max2_exact.d.ts.map +1 -0
  63. package/src/core/math/max2_exact.js +30 -0
  64. package/src/core/math/min2_exact.d.ts +20 -0
  65. package/src/core/math/min2_exact.d.ts.map +1 -0
  66. package/src/core/math/min2_exact.js +35 -0
  67. package/src/engine/Clock.d.ts +15 -0
  68. package/src/engine/Clock.d.ts.map +1 -1
  69. package/src/engine/Clock.js +29 -5
  70. package/src/engine/Engine.d.ts.map +1 -1
  71. package/src/engine/Engine.js +11 -19
  72. package/src/engine/ecs/ik/IKGoalSystem.d.ts.map +1 -1
  73. package/src/engine/ecs/ik/IKGoalSystem.js +3 -19
  74. package/src/engine/ecs/parent/parent_entity_model_of.d.ts +17 -0
  75. package/src/engine/ecs/parent/parent_entity_model_of.d.ts.map +1 -0
  76. package/src/engine/ecs/parent/parent_entity_model_of.js +26 -0
  77. package/src/engine/ecs/transform/t64_read_pose_array.d.ts +15 -0
  78. package/src/engine/ecs/transform/t64_read_pose_array.d.ts.map +1 -0
  79. package/src/engine/ecs/transform/t64_read_pose_array.js +24 -0
  80. package/src/engine/graphics/ecs/mesh-v2/MeshSkin.d.ts +57 -0
  81. package/src/engine/graphics/ecs/mesh-v2/MeshSkin.d.ts.map +1 -0
  82. package/src/engine/graphics/ecs/mesh-v2/MeshSkin.js +84 -0
  83. package/src/engine/graphics/geometry/geometry_construct_triangle_normal_area_weighted.d.ts +2 -0
  84. package/src/engine/graphics/geometry/geometry_construct_triangle_normal_area_weighted.d.ts.map +1 -1
  85. package/src/engine/graphics/geometry/geometry_construct_triangle_normal_area_weighted.js +10 -21
  86. package/src/engine/graphics3/AnimationGraphSystem.d.ts +28 -13
  87. package/src/engine/graphics3/AnimationGraphSystem.d.ts.map +1 -1
  88. package/src/engine/graphics3/AnimationGraphSystem.js +107 -64
  89. package/src/engine/graphics3/AnimationSystem.d.ts +29 -15
  90. package/src/engine/graphics3/AnimationSystem.d.ts.map +1 -1
  91. package/src/engine/graphics3/AnimationSystem.js +112 -61
  92. package/src/engine/graphics3/MeshSkinSystem.d.ts +56 -0
  93. package/src/engine/graphics3/MeshSkinSystem.d.ts.map +1 -0
  94. package/src/engine/graphics3/MeshSkinSystem.js +317 -0
  95. package/src/engine/graphics3/MeshSystem.d.ts +15 -35
  96. package/src/engine/graphics3/MeshSystem.d.ts.map +1 -1
  97. package/src/engine/graphics3/MeshSystem.js +21 -298
  98. package/src/engine/graphics3/RowChains.d.ts +76 -0
  99. package/src/engine/graphics3/RowChains.d.ts.map +1 -0
  100. package/src/engine/graphics3/RowChains.js +347 -0
  101. package/src/engine/graphics3/ShadedGeometrySystem.d.ts +6 -0
  102. package/src/engine/graphics3/ShadedGeometrySystem.d.ts.map +1 -1
  103. package/src/engine/graphics3/ShadedGeometrySystem.js +329 -309
  104. package/src/engine/graphics3/animation/AnimationClips.d.ts +56 -0
  105. package/src/engine/graphics3/animation/AnimationClips.d.ts.map +1 -0
  106. package/src/engine/graphics3/animation/AnimationClips.js +79 -0
  107. package/src/engine/graphics3/animation/ClipListPlayer.d.ts +13 -14
  108. package/src/engine/graphics3/animation/ClipListPlayer.d.ts.map +1 -1
  109. package/src/engine/graphics3/animation/ClipListPlayer.js +262 -263
  110. package/src/engine/graphics3/animation/write_clip_playback.d.ts +3 -3
  111. package/src/engine/graphics3/animation/write_clip_playback.js +4 -4
  112. package/src/engine/graphics3/pose/query_entity_node_world_pose.d.ts +5 -0
  113. package/src/engine/graphics3/pose/query_entity_node_world_pose.d.ts.map +1 -1
  114. package/src/engine/graphics3/pose/query_entity_node_world_pose.js +80 -75
  115. package/src/engine/graphics3/prefab/PrefabInstance.d.ts +4 -24
  116. package/src/engine/graphics3/prefab/PrefabInstance.d.ts.map +1 -1
  117. package/src/engine/graphics3/prefab/PrefabInstance.js +60 -80
  118. package/src/engine/graphics3/prefab/prefab_instantiate.d.ts +16 -3
  119. package/src/engine/graphics3/prefab/prefab_instantiate.d.ts.map +1 -1
  120. package/src/engine/graphics3/prefab/prefab_instantiate.js +49 -12
  121. package/src/engine/graphics3/prefab/prefab_place.d.ts +31 -17
  122. package/src/engine/graphics3/prefab/prefab_place.d.ts.map +1 -1
  123. package/src/engine/graphics3/prefab/prefab_place.js +175 -130
  124. package/src/engine/graphics3/register_clips.d.ts +93 -0
  125. package/src/engine/graphics3/register_clips.d.ts.map +1 -0
  126. package/src/engine/graphics3/register_clips.js +166 -0
  127. package/src/engine/physics/broadphase/compute_fat_world_aabb.d.ts +9 -0
  128. package/src/engine/physics/broadphase/compute_fat_world_aabb.d.ts.map +1 -1
  129. package/src/engine/physics/broadphase/compute_fat_world_aabb.js +3 -1
  130. package/src/engine/physics/cloth/MEASUREMENTS.md +795 -0
  131. package/src/engine/physics/cloth/PLAN.md +349 -17
  132. package/src/engine/physics/cloth/build/ClothProxy.d.ts +113 -61
  133. package/src/engine/physics/cloth/build/ClothProxy.d.ts.map +1 -1
  134. package/src/engine/physics/cloth/build/ClothProxy.js +142 -77
  135. package/src/engine/physics/cloth/build/cloth_bind_in_frame.d.ts +44 -0
  136. package/src/engine/physics/cloth/build/cloth_bind_in_frame.d.ts.map +1 -0
  137. package/src/engine/physics/cloth/build/cloth_bind_in_frame.js +107 -0
  138. package/src/engine/physics/cloth/build/cloth_proxy_from_joints.d.ts +43 -30
  139. package/src/engine/physics/cloth/build/cloth_proxy_from_joints.d.ts.map +1 -1
  140. package/src/engine/physics/cloth/build/cloth_proxy_from_joints.js +371 -284
  141. package/src/engine/physics/cloth/build/cloth_proxy_from_mesh.d.ts +62 -0
  142. package/src/engine/physics/cloth/build/cloth_proxy_from_mesh.d.ts.map +1 -0
  143. package/src/engine/physics/cloth/build/cloth_proxy_from_mesh.js +275 -0
  144. package/src/engine/physics/cloth/collider/ClothColliderIndex.d.ts +7 -0
  145. package/src/engine/physics/cloth/collider/ClothColliderIndex.d.ts.map +1 -1
  146. package/src/engine/physics/cloth/collider/ClothColliderIndex.js +85 -67
  147. package/src/engine/physics/cloth/collider/cloth_collider_bounds.d.ts.map +1 -1
  148. package/src/engine/physics/cloth/collider/cloth_collider_bounds.js +19 -101
  149. package/src/engine/physics/cloth/collider/cloth_collider_pack.d.ts +2 -5
  150. package/src/engine/physics/cloth/collider/cloth_collider_pack.d.ts.map +1 -1
  151. package/src/engine/physics/cloth/collider/cloth_collider_pack.js +7 -15
  152. package/src/engine/physics/cloth/collider/cloth_collider_sdf.d.ts +1 -1
  153. package/src/engine/physics/cloth/collider/cloth_collider_sdf.d.ts.map +1 -1
  154. package/src/engine/physics/cloth/collider/cloth_collider_sdf.js +17 -62
  155. package/src/engine/physics/cloth/ecs/Cloth.d.ts +17 -9
  156. package/src/engine/physics/cloth/ecs/Cloth.d.ts.map +1 -1
  157. package/src/engine/physics/cloth/ecs/Cloth.js +220 -212
  158. package/src/engine/physics/cloth/ecs/ClothColliderFlags.d.ts +0 -1
  159. package/src/engine/physics/cloth/ecs/ClothColliderFlags.js +6 -19
  160. package/src/engine/physics/cloth/ecs/ClothColliderSystem.d.ts +1 -2
  161. package/src/engine/physics/cloth/ecs/ClothColliderSystem.d.ts.map +1 -1
  162. package/src/engine/physics/cloth/ecs/ClothColliderSystem.js +3 -12
  163. package/src/engine/physics/cloth/ecs/ClothDynamicsFlags.js +6 -0
  164. package/src/engine/physics/cloth/ecs/ClothHold.d.ts +91 -0
  165. package/src/engine/physics/cloth/ecs/ClothHold.d.ts.map +1 -0
  166. package/src/engine/physics/cloth/ecs/ClothHold.js +103 -0
  167. package/src/engine/physics/cloth/ecs/ClothInstance.d.ts +254 -48
  168. package/src/engine/physics/cloth/ecs/ClothInstance.d.ts.map +1 -1
  169. package/src/engine/physics/cloth/ecs/ClothInstance.js +277 -47
  170. package/src/engine/physics/cloth/ecs/ClothPin.d.ts +73 -0
  171. package/src/engine/physics/cloth/ecs/ClothPin.d.ts.map +1 -0
  172. package/src/engine/physics/cloth/ecs/ClothPin.js +92 -0
  173. package/src/engine/physics/cloth/ecs/ClothPinSerializationAdapter.d.ts +36 -0
  174. package/src/engine/physics/cloth/ecs/ClothPinSerializationAdapter.d.ts.map +1 -0
  175. package/src/engine/physics/cloth/ecs/ClothPinSerializationAdapter.js +61 -0
  176. package/src/engine/physics/cloth/ecs/ClothRig.d.ts +23 -17
  177. package/src/engine/physics/cloth/ecs/ClothRig.d.ts.map +1 -1
  178. package/src/engine/physics/cloth/ecs/ClothRig.js +29 -27
  179. package/src/engine/physics/cloth/ecs/ClothSystem.d.ts +12 -14
  180. package/src/engine/physics/cloth/ecs/ClothSystem.d.ts.map +1 -1
  181. package/src/engine/physics/cloth/ecs/ClothSystem.js +20 -15
  182. package/src/engine/physics/cloth/ecs/ClothWorld.d.ts +57 -36
  183. package/src/engine/physics/cloth/ecs/ClothWorld.d.ts.map +1 -1
  184. package/src/engine/physics/cloth/ecs/ClothWorld.js +754 -207
  185. package/src/engine/physics/cloth/ecs/WorkerClothSystem.d.ts +12 -13
  186. package/src/engine/physics/cloth/ecs/WorkerClothSystem.d.ts.map +1 -1
  187. package/src/engine/physics/cloth/ecs/WorkerClothSystem.js +20 -14
  188. package/src/engine/physics/cloth/ecs/cloth_build_rows.d.ts +63 -11
  189. package/src/engine/physics/cloth/ecs/cloth_build_rows.d.ts.map +1 -1
  190. package/src/engine/physics/cloth/ecs/cloth_build_rows.js +297 -101
  191. package/src/engine/physics/cloth/ecs/cloth_dynamics_map.d.ts +9 -7
  192. package/src/engine/physics/cloth/ecs/cloth_dynamics_map.d.ts.map +1 -1
  193. package/src/engine/physics/cloth/ecs/cloth_dynamics_map.js +12 -10
  194. package/src/engine/physics/cloth/ecs/cloth_gather_colliders.d.ts +3 -3
  195. package/src/engine/physics/cloth/ecs/cloth_gather_colliders.d.ts.map +1 -1
  196. package/src/engine/physics/cloth/ecs/cloth_gather_colliders.js +60 -120
  197. package/src/engine/physics/cloth/ecs/cloth_geodesic.d.ts +37 -0
  198. package/src/engine/physics/cloth/ecs/cloth_geodesic.d.ts.map +1 -0
  199. package/src/engine/physics/cloth/ecs/cloth_geodesic.js +135 -0
  200. package/src/engine/physics/cloth/ecs/cloth_holds.d.ts +97 -0
  201. package/src/engine/physics/cloth/ecs/cloth_holds.d.ts.map +1 -0
  202. package/src/engine/physics/cloth/ecs/cloth_holds.js +583 -0
  203. package/src/engine/physics/cloth/ecs/cloth_reconstruct_pose.d.ts +2 -2
  204. package/src/engine/physics/cloth/ecs/cloth_reconstruct_pose.d.ts.map +1 -1
  205. package/src/engine/physics/cloth/ecs/cloth_reconstruct_pose.js +168 -51
  206. package/src/engine/physics/cloth/ecs/cloth_seed_rig.d.ts +17 -22
  207. package/src/engine/physics/cloth/ecs/cloth_seed_rig.d.ts.map +1 -1
  208. package/src/engine/physics/cloth/ecs/cloth_seed_rig.js +55 -117
  209. package/src/engine/physics/cloth/ecs/cloth_seed_subtree.d.ts +21 -6
  210. package/src/engine/physics/cloth/ecs/cloth_seed_subtree.d.ts.map +1 -1
  211. package/src/engine/physics/cloth/ecs/cloth_seed_subtree.js +51 -42
  212. package/src/engine/physics/cloth/ecs/cloth_write_back.d.ts +5 -0
  213. package/src/engine/physics/cloth/ecs/cloth_write_back.d.ts.map +1 -1
  214. package/src/engine/physics/cloth/ecs/cloth_write_back.js +62 -50
  215. package/src/engine/physics/cloth/ecs/cloth_write_back_rig.d.ts.map +1 -1
  216. package/src/engine/physics/cloth/ecs/cloth_write_back_rig.js +65 -58
  217. package/src/engine/physics/cloth/playground/cloth_playground_build.d.ts.map +1 -1
  218. package/src/engine/physics/cloth/playground/cloth_playground_build.js +2 -3
  219. package/src/engine/physics/cloth/playground/collide_main.js +3 -29
  220. package/src/engine/physics/cloth/playground/garment_build.d.ts.map +1 -1
  221. package/src/engine/physics/cloth/playground/garment_build.js +17 -5
  222. package/src/engine/physics/cloth/playground/garment_main.js +5 -20
  223. package/src/engine/physics/cloth/playground/main.js +6 -48
  224. package/src/engine/physics/cloth/playground/rig_build.d.ts.map +1 -1
  225. package/src/engine/physics/cloth/playground/rig_build.js +302 -296
  226. package/src/engine/physics/cloth/playground/rig_main.js +947 -955
  227. package/src/engine/physics/cloth/playground/wind_main.js +8 -7
  228. package/src/engine/physics/cloth/solver/ClothState.d.ts +45 -7
  229. package/src/engine/physics/cloth/solver/ClothState.d.ts.map +1 -1
  230. package/src/engine/physics/cloth/solver/ClothState.js +79 -83
  231. package/src/engine/physics/cloth/solver/cloth_color_particles.d.ts +10 -8
  232. package/src/engine/physics/cloth/solver/cloth_color_particles.d.ts.map +1 -1
  233. package/src/engine/physics/cloth/solver/cloth_color_particles.js +30 -102
  234. package/src/engine/physics/cloth/solver/cloth_contact_find.d.ts +6 -1
  235. package/src/engine/physics/cloth/solver/cloth_contact_find.d.ts.map +1 -1
  236. package/src/engine/physics/cloth/solver/cloth_contact_find.js +9 -3
  237. package/src/engine/physics/cloth/solver/cloth_hold_line.d.ts +114 -0
  238. package/src/engine/physics/cloth/solver/cloth_hold_line.d.ts.map +1 -0
  239. package/src/engine/physics/cloth/solver/cloth_hold_line.js +350 -0
  240. package/src/engine/physics/cloth/solver/cloth_kinetic_energy.d.ts +21 -0
  241. package/src/engine/physics/cloth/solver/cloth_kinetic_energy.d.ts.map +1 -0
  242. package/src/engine/physics/cloth/solver/cloth_kinetic_energy.js +45 -0
  243. package/src/engine/physics/cloth/solver/cloth_particle_coupling.d.ts +32 -0
  244. package/src/engine/physics/cloth/solver/cloth_particle_coupling.d.ts.map +1 -0
  245. package/src/engine/physics/cloth/solver/cloth_particle_coupling.js +133 -0
  246. package/src/engine/physics/cloth/solver/cloth_particle_of_source.d.ts +16 -0
  247. package/src/engine/physics/cloth/solver/cloth_particle_of_source.d.ts.map +1 -0
  248. package/src/engine/physics/cloth/solver/cloth_particle_of_source.js +19 -0
  249. package/src/engine/physics/cloth/solver/cloth_self_find.d.ts +6 -2
  250. package/src/engine/physics/cloth/solver/cloth_self_find.d.ts.map +1 -1
  251. package/src/engine/physics/cloth/solver/cloth_self_find.js +19 -68
  252. package/src/engine/physics/cloth/solver/cloth_solve_vertex.d.ts.map +1 -1
  253. package/src/engine/physics/cloth/solver/cloth_solve_vertex.js +30 -65
  254. package/src/engine/physics/cloth/solver/cloth_solver_constants.d.ts +24 -12
  255. package/src/engine/physics/cloth/solver/cloth_solver_constants.d.ts.map +1 -1
  256. package/src/engine/physics/cloth/solver/cloth_solver_constants.js +24 -12
  257. package/src/engine/physics/cloth/solver/cloth_step.d.ts +16 -0
  258. package/src/engine/physics/cloth/solver/cloth_step.d.ts.map +1 -1
  259. package/src/engine/physics/cloth/solver/cloth_step.js +189 -48
  260. package/src/engine/physics/cloth/solver/cloth_step_instance.d.ts +1 -0
  261. package/src/engine/physics/cloth/solver/cloth_step_instance.d.ts.map +1 -1
  262. package/src/engine/physics/cloth/solver/cloth_step_instance.js +12 -6
  263. package/src/engine/physics/cloth/solver/cloth_stretch_residual.d.ts +21 -0
  264. package/src/engine/physics/cloth/solver/cloth_stretch_residual.d.ts.map +1 -0
  265. package/src/engine/physics/cloth/solver/cloth_stretch_residual.js +54 -0
  266. package/src/engine/physics/cloth/solver/cloth_vertex_accumulator.d.ts +15 -0
  267. package/src/engine/physics/cloth/solver/cloth_vertex_accumulator.d.ts.map +1 -1
  268. package/src/engine/physics/cloth/solver/cloth_vertex_accumulator.js +28 -0
  269. package/src/engine/physics/cloth/solver/cloth_worst_tether_ratio.d.ts +30 -0
  270. package/src/engine/physics/cloth/solver/cloth_worst_tether_ratio.d.ts.map +1 -0
  271. package/src/engine/physics/cloth/solver/cloth_worst_tether_ratio.js +56 -0
  272. package/src/engine/physics/cloth/solver/constraint/cloth_contact_row.d.ts.map +1 -1
  273. package/src/engine/physics/cloth/solver/constraint/cloth_contact_row.js +3 -17
  274. package/src/engine/physics/cloth/solver/constraint/cloth_leash_row.d.ts +1 -1
  275. package/src/engine/physics/cloth/solver/constraint/cloth_leash_row.d.ts.map +1 -1
  276. package/src/engine/physics/cloth/solver/constraint/cloth_leash_row.js +353 -346
  277. package/src/engine/physics/cloth/solver/constraint/cloth_self_row.d.ts +7 -5
  278. package/src/engine/physics/cloth/solver/constraint/cloth_self_row.d.ts.map +1 -1
  279. package/src/engine/physics/cloth/solver/constraint/cloth_self_row.js +7 -5
  280. package/src/engine/physics/cloth/wind/ClothFluidWind.d.ts +2 -1
  281. package/src/engine/physics/cloth/wind/ClothFluidWind.d.ts.map +1 -1
  282. package/src/engine/physics/cloth/wind/ClothFluidWind.js +7 -25
  283. package/src/engine/physics/cloth/wind/cloth_sample_air.d.ts +12 -10
  284. package/src/engine/physics/cloth/wind/cloth_sample_air.d.ts.map +1 -1
  285. package/src/engine/physics/cloth/wind/cloth_sample_air.js +60 -82
  286. package/src/engine/physics/ecs/ContactProbeSystem.d.ts.map +1 -1
  287. package/src/engine/physics/ecs/ContactProbeSystem.js +2 -18
  288. package/src/engine/physics/ecs/PhysicsSystem.d.ts.map +1 -1
  289. package/src/engine/physics/ecs/PhysicsSystem.js +9 -50
  290. package/src/engine/physics/fluid/ecs/FluidObstacleSystem.d.ts +4 -4
  291. package/src/engine/physics/fluid/ecs/fluid_sample_domain_bounds.d.ts +24 -0
  292. package/src/engine/physics/fluid/ecs/fluid_sample_domain_bounds.d.ts.map +1 -0
  293. package/src/engine/physics/fluid/ecs/fluid_sample_domain_bounds.js +42 -0
  294. package/src/engine/physics/fluid/ecs/fluid_sample_velocity_world_mps.d.ts +25 -0
  295. package/src/engine/physics/fluid/ecs/fluid_sample_velocity_world_mps.d.ts.map +1 -0
  296. package/src/engine/physics/fluid/ecs/fluid_sample_velocity_world_mps.js +40 -0
  297. package/src/engine/physics/inverse_kinematics/frame_fabrik/frame_fabrik_solve.d.ts.map +1 -1
  298. package/src/engine/physics/inverse_kinematics/frame_fabrik/frame_fabrik_solve.js +40 -90
  299. package/src/engine/physics/narrowphase/capsule_contacts.d.ts.map +1 -1
  300. package/src/engine/physics/narrowphase/capsule_contacts.js +3 -5
  301. package/src/engine/physics/narrowphase/decomposition/mesh_enumerate_triangles.d.ts.map +1 -1
  302. package/src/engine/physics/narrowphase/decomposition/mesh_enumerate_triangles.js +2 -14
  303. package/src/engine/physics/narrowphase/hull_sphere_contact.d.ts.map +1 -1
  304. package/src/engine/physics/narrowphase/hull_sphere_contact.js +2 -5
  305. package/src/engine/physics/narrowphase/narrowphase_step.d.ts.map +1 -1
  306. package/src/engine/physics/narrowphase/narrowphase_step.js +13 -32
  307. package/src/engine/physics/narrowphase/sphere_box_contact.d.ts.map +1 -1
  308. package/src/engine/physics/narrowphase/sphere_box_contact.js +2 -5
  309. package/src/engine/simulation/Ticker.d.ts +13 -0
  310. package/src/engine/simulation/Ticker.d.ts.map +1 -1
  311. package/src/engine/simulation/Ticker.js +43 -8
  312. package/src/format/texture/basis/transcode/etc1s_to_astc.d.ts.map +1 -1
  313. package/src/format/texture/basis/transcode/etc1s_to_astc.js +2 -1
  314. package/src/shade/RENDERER_CONTRACT.md +8 -2
  315. package/src/shade/playground/image_decode_bench/main.js +2 -1
  316. package/src/shade/playground/mesh_row_ceiling/main.js +2 -1
  317. package/src/shade/playground/skinned_blas_refit/diff_traced_against_rasterized.d.ts.map +1 -1
  318. package/src/shade/playground/skinned_blas_refit/diff_traced_against_rasterized.js +2 -1
  319. package/src/shade/playground/skinned_blas_refit/main.d.ts.map +1 -1
  320. package/src/shade/playground/skinned_blas_refit/main.js +11 -19
  321. package/src/shade/playground/skinned_blas_refit/place_character.d.ts +6 -3
  322. package/src/shade/playground/skinned_blas_refit/place_character.d.ts.map +1 -1
  323. package/src/shade/playground/skinned_blas_refit/place_character.js +90 -90
  324. package/src/shade/playground/skinned_mesh_soup/main.d.ts.map +1 -1
  325. package/src/shade/playground/skinned_mesh_soup/main.js +502 -509
  326. package/src/shade/playground/skinned_mesh_soup/verify_clone_vertices.d.ts.map +1 -1
  327. package/src/shade/playground/skinned_mesh_soup/verify_clone_vertices.js +2 -1
  328. package/src/shade/playground/ssr_variance/statistics.d.ts.map +1 -1
  329. package/src/shade/playground/ssr_variance/statistics.js +2 -1
  330. package/src/shade/playground/texture_encode/README.md +129 -109
  331. package/src/shade/playground/texture_encode/main.d.ts.map +1 -1
  332. package/src/shade/playground/texture_encode/main.js +1431 -1430
  333. package/src/shade/playground/volumetrics_froxel/measure.d.ts.map +1 -1
  334. package/src/shade/playground/volumetrics_froxel/measure.js +2 -1
  335. package/src/shade/renderer/animation/GPUAnimationManager.d.ts +45 -14
  336. package/src/shade/renderer/animation/GPUAnimationManager.d.ts.map +1 -1
  337. package/src/shade/renderer/animation/GPUAnimationManager.js +316 -64
  338. package/src/shade/renderer/animation/skinning/GPUMeshSkinningContext.d.ts +5 -0
  339. package/src/shade/renderer/animation/skinning/GPUMeshSkinningContext.d.ts.map +1 -1
  340. package/src/shade/renderer/animation/skinning/GPUMeshSkinningContext.js +11 -1
  341. package/src/shade/renderer/buffer/table/gpu_database_check_links.d.ts.map +1 -1
  342. package/src/shade/renderer/buffer/table/gpu_database_check_links.js +2 -1
  343. package/src/shade/renderer/geometry/BoxGeometry.d.ts +1 -11
  344. package/src/shade/renderer/geometry/BoxGeometry.d.ts.map +1 -1
  345. package/src/shade/renderer/geometry/BoxGeometry.js +6 -13
  346. package/src/shade/renderer/geometry/CapsuleGeometry.d.ts +19 -0
  347. package/src/shade/renderer/geometry/CapsuleGeometry.d.ts.map +1 -0
  348. package/src/shade/renderer/geometry/CapsuleGeometry.js +24 -0
  349. package/src/shade/renderer/geometry/ConeGeometry.d.ts +20 -0
  350. package/src/shade/renderer/geometry/ConeGeometry.d.ts.map +1 -0
  351. package/src/shade/renderer/geometry/ConeGeometry.js +33 -0
  352. package/src/shade/renderer/geometry/CylinderGeometry.d.ts +21 -0
  353. package/src/shade/renderer/geometry/CylinderGeometry.d.ts.map +1 -0
  354. package/src/shade/renderer/geometry/CylinderGeometry.js +35 -0
  355. package/src/shade/renderer/geometry/PlaneGeometry.d.ts +17 -0
  356. package/src/shade/renderer/geometry/PlaneGeometry.d.ts.map +1 -0
  357. package/src/shade/renderer/geometry/PlaneGeometry.js +22 -0
  358. package/src/shade/renderer/geometry/TorusGeometry.d.ts +18 -0
  359. package/src/shade/renderer/geometry/TorusGeometry.d.ts.map +1 -0
  360. package/src/shade/renderer/geometry/TorusGeometry.js +23 -0
  361. package/src/shade/renderer/geometry/UVSphereGeometry.d.ts +21 -0
  362. package/src/shade/renderer/geometry/UVSphereGeometry.d.ts.map +1 -0
  363. package/src/shade/renderer/geometry/UVSphereGeometry.js +34 -0
  364. package/src/shade/renderer/geometry/primitives/make_capsule_geometry.d.ts +19 -0
  365. package/src/shade/renderer/geometry/primitives/make_capsule_geometry.d.ts.map +1 -0
  366. package/src/shade/renderer/geometry/primitives/make_capsule_geometry.js +205 -0
  367. package/src/shade/renderer/geometry/primitives/make_cone_geometry.d.ts +21 -0
  368. package/src/shade/renderer/geometry/primitives/make_cone_geometry.d.ts.map +1 -0
  369. package/src/shade/renderer/geometry/primitives/make_cone_geometry.js +36 -0
  370. package/src/shade/renderer/geometry/primitives/make_cylinder_geometry.d.ts +1 -1
  371. package/src/shade/renderer/geometry/primitives/make_cylinder_geometry.d.ts.map +1 -1
  372. package/src/shade/renderer/geometry/primitives/make_cylinder_geometry.js +44 -9
  373. package/src/shade/renderer/geometry/primitives/make_uv_sphere_geometry.d.ts +20 -0
  374. package/src/shade/renderer/geometry/primitives/make_uv_sphere_geometry.d.ts.map +1 -0
  375. package/src/shade/renderer/geometry/primitives/make_uv_sphere_geometry.js +190 -0
  376. package/src/shade/renderer/geometry/virtual/build/level/vgeo_build_group_step.d.ts.map +1 -1
  377. package/src/shade/renderer/geometry/virtual/build/level/vgeo_build_group_step.js +3 -2
  378. package/src/shade/renderer/geometry/virtual/build/level/vgeo_build_leaf_frontier.d.ts.map +1 -1
  379. package/src/shade/renderer/geometry/virtual/build/level/vgeo_build_leaf_frontier.js +2 -1
  380. package/src/shade/renderer/geometry/virtual/build/level/vgeo_partition_into_groups.d.ts.map +1 -1
  381. package/src/shade/renderer/geometry/virtual/build/level/vgeo_partition_into_groups.js +2 -1
  382. package/src/shade/renderer/geometry/virtual/build/level/vgeo_run_round.d.ts.map +1 -1
  383. package/src/shade/renderer/geometry/virtual/build/level/vgeo_run_round.js +2 -1
  384. package/src/shade/renderer/geometry/virtual/build/level/vgeo_try_repack.d.ts.map +1 -1
  385. package/src/shade/renderer/geometry/virtual/build/level/vgeo_try_repack.js +3 -2
  386. package/src/shade/renderer/geometry/virtual/build/partition/vgeo_graph_components.d.ts.map +1 -1
  387. package/src/shade/renderer/geometry/virtual/build/partition/vgeo_graph_components.js +2 -1
  388. package/src/shade/renderer/geometry/virtual/build/partition/vgeo_split_face_set_packed.d.ts.map +1 -1
  389. package/src/shade/renderer/geometry/virtual/build/partition/vgeo_split_face_set_packed.js +2 -1
  390. package/src/shade/renderer/geometry/virtual/format/vgeo_write_container.d.ts.map +1 -1
  391. package/src/shade/renderer/geometry/virtual/format/vgeo_write_container.js +3 -2
  392. package/src/shade/renderer/geometry/virtual/runtime/graph_vgeo_expand_instances_to_meshlets.d.ts.map +1 -1
  393. package/src/shade/renderer/geometry/virtual/runtime/graph_vgeo_expand_instances_to_meshlets.js +7 -2
  394. package/src/shade/renderer/gpu_primitive/prefix_sum/v1/graph_prefix_scan_csdldf.d.ts +26 -8
  395. package/src/shade/renderer/gpu_primitive/prefix_sum/v1/graph_prefix_scan_csdldf.d.ts.map +1 -1
  396. package/src/shade/renderer/gpu_primitive/prefix_sum/v1/graph_prefix_scan_csdldf.js +56 -39
  397. package/src/shade/renderer/gpu_primitive/prefix_sum/v1/shader_prefix_scan_csdldf.d.ts +7 -0
  398. package/src/shade/renderer/gpu_primitive/prefix_sum/v1/shader_prefix_scan_csdldf.d.ts.map +1 -1
  399. package/src/shade/renderer/gpu_primitive/prefix_sum/v1/shader_prefix_scan_csdldf.js +46 -4
  400. package/src/shade/renderer/gpu_primitive/prefix_sum/v1/test_prefix_sum.d.ts.map +1 -1
  401. package/src/shade/renderer/gpu_primitive/prefix_sum/v1/test_prefix_sum.js +4 -2
  402. package/src/shade/renderer/gpu_primitive/sort/defs.d.ts +2 -2
  403. package/src/shade/renderer/gpu_primitive/sort/defs.js +79 -79
  404. package/src/shade/renderer/gpu_primitive/sort/graph_radix_sort.d.ts +1 -1
  405. package/src/shade/renderer/gpu_primitive/sort/graph_radix_sort.d.ts.map +1 -1
  406. package/src/shade/renderer/gpu_primitive/sort/graph_radix_sort.js +7 -3
  407. package/src/shade/renderer/particles/GPUParticleSystem.js +1 -1
  408. package/src/shade/renderer/particles/coherence/graph_particle_bucket.d.ts +4 -3
  409. package/src/shade/renderer/particles/coherence/graph_particle_bucket.d.ts.map +1 -1
  410. package/src/shade/renderer/particles/coherence/graph_particle_bucket.js +200 -194
  411. package/src/shade/renderer/particles/graph_particles.d.ts.map +1 -1
  412. package/src/shade/renderer/particles/graph_particles.js +6 -2
  413. package/src/shade/renderer/particles/optimizer/dag/particle_vector_extract.d.ts.map +1 -1
  414. package/src/shade/renderer/particles/optimizer/dag/particle_vector_extract.js +3 -2
  415. package/src/shade/renderer/particles/warmup/graph_particle_warmup.d.ts.map +1 -1
  416. package/src/shade/renderer/particles/warmup/graph_particle_warmup.js +334 -329
  417. package/src/shade/renderer/rasterize/bucket/prepare_meshlet_draw_commands_by_material.d.ts.map +1 -1
  418. package/src/shade/renderer/rasterize/bucket/prepare_meshlet_draw_commands_by_material.js +7 -2
  419. package/src/shade/renderer/rasterize/expand/mesh/graph_expand_meshes_to_meshlets.d.ts.map +1 -1
  420. package/src/shade/renderer/rasterize/expand/mesh/graph_expand_meshes_to_meshlets.js +16 -4
  421. package/src/shade/renderer/texture/COMPRESSED_TEXTURE_PLAN_2026_09_01.md +2444 -2345
  422. package/src/shade/renderer/texture/encode/chunk_astc_encode_block_4x4_rgb.d.ts.map +1 -1
  423. package/src/shade/renderer/texture/encode/chunk_astc_encode_block_4x4_rgb.js +312 -310
  424. package/src/shade/renderer/texture/encode/chunk_bc1_encode_block.d.ts +3 -3
  425. package/src/shade/renderer/texture/encode/chunk_bc1_encode_block.d.ts.map +1 -1
  426. package/src/shade/renderer/texture/encode/chunk_bc1_encode_block.js +383 -375
  427. package/src/shade/renderer/texture/encode/chunk_bc6h_encode_block_mode11.d.ts.map +1 -1
  428. package/src/shade/renderer/texture/encode/chunk_bc6h_encode_block_mode11.js +349 -346
  429. package/src/shade/renderer/texture/encode/chunk_bc7_encode_block.d.ts +58 -0
  430. package/src/shade/renderer/texture/encode/chunk_bc7_encode_block.d.ts.map +1 -0
  431. package/src/shade/renderer/texture/encode/chunk_bc7_encode_block.js +536 -0
  432. package/src/shade/renderer/texture/encode/chunk_bc7_encode_block_mode6.d.ts +21 -7
  433. package/src/shade/renderer/texture/encode/chunk_bc7_encode_block_mode6.d.ts.map +1 -1
  434. package/src/shade/renderer/texture/encode/chunk_bc7_encode_block_mode6.js +291 -327
  435. package/src/shade/renderer/texture/encode/chunk_bc7_pack_mode1.d.ts +25 -0
  436. package/src/shade/renderer/texture/encode/chunk_bc7_pack_mode1.d.ts.map +1 -0
  437. package/src/shade/renderer/texture/encode/chunk_bc7_pack_mode1.js +99 -0
  438. package/src/shade/renderer/texture/encode/chunk_bc7_pack_mode6.d.ts +5 -3
  439. package/src/shade/renderer/texture/encode/chunk_bc7_pack_mode6.d.ts.map +1 -1
  440. package/src/shade/renderer/texture/encode/chunk_bc7_pack_mode6.js +47 -71
  441. package/src/shade/renderer/texture/encode/chunk_bc7_partition_2.d.ts +10 -0
  442. package/src/shade/renderer/texture/encode/chunk_bc7_partition_2.d.ts.map +1 -0
  443. package/src/shade/renderer/texture/encode/chunk_bc7_partition_2.js +50 -0
  444. package/src/shade/renderer/texture/encode/shader_texture_encode_bc7.d.ts +4 -5
  445. package/src/shade/renderer/texture/encode/shader_texture_encode_bc7.d.ts.map +1 -1
  446. package/src/shade/renderer/texture/encode/shader_texture_encode_bc7.js +7 -8
  447. package/src/shade/renderer/water/chunk_water_transport.d.ts.map +1 -1
  448. package/src/shade/renderer/water/chunk_water_transport.js +7 -5
  449. package/src/shade/renderer/water/medium/GPUWaterBodies.d.ts.map +1 -1
  450. package/src/shade/renderer/water/medium/GPUWaterBodies.js +8 -2
  451. package/src/shade/renderer/water/optics/chunk_water_receiver_downwelling.d.ts +3 -2
  452. package/src/shade/renderer/water/optics/chunk_water_receiver_downwelling.d.ts.map +1 -1
  453. package/src/shade/renderer/water/optics/chunk_water_receiver_downwelling.js +3 -2
  454. package/src/shade/renderer/water/shader_water.d.ts.map +1 -1
  455. package/src/shade/renderer/water/shader_water.js +3 -1
  456. package/src/shade/renderer/water/surface/GPUWaterSurface.d.ts.map +1 -1
  457. package/src/shade/renderer/water/surface/GPUWaterSurface.js +3 -1
  458. package/src/shade/renderer/water/surface/graph_water_tessellation.d.ts.map +1 -1
  459. package/src/shade/renderer/water/surface/graph_water_tessellation.js +11 -4
  460. package/src/shade/renderer/water/surface/particles/GPUWaterParticles.d.ts.map +1 -1
  461. package/src/shade/renderer/water/surface/particles/GPUWaterParticles.js +37 -20
  462. package/src/shade/wgsl/validate_wgsl_source.d.ts.map +1 -1
  463. package/src/shade/wgsl/validate_wgsl_source.js +74 -3
  464. package/src/engine/graphics3/register_instance_animation.d.ts +0 -114
  465. package/src/engine/graphics3/register_instance_animation.d.ts.map +0 -1
  466. package/src/engine/graphics3/register_instance_animation.js +0 -201
@@ -1,346 +1,349 @@
1
- import { CodeChunk } from "../../shader/compiler/CodeChunk.js";
2
- import { chunk_bc6h_pack_mode11 } from "./chunk_bc6h_pack_mode11.js";
3
-
4
- /**
5
- * Encode sixteen HDR RGB texels as one BC6H block in mode 11, the unsigned format.
6
- *
7
- * **The line is fitted in the half-float bit domain, because that is the domain the decoder
8
- * interpolates in.** A BC6H endpoint is a half-float bit pattern quantised to ten bits; the decoder
9
- * unquantises it to a sixteen-bit integer, interpolates the two ends linearly with BC7's four-bit
10
- * weights, scales the result by 31/64 and reinterprets the integer *as a half*. So the palette is
11
- * linear in bit patterns, not in values — which is a log-like scale, sixteen steps between two
12
- * ends a few octaves apart being spaced by ratio rather than by difference. Fitting in that domain
13
- * is what Narkowicz's real-time BC6H does with `f32tof16` before anything else, and it is why an
14
- * error measured there is a relative error, which is what an HDR image wants judged.
15
- *
16
- * The fit is {@link chunk_bc1_encode_block}'s line in that domain: the principal axis, the extreme
17
- * projections, two rounds of least squares with the sixteen decode weights, then quantisation to
18
- * ten bits and one round of coordinate descent over the six stored components, every candidate
19
- * scored against the palette the decoder builds. The anchor is honoured by writing the block the
20
- * other way up when texel 0 lands in the upper half.
21
- *
22
- * **Mode 11 only.** It has the finest endpoints of the one-region modes and no delta to fit; the
23
- * two-region modes are where a hard edge inside a block would gain, and they are a later chunk. On
24
- * the environment maps the format exists for, Narkowicz measured his mode-11-only fast path within
25
- * reach of offline encoders' fast presets.
26
- *
27
- * Half floats hold no infinity or NaN here and no sign: a negative texel clamps to zero, and
28
- * anything over the largest finite half to that. The conversion to half bits is written out rather
29
- * than taken from `pack2x16float`, so that the emulator and every device round the same way.
30
- *
31
- * @type {CodeChunk}
32
- */
33
- export const chunk_bc6h_encode_block_mode11 = CodeChunk.from(
34
- //language=WGSL
35
- `
36
- // the bit pattern of the half nearest a non-negative finite value, ties to even, as f32tof16 gives
37
- fn bc6h_half_bits(x: f32) -> f32 {
38
- let v = clamp(select(x, 0.0, x != x), 0.0, 65504.0);
39
-
40
- if (v == 0.0) {
41
- return 0.0;
42
- }
43
-
44
- let bits = bitcast<u32>(v);
45
- let exponent = i32((bits >> 23u) & 0xFFu) - 127;
46
-
47
- // a half's subnormals count in units of 2^-24; the tie goes to even, written out because the
48
- // emulator's round is half-up and a device's is half-even
49
- if (exponent < -14) {
50
- let scaled = v * 16777216.0;
51
- let whole = floor(scaled);
52
- let fraction = scaled - whole;
53
-
54
- let up = fraction > 0.5 || (fraction == 0.5 && (u32(whole) & 1u) == 1u);
55
-
56
- return whole + select(0.0, 1.0, up);
57
- }
58
-
59
- let mantissa = bits & 0x7FFFFFu;
60
- let kept = mantissa >> 13u;
61
- let dropped = mantissa & 0x1FFFu;
62
-
63
- var pattern = (u32(exponent + 15) << 10u) | kept;
64
-
65
- if (dropped > 0x1000u || (dropped == 0x1000u && (kept & 1u) == 1u)) {
66
- pattern += 1u;
67
- }
68
-
69
- return f32(min(pattern, 0x7BFFu));
70
- }
71
-
72
- // BC7's four-bit interpolation weights, which BC6H shares
73
- fn bc6h_weight4(index: u32) -> f32 {
74
- var weights = array<f32, 16>(0.0, 4.0, 9.0, 13.0, 17.0, 21.0, 26.0, 30.0, 34.0, 38.0, 43.0, 47.0, 51.0, 55.0, 60.0, 64.0);
75
-
76
- return weights[index];
77
- }
78
-
79
- // a ten-bit endpoint as the decoder unquantises it before interpolating
80
- fn bc6h_unquantize(q: vec3<f32>) -> vec3<f32> {
81
- let scaled = floor((q * 65536.0 + 32768.0) / 1024.0);
82
-
83
- return select(select(scaled, vec3<f32>(65535.0), q >= vec3<f32>(1023.0)), vec3<f32>(0.0), q <= vec3<f32>(0.0));
84
- }
85
-
86
- // a palette entry, as half bits, from two unquantised ends
87
- fn bc6h_palette_entry(u0: vec3<f32>, u1: vec3<f32>, index: u32) -> vec3<f32> {
88
- let w = bc6h_weight4(index);
89
-
90
- let interpolated = floor((u0 * (64.0 - w) + u1 * w + 32.0) / 64.0);
91
-
92
- return floor(interpolated * 31.0 / 64.0);
93
- }
94
-
95
- // a value in half bits quantised to the ten bits the block stores
96
- fn bc6h_quantize(bits: vec3<f32>) -> vec3<f32> {
97
- return clamp(round(bits * 1024.0 / 31744.0), vec3<f32>(0.0), vec3<f32>(1023.0));
98
- }
99
-
100
- // the index whose palette entry is nearest a texel, and the squared distance in half bits
101
- fn bc6h_nearest(u0: vec3<f32>, u1: vec3<f32>, texel: vec3<f32>) -> vec2<f32> {
102
- let p0 = bc6h_palette_entry(u0, u1, 0u);
103
- let p15 = bc6h_palette_entry(u0, u1, 15u);
104
-
105
- let direction = p15 - p0;
106
- let span = dot(direction, direction);
107
-
108
- var estimate = 0.0;
109
-
110
- if (span > 0.0) {
111
- estimate = clamp(round(dot(texel - p0, direction) / span * 15.0), 0.0, 15.0);
112
- }
113
-
114
- var best = estimate;
115
- var best_distance = 1e30;
116
-
117
- for (var offset = -1.0; offset <= 1.0; offset += 1.0) {
118
- let candidate = clamp(estimate + offset, 0.0, 15.0);
119
-
120
- let delta = bc6h_palette_entry(u0, u1, u32(candidate)) - texel;
121
- let distance = dot(delta, delta);
122
-
123
- if (distance < best_distance) {
124
- best_distance = distance;
125
- best = candidate;
126
- }
127
- }
128
-
129
- return vec2<f32>(best, best_distance);
130
- }
131
-
132
- fn bc6h_score(texels: array<vec3<f32>, 16>, q0: vec3<f32>, q1: vec3<f32>) -> f32 {
133
- let u0 = bc6h_unquantize(q0);
134
- let u1 = bc6h_unquantize(q1);
135
-
136
- var error = 0.0;
137
-
138
- for (var i = 0u; i < 16u; i++) {
139
- error += bc6h_nearest(u0, u1, texels[i]).y;
140
- }
141
-
142
- return error;
143
- }
144
-
145
- // the ends that best reproduce the texels at the weights they are nearest to on a real line
146
- fn bc6h_refine(texels: array<vec3<f32>, 16>, e0: vec3<f32>, e1: vec3<f32>) -> array<vec3<f32>, 2> {
147
- let direction = e1 - e0;
148
- let span = dot(direction, direction);
149
-
150
- var aa = 0.0;
151
- var ab = 0.0;
152
- var bb = 0.0;
153
- var ap = vec3<f32>(0.0);
154
- var bp = vec3<f32>(0.0);
155
-
156
- for (var i = 0u; i < 16u; i++) {
157
- var estimate = 0.0;
158
-
159
- if (span > 0.0) {
160
- estimate = clamp(round(dot(texels[i] - e0, direction) / span * 15.0), 0.0, 15.0);
161
- }
162
-
163
- var best_weight = 0.0;
164
- var best_distance = 1e30;
165
-
166
- for (var offset = -1.0; offset <= 1.0; offset += 1.0) {
167
- let candidate = clamp(estimate + offset, 0.0, 15.0);
168
- let weight = bc6h_weight4(u32(candidate)) / 64.0;
169
-
170
- let delta = mix(e0, e1, weight) - texels[i];
171
- let distance = dot(delta, delta);
172
-
173
- if (distance < best_distance) {
174
- best_distance = distance;
175
- best_weight = weight;
176
- }
177
- }
178
-
179
- let b = best_weight;
180
- let a = 1.0 - b;
181
-
182
- aa += a * a;
183
- ab += a * b;
184
- bb += b * b;
185
- ap += a * texels[i];
186
- bp += b * texels[i];
187
- }
188
-
189
- let determinant = aa * bb - ab * ab;
190
-
191
- var out: array<vec3<f32>, 2>;
192
-
193
- if (abs(determinant) < 1e-6) {
194
- out[0] = e0;
195
- out[1] = e1;
196
-
197
- return out;
198
- }
199
-
200
- out[0] = (bb * ap - ab * bp) / determinant;
201
- out[1] = (aa * bp - ab * ap) / determinant;
202
-
203
- return out;
204
- }
205
-
206
- fn bc6h_with_component(v: vec3<f32>, channel: u32, value: f32) -> vec3<f32> {
207
- return vec3<f32>(
208
- select(v.x, value, channel == 0u),
209
- select(v.y, value, channel == 1u),
210
- select(v.z, value, channel == 2u)
211
- );
212
- }
213
-
214
- fn bc6h_encode_block_mode11(texels: array<vec3<f32>, 16>) -> vec4<u32> {
215
- var bits: array<vec3<f32>, 16>;
216
-
217
- var low = vec3<f32>(65535.0);
218
- var high = vec3<f32>(0.0);
219
- var mean = vec3<f32>(0.0);
220
-
221
- for (var i = 0u; i < 16u; i++) {
222
- let v = vec3<f32>(bc6h_half_bits(texels[i].x), bc6h_half_bits(texels[i].y), bc6h_half_bits(texels[i].z));
223
-
224
- bits[i] = v;
225
- low = min(low, v);
226
- high = max(high, v);
227
- mean += v;
228
- }
229
-
230
- mean = mean / 16.0;
231
-
232
- let extent = high - low;
233
-
234
- var e0 = mean;
235
- var e1 = mean;
236
-
237
- if (max(extent.x, max(extent.y, extent.z)) >= 0.5) {
238
- var cov = array<f32, 6>(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
239
-
240
- for (var i = 0u; i < 16u; i++) {
241
- let d = bits[i] - mean;
242
-
243
- cov[0] += d.x * d.x;
244
- cov[1] += d.x * d.y;
245
- cov[2] += d.x * d.z;
246
- cov[3] += d.y * d.y;
247
- cov[4] += d.y * d.z;
248
- cov[5] += d.z * d.z;
249
- }
250
-
251
- var axis = extent;
252
-
253
- for (var iteration = 0u; iteration < 4u; iteration++) {
254
- let next = vec3<f32>(
255
- cov[0] * axis.x + cov[1] * axis.y + cov[2] * axis.z,
256
- cov[1] * axis.x + cov[3] * axis.y + cov[4] * axis.z,
257
- cov[2] * axis.x + cov[4] * axis.y + cov[5] * axis.z
258
- );
259
-
260
- let magnitude = length(next);
261
-
262
- if (magnitude < 1e-3) {
263
- break;
264
- }
265
-
266
- axis = next / magnitude;
267
- }
268
-
269
- axis = normalize(axis);
270
-
271
- var t_min = 1e30;
272
- var t_max = -1e30;
273
-
274
- for (var i = 0u; i < 16u; i++) {
275
- let t = dot(bits[i] - mean, axis);
276
-
277
- t_min = min(t_min, t);
278
- t_max = max(t_max, t);
279
- }
280
-
281
- e0 = mean + axis * t_min;
282
- e1 = mean + axis * t_max;
283
-
284
- for (var round = 0u; round < 2u; round++) {
285
- let refined = bc6h_refine(bits, e0, e1);
286
-
287
- e0 = clamp(refined[0], vec3<f32>(0.0), vec3<f32>(31743.0));
288
- e1 = clamp(refined[1], vec3<f32>(0.0), vec3<f32>(31743.0));
289
- }
290
- }
291
-
292
- var q0 = bc6h_quantize(e0);
293
- var q1 = bc6h_quantize(e1);
294
-
295
- var best = bc6h_score(bits, q0, q1);
296
-
297
- // coordinate descent over the six stored components, one round
298
- for (var component = 0u; component < 6u; component++) {
299
- let channel = component % 3u;
300
-
301
- for (var direction = -1.0; direction <= 1.0; direction += 2.0) {
302
- var c0 = q0;
303
- var c1 = q1;
304
-
305
- if (component < 3u) {
306
- c0 = bc6h_with_component(q0, channel, clamp(q0[channel] + direction, 0.0, 1023.0));
307
- } else {
308
- c1 = bc6h_with_component(q1, channel, clamp(q1[channel] + direction, 0.0, 1023.0));
309
- }
310
-
311
- let error = bc6h_score(bits, c0, c1);
312
-
313
- if (error < best) {
314
- best = error;
315
- q0 = c0;
316
- q1 = c1;
317
- }
318
- }
319
- }
320
-
321
- var indices: array<u32, 16>;
322
-
323
- let u0 = bc6h_unquantize(q0);
324
- let u1 = bc6h_unquantize(q1);
325
-
326
- for (var i = 0u; i < 16u; i++) {
327
- indices[i] = u32(bc6h_nearest(u0, u1, bits[i]).x);
328
- }
329
-
330
- // the anchor: texel 0's top bit is implied zero
331
- if (indices[0] >= 8u) {
332
- let swap = q0;
333
-
334
- q0 = q1;
335
- q1 = swap;
336
-
337
- for (var i = 0u; i < 16u; i++) {
338
- indices[i] = 15u - indices[i];
339
- }
340
- }
341
-
342
- return bc6h_pack_mode11(vec3<u32>(q0), vec3<u32>(q1), indices);
343
- }
344
- `, [
345
- chunk_bc6h_pack_mode11,
346
- ]);
1
+ import { CodeChunk } from "../../shader/compiler/CodeChunk.js";
2
+ import { chunk_bc6h_pack_mode11 } from "./chunk_bc6h_pack_mode11.js";
3
+
4
+ /**
5
+ * Encode sixteen HDR RGB texels as one BC6H block in mode 11, the unsigned format.
6
+ *
7
+ * **The line is fitted in the half-float bit domain, because that is the domain the decoder
8
+ * interpolates in.** A BC6H endpoint is a half-float bit pattern quantised to ten bits; the decoder
9
+ * unquantises it to a sixteen-bit integer, interpolates the two ends linearly with BC7's four-bit
10
+ * weights, scales the result by 31/64 and reinterprets the integer *as a half*. So the palette is
11
+ * linear in bit patterns, not in values — which is a log-like scale, sixteen steps between two
12
+ * ends a few octaves apart being spaced by ratio rather than by difference. Fitting in that domain
13
+ * is what Narkowicz's real-time BC6H does with `f32tof16` before anything else, and it is why an
14
+ * error measured there is a relative error, which is what an HDR image wants judged.
15
+ *
16
+ * The fit is {@link chunk_bc1_encode_block}'s line in that domain: the principal axis, the extreme
17
+ * projections, two rounds of least squares with the sixteen decode weights, then quantisation to
18
+ * ten bits and one round of coordinate descent over the six stored components, every candidate
19
+ * scored against the palette the decoder builds. The anchor is honoured by writing the block the
20
+ * other way up when texel 0 lands in the upper half.
21
+ *
22
+ * **Mode 11 only.** It has the finest endpoints of the one-region modes and no delta to fit; the
23
+ * two-region modes are where a hard edge inside a block would gain, and they are a later chunk. On
24
+ * the environment maps the format exists for, Narkowicz measured his mode-11-only fast path within
25
+ * reach of offline encoders' fast presets.
26
+ *
27
+ * Half floats hold no infinity or NaN here and no sign: a negative texel clamps to zero, and
28
+ * anything over the largest finite half to that. The conversion to half bits is written out rather
29
+ * than taken from `pack2x16float`, so that the emulator and every device round the same way.
30
+ *
31
+ * @type {CodeChunk}
32
+ */
33
+ export const chunk_bc6h_encode_block_mode11 = CodeChunk.from(
34
+ //language=WGSL
35
+ `
36
+ // the bit pattern of the half nearest a non-negative finite value, ties to even, as f32tof16 gives
37
+ fn bc6h_half_bits(x: f32) -> f32 {
38
+ let v = clamp(select(x, 0.0, x != x), 0.0, 65504.0);
39
+
40
+ if (v == 0.0) {
41
+ return 0.0;
42
+ }
43
+
44
+ let bits = bitcast<u32>(v);
45
+ let exponent = i32((bits >> 23u) & 0xFFu) - 127;
46
+
47
+ // a half's subnormals count in units of 2^-24; the tie goes to even, written out because the
48
+ // emulator's round is half-up and a device's is half-even
49
+ if (exponent < -14) {
50
+ let scaled = v * 16777216.0;
51
+ let whole = floor(scaled);
52
+ let fraction = scaled - whole;
53
+
54
+ let up = fraction > 0.5 || (fraction == 0.5 && (u32(whole) & 1u) == 1u);
55
+
56
+ return whole + select(0.0, 1.0, up);
57
+ }
58
+
59
+ let mantissa = bits & 0x7FFFFFu;
60
+ let kept = mantissa >> 13u;
61
+ let dropped = mantissa & 0x1FFFu;
62
+
63
+ var pattern = (u32(exponent + 15) << 10u) | kept;
64
+
65
+ if (dropped > 0x1000u || (dropped == 0x1000u && (kept & 1u) == 1u)) {
66
+ pattern += 1u;
67
+ }
68
+
69
+ return f32(min(pattern, 0x7BFFu));
70
+ }
71
+
72
+ // BC7's four-bit interpolation weights, which BC6H shares: 0, 4, 9, 13, 17, 21, 26, 30, 34, 38, 43,
73
+ // 47, 51, 55, 60, 64, every one of which this computes. Computed rather than looked up, as
74
+ // bc7_weight4 is: a function-local table indexed at run time lives in local memory, and it was an
75
+ // eighth of this encoder's time on a 4090
76
+ fn bc6h_weight4(index: u32) -> f32 {
77
+ return f32((index * 64u + 7u) / 15u);
78
+ }
79
+
80
+ // a ten-bit endpoint as the decoder unquantises it before interpolating
81
+ fn bc6h_unquantize(q: vec3<f32>) -> vec3<f32> {
82
+ let scaled = floor((q * 65536.0 + 32768.0) / 1024.0);
83
+
84
+ return select(select(scaled, vec3<f32>(65535.0), q >= vec3<f32>(1023.0)), vec3<f32>(0.0), q <= vec3<f32>(0.0));
85
+ }
86
+
87
+ // a palette entry, as half bits, from two unquantised ends
88
+ fn bc6h_palette_entry(u0: vec3<f32>, u1: vec3<f32>, index: u32) -> vec3<f32> {
89
+ let w = bc6h_weight4(index);
90
+
91
+ let interpolated = floor((u0 * (64.0 - w) + u1 * w + 32.0) / 64.0);
92
+
93
+ return floor(interpolated * 31.0 / 64.0);
94
+ }
95
+
96
+ // a value in half bits quantised to the ten bits the block stores
97
+ fn bc6h_quantize(bits: vec3<f32>) -> vec3<f32> {
98
+ return clamp(round(bits * 1024.0 / 31744.0), vec3<f32>(0.0), vec3<f32>(1023.0));
99
+ }
100
+
101
+ // the index whose palette entry is nearest a texel, and the squared distance in half bits
102
+ fn bc6h_nearest(u0: vec3<f32>, u1: vec3<f32>, texel: vec3<f32>) -> vec2<f32> {
103
+ let p0 = bc6h_palette_entry(u0, u1, 0u);
104
+ let p15 = bc6h_palette_entry(u0, u1, 15u);
105
+
106
+ let direction = p15 - p0;
107
+ let span = dot(direction, direction);
108
+
109
+ var estimate = 0.0;
110
+
111
+ if (span > 0.0) {
112
+ estimate = clamp(round(dot(texel - p0, direction) / span * 15.0), 0.0, 15.0);
113
+ }
114
+
115
+ var best = estimate;
116
+ var best_distance = 1e30;
117
+
118
+ // counted in integers: counted in floats, the same loops made the whole encoder a fifth slower on
119
+ // an RTX 4090, the bytes identical
120
+ for (var offset = -1; offset <= 1; offset++) {
121
+ let candidate = clamp(estimate + f32(offset), 0.0, 15.0);
122
+
123
+ let delta = bc6h_palette_entry(u0, u1, u32(candidate)) - texel;
124
+ let distance = dot(delta, delta);
125
+
126
+ if (distance < best_distance) {
127
+ best_distance = distance;
128
+ best = candidate;
129
+ }
130
+ }
131
+
132
+ return vec2<f32>(best, best_distance);
133
+ }
134
+
135
+ fn bc6h_score(texels: array<vec3<f32>, 16>, q0: vec3<f32>, q1: vec3<f32>) -> f32 {
136
+ let u0 = bc6h_unquantize(q0);
137
+ let u1 = bc6h_unquantize(q1);
138
+
139
+ var error = 0.0;
140
+
141
+ for (var i = 0u; i < 16u; i++) {
142
+ error += bc6h_nearest(u0, u1, texels[i]).y;
143
+ }
144
+
145
+ return error;
146
+ }
147
+
148
+ // the ends that best reproduce the texels at the weights they are nearest to on a real line
149
+ fn bc6h_refine(texels: array<vec3<f32>, 16>, e0: vec3<f32>, e1: vec3<f32>) -> array<vec3<f32>, 2> {
150
+ let direction = e1 - e0;
151
+ let span = dot(direction, direction);
152
+
153
+ var aa = 0.0;
154
+ var ab = 0.0;
155
+ var bb = 0.0;
156
+ var ap = vec3<f32>(0.0);
157
+ var bp = vec3<f32>(0.0);
158
+
159
+ for (var i = 0u; i < 16u; i++) {
160
+ var estimate = 0.0;
161
+
162
+ if (span > 0.0) {
163
+ estimate = clamp(round(dot(texels[i] - e0, direction) / span * 15.0), 0.0, 15.0);
164
+ }
165
+
166
+ var best_weight = 0.0;
167
+ var best_distance = 1e30;
168
+
169
+ for (var offset = -1; offset <= 1; offset++) {
170
+ let candidate = clamp(estimate + f32(offset), 0.0, 15.0);
171
+ let weight = bc6h_weight4(u32(candidate)) / 64.0;
172
+
173
+ let delta = mix(e0, e1, weight) - texels[i];
174
+ let distance = dot(delta, delta);
175
+
176
+ if (distance < best_distance) {
177
+ best_distance = distance;
178
+ best_weight = weight;
179
+ }
180
+ }
181
+
182
+ let b = best_weight;
183
+ let a = 1.0 - b;
184
+
185
+ aa += a * a;
186
+ ab += a * b;
187
+ bb += b * b;
188
+ ap += a * texels[i];
189
+ bp += b * texels[i];
190
+ }
191
+
192
+ let determinant = aa * bb - ab * ab;
193
+
194
+ var out: array<vec3<f32>, 2>;
195
+
196
+ if (abs(determinant) < 1e-6) {
197
+ out[0] = e0;
198
+ out[1] = e1;
199
+
200
+ return out;
201
+ }
202
+
203
+ out[0] = (bb * ap - ab * bp) / determinant;
204
+ out[1] = (aa * bp - ab * ap) / determinant;
205
+
206
+ return out;
207
+ }
208
+
209
+ fn bc6h_with_component(v: vec3<f32>, channel: u32, value: f32) -> vec3<f32> {
210
+ return vec3<f32>(
211
+ select(v.x, value, channel == 0u),
212
+ select(v.y, value, channel == 1u),
213
+ select(v.z, value, channel == 2u)
214
+ );
215
+ }
216
+
217
+ fn bc6h_encode_block_mode11(texels: array<vec3<f32>, 16>) -> vec4<u32> {
218
+ var bits: array<vec3<f32>, 16>;
219
+
220
+ var low = vec3<f32>(65535.0);
221
+ var high = vec3<f32>(0.0);
222
+ var mean = vec3<f32>(0.0);
223
+
224
+ for (var i = 0u; i < 16u; i++) {
225
+ let v = vec3<f32>(bc6h_half_bits(texels[i].x), bc6h_half_bits(texels[i].y), bc6h_half_bits(texels[i].z));
226
+
227
+ bits[i] = v;
228
+ low = min(low, v);
229
+ high = max(high, v);
230
+ mean += v;
231
+ }
232
+
233
+ mean = mean / 16.0;
234
+
235
+ let extent = high - low;
236
+
237
+ var e0 = mean;
238
+ var e1 = mean;
239
+
240
+ if (max(extent.x, max(extent.y, extent.z)) >= 0.5) {
241
+ var cov = array<f32, 6>(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
242
+
243
+ for (var i = 0u; i < 16u; i++) {
244
+ let d = bits[i] - mean;
245
+
246
+ cov[0] += d.x * d.x;
247
+ cov[1] += d.x * d.y;
248
+ cov[2] += d.x * d.z;
249
+ cov[3] += d.y * d.y;
250
+ cov[4] += d.y * d.z;
251
+ cov[5] += d.z * d.z;
252
+ }
253
+
254
+ var axis = extent;
255
+
256
+ for (var iteration = 0u; iteration < 4u; iteration++) {
257
+ let next = vec3<f32>(
258
+ cov[0] * axis.x + cov[1] * axis.y + cov[2] * axis.z,
259
+ cov[1] * axis.x + cov[3] * axis.y + cov[4] * axis.z,
260
+ cov[2] * axis.x + cov[4] * axis.y + cov[5] * axis.z
261
+ );
262
+
263
+ let magnitude = length(next);
264
+
265
+ if (magnitude < 1e-3) {
266
+ break;
267
+ }
268
+
269
+ axis = next / magnitude;
270
+ }
271
+
272
+ axis = normalize(axis);
273
+
274
+ var t_min = 1e30;
275
+ var t_max = -1e30;
276
+
277
+ for (var i = 0u; i < 16u; i++) {
278
+ let t = dot(bits[i] - mean, axis);
279
+
280
+ t_min = min(t_min, t);
281
+ t_max = max(t_max, t);
282
+ }
283
+
284
+ e0 = mean + axis * t_min;
285
+ e1 = mean + axis * t_max;
286
+
287
+ for (var round = 0u; round < 2u; round++) {
288
+ let refined = bc6h_refine(bits, e0, e1);
289
+
290
+ e0 = clamp(refined[0], vec3<f32>(0.0), vec3<f32>(31743.0));
291
+ e1 = clamp(refined[1], vec3<f32>(0.0), vec3<f32>(31743.0));
292
+ }
293
+ }
294
+
295
+ var q0 = bc6h_quantize(e0);
296
+ var q1 = bc6h_quantize(e1);
297
+
298
+ var best = bc6h_score(bits, q0, q1);
299
+
300
+ // coordinate descent over the six stored components, one round
301
+ for (var component = 0u; component < 6u; component++) {
302
+ let channel = component % 3u;
303
+
304
+ for (var direction = -1; direction <= 1; direction += 2) {
305
+ var c0 = q0;
306
+ var c1 = q1;
307
+
308
+ if (component < 3u) {
309
+ c0 = bc6h_with_component(q0, channel, clamp(q0[channel] + f32(direction), 0.0, 1023.0));
310
+ } else {
311
+ c1 = bc6h_with_component(q1, channel, clamp(q1[channel] + f32(direction), 0.0, 1023.0));
312
+ }
313
+
314
+ let error = bc6h_score(bits, c0, c1);
315
+
316
+ if (error < best) {
317
+ best = error;
318
+ q0 = c0;
319
+ q1 = c1;
320
+ }
321
+ }
322
+ }
323
+
324
+ var indices: array<u32, 16>;
325
+
326
+ let u0 = bc6h_unquantize(q0);
327
+ let u1 = bc6h_unquantize(q1);
328
+
329
+ for (var i = 0u; i < 16u; i++) {
330
+ indices[i] = u32(bc6h_nearest(u0, u1, bits[i]).x);
331
+ }
332
+
333
+ // the anchor: texel 0's top bit is implied zero
334
+ if (indices[0] >= 8u) {
335
+ let swap = q0;
336
+
337
+ q0 = q1;
338
+ q1 = swap;
339
+
340
+ for (var i = 0u; i < 16u; i++) {
341
+ indices[i] = 15u - indices[i];
342
+ }
343
+ }
344
+
345
+ return bc6h_pack_mode11(vec3<u32>(q0), vec3<u32>(q1), indices);
346
+ }
347
+ `, [
348
+ chunk_bc6h_pack_mode11,
349
+ ]);