@woosh/meep-engine 3.69.0 → 3.70.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 (398) hide show
  1. package/CHANGELOG.md +30 -1
  2. package/build/bundle-worker-terrain.js +1 -1
  3. package/package.json +1 -1
  4. package/src/core/bvh8/build/BVH8Converter.d.ts +16 -0
  5. package/src/core/bvh8/build/BVH8Converter.d.ts.map +1 -1
  6. package/src/core/bvh8/build/BVH8Converter.js +64 -37
  7. package/src/core/bvh8/build/bvh8_assign_slots_greedy.d.ts +25 -0
  8. package/src/core/bvh8/build/bvh8_assign_slots_greedy.d.ts.map +1 -0
  9. package/src/core/bvh8/build/bvh8_assign_slots_greedy.js +68 -0
  10. package/src/core/bvh8/build/bvh8_from_proxy.d.ts.map +1 -1
  11. package/src/core/bvh8/build/bvh8_from_proxy.js +2 -33
  12. package/src/core/bvh8/build/bvh8_node_fit_slots.d.ts +22 -0
  13. package/src/core/bvh8/build/bvh8_node_fit_slots.d.ts.map +1 -0
  14. package/src/core/bvh8/build/bvh8_node_fit_slots.js +115 -0
  15. package/src/core/bvh8/bvh8_depth.d.ts +8 -0
  16. package/src/core/bvh8/bvh8_depth.d.ts.map +1 -0
  17. package/src/core/bvh8/bvh8_depth.js +39 -0
  18. package/src/core/math/complex/complex_fft_radix2.d.ts +19 -0
  19. package/src/core/math/complex/complex_fft_radix2.d.ts.map +1 -0
  20. package/src/core/math/complex/complex_fft_radix2.js +71 -0
  21. package/src/engine/graphics3/GPUFluidSystem.d.ts +17 -4
  22. package/src/engine/graphics3/GPUFluidSystem.d.ts.map +1 -1
  23. package/src/engine/graphics3/GPUFluidSystem.js +113 -16
  24. package/src/engine/physics/cloth/playground/wind_main.js +7 -6
  25. package/src/engine/physics/cloth/wind/AbstractClothWind.d.ts +2 -2
  26. package/src/engine/physics/cloth/wind/AbstractClothWind.js +2 -2
  27. package/src/engine/physics/cloth/wind/ClothFluidWind.d.ts +3 -3
  28. package/src/engine/physics/cloth/wind/ClothFluidWind.d.ts.map +1 -1
  29. package/src/engine/physics/cloth/wind/ClothFluidWind.js +7 -9
  30. package/src/engine/physics/cloth/wind/ClothGPUFluidWind.d.ts +10 -10
  31. package/src/engine/physics/cloth/wind/ClothGPUFluidWind.d.ts.map +1 -1
  32. package/src/engine/physics/cloth/wind/ClothGPUFluidWind.js +14 -22
  33. package/src/engine/physics/fluid/FluidAtmosphere.d.ts +16 -2
  34. package/src/engine/physics/fluid/FluidAtmosphere.d.ts.map +1 -1
  35. package/src/engine/physics/fluid/FluidAtmosphere.js +17 -3
  36. package/src/engine/physics/fluid/ecs/FluidEffectorsComponentSerializationAdapter.d.ts +1 -2
  37. package/src/engine/physics/fluid/ecs/FluidEffectorsComponentSerializationAdapter.d.ts.map +1 -1
  38. package/src/engine/physics/fluid/ecs/FluidEffectorsComponentSerializationAdapter.js +1 -2
  39. package/src/engine/physics/fluid/ecs/FluidEffectorsSystem.d.ts +8 -5
  40. package/src/engine/physics/fluid/ecs/FluidEffectorsSystem.d.ts.map +1 -1
  41. package/src/engine/physics/fluid/ecs/FluidEffectorsSystem.js +60 -17
  42. package/src/engine/physics/fluid/effector/AbstractFluidEffector.d.ts +1 -1
  43. package/src/engine/physics/fluid/effector/AbstractFluidEffector.js +1 -1
  44. package/src/engine/physics/fluid/effector/GlobalFluidEffector.d.ts +33 -47
  45. package/src/engine/physics/fluid/effector/GlobalFluidEffector.d.ts.map +1 -1
  46. package/src/engine/physics/fluid/effector/GlobalFluidEffector.js +38 -176
  47. package/src/engine/physics/fluid/effector/GlobalFluidEffectorSerializationAdapter.d.ts +8 -11
  48. package/src/engine/physics/fluid/effector/GlobalFluidEffectorSerializationAdapter.d.ts.map +1 -1
  49. package/src/engine/physics/fluid/effector/GlobalFluidEffectorSerializationAdapter.js +13 -24
  50. package/src/engine/physics/fluid/effector/GlobalFluidEffectorSerializationUpgrader_0_1.d.ts +16 -0
  51. package/src/engine/physics/fluid/effector/GlobalFluidEffectorSerializationUpgrader_0_1.d.ts.map +1 -0
  52. package/src/engine/physics/fluid/effector/GlobalFluidEffectorSerializationUpgrader_0_1.js +35 -0
  53. package/src/engine/physics/fluid/fluid_apply_atmosphere.d.ts +1 -1
  54. package/src/engine/physics/fluid/fluid_apply_atmosphere.js +1 -1
  55. package/src/engine/physics/fluid/turbulence/FLUID_TURBULENCE_TILE.d.ts +28 -0
  56. package/src/engine/physics/fluid/turbulence/FLUID_TURBULENCE_TILE.d.ts.map +1 -0
  57. package/src/engine/physics/fluid/turbulence/FLUID_TURBULENCE_TILE.js +29 -0
  58. package/src/engine/physics/fluid/turbulence/fluid_atmosphere_velocity_at.d.ts +16 -0
  59. package/src/engine/physics/fluid/turbulence/fluid_atmosphere_velocity_at.d.ts.map +1 -0
  60. package/src/engine/physics/fluid/turbulence/fluid_atmosphere_velocity_at.js +49 -0
  61. package/src/engine/physics/fluid/turbulence/fluid_turbulence_inverse_tile_size.d.ts +11 -0
  62. package/src/engine/physics/fluid/turbulence/fluid_turbulence_inverse_tile_size.d.ts.map +1 -0
  63. package/src/engine/physics/fluid/turbulence/fluid_turbulence_inverse_tile_size.js +18 -0
  64. package/src/engine/physics/fluid/turbulence/fluid_turbulence_tile_data.d.ts +25 -0
  65. package/src/engine/physics/fluid/turbulence/fluid_turbulence_tile_data.d.ts.map +1 -0
  66. package/src/engine/physics/fluid/turbulence/fluid_turbulence_tile_data.js +65 -0
  67. package/src/engine/physics/fluid/turbulence/fluid_turbulence_tile_generate.d.ts +56 -0
  68. package/src/engine/physics/fluid/turbulence/fluid_turbulence_tile_generate.d.ts.map +1 -0
  69. package/src/engine/physics/fluid/turbulence/fluid_turbulence_tile_generate.js +313 -0
  70. package/src/engine/physics/fluid/turbulence/fluid_turbulence_tile_sample.d.ts +16 -0
  71. package/src/engine/physics/fluid/turbulence/fluid_turbulence_tile_sample.d.ts.map +1 -0
  72. package/src/engine/physics/fluid/turbulence/fluid_turbulence_tile_sample.js +69 -0
  73. package/src/generation/foliage/mesh/branch_ring_triangulate.d.ts +1 -1
  74. package/src/generation/foliage/mesh/branch_ring_triangulate.js +1 -1
  75. package/src/shade/playground/bvh_repro/README.md +8 -6
  76. package/src/shade/playground/bvh_repro/index.html +125 -124
  77. package/src/shade/playground/bvh_repro/main.js +259 -254
  78. package/src/shade/playground/foliage_wind/foliage_world.d.ts.map +1 -1
  79. package/src/shade/playground/foliage_wind/foliage_world.js +7 -4
  80. package/src/shade/playground/grass_surfaces/main.js +3 -2
  81. package/src/shade/playground/particle_ecs/bonfire_wind.d.ts +23 -13
  82. package/src/shade/playground/particle_ecs/bonfire_wind.d.ts.map +1 -1
  83. package/src/shade/playground/particle_ecs/bonfire_wind.js +30 -33
  84. package/src/shade/playground/skinned_blas_refit/README.md +26 -14
  85. package/src/shade/playground/skinned_blas_refit/shader_blas_audit_leaf_triangles.d.ts +14 -9
  86. package/src/shade/playground/skinned_blas_refit/shader_blas_audit_leaf_triangles.d.ts.map +1 -1
  87. package/src/shade/playground/skinned_blas_refit/shader_blas_audit_leaf_triangles.js +126 -127
  88. package/src/shade/playground/skinned_blas_refit/shader_blas_audit_points.js +95 -95
  89. package/src/shade/playground/skinned_blas_refit/shader_blas_audit_visibility.d.ts +9 -1
  90. package/src/shade/playground/skinned_blas_refit/shader_blas_audit_visibility.d.ts.map +1 -1
  91. package/src/shade/playground/skinned_blas_refit/shader_blas_audit_visibility.js +146 -135
  92. package/src/shade/playground/skinned_blas_refit/verify_clone_leaves.d.ts +6 -6
  93. package/src/shade/playground/skinned_blas_refit/verify_clone_leaves.d.ts.map +1 -1
  94. package/src/shade/playground/skinned_blas_refit/verify_clone_leaves.js +148 -134
  95. package/src/shade/playground/skinned_blas_refit/verify_leaf_triangles.d.ts +11 -8
  96. package/src/shade/playground/skinned_blas_refit/verify_leaf_triangles.d.ts.map +1 -1
  97. package/src/shade/playground/skinned_blas_refit/verify_leaf_triangles.js +342 -202
  98. package/src/shade/playground/skinned_blas_refit/verify_skinned_blas_refit.d.ts +12 -13
  99. package/src/shade/playground/skinned_blas_refit/verify_skinned_blas_refit.d.ts.map +1 -1
  100. package/src/shade/playground/skinned_blas_refit/verify_skinned_blas_refit.js +136 -116
  101. package/src/shade/playground/skinned_blas_refit/verify_traversal_reachability.d.ts +4 -4
  102. package/src/shade/playground/skinned_blas_refit/verify_traversal_reachability.d.ts.map +1 -1
  103. package/src/shade/playground/skinned_blas_refit/verify_traversal_reachability.js +255 -249
  104. package/src/shade/playground/water_surface/main.js +6 -3
  105. package/src/shade/renderer/animation/GPUAnimationManager.js +2 -2
  106. package/src/shade/renderer/animation/skinning/GPUMeshSkinningContext.d.ts.map +1 -1
  107. package/src/shade/renderer/animation/skinning/GPUMeshSkinningContext.js +7 -8
  108. package/src/shade/renderer/fluid/FLUID_FAR_FIELD_STRUCT.d.ts +111 -0
  109. package/src/shade/renderer/fluid/FLUID_FAR_FIELD_STRUCT.d.ts.map +1 -0
  110. package/src/shade/renderer/fluid/FLUID_FAR_FIELD_STRUCT.js +162 -0
  111. package/src/shade/renderer/fluid/GPUFluidCascade.d.ts +37 -8
  112. package/src/shade/renderer/fluid/GPUFluidCascade.d.ts.map +1 -1
  113. package/src/shade/renderer/fluid/GPUFluidCascade.js +149 -47
  114. package/src/shade/renderer/fluid/GPUFluidCascadeStack.d.ts +10 -3
  115. package/src/shade/renderer/fluid/GPUFluidCascadeStack.d.ts.map +1 -1
  116. package/src/shade/renderer/fluid/GPUFluidCascadeStack.js +69 -10
  117. package/src/shade/renderer/fluid/chunk_fluid_far_field.d.ts +19 -0
  118. package/src/shade/renderer/fluid/chunk_fluid_far_field.d.ts.map +1 -0
  119. package/src/shade/renderer/fluid/chunk_fluid_far_field.js +43 -0
  120. package/src/shade/renderer/fluid/coupling/FLUID_CASCADE_PARENT_STRUCT.d.ts +10 -9
  121. package/src/shade/renderer/fluid/coupling/FLUID_CASCADE_PARENT_STRUCT.d.ts.map +1 -1
  122. package/src/shade/renderer/fluid/coupling/FLUID_CASCADE_PARENT_STRUCT.js +14 -12
  123. package/src/shade/renderer/fluid/coupling/FLUID_CASCADE_RESTRICT_STRUCT.d.ts +3 -2
  124. package/src/shade/renderer/fluid/coupling/FLUID_CASCADE_RESTRICT_STRUCT.d.ts.map +1 -1
  125. package/src/shade/renderer/fluid/coupling/FLUID_CASCADE_RESTRICT_STRUCT.js +7 -5
  126. package/src/shade/renderer/fluid/coupling/chunk_fluid_cascade_epilogue.d.ts +17 -9
  127. package/src/shade/renderer/fluid/coupling/chunk_fluid_cascade_epilogue.d.ts.map +1 -1
  128. package/src/shade/renderer/fluid/coupling/chunk_fluid_cascade_epilogue.js +58 -18
  129. package/src/shade/renderer/fluid/coupling/chunk_fluid_cascade_parent.d.ts +23 -11
  130. package/src/shade/renderer/fluid/coupling/chunk_fluid_cascade_parent.d.ts.map +1 -1
  131. package/src/shade/renderer/fluid/coupling/chunk_fluid_cascade_parent.js +371 -335
  132. package/src/shade/renderer/fluid/coupling/shader_fluid_cascade_fill.d.ts.map +1 -1
  133. package/src/shade/renderer/fluid/coupling/shader_fluid_cascade_fill.js +2 -1
  134. package/src/shade/renderer/fluid/coupling/shader_fluid_cascade_ghosts.d.ts.map +1 -1
  135. package/src/shade/renderer/fluid/coupling/shader_fluid_cascade_ghosts.js +109 -108
  136. package/src/shade/renderer/fluid/coupling/shader_fluid_cascade_restrict.d.ts +5 -3
  137. package/src/shade/renderer/fluid/coupling/shader_fluid_cascade_restrict.d.ts.map +1 -1
  138. package/src/shade/renderer/fluid/coupling/shader_fluid_cascade_restrict.js +24 -12
  139. package/src/shade/renderer/fluid/mac/FLUID_MAC_STEP_STRUCT.d.ts +6 -2
  140. package/src/shade/renderer/fluid/mac/FLUID_MAC_STEP_STRUCT.d.ts.map +1 -1
  141. package/src/shade/renderer/fluid/mac/FLUID_MAC_STEP_STRUCT.js +10 -5
  142. package/src/shade/renderer/fluid/mac/FluidMacPasses.d.ts +20 -21
  143. package/src/shade/renderer/fluid/mac/FluidMacPasses.d.ts.map +1 -1
  144. package/src/shade/renderer/fluid/mac/FluidMacPasses.js +453 -427
  145. package/src/shade/renderer/fluid/mac/shader_fluid_mac_advect_correct.d.ts.map +1 -1
  146. package/src/shade/renderer/fluid/mac/shader_fluid_mac_advect_correct.js +2 -1
  147. package/src/shade/renderer/fluid/publish/FluidWindPublish.d.ts +13 -5
  148. package/src/shade/renderer/fluid/publish/FluidWindPublish.d.ts.map +1 -1
  149. package/src/shade/renderer/fluid/publish/FluidWindPublish.js +20 -10
  150. package/src/shade/renderer/fluid/publish/chunk_fluid_wind_publish_cell.d.ts +2 -2
  151. package/src/shade/renderer/fluid/publish/chunk_fluid_wind_publish_cell.js +2 -2
  152. package/src/shade/renderer/fluid/publish/shader_fluid_wind_publish.d.ts +5 -3
  153. package/src/shade/renderer/fluid/publish/shader_fluid_wind_publish.d.ts.map +1 -1
  154. package/src/shade/renderer/fluid/publish/shader_fluid_wind_publish.js +147 -142
  155. package/src/shade/renderer/fluid/query/GPUFluidQueries.js +2 -2
  156. package/src/shade/renderer/geometry/GPUGeometryManager.d.ts.map +1 -1
  157. package/src/shade/renderer/geometry/GPUGeometryManager.js +5 -7
  158. package/src/shade/renderer/geometry/MeshletGeometry.d.ts +4 -1
  159. package/src/shade/renderer/geometry/MeshletGeometry.d.ts.map +1 -1
  160. package/src/shade/renderer/geometry/MeshletGeometry.js +4 -1
  161. package/src/shade/renderer/geometry/MeshletGeometrySerializationAdapter.d.ts +20 -0
  162. package/src/shade/renderer/geometry/MeshletGeometrySerializationAdapter.d.ts.map +1 -1
  163. package/src/shade/renderer/geometry/MeshletGeometrySerializationAdapter.js +35 -3
  164. package/src/shade/renderer/geometry/blas_from_meshlets.d.ts +9 -3
  165. package/src/shade/renderer/geometry/blas_from_meshlets.d.ts.map +1 -1
  166. package/src/shade/renderer/geometry/blas_from_meshlets.js +16 -30
  167. package/src/shade/renderer/geometry/bvh/BLAS8_REFIT_TARGET_STRUCT.d.ts +14 -0
  168. package/src/shade/renderer/geometry/bvh/BLAS8_REFIT_TARGET_STRUCT.d.ts.map +1 -0
  169. package/src/shade/renderer/geometry/bvh/BLAS8_REFIT_TARGET_STRUCT.js +33 -0
  170. package/src/shade/renderer/geometry/bvh/GPUBLASRefitBatch.d.ts +18 -21
  171. package/src/shade/renderer/geometry/bvh/GPUBLASRefitBatch.d.ts.map +1 -1
  172. package/src/shade/renderer/geometry/bvh/GPUBLASRefitBatch.js +78 -158
  173. package/src/shade/renderer/geometry/bvh/GPUGeometryBVHManager.d.ts +18 -39
  174. package/src/shade/renderer/geometry/bvh/GPUGeometryBVHManager.d.ts.map +1 -1
  175. package/src/shade/renderer/geometry/bvh/GPUGeometryBVHManager.js +39 -398
  176. package/src/shade/renderer/geometry/bvh/GPUGeometryMeshletsBVH.d.ts +6 -7
  177. package/src/shade/renderer/geometry/bvh/GPUGeometryMeshletsBVH.d.ts.map +1 -1
  178. package/src/shade/renderer/geometry/bvh/GPUGeometryMeshletsBVH.js +5 -7
  179. package/src/shade/renderer/geometry/bvh/bvh8_build_for_meshlets.d.ts +36 -0
  180. package/src/shade/renderer/geometry/bvh/bvh8_build_for_meshlets.d.ts.map +1 -0
  181. package/src/shade/renderer/geometry/bvh/bvh8_build_for_meshlets.js +179 -0
  182. package/src/shade/renderer/geometry/bvh/meshlet_batch_to_clustered_bvh.d.ts +30 -0
  183. package/src/shade/renderer/geometry/bvh/meshlet_batch_to_clustered_bvh.d.ts.map +1 -0
  184. package/src/shade/renderer/geometry/bvh/meshlet_batch_to_clustered_bvh.js +207 -0
  185. package/src/shade/renderer/geometry/bvh/shader_blas8_refit_batch.d.ts +52 -0
  186. package/src/shade/renderer/geometry/bvh/shader_blas8_refit_batch.d.ts.map +1 -0
  187. package/src/shade/renderer/geometry/bvh/shader_blas8_refit_batch.js +464 -0
  188. package/src/shade/renderer/geometry/meshlet/MeshletBatch.d.ts +12 -0
  189. package/src/shade/renderer/geometry/meshlet/MeshletBatch.d.ts.map +1 -1
  190. package/src/shade/renderer/geometry/meshlet/MeshletBatch.js +37 -0
  191. package/src/shade/renderer/geometry/sdf/bake/shader_mesh_sdf_classify.d.ts.map +1 -1
  192. package/src/shade/renderer/geometry/sdf/bake/shader_mesh_sdf_classify.js +4 -4
  193. package/src/shade/renderer/geometry/sdf/bake/shader_mesh_sdf_evaluate.d.ts.map +1 -1
  194. package/src/shade/renderer/geometry/sdf/bake/shader_mesh_sdf_evaluate.js +2 -2
  195. package/src/shade/renderer/geometry/sdf/chunk_blas_query_band_sdf.d.ts.map +1 -1
  196. package/src/shade/renderer/geometry/sdf/chunk_blas_query_band_sdf.js +2 -2
  197. package/src/shade/renderer/geometry/sdf/shader_sdf_visualize.d.ts.map +1 -1
  198. package/src/shade/renderer/geometry/sdf/shader_sdf_visualize.js +4 -4
  199. package/src/shade/renderer/geometry/sdf/surface/shader_mesh_surface_trace.d.ts.map +1 -1
  200. package/src/shade/renderer/geometry/sdf/surface/shader_mesh_surface_trace.js +2 -2
  201. package/src/shade/renderer/geometry/sr_create_group_RTX.d.ts.map +1 -1
  202. package/src/shade/renderer/geometry/sr_create_group_RTX.js +4 -4
  203. package/src/shade/renderer/global_illumination/brick4/gpu/bake/brick4_bake_basic.d.ts.map +1 -1
  204. package/src/shade/renderer/global_illumination/brick4/gpu/bake/brick4_bake_basic.js +1 -0
  205. package/src/shade/renderer/global_illumination/lpv/bake/GPULightProbeVolumeRenderer.d.ts.map +1 -1
  206. package/src/shade/renderer/global_illumination/lpv/bake/GPULightProbeVolumeRenderer.js +1 -0
  207. package/src/shade/renderer/global_illumination/lpv/placement/graph_generate_probe_locations.d.ts.map +1 -1
  208. package/src/shade/renderer/global_illumination/lpv/placement/graph_generate_probe_locations.js +372 -376
  209. package/src/shade/renderer/global_illumination/probe_clipmap/brick/mesh/MESH_BRICK.d.ts +9 -10
  210. package/src/shade/renderer/global_illumination/probe_clipmap/brick/mesh/MESH_BRICK.d.ts.map +1 -1
  211. package/src/shade/renderer/global_illumination/probe_clipmap/brick/mesh/MESH_BRICK.js +10 -11
  212. package/src/shade/renderer/global_illumination/probe_clipmap/brick/mesh/chunk_mesh_brick_walk.d.ts +2 -2
  213. package/src/shade/renderer/global_illumination/probe_clipmap/brick/mesh/chunk_mesh_brick_walk.js +2 -2
  214. package/src/shade/renderer/global_illumination/probe_clipmap/brick/mesh/shader_mesh_brick_gather.d.ts +12 -8
  215. package/src/shade/renderer/global_illumination/probe_clipmap/brick/mesh/shader_mesh_brick_gather.d.ts.map +1 -1
  216. package/src/shade/renderer/global_illumination/probe_clipmap/brick/mesh/shader_mesh_brick_gather.js +109 -60
  217. package/src/shade/renderer/global_illumination/probe_clipmap/debug/graph_probe_clipmap_debug_mesh_sdf.js +2 -2
  218. package/src/shade/renderer/global_illumination/probe_clipmap/debug/graph_probe_clipmap_debug_mesh_surfaces.js +2 -2
  219. package/src/shade/renderer/gpu_primitive/bvh/BVH_BUFFER_LAYOUT.d.ts +2 -2
  220. package/src/shade/renderer/gpu_primitive/bvh/BVH_BUFFER_LAYOUT.js +70 -70
  221. package/src/shade/renderer/gpu_primitive/bvh/BVH_BUILD_SETTINGS_STRUCT.d.ts +6 -7
  222. package/src/shade/renderer/gpu_primitive/bvh/BVH_BUILD_SETTINGS_STRUCT.d.ts.map +1 -1
  223. package/src/shade/renderer/gpu_primitive/bvh/BVH_BUILD_SETTINGS_STRUCT.js +6 -7
  224. package/src/shade/renderer/gpu_primitive/bvh/graph_bvh_build_lbvh.d.ts +3 -3
  225. package/src/shade/renderer/gpu_primitive/bvh/graph_bvh_build_lbvh.js +3 -3
  226. package/src/shade/renderer/gpu_primitive/bvh/shader_bvh_build_single_workgroup.js +1 -1
  227. package/src/shade/renderer/gpu_primitive/bvh/shader_bvh_emit_hierarchy.d.ts +2 -2
  228. package/src/shade/renderer/gpu_primitive/bvh/shader_bvh_emit_hierarchy.js +3 -3
  229. package/src/shade/renderer/gpu_primitive/bvh8/BVH8_TREE_BUFFER_LAYOUT.d.ts +69 -0
  230. package/src/shade/renderer/gpu_primitive/bvh8/BVH8_TREE_BUFFER_LAYOUT.d.ts.map +1 -0
  231. package/src/shade/renderer/gpu_primitive/bvh8/BVH8_TREE_BUFFER_LAYOUT.js +89 -0
  232. package/src/shade/renderer/gpu_primitive/bvh8/bvh8_encode_from_bvh2.d.ts +41 -0
  233. package/src/shade/renderer/gpu_primitive/bvh8/bvh8_encode_from_bvh2.d.ts.map +1 -0
  234. package/src/shade/renderer/gpu_primitive/bvh8/bvh8_encode_from_bvh2.js +348 -0
  235. package/src/shade/renderer/gpu_primitive/bvh8/check_bvh8_tree.d.ts +34 -0
  236. package/src/shade/renderer/gpu_primitive/bvh8/check_bvh8_tree.d.ts.map +1 -0
  237. package/src/shade/renderer/gpu_primitive/bvh8/check_bvh8_tree.js +291 -0
  238. package/src/shade/renderer/gpu_primitive/bvh8/chunk_bvh8_encode_assign.d.ts +31 -0
  239. package/src/shade/renderer/gpu_primitive/bvh8/chunk_bvh8_encode_assign.d.ts.map +1 -0
  240. package/src/shade/renderer/gpu_primitive/bvh8/chunk_bvh8_encode_assign.js +175 -0
  241. package/src/shade/renderer/gpu_primitive/bvh8/chunk_bvh8_encode_depth.d.ts +27 -0
  242. package/src/shade/renderer/gpu_primitive/bvh8/chunk_bvh8_encode_depth.d.ts.map +1 -0
  243. package/src/shade/renderer/gpu_primitive/bvh8/chunk_bvh8_encode_depth.js +48 -0
  244. package/src/shade/renderer/gpu_primitive/bvh8/chunk_bvh8_encode_gather.d.ts +26 -0
  245. package/src/shade/renderer/gpu_primitive/bvh8/chunk_bvh8_encode_gather.d.ts.map +1 -0
  246. package/src/shade/renderer/gpu_primitive/bvh8/chunk_bvh8_encode_gather.js +118 -0
  247. package/src/shade/renderer/gpu_primitive/bvh8/chunk_bvh8_encode_node.d.ts +22 -0
  248. package/src/shade/renderer/gpu_primitive/bvh8/chunk_bvh8_encode_node.d.ts.map +1 -0
  249. package/src/shade/renderer/gpu_primitive/bvh8/chunk_bvh8_encode_node.js +143 -0
  250. package/src/shade/renderer/gpu_primitive/bvh8/chunk_bvh8_encode_sums.d.ts +36 -0
  251. package/src/shade/renderer/gpu_primitive/bvh8/chunk_bvh8_encode_sums.d.ts.map +1 -0
  252. package/src/shade/renderer/gpu_primitive/bvh8/chunk_bvh8_encode_sums.js +97 -0
  253. package/src/shade/renderer/gpu_primitive/bvh8/graph_bvh8_encode_from_bvh2.d.ts +49 -0
  254. package/src/shade/renderer/gpu_primitive/bvh8/graph_bvh8_encode_from_bvh2.d.ts.map +1 -0
  255. package/src/shade/renderer/gpu_primitive/bvh8/graph_bvh8_encode_from_bvh2.js +265 -0
  256. package/src/shade/renderer/gpu_primitive/bvh8/shader_bvh8_encode_assign.d.ts +37 -0
  257. package/src/shade/renderer/gpu_primitive/bvh8/shader_bvh8_encode_assign.d.ts.map +1 -0
  258. package/src/shade/renderer/gpu_primitive/bvh8/shader_bvh8_encode_assign.js +109 -0
  259. package/src/shade/renderer/gpu_primitive/bvh8/shader_bvh8_encode_count.d.ts +15 -0
  260. package/src/shade/renderer/gpu_primitive/bvh8/shader_bvh8_encode_count.d.ts.map +1 -0
  261. package/src/shade/renderer/gpu_primitive/bvh8/shader_bvh8_encode_count.js +85 -0
  262. package/src/shade/renderer/gpu_primitive/bvh8/shader_bvh8_encode_count_single_workgroup.d.ts +26 -0
  263. package/src/shade/renderer/gpu_primitive/bvh8/shader_bvh8_encode_count_single_workgroup.d.ts.map +1 -0
  264. package/src/shade/renderer/gpu_primitive/bvh8/shader_bvh8_encode_count_single_workgroup.js +200 -0
  265. package/src/shade/renderer/gpu_primitive/bvh8/shader_bvh8_encode_parents.d.ts +19 -0
  266. package/src/shade/renderer/gpu_primitive/bvh8/shader_bvh8_encode_parents.d.ts.map +1 -0
  267. package/src/shade/renderer/gpu_primitive/bvh8/shader_bvh8_encode_parents.js +81 -0
  268. package/src/shade/renderer/gpu_primitive/bvh8/shader_bvh8_encode_write.d.ts +14 -0
  269. package/src/shade/renderer/gpu_primitive/bvh8/shader_bvh8_encode_write.d.ts.map +1 -0
  270. package/src/shade/renderer/gpu_primitive/bvh8/shader_bvh8_encode_write.js +101 -0
  271. package/src/shade/renderer/gpu_primitive/bvh8/verify_gpu_bvh8_encode.d.ts +19 -0
  272. package/src/shade/renderer/gpu_primitive/bvh8/verify_gpu_bvh8_encode.d.ts.map +1 -0
  273. package/src/shade/renderer/gpu_primitive/bvh8/verify_gpu_bvh8_encode.js +361 -0
  274. package/src/shade/renderer/grass/surface/shader_grass_surface_bake.d.ts.map +1 -1
  275. package/src/shade/renderer/grass/surface/shader_grass_surface_bake.js +5 -6
  276. package/src/shade/renderer/lightmap/GPULightMap.d.ts.map +1 -1
  277. package/src/shade/renderer/lightmap/GPULightMap.js +1 -0
  278. package/src/shade/renderer/path_tracer/accumulating/AccumulatingPathTracer.d.ts.map +1 -1
  279. package/src/shade/renderer/path_tracer/accumulating/AccumulatingPathTracer.js +1 -0
  280. package/src/shade/renderer/path_tracer/graph_path_trace_scene.d.ts.map +1 -1
  281. package/src/shade/renderer/path_tracer/graph_path_trace_scene.js +1 -0
  282. package/src/shade/renderer/scene/GPUInstancesAccelerationStructure.d.ts +8 -4
  283. package/src/shade/renderer/scene/GPUInstancesAccelerationStructure.d.ts.map +1 -1
  284. package/src/shade/renderer/scene/GPUInstancesAccelerationStructure.js +60 -33
  285. package/src/shade/renderer/scene/verify_gpu_tlas_build.d.ts +6 -6
  286. package/src/shade/renderer/scene/verify_gpu_tlas_build.d.ts.map +1 -1
  287. package/src/shade/renderer/scene/verify_gpu_tlas_build.js +23 -53
  288. package/src/shade/renderer/shader/chunk/bvh/bvh8/webgpu/BVH8_INODE_STRUCT.d.ts +3 -1
  289. package/src/shade/renderer/shader/chunk/bvh/bvh8/webgpu/BVH8_INODE_STRUCT.d.ts.map +1 -1
  290. package/src/shade/renderer/shader/chunk/bvh/bvh8/webgpu/BVH8_INODE_STRUCT.js +5 -3
  291. package/src/shade/renderer/shader/chunk/bvh/bvh8/webgpu/BVH8_MAX_DEPTH.d.ts +28 -0
  292. package/src/shade/renderer/shader/chunk/bvh/bvh8/webgpu/BVH8_MAX_DEPTH.d.ts.map +1 -0
  293. package/src/shade/renderer/shader/chunk/bvh/bvh8/webgpu/BVH8_MAX_DEPTH.js +29 -0
  294. package/src/shade/renderer/shader/chunk/bvh/bvh8/webgpu/chunk_bvh8_node_grid.d.ts +25 -0
  295. package/src/shade/renderer/shader/chunk/bvh/bvh8/webgpu/chunk_bvh8_node_grid.d.ts.map +1 -0
  296. package/src/shade/renderer/shader/chunk/bvh/bvh8/webgpu/chunk_bvh8_node_grid.js +97 -0
  297. package/src/shade/renderer/shader/chunk/bvh/bvh8/webgpu/chunk_bvh8_node_intersect.d.ts +8 -0
  298. package/src/shade/renderer/shader/chunk/bvh/bvh8/webgpu/chunk_bvh8_node_intersect.d.ts.map +1 -1
  299. package/src/shade/renderer/shader/chunk/bvh/bvh8/webgpu/chunk_bvh8_node_intersect.js +23 -14
  300. package/src/shade/renderer/shader/chunk/bvh/bvh8/webgpu/chunk_bvh8_node_slot_distances.d.ts +36 -0
  301. package/src/shade/renderer/shader/chunk/bvh/bvh8/webgpu/chunk_bvh8_node_slot_distances.d.ts.map +1 -0
  302. package/src/shade/renderer/shader/chunk/bvh/bvh8/webgpu/chunk_bvh8_node_slot_distances.js +222 -0
  303. package/src/shade/renderer/shader/chunk/bvh/bvh8/webgpu/chunk_bvh8_ray_direction_rcp.d.ts +20 -0
  304. package/src/shade/renderer/shader/chunk/bvh/bvh8/webgpu/chunk_bvh8_ray_direction_rcp.d.ts.map +1 -0
  305. package/src/shade/renderer/shader/chunk/bvh/bvh8/webgpu/chunk_bvh8_ray_direction_rcp.js +30 -0
  306. package/src/shade/renderer/shader/chunk/bvh/bvh8/webgpu/chunk_bvh8_tree_read.d.ts +30 -0
  307. package/src/shade/renderer/shader/chunk/bvh/bvh8/webgpu/chunk_bvh8_tree_read.d.ts.map +1 -0
  308. package/src/shade/renderer/shader/chunk/bvh/bvh8/webgpu/chunk_bvh8_tree_read.js +91 -0
  309. package/src/shade/renderer/shader/chunk/bvh/bvh8/webgpu/chunk_bvh8_waiting_slots.d.ts +23 -0
  310. package/src/shade/renderer/shader/chunk/bvh/bvh8/webgpu/chunk_bvh8_waiting_slots.d.ts.map +1 -0
  311. package/src/shade/renderer/shader/chunk/bvh/bvh8/webgpu/chunk_bvh8_waiting_slots.js +40 -0
  312. package/src/shade/renderer/shader/chunk/geometry/ray/chunk_ray_query_blas_nearest.d.ts +22 -0
  313. package/src/shade/renderer/shader/chunk/geometry/ray/chunk_ray_query_blas_nearest.d.ts.map +1 -1
  314. package/src/shade/renderer/shader/chunk/geometry/ray/chunk_ray_query_blas_nearest.js +121 -70
  315. package/src/shade/renderer/shader/chunk/geometry/ray/chunk_ray_query_blas_occluded.d.ts +13 -1
  316. package/src/shade/renderer/shader/chunk/geometry/ray/chunk_ray_query_blas_occluded.d.ts.map +1 -1
  317. package/src/shade/renderer/shader/chunk/geometry/ray/chunk_ray_query_blas_occluded.js +117 -61
  318. package/src/shade/renderer/shader/chunk/geometry/ray/chunk_ray_query_nearest.d.ts +21 -0
  319. package/src/shade/renderer/shader/chunk/geometry/ray/chunk_ray_query_nearest.d.ts.map +1 -1
  320. package/src/shade/renderer/shader/chunk/geometry/ray/chunk_ray_query_nearest.js +111 -72
  321. package/src/shade/renderer/shader/chunk/geometry/ray/chunk_ray_query_nearest_among.d.ts +1 -2
  322. package/src/shade/renderer/shader/chunk/geometry/ray/chunk_ray_query_nearest_among.d.ts.map +1 -1
  323. package/src/shade/renderer/shader/chunk/geometry/ray/chunk_ray_query_nearest_among.js +83 -54
  324. package/src/shade/renderer/shader/chunk/geometry/ray/chunk_ray_query_occluded.d.ts +14 -0
  325. package/src/shade/renderer/shader/chunk/geometry/ray/chunk_ray_query_occluded.d.ts.map +1 -1
  326. package/src/shade/renderer/shader/chunk/geometry/ray/chunk_ray_query_occluded.js +92 -60
  327. package/src/shade/renderer/shader/chunk/sdf/chunk_point_query_blas_nearest.d.ts +22 -0
  328. package/src/shade/renderer/shader/chunk/sdf/chunk_point_query_blas_nearest.d.ts.map +1 -1
  329. package/src/shade/renderer/shader/chunk/sdf/chunk_point_query_blas_nearest.js +153 -106
  330. package/src/shade/renderer/shader/chunk/sdf/chunk_scene_point_query_nearest.d.ts +21 -0
  331. package/src/shade/renderer/shader/chunk/sdf/chunk_scene_point_query_nearest.d.ts.map +1 -1
  332. package/src/shade/renderer/shader/chunk/sdf/chunk_scene_point_query_nearest.js +115 -74
  333. package/src/shade/renderer/shader/chunk/sdf/chunk_scene_sdf_raymarch.d.ts +5 -2
  334. package/src/shade/renderer/shader/chunk/sdf/chunk_scene_sdf_raymarch.d.ts.map +1 -1
  335. package/src/shade/renderer/shader/chunk/sdf/chunk_scene_sdf_raymarch.js +89 -63
  336. package/src/shade/renderer/shader/chunk/sdf/chunk_sdf_query_distance.d.ts +15 -0
  337. package/src/shade/renderer/shader/chunk/sdf/chunk_sdf_query_distance.d.ts.map +1 -1
  338. package/src/shade/renderer/shader/chunk/sdf/chunk_sdf_query_distance.js +108 -63
  339. package/src/shade/renderer/shadow/sdf/chunk_ray_query_sdf_raycast.d.ts +14 -0
  340. package/src/shade/renderer/shadow/sdf/chunk_ray_query_sdf_raycast.d.ts.map +1 -1
  341. package/src/shade/renderer/shadow/sdf/chunk_ray_query_sdf_raycast.js +94 -60
  342. package/src/shade/renderer/shadow/sdf/graph_draw_sdf_shadows.d.ts.map +1 -1
  343. package/src/shade/renderer/shadow/sdf/graph_draw_sdf_shadows.js +4 -4
  344. package/src/shade/renderer/volumetrics/graph_build_volumetrics.js +2 -2
  345. package/src/shade/renderer/water/query/shader_water_surface_query.d.ts.map +1 -1
  346. package/src/shade/renderer/water/query/shader_water_surface_query.js +227 -227
  347. package/src/shade/renderer/water/surface/particles/chunk_water_particle_step.d.ts.map +1 -1
  348. package/src/shade/renderer/water/surface/particles/chunk_water_particle_step.js +7 -4
  349. package/src/shade/renderer/water/surface/particles/shader_water_particles.js +2 -2
  350. package/src/shade/renderer/wind/GPUSceneWind.d.ts +36 -4
  351. package/src/shade/renderer/wind/GPUSceneWind.d.ts.map +1 -1
  352. package/src/shade/renderer/wind/GPUSceneWind.js +150 -4
  353. package/src/shade/renderer/wind/WIND_FIELD_STRUCT.d.ts +9 -3
  354. package/src/shade/renderer/wind/WIND_FIELD_STRUCT.d.ts.map +1 -1
  355. package/src/shade/renderer/wind/WIND_FIELD_STRUCT.js +13 -3
  356. package/src/shade/renderer/wind/WIND_FIELD_UNIFORM.d.ts +6 -6
  357. package/src/shade/renderer/wind/WIND_FIELD_UNIFORM.js +6 -6
  358. package/src/shade/renderer/wind/chunk_fluid_turbulence.d.ts +39 -0
  359. package/src/shade/renderer/wind/chunk_fluid_turbulence.d.ts.map +1 -0
  360. package/src/shade/renderer/wind/chunk_fluid_turbulence.js +63 -0
  361. package/src/shade/renderer/wind/chunk_wind_field_sample_cascades.d.ts +10 -7
  362. package/src/shade/renderer/wind/chunk_wind_field_sample_cascades.d.ts.map +1 -1
  363. package/src/shade/renderer/wind/chunk_wind_field_sample_cascades.js +34 -11
  364. package/src/shade/renderer/wind/chunk_wind_field_sample_uniform.d.ts +2 -2
  365. package/src/shade/renderer/wind/chunk_wind_field_sample_uniform.js +2 -2
  366. package/src/shade/renderer/wind/wind_field_add_resources.d.ts +6 -4
  367. package/src/shade/renderer/wind/wind_field_add_resources.d.ts.map +1 -1
  368. package/src/shade/renderer/wind/wind_field_add_resources.js +9 -6
  369. package/src/shade/renderer/geometry/bvh/BLAS_REFIT_TARGET_STRUCT.d.ts +0 -18
  370. package/src/shade/renderer/geometry/bvh/BLAS_REFIT_TARGET_STRUCT.d.ts.map +0 -1
  371. package/src/shade/renderer/geometry/bvh/BLAS_REFIT_TARGET_STRUCT.js +0 -50
  372. package/src/shade/renderer/geometry/bvh/bvh2_derive_topology.d.ts +0 -23
  373. package/src/shade/renderer/geometry/bvh/bvh2_derive_topology.d.ts.map +0 -1
  374. package/src/shade/renderer/geometry/bvh/bvh2_derive_topology.js +0 -87
  375. package/src/shade/renderer/geometry/bvh/shader_blas_refit_batch.d.ts +0 -42
  376. package/src/shade/renderer/geometry/bvh/shader_blas_refit_batch.d.ts.map +0 -1
  377. package/src/shade/renderer/geometry/bvh/shader_blas_refit_batch.js +0 -141
  378. package/src/shade/renderer/geometry/bvh/shader_blas_refit_batch_seed.d.ts +0 -21
  379. package/src/shade/renderer/geometry/bvh/shader_blas_refit_batch_seed.d.ts.map +0 -1
  380. package/src/shade/renderer/geometry/bvh/shader_blas_refit_batch_seed.js +0 -75
  381. package/src/shade/renderer/geometry/meshlet_batch_to_bvh.d.ts +0 -17
  382. package/src/shade/renderer/geometry/meshlet_batch_to_bvh.d.ts.map +0 -1
  383. package/src/shade/renderer/geometry/meshlet_batch_to_bvh.js +0 -247
  384. package/src/shade/renderer/shader/chunk/bvh/bvh8/webgpu/chunk_bvh8_ray_query_blas_occlusion.d.ts +0 -7
  385. package/src/shade/renderer/shader/chunk/bvh/bvh8/webgpu/chunk_bvh8_ray_query_blas_occlusion.d.ts.map +0 -1
  386. package/src/shade/renderer/shader/chunk/bvh/bvh8/webgpu/chunk_bvh8_ray_query_blas_occlusion.js +0 -226
  387. package/src/shade/renderer/shader/chunk/light/lpv/chunk_lpv_mask_visibility_via_rays.d.ts +0 -8
  388. package/src/shade/renderer/shader/chunk/light/lpv/chunk_lpv_mask_visibility_via_rays.d.ts.map +0 -1
  389. package/src/shade/renderer/shader/chunk/light/lpv/chunk_lpv_mask_visibility_via_rays.js +0 -45
  390. package/src/shade/renderer/shader/chunk/light/sample/chunk_ray_sample_light.d.ts +0 -3
  391. package/src/shade/renderer/shader/chunk/light/sample/chunk_ray_sample_light.d.ts.map +0 -1
  392. package/src/shade/renderer/shader/chunk/light/sample/chunk_ray_sample_light.js +0 -105
  393. package/src/shade/renderer/shadow/sdf/chunk_ray_query_sdf_distance.d.ts +0 -6
  394. package/src/shade/renderer/shadow/sdf/chunk_ray_query_sdf_distance.d.ts.map +0 -1
  395. package/src/shade/renderer/shadow/sdf/chunk_ray_query_sdf_distance.js +0 -86
  396. package/src/shade/renderer/shadow/sdf/chunk_ray_query_sdf_raycast_traversal_count.d.ts +0 -2
  397. package/src/shade/renderer/shadow/sdf/chunk_ray_query_sdf_raycast_traversal_count.d.ts.map +0 -1
  398. package/src/shade/renderer/shadow/sdf/chunk_ray_query_sdf_raycast_traversal_count.js +0 -136
@@ -1,335 +1,371 @@
1
- import { chunk_grid3d_to_index } from "../../shader/chunk/grid/chunk_grid3d_to_index.js";
2
- import { chunk_grid_tile_window } from "../../shader/chunk/grid/chunk_grid_tile_window.js";
3
- import { chunk_is_finite } from "../../shader/chunk/math/chunk_is_finite.js";
4
- import { chunk_texture3d_trilinear_interpolate } from "../../shader/chunk/texture/sample/chunk_texture3d_trilinear_corners.js";
5
- import { TEXTURE3D_TRILINEAR_CORNERS_STRUCT } from "../../shader/chunk/texture/TEXTURE3D_TRILINEAR_CORNERS_STRUCT.js";
6
- import { CodeChunk } from "../../shader/compiler/CodeChunk.js";
7
-
8
- /*
9
- What a cascade reads of its parent (GPU_FLUID_CASCADES_PROPOSAL_2026_10_16.md §7, §9), through the
10
- uniform `parent` (FLUID_CASCADE_PARENT_STRUCT), which every shader including one of these chunks
11
- declares under that name.
12
-
13
- A child addresses its parent by `offset = step.cells.corner − parent.origin` (or its pass's own copy
14
- of the child's corner): child-lattice cells from the parent's window start to the child's, a
15
- multiple of 4. With it, child window-local lattice points become parent window-local coordinates
16
- by halving, so nothing here sees a world coordinate.
17
-
18
- Both reads are trilinear with weights of 0, ¼, ½ or ¾, which f32 holds exactly. The velocity read
19
- blends the parent's DEVIATIONS from the far field and adds the far field after, so air the far field
20
- alone moves (a deviation of exactly 0 at every corner) reads as the far field exactly.
21
- */
22
-
23
- /**
24
- * The parent's identity read at a face of the child, one concrete function per component:
25
- * `fluid_parent_face_u(face, offset)`, `_v`, `_w`, `face` a window-local face of the child's lattice
26
- * for that component (u face `(i, j, k)` at cell coordinate `(i − ½, j, k)`).
27
- *
28
- * Child u face `i` lies on parent u lattice coordinate `(i + offset)/2` along x and
29
- * `(j + offset − ½)/2` across it; likewise v along y and w along z. The tap's eight parent faces are
30
- * read as deviations, `v − parent.far_velocity`, and one beyond the parent's window as 0; the read is
31
- * `parent.read_far_velocity + parent.keep · trilinear(deviations)`.
32
- *
33
- * Binds `parent_u`, `parent_v`, `parent_w`: the parent's persistent faces, `texture_3d<f32>`
34
- * (`r32float`), toroidal through `parent.faces_*`. A far-field parent binds stand-ins it never reads.
35
- *
36
- * Reads 8 texels a call; beside the far field (a window of size 0) none, and it answers
37
- * `parent.read_far_velocity` before any window test. That early answer is measured: a lone 64×32×64
38
- * cascade's predict went from 56.3 to 27.6 µs and its correct from 84.0 to 44.0 on an RTX 4090
39
- * (pipelines swapped in one run, per-dispatch medians), the seams' empty-window tests and blend being
40
- * most of what a beyond-window read cost there.
41
- *
42
- * @type {CodeChunk}
43
- */
44
- export const chunk_fluid_cascade_parent_velocity = CodeChunk.from(
45
- //language=WGSL
46
- `
47
- fn fluid_parent_deviation_u(lattice: vec3<i32>) -> f32 {
48
- if (!grid_tile_window_contains(lattice, parent.faces_u.size)) {
49
- return 0.0;
50
- }
51
-
52
- let storage = grid_tile_window_storage(lattice, parent.faces_u.corner_storage, parent.faces_u.period);
53
-
54
- return textureLoad(parent_u, storage, 0).r - parent.far_velocity.x;
55
- }
56
-
57
- fn fluid_parent_deviation_v(lattice: vec3<i32>) -> f32 {
58
- if (!grid_tile_window_contains(lattice, parent.faces_v.size)) {
59
- return 0.0;
60
- }
61
-
62
- let storage = grid_tile_window_storage(lattice, parent.faces_v.corner_storage, parent.faces_v.period);
63
-
64
- return textureLoad(parent_v, storage, 0).r - parent.far_velocity.y;
65
- }
66
-
67
- fn fluid_parent_deviation_w(lattice: vec3<i32>) -> f32 {
68
- if (!grid_tile_window_contains(lattice, parent.faces_w.size)) {
69
- return 0.0;
70
- }
71
-
72
- let storage = grid_tile_window_storage(lattice, parent.faces_w.corner_storage, parent.faces_w.period);
73
-
74
- return textureLoad(parent_w, storage, 0).r - parent.far_velocity.z;
75
- }
76
-
77
- fn fluid_parent_face_u(face: vec3<i32>, offset: vec3<i32>) -> f32 {
78
- // the far field: nothing to read, every corner would count 0
79
- if (parent.faces_u.size.x == 0u) {
80
- return parent.read_far_velocity.x;
81
- }
82
-
83
- let lattice = (vec3<f32>(face + offset) - vec3<f32>(0.0, 0.5, 0.5)) * 0.5;
84
- let base = floor(lattice);
85
- let lo = vec3<i32>(base);
86
- let hi = lo + vec3<i32>(1);
87
-
88
- var z0: vec4<f32>;
89
- var z1: vec4<f32>;
90
-
91
- if (all(lo >= vec3<i32>(0)) && all(vec3<u32>(hi) < parent.faces_u.size)) {
92
- let s0 = grid_tile_window_storage(lo, parent.faces_u.corner_storage, parent.faces_u.period);
93
- let s1_raw = s0 + vec3<u32>(1u);
94
- let s1 = select(s1_raw, vec3<u32>(0u), s1_raw == parent.faces_u.period);
95
- let far = vec4<f32>(parent.far_velocity.x);
96
-
97
- z0 = vec4<f32>(
98
- textureLoad(parent_u, s0, 0).r,
99
- textureLoad(parent_u, vec3<u32>(s1.x, s0.y, s0.z), 0).r,
100
- textureLoad(parent_u, vec3<u32>(s0.x, s1.y, s0.z), 0).r,
101
- textureLoad(parent_u, vec3<u32>(s1.x, s1.y, s0.z), 0).r
102
- ) - far;
103
- z1 = vec4<f32>(
104
- textureLoad(parent_u, vec3<u32>(s0.x, s0.y, s1.z), 0).r,
105
- textureLoad(parent_u, vec3<u32>(s1.x, s0.y, s1.z), 0).r,
106
- textureLoad(parent_u, vec3<u32>(s0.x, s1.y, s1.z), 0).r,
107
- textureLoad(parent_u, s1, 0).r
108
- ) - far;
109
- } else {
110
- z0 = vec4<f32>(
111
- fluid_parent_deviation_u(lo),
112
- fluid_parent_deviation_u(vec3<i32>(hi.x, lo.y, lo.z)),
113
- fluid_parent_deviation_u(vec3<i32>(lo.x, hi.y, lo.z)),
114
- fluid_parent_deviation_u(vec3<i32>(hi.x, hi.y, lo.z))
115
- );
116
- z1 = vec4<f32>(
117
- fluid_parent_deviation_u(vec3<i32>(lo.x, lo.y, hi.z)),
118
- fluid_parent_deviation_u(vec3<i32>(hi.x, lo.y, hi.z)),
119
- fluid_parent_deviation_u(vec3<i32>(lo.x, hi.y, hi.z)),
120
- fluid_parent_deviation_u(hi)
121
- );
122
- }
123
-
124
- let corners = ${TEXTURE3D_TRILINEAR_CORNERS_STRUCT.wgsl_ref}(z0, z1, lattice - base);
125
-
126
- return parent.read_far_velocity.x + parent.keep * texture3d_trilinear_interpolate(corners);
127
- }
128
-
129
- fn fluid_parent_face_v(face: vec3<i32>, offset: vec3<i32>) -> f32 {
130
- // the far field: nothing to read, every corner would count 0
131
- if (parent.faces_v.size.x == 0u) {
132
- return parent.read_far_velocity.y;
133
- }
134
-
135
- let lattice = (vec3<f32>(face + offset) - vec3<f32>(0.5, 0.0, 0.5)) * 0.5;
136
- let base = floor(lattice);
137
- let lo = vec3<i32>(base);
138
- let hi = lo + vec3<i32>(1);
139
-
140
- var z0: vec4<f32>;
141
- var z1: vec4<f32>;
142
-
143
- if (all(lo >= vec3<i32>(0)) && all(vec3<u32>(hi) < parent.faces_v.size)) {
144
- let s0 = grid_tile_window_storage(lo, parent.faces_v.corner_storage, parent.faces_v.period);
145
- let s1_raw = s0 + vec3<u32>(1u);
146
- let s1 = select(s1_raw, vec3<u32>(0u), s1_raw == parent.faces_v.period);
147
- let far = vec4<f32>(parent.far_velocity.y);
148
-
149
- z0 = vec4<f32>(
150
- textureLoad(parent_v, s0, 0).r,
151
- textureLoad(parent_v, vec3<u32>(s1.x, s0.y, s0.z), 0).r,
152
- textureLoad(parent_v, vec3<u32>(s0.x, s1.y, s0.z), 0).r,
153
- textureLoad(parent_v, vec3<u32>(s1.x, s1.y, s0.z), 0).r
154
- ) - far;
155
- z1 = vec4<f32>(
156
- textureLoad(parent_v, vec3<u32>(s0.x, s0.y, s1.z), 0).r,
157
- textureLoad(parent_v, vec3<u32>(s1.x, s0.y, s1.z), 0).r,
158
- textureLoad(parent_v, vec3<u32>(s0.x, s1.y, s1.z), 0).r,
159
- textureLoad(parent_v, s1, 0).r
160
- ) - far;
161
- } else {
162
- z0 = vec4<f32>(
163
- fluid_parent_deviation_v(lo),
164
- fluid_parent_deviation_v(vec3<i32>(hi.x, lo.y, lo.z)),
165
- fluid_parent_deviation_v(vec3<i32>(lo.x, hi.y, lo.z)),
166
- fluid_parent_deviation_v(vec3<i32>(hi.x, hi.y, lo.z))
167
- );
168
- z1 = vec4<f32>(
169
- fluid_parent_deviation_v(vec3<i32>(lo.x, lo.y, hi.z)),
170
- fluid_parent_deviation_v(vec3<i32>(hi.x, lo.y, hi.z)),
171
- fluid_parent_deviation_v(vec3<i32>(lo.x, hi.y, hi.z)),
172
- fluid_parent_deviation_v(hi)
173
- );
174
- }
175
-
176
- let corners = ${TEXTURE3D_TRILINEAR_CORNERS_STRUCT.wgsl_ref}(z0, z1, lattice - base);
177
-
178
- return parent.read_far_velocity.y + parent.keep * texture3d_trilinear_interpolate(corners);
179
- }
180
-
181
- fn fluid_parent_face_w(face: vec3<i32>, offset: vec3<i32>) -> f32 {
182
- // the far field: nothing to read, every corner would count 0
183
- if (parent.faces_w.size.x == 0u) {
184
- return parent.read_far_velocity.z;
185
- }
186
-
187
- let lattice = (vec3<f32>(face + offset) - vec3<f32>(0.5, 0.5, 0.0)) * 0.5;
188
- let base = floor(lattice);
189
- let lo = vec3<i32>(base);
190
- let hi = lo + vec3<i32>(1);
191
-
192
- var z0: vec4<f32>;
193
- var z1: vec4<f32>;
194
-
195
- if (all(lo >= vec3<i32>(0)) && all(vec3<u32>(hi) < parent.faces_w.size)) {
196
- let s0 = grid_tile_window_storage(lo, parent.faces_w.corner_storage, parent.faces_w.period);
197
- let s1_raw = s0 + vec3<u32>(1u);
198
- let s1 = select(s1_raw, vec3<u32>(0u), s1_raw == parent.faces_w.period);
199
- let far = vec4<f32>(parent.far_velocity.z);
200
-
201
- z0 = vec4<f32>(
202
- textureLoad(parent_w, s0, 0).r,
203
- textureLoad(parent_w, vec3<u32>(s1.x, s0.y, s0.z), 0).r,
204
- textureLoad(parent_w, vec3<u32>(s0.x, s1.y, s0.z), 0).r,
205
- textureLoad(parent_w, vec3<u32>(s1.x, s1.y, s0.z), 0).r
206
- ) - far;
207
- z1 = vec4<f32>(
208
- textureLoad(parent_w, vec3<u32>(s0.x, s0.y, s1.z), 0).r,
209
- textureLoad(parent_w, vec3<u32>(s1.x, s0.y, s1.z), 0).r,
210
- textureLoad(parent_w, vec3<u32>(s0.x, s1.y, s1.z), 0).r,
211
- textureLoad(parent_w, s1, 0).r
212
- ) - far;
213
- } else {
214
- z0 = vec4<f32>(
215
- fluid_parent_deviation_w(lo),
216
- fluid_parent_deviation_w(vec3<i32>(hi.x, lo.y, lo.z)),
217
- fluid_parent_deviation_w(vec3<i32>(lo.x, hi.y, lo.z)),
218
- fluid_parent_deviation_w(vec3<i32>(hi.x, hi.y, lo.z))
219
- );
220
- z1 = vec4<f32>(
221
- fluid_parent_deviation_w(vec3<i32>(lo.x, lo.y, hi.z)),
222
- fluid_parent_deviation_w(vec3<i32>(hi.x, lo.y, hi.z)),
223
- fluid_parent_deviation_w(vec3<i32>(lo.x, hi.y, hi.z)),
224
- fluid_parent_deviation_w(hi)
225
- );
226
- }
227
-
228
- let corners = ${TEXTURE3D_TRILINEAR_CORNERS_STRUCT.wgsl_ref}(z0, z1, lattice - base);
229
-
230
- return parent.read_far_velocity.z + parent.keep * texture3d_trilinear_interpolate(corners);
231
- }
232
- `, [
233
- TEXTURE3D_TRILINEAR_CORNERS_STRUCT.declaration_chunk,
234
- chunk_texture3d_trilinear_interpolate,
235
- chunk_grid_tile_window,
236
- ]
237
- );
238
-
239
- /**
240
- * `fluid_parent_pressure(q)`: the parent's kinematic pressure (m²/s², the child's units) at the
241
- * centre of child-lattice cell `q`, counted from `parent.origin`: the Dirichlet value of a ghost cell
242
- * beyond the child's window (§9).
243
- *
244
- * The centre of child cell `q` is parent cell coordinate `(q − ½)/2` (parent cell `P` centred at `P`),
245
- * a quarter of a parent cell off a parent centre on every axis, so the read is trilinear over eight
246
- * parent cells at weights ¾ and ¼. A parent cell beyond the parent's window reads 0, as does a value
247
- * that is not finite.
248
- *
249
- * Binds `parent_pressure`: the parent's pressure, `array<f32>`, toroidal through `parent.cells`.
250
- *
251
- * Reads 8 elements a call; beside the far field, none.
252
- *
253
- * @type {CodeChunk}
254
- */
255
- export const chunk_fluid_cascade_parent_pressure = CodeChunk.from(
256
- //language=WGSL
257
- `
258
- fn fluid_parent_pressure_sanitize(value: f32) -> f32 {
259
- return select(0.0, value, is_finite(value));
260
- }
261
-
262
- fn fluid_parent_pressure_cell(cell: vec3<i32>) -> f32 {
263
- if (!grid_tile_window_contains(cell, parent.cells.size)) {
264
- return 0.0;
265
- }
266
-
267
- let storage = grid_tile_window_storage(cell, parent.cells.corner_storage, parent.cells.period);
268
- let value = parent_pressure[grid3d_to_index(storage, parent.cells.period.xy)];
269
-
270
- return fluid_parent_pressure_sanitize(value);
271
- }
272
-
273
- fn fluid_parent_pressure(q: vec3<i32>) -> f32 {
274
- if (parent.cells.size.x == 0u) {
275
- return 0.0;
276
- }
277
-
278
- let position = (vec3<f32>(q) - vec3<f32>(0.5)) * 0.5;
279
- let base = floor(position);
280
- let lo = vec3<i32>(base);
281
- let hi = lo + vec3<i32>(1);
282
-
283
- var z0: vec4<f32>;
284
- var z1: vec4<f32>;
285
-
286
- if (all(lo >= vec3<i32>(0)) && all(vec3<u32>(hi) < parent.cells.size)) {
287
- let s0 = grid_tile_window_storage(lo, parent.cells.corner_storage, parent.cells.period);
288
- let s1_raw = s0 + vec3<u32>(1u);
289
- let s1 = select(s1_raw, vec3<u32>(0u), s1_raw == parent.cells.period);
290
- let px = parent.cells.period.x;
291
- let py = parent.cells.period.y;
292
- let row00 = px * (s0.y + py * s0.z);
293
- let row10 = px * (s1.y + py * s0.z);
294
- let row01 = px * (s0.y + py * s1.z);
295
- let row11 = px * (s1.y + py * s1.z);
296
-
297
- z0 = vec4<f32>(
298
- fluid_parent_pressure_sanitize(parent_pressure[s0.x + row00]),
299
- fluid_parent_pressure_sanitize(parent_pressure[s1.x + row00]),
300
- fluid_parent_pressure_sanitize(parent_pressure[s0.x + row10]),
301
- fluid_parent_pressure_sanitize(parent_pressure[s1.x + row10])
302
- );
303
- z1 = vec4<f32>(
304
- fluid_parent_pressure_sanitize(parent_pressure[s0.x + row01]),
305
- fluid_parent_pressure_sanitize(parent_pressure[s1.x + row01]),
306
- fluid_parent_pressure_sanitize(parent_pressure[s0.x + row11]),
307
- fluid_parent_pressure_sanitize(parent_pressure[s1.x + row11])
308
- );
309
- } else {
310
- z0 = vec4<f32>(
311
- fluid_parent_pressure_cell(lo),
312
- fluid_parent_pressure_cell(vec3<i32>(hi.x, lo.y, lo.z)),
313
- fluid_parent_pressure_cell(vec3<i32>(lo.x, hi.y, lo.z)),
314
- fluid_parent_pressure_cell(vec3<i32>(hi.x, hi.y, lo.z))
315
- );
316
- z1 = vec4<f32>(
317
- fluid_parent_pressure_cell(vec3<i32>(lo.x, lo.y, hi.z)),
318
- fluid_parent_pressure_cell(vec3<i32>(hi.x, lo.y, hi.z)),
319
- fluid_parent_pressure_cell(vec3<i32>(lo.x, hi.y, hi.z)),
320
- fluid_parent_pressure_cell(hi)
321
- );
322
- }
323
-
324
- let corners = ${TEXTURE3D_TRILINEAR_CORNERS_STRUCT.wgsl_ref}(z0, z1, position - base);
325
-
326
- return texture3d_trilinear_interpolate(corners);
327
- }
328
- `, [
329
- TEXTURE3D_TRILINEAR_CORNERS_STRUCT.declaration_chunk,
330
- chunk_texture3d_trilinear_interpolate,
331
- chunk_grid_tile_window,
332
- chunk_grid3d_to_index,
333
- chunk_is_finite,
334
- ]
335
- );
1
+ import { chunk_grid3d_to_index } from "../../shader/chunk/grid/chunk_grid3d_to_index.js";
2
+ import { chunk_grid_tile_window } from "../../shader/chunk/grid/chunk_grid_tile_window.js";
3
+ import { chunk_is_finite } from "../../shader/chunk/math/chunk_is_finite.js";
4
+ import { chunk_texture3d_trilinear_interpolate } from "../../shader/chunk/texture/sample/chunk_texture3d_trilinear_corners.js";
5
+ import { TEXTURE3D_TRILINEAR_CORNERS_STRUCT } from "../../shader/chunk/texture/TEXTURE3D_TRILINEAR_CORNERS_STRUCT.js";
6
+ import { CodeChunk } from "../../shader/compiler/CodeChunk.js";
7
+ import { chunk_fluid_far_field } from "../chunk_fluid_far_field.js";
8
+
9
+ /*
10
+ What a cascade reads of its parent (GPU_FLUID_CASCADES_PROPOSAL_2026_10_16.md §7, §9), through the
11
+ uniform `parent` (FLUID_CASCADE_PARENT_STRUCT), which every shader including one of these chunks
12
+ declares under that name.
13
+
14
+ A child addresses its parent by `offset = step.cells.corner − parent.origin` (or its pass's own copy
15
+ of the child's corner): child-lattice cells from the parent's window start to the child's, a
16
+ multiple of 4. With it, child window-local lattice points become parent window-local coordinates
17
+ by halving, so nothing here sees a world coordinate.
18
+
19
+ Both reads are trilinear with weights of 0, ¼, ½ or ¾, which f32 holds exactly. The velocity read
20
+ blends the parent's DEVIATIONS from its far field and adds the far field at the read's instant after,
21
+ so air the far field alone moves reads as the far field: exactly with no turbulence, and to the
22
+ turbulence's curvature over a parent cell with it.
23
+ */
24
+
25
+ /**
26
+ * The parent's identity read at a face of the child, one concrete function per component:
27
+ * `fluid_parent_face_u(face, offset)`, `_v`, `_w`, `face` a window-local face of the child's lattice
28
+ * for that component (u face `(i, j, k)` at cell coordinate `(i − ½, j, k)`), and the deviation it adds
29
+ * to the far field, `fluid_parent_face_deviation_u(face, offset)`, `_v`, `_w`.
30
+ *
31
+ * Child u face `i` lies on parent u lattice coordinate `(i + offset)/2` along x and
32
+ * `(j + offset − ½)/2` across it; likewise v along y and w along z. In child-lattice cells counted
33
+ * from `parent.origin` the face is at `face + offset − (½, 0, 0)`, which is where both far fields,
34
+ * `parent.far` and `parent.read`, are laid.
35
+ *
36
+ * The deviation: the tap's eight parent faces are read less the parent's far field's mean,
37
+ * `v − parent.far.mean`, and one beyond the parent's window as the parent's far field's eddy at the
38
+ * face, `σ·T`; the trilinear of those, less that eddy, is the parent's deviation from its far field at
39
+ * the face, which the read keeps `parent.keep` of. A smooth far field differs from its trilinear over
40
+ * the parent's corners by a fraction of its curvature over a parent cell, which a tile of
41
+ * `FLUID_TURBULENCE_TEXELS_PER_LENGTH` texels a length scale keeps small; with no turbulence the
42
+ * eddy is 0 and the deviation is exact.
43
+ *
44
+ * The read: `v_far(t_read)` at the face, `parent.read`, plus the deviation.
45
+ *
46
+ * Binds `parent_u`, `parent_v`, `parent_w`: the parent's persistent faces, `texture_3d<f32>`
47
+ * (`r32float`), toroidal through `parent.faces_*`; and the turbulence tile
48
+ * (`fluid_turbulence_add_resources`). A far-field parent binds stand-ins it never reads.
49
+ *
50
+ * Reads 8 texels a call, and the tile once for each far field that has turbulence; beside the far
51
+ * field (a window of size 0) no texel, and the deviation answers 0 before any window test. That early
52
+ * answer is measured: a lone 64×32×64 cascade's predict went from 56.3 to 27.6 µs and its correct from
53
+ * 84.0 to 44.0 on an RTX 4090 (pipelines swapped in one run, per-dispatch medians), the seams'
54
+ * empty-window tests and blend being most of what a beyond-window read cost there.
55
+ *
56
+ * @type {CodeChunk}
57
+ */
58
+ export const chunk_fluid_cascade_parent_velocity = CodeChunk.from(
59
+ //language=WGSL
60
+ `
61
+ fn fluid_parent_deviation_u(lattice: vec3<i32>, outside: f32) -> f32 {
62
+ if (!grid_tile_window_contains(lattice, parent.faces_u.size)) {
63
+ return outside;
64
+ }
65
+
66
+ let storage = grid_tile_window_storage(lattice, parent.faces_u.corner_storage, parent.faces_u.period);
67
+
68
+ return textureLoad(parent_u, storage, 0).r - parent.far.mean.x;
69
+ }
70
+
71
+ fn fluid_parent_deviation_v(lattice: vec3<i32>, outside: f32) -> f32 {
72
+ if (!grid_tile_window_contains(lattice, parent.faces_v.size)) {
73
+ return outside;
74
+ }
75
+
76
+ let storage = grid_tile_window_storage(lattice, parent.faces_v.corner_storage, parent.faces_v.period);
77
+
78
+ return textureLoad(parent_v, storage, 0).r - parent.far.mean.y;
79
+ }
80
+
81
+ fn fluid_parent_deviation_w(lattice: vec3<i32>, outside: f32) -> f32 {
82
+ if (!grid_tile_window_contains(lattice, parent.faces_w.size)) {
83
+ return outside;
84
+ }
85
+
86
+ let storage = grid_tile_window_storage(lattice, parent.faces_w.corner_storage, parent.faces_w.period);
87
+
88
+ return textureLoad(parent_w, storage, 0).r - parent.far.mean.z;
89
+ }
90
+
91
+ fn fluid_parent_face_deviation_u(face: vec3<i32>, offset: vec3<i32>) -> f32 {
92
+ // the far field: nothing to read, every corner would count 0
93
+ if (parent.faces_u.size.x == 0u) {
94
+ return 0.0;
95
+ }
96
+
97
+ // the parent's own far field's eddy at the face, which a corner beyond its window takes
98
+ let eddy = parent.far.sigma * fluid_far_unit(parent.far, vec3<f32>(face + offset) - vec3<f32>(0.5, 0.0, 0.0)).x;
99
+
100
+ let lattice = (vec3<f32>(face + offset) - vec3<f32>(0.0, 0.5, 0.5)) * 0.5;
101
+ let base = floor(lattice);
102
+ let lo = vec3<i32>(base);
103
+ let hi = lo + vec3<i32>(1);
104
+
105
+ var z0: vec4<f32>;
106
+ var z1: vec4<f32>;
107
+
108
+ if (all(lo >= vec3<i32>(0)) && all(vec3<u32>(hi) < parent.faces_u.size)) {
109
+ let s0 = grid_tile_window_storage(lo, parent.faces_u.corner_storage, parent.faces_u.period);
110
+ let s1_raw = s0 + vec3<u32>(1u);
111
+ let s1 = select(s1_raw, vec3<u32>(0u), s1_raw == parent.faces_u.period);
112
+ let mean = vec4<f32>(parent.far.mean.x);
113
+
114
+ z0 = vec4<f32>(
115
+ textureLoad(parent_u, s0, 0).r,
116
+ textureLoad(parent_u, vec3<u32>(s1.x, s0.y, s0.z), 0).r,
117
+ textureLoad(parent_u, vec3<u32>(s0.x, s1.y, s0.z), 0).r,
118
+ textureLoad(parent_u, vec3<u32>(s1.x, s1.y, s0.z), 0).r
119
+ ) - mean;
120
+ z1 = vec4<f32>(
121
+ textureLoad(parent_u, vec3<u32>(s0.x, s0.y, s1.z), 0).r,
122
+ textureLoad(parent_u, vec3<u32>(s1.x, s0.y, s1.z), 0).r,
123
+ textureLoad(parent_u, vec3<u32>(s0.x, s1.y, s1.z), 0).r,
124
+ textureLoad(parent_u, s1, 0).r
125
+ ) - mean;
126
+ } else {
127
+ z0 = vec4<f32>(
128
+ fluid_parent_deviation_u(lo, eddy),
129
+ fluid_parent_deviation_u(vec3<i32>(hi.x, lo.y, lo.z), eddy),
130
+ fluid_parent_deviation_u(vec3<i32>(lo.x, hi.y, lo.z), eddy),
131
+ fluid_parent_deviation_u(vec3<i32>(hi.x, hi.y, lo.z), eddy)
132
+ );
133
+ z1 = vec4<f32>(
134
+ fluid_parent_deviation_u(vec3<i32>(lo.x, lo.y, hi.z), eddy),
135
+ fluid_parent_deviation_u(vec3<i32>(hi.x, lo.y, hi.z), eddy),
136
+ fluid_parent_deviation_u(vec3<i32>(lo.x, hi.y, hi.z), eddy),
137
+ fluid_parent_deviation_u(hi, eddy)
138
+ );
139
+ }
140
+
141
+ let corners = ${TEXTURE3D_TRILINEAR_CORNERS_STRUCT.wgsl_ref}(z0, z1, lattice - base);
142
+
143
+ return parent.keep * (texture3d_trilinear_interpolate(corners) - eddy);
144
+ }
145
+
146
+ fn fluid_parent_face_u(face: vec3<i32>, offset: vec3<i32>) -> f32 {
147
+ return fluid_far_field(parent.read, vec3<f32>(face + offset) - vec3<f32>(0.5, 0.0, 0.0)).x + fluid_parent_face_deviation_u(face, offset);
148
+ }
149
+
150
+ fn fluid_parent_face_deviation_v(face: vec3<i32>, offset: vec3<i32>) -> f32 {
151
+ // the far field: nothing to read, every corner would count 0
152
+ if (parent.faces_v.size.x == 0u) {
153
+ return 0.0;
154
+ }
155
+
156
+ // the parent's own far field's eddy at the face, which a corner beyond its window takes
157
+ let eddy = parent.far.sigma * fluid_far_unit(parent.far, vec3<f32>(face + offset) - vec3<f32>(0.0, 0.5, 0.0)).y;
158
+
159
+ let lattice = (vec3<f32>(face + offset) - vec3<f32>(0.5, 0.0, 0.5)) * 0.5;
160
+ let base = floor(lattice);
161
+ let lo = vec3<i32>(base);
162
+ let hi = lo + vec3<i32>(1);
163
+
164
+ var z0: vec4<f32>;
165
+ var z1: vec4<f32>;
166
+
167
+ if (all(lo >= vec3<i32>(0)) && all(vec3<u32>(hi) < parent.faces_v.size)) {
168
+ let s0 = grid_tile_window_storage(lo, parent.faces_v.corner_storage, parent.faces_v.period);
169
+ let s1_raw = s0 + vec3<u32>(1u);
170
+ let s1 = select(s1_raw, vec3<u32>(0u), s1_raw == parent.faces_v.period);
171
+ let mean = vec4<f32>(parent.far.mean.y);
172
+
173
+ z0 = vec4<f32>(
174
+ textureLoad(parent_v, s0, 0).r,
175
+ textureLoad(parent_v, vec3<u32>(s1.x, s0.y, s0.z), 0).r,
176
+ textureLoad(parent_v, vec3<u32>(s0.x, s1.y, s0.z), 0).r,
177
+ textureLoad(parent_v, vec3<u32>(s1.x, s1.y, s0.z), 0).r
178
+ ) - mean;
179
+ z1 = vec4<f32>(
180
+ textureLoad(parent_v, vec3<u32>(s0.x, s0.y, s1.z), 0).r,
181
+ textureLoad(parent_v, vec3<u32>(s1.x, s0.y, s1.z), 0).r,
182
+ textureLoad(parent_v, vec3<u32>(s0.x, s1.y, s1.z), 0).r,
183
+ textureLoad(parent_v, s1, 0).r
184
+ ) - mean;
185
+ } else {
186
+ z0 = vec4<f32>(
187
+ fluid_parent_deviation_v(lo, eddy),
188
+ fluid_parent_deviation_v(vec3<i32>(hi.x, lo.y, lo.z), eddy),
189
+ fluid_parent_deviation_v(vec3<i32>(lo.x, hi.y, lo.z), eddy),
190
+ fluid_parent_deviation_v(vec3<i32>(hi.x, hi.y, lo.z), eddy)
191
+ );
192
+ z1 = vec4<f32>(
193
+ fluid_parent_deviation_v(vec3<i32>(lo.x, lo.y, hi.z), eddy),
194
+ fluid_parent_deviation_v(vec3<i32>(hi.x, lo.y, hi.z), eddy),
195
+ fluid_parent_deviation_v(vec3<i32>(lo.x, hi.y, hi.z), eddy),
196
+ fluid_parent_deviation_v(hi, eddy)
197
+ );
198
+ }
199
+
200
+ let corners = ${TEXTURE3D_TRILINEAR_CORNERS_STRUCT.wgsl_ref}(z0, z1, lattice - base);
201
+
202
+ return parent.keep * (texture3d_trilinear_interpolate(corners) - eddy);
203
+ }
204
+
205
+ fn fluid_parent_face_v(face: vec3<i32>, offset: vec3<i32>) -> f32 {
206
+ return fluid_far_field(parent.read, vec3<f32>(face + offset) - vec3<f32>(0.0, 0.5, 0.0)).y + fluid_parent_face_deviation_v(face, offset);
207
+ }
208
+
209
+ fn fluid_parent_face_deviation_w(face: vec3<i32>, offset: vec3<i32>) -> f32 {
210
+ // the far field: nothing to read, every corner would count 0
211
+ if (parent.faces_w.size.x == 0u) {
212
+ return 0.0;
213
+ }
214
+
215
+ // the parent's own far field's eddy at the face, which a corner beyond its window takes
216
+ let eddy = parent.far.sigma * fluid_far_unit(parent.far, vec3<f32>(face + offset) - vec3<f32>(0.0, 0.0, 0.5)).z;
217
+
218
+ let lattice = (vec3<f32>(face + offset) - vec3<f32>(0.5, 0.5, 0.0)) * 0.5;
219
+ let base = floor(lattice);
220
+ let lo = vec3<i32>(base);
221
+ let hi = lo + vec3<i32>(1);
222
+
223
+ var z0: vec4<f32>;
224
+ var z1: vec4<f32>;
225
+
226
+ if (all(lo >= vec3<i32>(0)) && all(vec3<u32>(hi) < parent.faces_w.size)) {
227
+ let s0 = grid_tile_window_storage(lo, parent.faces_w.corner_storage, parent.faces_w.period);
228
+ let s1_raw = s0 + vec3<u32>(1u);
229
+ let s1 = select(s1_raw, vec3<u32>(0u), s1_raw == parent.faces_w.period);
230
+ let mean = vec4<f32>(parent.far.mean.z);
231
+
232
+ z0 = vec4<f32>(
233
+ textureLoad(parent_w, s0, 0).r,
234
+ textureLoad(parent_w, vec3<u32>(s1.x, s0.y, s0.z), 0).r,
235
+ textureLoad(parent_w, vec3<u32>(s0.x, s1.y, s0.z), 0).r,
236
+ textureLoad(parent_w, vec3<u32>(s1.x, s1.y, s0.z), 0).r
237
+ ) - mean;
238
+ z1 = vec4<f32>(
239
+ textureLoad(parent_w, vec3<u32>(s0.x, s0.y, s1.z), 0).r,
240
+ textureLoad(parent_w, vec3<u32>(s1.x, s0.y, s1.z), 0).r,
241
+ textureLoad(parent_w, vec3<u32>(s0.x, s1.y, s1.z), 0).r,
242
+ textureLoad(parent_w, s1, 0).r
243
+ ) - mean;
244
+ } else {
245
+ z0 = vec4<f32>(
246
+ fluid_parent_deviation_w(lo, eddy),
247
+ fluid_parent_deviation_w(vec3<i32>(hi.x, lo.y, lo.z), eddy),
248
+ fluid_parent_deviation_w(vec3<i32>(lo.x, hi.y, lo.z), eddy),
249
+ fluid_parent_deviation_w(vec3<i32>(hi.x, hi.y, lo.z), eddy)
250
+ );
251
+ z1 = vec4<f32>(
252
+ fluid_parent_deviation_w(vec3<i32>(lo.x, lo.y, hi.z), eddy),
253
+ fluid_parent_deviation_w(vec3<i32>(hi.x, lo.y, hi.z), eddy),
254
+ fluid_parent_deviation_w(vec3<i32>(lo.x, hi.y, hi.z), eddy),
255
+ fluid_parent_deviation_w(hi, eddy)
256
+ );
257
+ }
258
+
259
+ let corners = ${TEXTURE3D_TRILINEAR_CORNERS_STRUCT.wgsl_ref}(z0, z1, lattice - base);
260
+
261
+ return parent.keep * (texture3d_trilinear_interpolate(corners) - eddy);
262
+ }
263
+
264
+ fn fluid_parent_face_w(face: vec3<i32>, offset: vec3<i32>) -> f32 {
265
+ return fluid_far_field(parent.read, vec3<f32>(face + offset) - vec3<f32>(0.0, 0.0, 0.5)).z + fluid_parent_face_deviation_w(face, offset);
266
+ }
267
+ `, [
268
+ TEXTURE3D_TRILINEAR_CORNERS_STRUCT.declaration_chunk,
269
+ chunk_texture3d_trilinear_interpolate,
270
+ chunk_grid_tile_window,
271
+ chunk_fluid_far_field,
272
+ ]
273
+ );
274
+
275
+ /**
276
+ * `fluid_parent_pressure(q)`: the parent's kinematic pressure (m²/s², the child's units) at the
277
+ * centre of child-lattice cell `q`, counted from `parent.origin`: the Dirichlet value of a ghost cell
278
+ * beyond the child's window (§9).
279
+ *
280
+ * The centre of child cell `q` is parent cell coordinate `(q − ½)/2` (parent cell `P` centred at `P`),
281
+ * a quarter of a parent cell off a parent centre on every axis, so the read is trilinear over eight
282
+ * parent cells at weights ¾ and ¼. A parent cell beyond the parent's window reads 0, as does a value
283
+ * that is not finite.
284
+ *
285
+ * Binds `parent_pressure`: the parent's pressure, `array<f32>`, toroidal through `parent.cells`.
286
+ *
287
+ * Reads 8 elements a call; beside the far field, none.
288
+ *
289
+ * @type {CodeChunk}
290
+ */
291
+ export const chunk_fluid_cascade_parent_pressure = CodeChunk.from(
292
+ //language=WGSL
293
+ `
294
+ fn fluid_parent_pressure_sanitize(value: f32) -> f32 {
295
+ return select(0.0, value, is_finite(value));
296
+ }
297
+
298
+ fn fluid_parent_pressure_cell(cell: vec3<i32>) -> f32 {
299
+ if (!grid_tile_window_contains(cell, parent.cells.size)) {
300
+ return 0.0;
301
+ }
302
+
303
+ let storage = grid_tile_window_storage(cell, parent.cells.corner_storage, parent.cells.period);
304
+ let value = parent_pressure[grid3d_to_index(storage, parent.cells.period.xy)];
305
+
306
+ return fluid_parent_pressure_sanitize(value);
307
+ }
308
+
309
+ fn fluid_parent_pressure(q: vec3<i32>) -> f32 {
310
+ if (parent.cells.size.x == 0u) {
311
+ return 0.0;
312
+ }
313
+
314
+ let position = (vec3<f32>(q) - vec3<f32>(0.5)) * 0.5;
315
+ let base = floor(position);
316
+ let lo = vec3<i32>(base);
317
+ let hi = lo + vec3<i32>(1);
318
+
319
+ var z0: vec4<f32>;
320
+ var z1: vec4<f32>;
321
+
322
+ if (all(lo >= vec3<i32>(0)) && all(vec3<u32>(hi) < parent.cells.size)) {
323
+ let s0 = grid_tile_window_storage(lo, parent.cells.corner_storage, parent.cells.period);
324
+ let s1_raw = s0 + vec3<u32>(1u);
325
+ let s1 = select(s1_raw, vec3<u32>(0u), s1_raw == parent.cells.period);
326
+ let px = parent.cells.period.x;
327
+ let py = parent.cells.period.y;
328
+ let row00 = px * (s0.y + py * s0.z);
329
+ let row10 = px * (s1.y + py * s0.z);
330
+ let row01 = px * (s0.y + py * s1.z);
331
+ let row11 = px * (s1.y + py * s1.z);
332
+
333
+ z0 = vec4<f32>(
334
+ fluid_parent_pressure_sanitize(parent_pressure[s0.x + row00]),
335
+ fluid_parent_pressure_sanitize(parent_pressure[s1.x + row00]),
336
+ fluid_parent_pressure_sanitize(parent_pressure[s0.x + row10]),
337
+ fluid_parent_pressure_sanitize(parent_pressure[s1.x + row10])
338
+ );
339
+ z1 = vec4<f32>(
340
+ fluid_parent_pressure_sanitize(parent_pressure[s0.x + row01]),
341
+ fluid_parent_pressure_sanitize(parent_pressure[s1.x + row01]),
342
+ fluid_parent_pressure_sanitize(parent_pressure[s0.x + row11]),
343
+ fluid_parent_pressure_sanitize(parent_pressure[s1.x + row11])
344
+ );
345
+ } else {
346
+ z0 = vec4<f32>(
347
+ fluid_parent_pressure_cell(lo),
348
+ fluid_parent_pressure_cell(vec3<i32>(hi.x, lo.y, lo.z)),
349
+ fluid_parent_pressure_cell(vec3<i32>(lo.x, hi.y, lo.z)),
350
+ fluid_parent_pressure_cell(vec3<i32>(hi.x, hi.y, lo.z))
351
+ );
352
+ z1 = vec4<f32>(
353
+ fluid_parent_pressure_cell(vec3<i32>(lo.x, lo.y, hi.z)),
354
+ fluid_parent_pressure_cell(vec3<i32>(hi.x, lo.y, hi.z)),
355
+ fluid_parent_pressure_cell(vec3<i32>(lo.x, hi.y, hi.z)),
356
+ fluid_parent_pressure_cell(hi)
357
+ );
358
+ }
359
+
360
+ let corners = ${TEXTURE3D_TRILINEAR_CORNERS_STRUCT.wgsl_ref}(z0, z1, position - base);
361
+
362
+ return texture3d_trilinear_interpolate(corners);
363
+ }
364
+ `, [
365
+ TEXTURE3D_TRILINEAR_CORNERS_STRUCT.declaration_chunk,
366
+ chunk_texture3d_trilinear_interpolate,
367
+ chunk_grid_tile_window,
368
+ chunk_grid3d_to_index,
369
+ chunk_is_finite,
370
+ ]
371
+ );