@woosh/meep-engine 3.64.1 → 3.65.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 (324) hide show
  1. package/CHANGELOG.md +85 -0
  2. package/build/bundle-worker-image-decoder.js +1 -1
  3. package/build/bundle-worker-terrain.js +1 -1
  4. package/package.json +1 -1
  5. package/src/core/binary/BinaryBuffer.d.ts +5 -0
  6. package/src/core/binary/BinaryBuffer.d.ts.map +1 -1
  7. package/src/core/binary/BinaryBuffer.js +39 -5
  8. package/src/core/geom/3d/topology/struct/binary/io/bt_boundary_loop.d.ts +65 -6
  9. package/src/core/geom/3d/topology/struct/binary/io/bt_boundary_loop.d.ts.map +1 -1
  10. package/src/core/geom/3d/topology/struct/binary/io/bt_boundary_loop.js +451 -101
  11. package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_close_boundary_holes.d.ts +4 -2
  12. package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_close_boundary_holes.d.ts.map +1 -1
  13. package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_close_boundary_holes.js +4 -2
  14. package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_fill_small_holes.d.ts +8 -1
  15. package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_fill_small_holes.d.ts.map +1 -1
  16. package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_fill_small_holes.js +45 -10
  17. package/src/core/geom/3d/topology/struct/binary/query/bt_mesh_face_find_path_polyanya.d.ts.map +1 -1
  18. package/src/core/geom/3d/topology/struct/binary/query/bt_mesh_face_find_path_polyanya.js +237 -119
  19. package/src/engine/graphics/ecs/grass/GrassSpecies.d.ts +143 -0
  20. package/src/engine/graphics/ecs/grass/GrassSpecies.d.ts.map +1 -0
  21. package/src/engine/graphics/ecs/grass/GrassSpecies.js +189 -0
  22. package/src/engine/graphics/ecs/grass/GrassSurface.d.ts +25 -0
  23. package/src/engine/graphics/ecs/grass/GrassSurface.d.ts.map +1 -0
  24. package/src/engine/graphics/ecs/grass/GrassSurface.js +32 -0
  25. package/src/engine/graphics/ecs/grass/GroundCover.d.ts +68 -0
  26. package/src/engine/graphics/ecs/grass/GroundCover.d.ts.map +1 -0
  27. package/src/engine/graphics/ecs/grass/GroundCover.js +85 -0
  28. package/src/engine/graphics3/GrassSurfaceSystem.d.ts +153 -0
  29. package/src/engine/graphics3/GrassSurfaceSystem.d.ts.map +1 -0
  30. package/src/engine/graphics3/GrassSurfaceSystem.js +1076 -0
  31. package/src/engine/graphics3/GroundCoverSystem.d.ts +33 -0
  32. package/src/engine/graphics3/GroundCoverSystem.d.ts.map +1 -0
  33. package/src/engine/graphics3/GroundCoverSystem.js +58 -0
  34. package/src/engine/network/NetworkSession.d.ts.map +1 -1
  35. package/src/engine/network/NetworkSession.js +372 -110
  36. package/src/engine/network/orchestrator/NetworkPeer.d.ts.map +1 -1
  37. package/src/engine/network/orchestrator/NetworkPeer.js +6 -1
  38. package/src/engine/network/orchestrator/ServerAuthoritativeClient.d.ts.map +1 -1
  39. package/src/engine/network/orchestrator/ServerAuthoritativeClient.js +9 -2
  40. package/src/engine/network/orchestrator/ServerAuthoritativeServer.d.ts.map +1 -1
  41. package/src/engine/network/orchestrator/ServerAuthoritativeServer.js +325 -140
  42. package/src/engine/network/sim/SimActionExecutor.d.ts +4 -1
  43. package/src/engine/network/sim/SimActionExecutor.d.ts.map +1 -1
  44. package/src/engine/network/sim/SimActionExecutor.js +65 -9
  45. package/src/engine/network/state/PredictionHistory.d.ts.map +1 -1
  46. package/src/engine/network/state/PredictionHistory.js +6 -1
  47. package/src/engine/network/time/AdaptiveRenderDelay.d.ts +25 -14
  48. package/src/engine/network/time/AdaptiveRenderDelay.d.ts.map +1 -1
  49. package/src/engine/network/time/AdaptiveRenderDelay.js +38 -20
  50. package/src/engine/network/time/RenderPlayout.d.ts +23 -3
  51. package/src/engine/network/time/RenderPlayout.d.ts.map +1 -1
  52. package/src/engine/network/time/RenderPlayout.js +40 -4
  53. package/src/engine/physics/fluid/ecs/FluidObstacleSystem.d.ts +4 -4
  54. package/src/engine/physics/fluid/obstacle/chunk_fluid_obstacle_record.d.ts +5 -1
  55. package/src/engine/physics/fluid/obstacle/chunk_fluid_obstacle_record.d.ts.map +1 -1
  56. package/src/engine/physics/fluid/obstacle/chunk_fluid_obstacle_record.js +27 -1
  57. package/src/shade/device/shader/ShaderModuleCompiler.d.ts +2 -0
  58. package/src/shade/device/shader/ShaderModuleCompiler.d.ts.map +1 -1
  59. package/src/shade/device/shader/ShaderModuleCompiler.js +25 -2
  60. package/src/shade/playground/grass_surfaces/index.html +75 -0
  61. package/src/shade/playground/grass_surfaces/main.d.ts +2 -0
  62. package/src/shade/playground/grass_surfaces/main.d.ts.map +1 -0
  63. package/src/shade/playground/grass_surfaces/main.js +593 -0
  64. package/src/shade/playground/grass_surfaces/read_grass_surfaces.d.ts +62 -0
  65. package/src/shade/playground/grass_surfaces/read_grass_surfaces.d.ts.map +1 -0
  66. package/src/shade/playground/grass_surfaces/read_grass_surfaces.js +188 -0
  67. package/src/shade/playground/probe_clipmap_box/README.md +5 -1
  68. package/src/shade/playground/probe_clipmap_box/index.html +12 -0
  69. package/src/shade/playground/probe_clipmap_box/main.d.ts.map +1 -1
  70. package/src/shade/playground/probe_clipmap_box/main.js +15 -0
  71. package/src/shade/playground/probe_clipmap_box/scene.d.ts +8 -1
  72. package/src/shade/playground/probe_clipmap_box/scene.d.ts.map +1 -1
  73. package/src/shade/playground/probe_clipmap_box/scene.js +74 -6
  74. package/src/shade/renderer/Renderer.d.ts.map +1 -1
  75. package/src/shade/renderer/Renderer.js +47 -43
  76. package/src/shade/renderer/extension/ViewTextures.d.ts +12 -5
  77. package/src/shade/renderer/extension/ViewTextures.d.ts.map +1 -1
  78. package/src/shade/renderer/extension/ViewTextures.js +19 -5
  79. package/src/shade/renderer/fluid/GPUFluidCascadeStack.d.ts +3 -1
  80. package/src/shade/renderer/fluid/GPUFluidCascadeStack.d.ts.map +1 -1
  81. package/src/shade/renderer/fluid/GPUFluidCascadeStack.js +6 -1
  82. package/src/shade/renderer/fluid/forcing/GPUFluidForcing.d.ts +7 -0
  83. package/src/shade/renderer/fluid/forcing/GPUFluidForcing.d.ts.map +1 -1
  84. package/src/shade/renderer/fluid/forcing/GPUFluidForcing.js +10 -0
  85. package/src/shade/renderer/geometry/sdf/GPUGeometrySDFManager.d.ts +7 -1
  86. package/src/shade/renderer/geometry/sdf/GPUGeometrySDFManager.d.ts.map +1 -1
  87. package/src/shade/renderer/geometry/sdf/GPUGeometrySDFManager.js +46 -15
  88. package/src/shade/renderer/geometry/sdf/bundle/ModelCacheBundle.d.ts +3 -2
  89. package/src/shade/renderer/geometry/sdf/bundle/ModelCacheBundle.d.ts.map +1 -1
  90. package/src/shade/renderer/geometry/sdf/bundle/ModelCacheBundle.js +3 -2
  91. package/src/shade/renderer/geometry/sdf/bundle/model_cache_bundle_sort_morton.d.ts +22 -0
  92. package/src/shade/renderer/geometry/sdf/bundle/model_cache_bundle_sort_morton.d.ts.map +1 -0
  93. package/src/shade/renderer/geometry/sdf/bundle/model_cache_bundle_sort_morton.js +247 -0
  94. package/src/shade/renderer/global_illumination/probe_clipmap/GPUProbeClipmapGI.d.ts +50 -0
  95. package/src/shade/renderer/global_illumination/probe_clipmap/GPUProbeClipmapGI.d.ts.map +1 -1
  96. package/src/shade/renderer/global_illumination/probe_clipmap/GPUProbeClipmapGI.js +101 -0
  97. package/src/shade/renderer/global_illumination/probe_clipmap/ProbeClipmapSettings.d.ts +2 -1
  98. package/src/shade/renderer/global_illumination/probe_clipmap/ProbeClipmapSettings.d.ts.map +1 -1
  99. package/src/shade/renderer/global_illumination/probe_clipmap/ProbeClipmapSettings.js +2 -1
  100. package/src/shade/renderer/global_illumination/probe_clipmap/brick/GPUBrickClipmap.d.ts +8 -0
  101. package/src/shade/renderer/global_illumination/probe_clipmap/brick/GPUBrickClipmap.d.ts.map +1 -1
  102. package/src/shade/renderer/global_illumination/probe_clipmap/brick/GPUBrickClipmap.js +12 -0
  103. package/src/shade/renderer/global_illumination/probe_clipmap/brick/chunk_brick_clipmap_trace.d.ts +12 -6
  104. package/src/shade/renderer/global_illumination/probe_clipmap/brick/chunk_brick_clipmap_trace.d.ts.map +1 -1
  105. package/src/shade/renderer/global_illumination/probe_clipmap/brick/chunk_brick_clipmap_trace.js +35 -29
  106. package/src/shade/renderer/global_illumination/probe_clipmap/debug/graph_probe_clipmap_debug_brick_clipmap.d.ts.map +1 -1
  107. package/src/shade/renderer/global_illumination/probe_clipmap/debug/graph_probe_clipmap_debug_brick_clipmap.js +4 -2
  108. package/src/shade/renderer/global_illumination/probe_clipmap/debug/graph_probe_clipmap_debug_brick_material.d.ts.map +1 -1
  109. package/src/shade/renderer/global_illumination/probe_clipmap/debug/graph_probe_clipmap_debug_brick_material.js +6 -4
  110. package/src/shade/renderer/global_illumination/probe_clipmap/material/GPUBrickMaterial.d.ts.map +1 -1
  111. package/src/shade/renderer/global_illumination/probe_clipmap/material/GPUBrickMaterial.js +2 -1
  112. package/src/shade/renderer/global_illumination/probe_clipmap/material/chunk_brick_material.d.ts +6 -5
  113. package/src/shade/renderer/global_illumination/probe_clipmap/material/chunk_brick_material.d.ts.map +1 -1
  114. package/src/shade/renderer/global_illumination/probe_clipmap/material/chunk_brick_material.js +15 -14
  115. package/src/shade/renderer/global_illumination/probe_clipmap/material/shader_brick_material_gather.d.ts.map +1 -1
  116. package/src/shade/renderer/global_illumination/probe_clipmap/material/shader_brick_material_gather.js +4 -2
  117. package/src/shade/renderer/global_illumination/probe_clipmap/probe/GPUProbeClipmap.d.ts +19 -2
  118. package/src/shade/renderer/global_illumination/probe_clipmap/probe/GPUProbeClipmap.d.ts.map +1 -1
  119. package/src/shade/renderer/global_illumination/probe_clipmap/probe/GPUProbeClipmap.js +128 -10
  120. package/src/shade/renderer/global_illumination/probe_clipmap/probe/PROBE_CLIPMAP.d.ts +19 -1
  121. package/src/shade/renderer/global_illumination/probe_clipmap/probe/PROBE_CLIPMAP.d.ts.map +1 -1
  122. package/src/shade/renderer/global_illumination/probe_clipmap/probe/PROBE_CLIPMAP.js +27 -2
  123. package/src/shade/renderer/global_illumination/probe_clipmap/probe/ProbeClipmapScreenWants.d.ts +19 -11
  124. package/src/shade/renderer/global_illumination/probe_clipmap/probe/ProbeClipmapScreenWants.d.ts.map +1 -1
  125. package/src/shade/renderer/global_illumination/probe_clipmap/probe/ProbeClipmapScreenWants.js +35 -11
  126. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap.d.ts.map +1 -1
  127. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap.js +3 -1
  128. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_box_cages.d.ts +40 -0
  129. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_box_cages.d.ts.map +1 -0
  130. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_box_cages.js +174 -0
  131. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_hit_material.d.ts +4 -4
  132. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_hit_material.js +10 -10
  133. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_parallax.d.ts +31 -0
  134. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_parallax.d.ts.map +1 -0
  135. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_parallax.js +54 -0
  136. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_sample_radiance.d.ts +8 -4
  137. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_sample_radiance.d.ts.map +1 -1
  138. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_sample_radiance.js +10 -21
  139. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_want.d.ts +7 -2
  140. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_want.d.ts.map +1 -1
  141. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_want.js +33 -29
  142. package/src/shade/renderer/global_illumination/probe_clipmap/probe/graph_probe_clipmap_want_meshlets.d.ts +28 -0
  143. package/src/shade/renderer/global_illumination/probe_clipmap/probe/graph_probe_clipmap_want_meshlets.d.ts.map +1 -0
  144. package/src/shade/renderer/global_illumination/probe_clipmap/probe/graph_probe_clipmap_want_meshlets.js +138 -0
  145. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_due.d.ts +13 -9
  146. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_due.d.ts.map +1 -1
  147. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_due.js +18 -11
  148. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_light.js +1 -1
  149. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_relocate.d.ts.map +1 -1
  150. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_relocate.js +4 -2
  151. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_retire.d.ts.map +1 -1
  152. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_retire.js +2 -3
  153. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_schedule.d.ts +5 -3
  154. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_schedule.d.ts.map +1 -1
  155. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_schedule.js +15 -30
  156. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_shade.js +1 -1
  157. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_trace.d.ts.map +1 -1
  158. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_trace.js +4 -2
  159. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_want.d.ts +11 -0
  160. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_want.d.ts.map +1 -1
  161. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_want.js +29 -2
  162. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_want_late.d.ts +40 -0
  163. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_want_late.d.ts.map +1 -0
  164. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_want_late.js +126 -0
  165. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_want_meshlets.d.ts +36 -0
  166. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_want_meshlets.d.ts.map +1 -0
  167. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_want_meshlets.js +221 -0
  168. package/src/shade/renderer/gpu_primitive/age_eviction/chunk_age_eviction.d.ts +40 -0
  169. package/src/shade/renderer/gpu_primitive/age_eviction/chunk_age_eviction.d.ts.map +1 -0
  170. package/src/shade/renderer/gpu_primitive/age_eviction/chunk_age_eviction.js +86 -0
  171. package/src/shade/renderer/grass/blade/GPUGrassBlades.d.ts +135 -0
  172. package/src/shade/renderer/grass/blade/GPUGrassBlades.d.ts.map +1 -0
  173. package/src/shade/renderer/grass/blade/GPUGrassBlades.js +676 -0
  174. package/src/shade/renderer/grass/blade/GRASS_BLADE.d.ts +145 -0
  175. package/src/shade/renderer/grass/blade/GRASS_BLADE.d.ts.map +1 -0
  176. package/src/shade/renderer/grass/blade/GRASS_BLADE.js +179 -0
  177. package/src/shade/renderer/grass/blade/chunk_grass_blade.d.ts +63 -0
  178. package/src/shade/renderer/grass/blade/chunk_grass_blade.d.ts.map +1 -0
  179. package/src/shade/renderer/grass/blade/chunk_grass_blade.js +244 -0
  180. package/src/shade/renderer/grass/blade/chunk_grass_blade_wind.d.ts +58 -0
  181. package/src/shade/renderer/grass/blade/chunk_grass_blade_wind.d.ts.map +1 -0
  182. package/src/shade/renderer/grass/blade/chunk_grass_blade_wind.js +174 -0
  183. package/src/shade/renderer/grass/blade/grass_blade_id_draw.d.ts +25 -0
  184. package/src/shade/renderer/grass/blade/grass_blade_id_draw.d.ts.map +1 -0
  185. package/src/shade/renderer/grass/blade/grass_blade_id_draw.js +133 -0
  186. package/src/shade/renderer/grass/blade/grass_blade_mechanics.d.ts +80 -0
  187. package/src/shade/renderer/grass/blade/grass_blade_mechanics.d.ts.map +1 -0
  188. package/src/shade/renderer/grass/blade/grass_blade_mechanics.js +92 -0
  189. package/src/shade/renderer/grass/blade/grass_blade_resolve.d.ts +29 -0
  190. package/src/shade/renderer/grass/blade/grass_blade_resolve.d.ts.map +1 -0
  191. package/src/shade/renderer/grass/blade/grass_blade_resolve.js +175 -0
  192. package/src/shade/renderer/grass/blade/shader_grass_blade_draw_args.d.ts +14 -0
  193. package/src/shade/renderer/grass/blade/shader_grass_blade_draw_args.d.ts.map +1 -0
  194. package/src/shade/renderer/grass/blade/shader_grass_blade_draw_args.js +45 -0
  195. package/src/shade/renderer/grass/blade/shader_grass_blade_expand.d.ts +61 -0
  196. package/src/shade/renderer/grass/blade/shader_grass_blade_expand.d.ts.map +1 -0
  197. package/src/shade/renderer/grass/blade/shader_grass_blade_expand.js +340 -0
  198. package/src/shade/renderer/grass/blade/shader_grass_cell_count.d.ts +46 -0
  199. package/src/shade/renderer/grass/blade/shader_grass_cell_count.d.ts.map +1 -0
  200. package/src/shade/renderer/grass/blade/shader_grass_cell_count.js +280 -0
  201. package/src/shade/renderer/grass/population/chunk_grass_population.d.ts +60 -0
  202. package/src/shade/renderer/grass/population/chunk_grass_population.d.ts.map +1 -0
  203. package/src/shade/renderer/grass/population/chunk_grass_population.js +171 -0
  204. package/src/shade/renderer/grass/press/GPUGrassPress.d.ts +99 -0
  205. package/src/shade/renderer/grass/press/GPUGrassPress.d.ts.map +1 -0
  206. package/src/shade/renderer/grass/press/GPUGrassPress.js +436 -0
  207. package/src/shade/renderer/grass/press/GRASS_PRESS.d.ts +179 -0
  208. package/src/shade/renderer/grass/press/GRASS_PRESS.d.ts.map +1 -0
  209. package/src/shade/renderer/grass/press/GRASS_PRESS.js +217 -0
  210. package/src/shade/renderer/grass/press/chunk_grass_press.d.ts +65 -0
  211. package/src/shade/renderer/grass/press/chunk_grass_press.d.ts.map +1 -0
  212. package/src/shade/renderer/grass/press/chunk_grass_press.js +296 -0
  213. package/src/shade/renderer/grass/press/shader_grass_press_mark.d.ts +31 -0
  214. package/src/shade/renderer/grass/press/shader_grass_press_mark.d.ts.map +1 -0
  215. package/src/shade/renderer/grass/press/shader_grass_press_mark.js +169 -0
  216. package/src/shade/renderer/grass/press/shader_grass_press_stamp.d.ts +27 -0
  217. package/src/shade/renderer/grass/press/shader_grass_press_stamp.d.ts.map +1 -0
  218. package/src/shade/renderer/grass/press/shader_grass_press_stamp.js +183 -0
  219. package/src/shade/renderer/grass/surface/GPUGrassSurfaces.d.ts +193 -0
  220. package/src/shade/renderer/grass/surface/GPUGrassSurfaces.d.ts.map +1 -0
  221. package/src/shade/renderer/grass/surface/GPUGrassSurfaces.js +1253 -0
  222. package/src/shade/renderer/grass/surface/GRASS_SURFACE.d.ts +211 -0
  223. package/src/shade/renderer/grass/surface/GRASS_SURFACE.d.ts.map +1 -0
  224. package/src/shade/renderer/grass/surface/GRASS_SURFACE.js +241 -0
  225. package/src/shade/renderer/grass/surface/GRASS_SURFACE_VIEW.d.ts +82 -0
  226. package/src/shade/renderer/grass/surface/GRASS_SURFACE_VIEW.d.ts.map +1 -0
  227. package/src/shade/renderer/grass/surface/GRASS_SURFACE_VIEW.js +111 -0
  228. package/src/shade/renderer/grass/surface/chunk_grass_column_cross.d.ts +39 -0
  229. package/src/shade/renderer/grass/surface/chunk_grass_column_cross.d.ts.map +1 -0
  230. package/src/shade/renderer/grass/surface/chunk_grass_column_cross.js +85 -0
  231. package/src/shade/renderer/grass/surface/chunk_grass_directory.d.ts +29 -0
  232. package/src/shade/renderer/grass/surface/chunk_grass_directory.d.ts.map +1 -0
  233. package/src/shade/renderer/grass/surface/chunk_grass_directory.js +112 -0
  234. package/src/shade/renderer/grass/surface/chunk_grass_slot.d.ts +27 -0
  235. package/src/shade/renderer/grass/surface/chunk_grass_slot.d.ts.map +1 -0
  236. package/src/shade/renderer/grass/surface/chunk_grass_slot.js +50 -0
  237. package/src/shade/renderer/grass/surface/chunk_grass_surface_frame.d.ts +21 -0
  238. package/src/shade/renderer/grass/surface/chunk_grass_surface_frame.d.ts.map +1 -0
  239. package/src/shade/renderer/grass/surface/chunk_grass_surface_frame.js +41 -0
  240. package/src/shade/renderer/grass/surface/chunk_grass_surface_window.d.ts +32 -0
  241. package/src/shade/renderer/grass/surface/chunk_grass_surface_window.d.ts.map +1 -0
  242. package/src/shade/renderer/grass/surface/chunk_grass_surface_window.js +136 -0
  243. package/src/shade/renderer/grass/surface/chunk_grass_surfel.d.ts +37 -0
  244. package/src/shade/renderer/grass/surface/chunk_grass_surfel.d.ts.map +1 -0
  245. package/src/shade/renderer/grass/surface/chunk_grass_surfel.js +85 -0
  246. package/src/shade/renderer/grass/surface/chunk_grass_tile.d.ts +25 -0
  247. package/src/shade/renderer/grass/surface/chunk_grass_tile.d.ts.map +1 -0
  248. package/src/shade/renderer/grass/surface/chunk_grass_tile.js +52 -0
  249. package/src/shade/renderer/grass/surface/shader_grass_directory_fill.d.ts +23 -0
  250. package/src/shade/renderer/grass/surface/shader_grass_directory_fill.d.ts.map +1 -0
  251. package/src/shade/renderer/grass/surface/shader_grass_directory_fill.js +87 -0
  252. package/src/shade/renderer/grass/surface/shader_grass_surface_bake.d.ts +43 -0
  253. package/src/shade/renderer/grass/surface/shader_grass_surface_bake.d.ts.map +1 -0
  254. package/src/shade/renderer/grass/surface/shader_grass_surface_bake.js +265 -0
  255. package/src/shade/renderer/grass/surface/shader_grass_surface_bake_command.d.ts +13 -0
  256. package/src/shade/renderer/grass/surface/shader_grass_surface_bake_command.d.ts.map +1 -0
  257. package/src/shade/renderer/grass/surface/shader_grass_surface_bake_command.js +49 -0
  258. package/src/shade/renderer/grass/surface/shader_grass_surface_invalidate.d.ts +62 -0
  259. package/src/shade/renderer/grass/surface/shader_grass_surface_invalidate.d.ts.map +1 -0
  260. package/src/shade/renderer/grass/surface/shader_grass_surface_invalidate.js +162 -0
  261. package/src/shade/renderer/grass/surface/shader_grass_surface_retire.d.ts +40 -0
  262. package/src/shade/renderer/grass/surface/shader_grass_surface_retire.d.ts.map +1 -0
  263. package/src/shade/renderer/grass/surface/shader_grass_surface_retire.js +155 -0
  264. package/src/shade/renderer/grass/surface/shader_grass_surface_schedule.d.ts +19 -0
  265. package/src/shade/renderer/grass/surface/shader_grass_surface_schedule.d.ts.map +1 -0
  266. package/src/shade/renderer/grass/surface/shader_grass_surface_schedule.js +58 -0
  267. package/src/shade/renderer/grass/surface/shader_grass_surface_want.d.ts +30 -0
  268. package/src/shade/renderer/grass/surface/shader_grass_surface_want.d.ts.map +1 -0
  269. package/src/shade/renderer/grass/surface/shader_grass_surface_want.js +251 -0
  270. package/src/shade/renderer/grass/surface/shader_grass_surface_window_count.d.ts +21 -0
  271. package/src/shade/renderer/grass/surface/shader_grass_surface_window_count.d.ts.map +1 -0
  272. package/src/shade/renderer/grass/surface/shader_grass_surface_window_count.js +75 -0
  273. package/src/shade/renderer/postprocess/velocity/graph_add_per_object_velocity.d.ts.map +1 -1
  274. package/src/shade/renderer/postprocess/velocity/graph_add_per_object_velocity.js +4 -23
  275. package/src/shade/renderer/postprocess/velocity/view_velocity_matrices.d.ts +12 -0
  276. package/src/shade/renderer/postprocess/velocity/view_velocity_matrices.d.ts.map +1 -0
  277. package/src/shade/renderer/postprocess/velocity/view_velocity_matrices.js +29 -0
  278. package/src/shade/renderer/rasterize/native/avboit/graph_rasterize_meshes_transparent_avboit.d.ts.map +1 -1
  279. package/src/shade/renderer/rasterize/native/avboit/graph_rasterize_meshes_transparent_avboit.js +22 -0
  280. package/src/shade/renderer/scene/GPUSceneContext.d.ts.map +1 -1
  281. package/src/shade/renderer/scene/GPUSceneContext.js +3 -0
  282. package/src/shade/renderer/scene/GRASS_SURFACE_PARAMS_STRUCT.d.ts +27 -0
  283. package/src/shade/renderer/scene/GRASS_SURFACE_PARAMS_STRUCT.d.ts.map +1 -0
  284. package/src/shade/renderer/scene/GRASS_SURFACE_PARAMS_STRUCT.js +38 -0
  285. package/src/shade/renderer/scene/MESH_GROUND_COVER_STRUCT.d.ts +28 -0
  286. package/src/shade/renderer/scene/MESH_GROUND_COVER_STRUCT.d.ts.map +1 -0
  287. package/src/shade/renderer/scene/MESH_GROUND_COVER_STRUCT.js +58 -0
  288. package/src/shade/renderer/scene/SCENE_DATABASE_SPEC.d.ts.map +1 -1
  289. package/src/shade/renderer/scene/SCENE_DATABASE_SPEC.js +8 -0
  290. package/src/shade/renderer/shader/chunk/geometry/ray/chunk_ray_query_nearest_among.d.ts +37 -0
  291. package/src/shade/renderer/shader/chunk/geometry/ray/chunk_ray_query_nearest_among.d.ts.map +1 -0
  292. package/src/shade/renderer/shader/chunk/geometry/ray/chunk_ray_query_nearest_among.js +148 -0
  293. package/src/shade/renderer/shader/chunk/sdf/chunk_shape_record_line_span.d.ts +20 -0
  294. package/src/shade/renderer/shader/chunk/sdf/chunk_shape_record_line_span.d.ts.map +1 -0
  295. package/src/shade/renderer/shader/chunk/sdf/chunk_shape_record_line_span.js +169 -0
  296. package/src/shade/renderer/texture/atlas/chunk_tile_atlas_slot_origin.d.ts +18 -0
  297. package/src/shade/renderer/texture/atlas/chunk_tile_atlas_slot_origin.d.ts.map +1 -1
  298. package/src/shade/renderer/texture/atlas/chunk_tile_atlas_slot_origin.js +28 -0
  299. package/src/shade/renderer/texture/atlas/tile_atlas_slot_shift.d.ts +13 -0
  300. package/src/shade/renderer/texture/atlas/tile_atlas_slot_shift.d.ts.map +1 -0
  301. package/src/shade/renderer/texture/atlas/tile_atlas_slot_shift.js +22 -0
  302. package/src/shade/renderer/water/GPUWaterRenderer.d.ts.map +1 -1
  303. package/src/shade/renderer/water/GPUWaterRenderer.js +4 -0
  304. package/src/shade/renderer/wind/GPUSceneWind.d.ts +52 -5
  305. package/src/shade/renderer/wind/GPUSceneWind.d.ts.map +1 -1
  306. package/src/shade/renderer/wind/GPUSceneWind.js +164 -8
  307. package/src/shade/renderer/wind/WIND_FIELD_UNIFORM.d.ts +3 -1
  308. package/src/shade/renderer/wind/WIND_FIELD_UNIFORM.d.ts.map +1 -1
  309. package/src/shade/renderer/wind/WIND_FIELD_UNIFORM.js +3 -1
  310. package/src/shade/renderer/wind/chunk_wind_field_sample_cascades.d.ts +2 -1
  311. package/src/shade/renderer/wind/chunk_wind_field_sample_cascades.d.ts.map +1 -1
  312. package/src/shade/renderer/wind/chunk_wind_field_sample_cascades.js +18 -13
  313. package/src/shade/renderer/wind/chunk_wind_field_sample_previous.d.ts +13 -0
  314. package/src/shade/renderer/wind/chunk_wind_field_sample_previous.d.ts.map +1 -0
  315. package/src/shade/renderer/wind/chunk_wind_field_sample_previous.js +23 -0
  316. package/src/shade/renderer/wind/chunk_wind_field_sample_uniform.d.ts +1 -0
  317. package/src/shade/renderer/wind/chunk_wind_field_sample_uniform.d.ts.map +1 -1
  318. package/src/shade/renderer/wind/chunk_wind_field_sample_uniform.js +6 -1
  319. package/src/shade/renderer/wind/wind_field_add_resources.d.ts +11 -0
  320. package/src/shade/renderer/wind/wind_field_add_resources.d.ts.map +1 -1
  321. package/src/shade/renderer/wind/wind_field_add_resources.js +15 -0
  322. package/src/shade/wgsl/emulator/WGSLJavaScriptCompiler.js +1 -1
  323. package/src/shade/wgsl/emulator/WGSLLanguageCore.d.ts.map +1 -1
  324. package/src/shade/wgsl/emulator/WGSLLanguageCore.js +2 -0
@@ -0,0 +1,175 @@
1
+ import { ColorTargetState } from "../../../descriptor/pipeline/render/ColorTargetState.js";
2
+ import { RenderPipelineDescriptor } from "../../../descriptor/pipeline/render/RenderPipelineDescriptor.js";
3
+ import { CAMERA_RESOURCE } from "../../camera/CAMERA_RESOURCE.js";
4
+ import { G_BUFFER_COLOR_TARGETS } from "../../gbuffer/G_BUFFER_COLOR_TARGETS.js";
5
+ import { VISIBILITY_FORMAT, VISIBILITY_NONE } from "../../rasterize/visibility/VISIBILITY_BUFFER.js";
6
+ import { TRANSFORMS_TABLE } from "../../scene/chunk_scene_database_access.js";
7
+ import { SCENE_DATABASE_RESOURCE } from "../../scene/SCENE_DATABASE_RESOURCE.js";
8
+ import { chunk_rgbe9995_encode } from "../../shader/chunk/color/rgbe9995/chunk_rgbe9995_encode.js";
9
+ import { chunk_encode_g_buffer_face_normal } from "../../shader/chunk/geometry/normal/chunk_encode_g_buffer_face_normal.js";
10
+ import { chunk_mat4_inverse } from "../../shader/chunk/geometry/mat4/chunk_mat4_inverse.js";
11
+ import { chunk_encode_g_buffer_normal } from "../../shader/chunk/geometry/normal/chunk_encode_g_buffer_normal.js";
12
+ import { CodeChunk } from "../../shader/compiler/CodeChunk.js";
13
+ import { vertex_full_viewport_quad } from "../../shader/fullscreen/vertex_full_viewport_quad.js";
14
+ import { ShaderResourceSetDescriptor } from "../../shader/resource/ShaderResourceSetDescriptor.js";
15
+ import { ShaderDescriptor } from "../../shader/ShaderDescriptor.js";
16
+ import { mat4x4f } from "../../shader/type/WEBGPU_WGSL_PRIMITIVE_TYPES.js";
17
+ import { chunk_grass_surface_frame } from "../surface/chunk_grass_surface_frame.js";
18
+ import { chunk_grass_blade } from "./chunk_grass_blade.js";
19
+ import { GRASS_BLADE_ID_ACROSS_BITS, GRASS_BLADE_ID_ALONG_BITS, GRASS_BLADE_ID_NONE } from "./GRASS_BLADE.js";
20
+ import { GRASS_BLADE_LIST_STRUCT_READ, GRASS_SPECIES_RESOURCE } from "./shader_grass_blade_expand.js";
21
+
22
+ const resources = new ShaderResourceSetDescriptor();
23
+
24
+ resources.createGroup()
25
+ .add(CAMERA_RESOURCE)
26
+ .add(SCENE_DATABASE_RESOURCE)
27
+ .addStorageBuffer("grass_blades", GRASS_BLADE_LIST_STRUCT_READ)
28
+ .add(GRASS_SPECIES_RESOURCE)
29
+ .addTexture("grass_ids", "uint")
30
+ .addTexture("scene_depth")
31
+ .addUniform("inverse_view_projection", mat4x4f)
32
+ .addUniform("view_projection_previous", mat4x4f);
33
+
34
+ const ALONG_STEPS = 2 ** GRASS_BLADE_ID_ALONG_BITS - 1;
35
+ const ACROSS_STEPS = 2 ** GRASS_BLADE_ID_ACROSS_BITS - 1;
36
+
37
+ const body = CodeChunk.from(
38
+ //language=WGSL
39
+ `
40
+ struct GrassResolveOutput {
41
+ @location(0) pbr: vec4<f32>,
42
+ @location(1) normal: u32,
43
+ @location(2) albedo: vec4<f32>,
44
+ @location(3) emissive: u32,
45
+ @location(4) visibility: u32,
46
+ @location(5) velocity: vec2<f32>,
47
+ }
48
+
49
+ @fragment
50
+ fn fs_main(@builtin(position) position: vec4<f32>) -> GrassResolveOutput {
51
+ let id = textureLoad(grass_ids, vec2<i32>(position.xy), 0).x;
52
+
53
+ if (id == ${GRASS_BLADE_ID_NONE}u) {
54
+ discard;
55
+ }
56
+
57
+ let blade = grass_blade_unpack(grass_blades.records[(id >> ${GRASS_BLADE_ID_ALONG_BITS + GRASS_BLADE_ID_ACROSS_BITS}u) - 1u]);
58
+
59
+ let along = f32((id >> ${GRASS_BLADE_ID_ACROSS_BITS}u) & ${ALONG_STEPS}u) / ${ALONG_STEPS}.0;
60
+ let across = f32(id & ${ACROSS_STEPS}u) / ${ACROSS_STEPS}.0 * 2.0 - 1.0;
61
+
62
+ let species = grass_species[blade.species];
63
+
64
+ let frame = grass_surface_frame(${TRANSFORMS_TABLE.marshalling_method_read_field('global')}(&scene_database, blade.surface));
65
+
66
+ // the face the view sees, rounded across the blade's width
67
+ let side = grass_blade_across(blade);
68
+
69
+ var face = normalize(cross(side, grass_blade_tangent(blade, along)));
70
+
71
+ let eye = grass_world_to_frame(frame, camera.transform[3].xyz);
72
+
73
+ if (dot(face, eye - grass_blade_point(blade, along)) < 0.0) {
74
+ face = -face;
75
+ }
76
+
77
+ let rounded = normalize(face + side * (across * species.more.z));
78
+
79
+ // a blade that stands for many takes their mean normal, which is the ground's, and their spread as roughness
80
+ let normal = normalize((frame * vec4<f32>(mix(blade.ground, rounded, blade.thinning), 0.0)).xyz);
81
+ let roughness = mix(1.0, species.shape.w, blade.thinning);
82
+
83
+ let tint = 1.0 + species.more.y * (f32(blade.seed) / 255.0 * 2.0 - 1.0);
84
+
85
+ var out: GrassResolveOutput;
86
+
87
+ out.pbr = vec4<f32>(0.0, roughness, encode_g_buffer_face_normal(normal));
88
+ out.normal = encode_g_buffer_normal(normal);
89
+ out.albedo = vec4<f32>(mix(species.root.rgb, species.tip.rgb, along) * tint, 1.0);
90
+ out.emissive = rgbe9995_encode(vec3<f32>(0.0));
91
+
92
+ // no meshlet is under a blade
93
+ out.visibility = ${VISIBILITY_NONE}u;
94
+
95
+ // where this point of the blade was a frame ago: on the blade as it was bent then, carried by its surface
96
+ let pixel = position.xy;
97
+ let size = vec2<f32>(textureDimensions(scene_depth));
98
+
99
+ let depth = textureLoad(scene_depth, vec2<i32>(pixel), 0).r;
100
+
101
+ let here = inverse_view_projection * vec4<f32>(pixel.x / size.x * 2.0 - 1.0, 1.0 - pixel.y / size.y * 2.0, depth, 1.0);
102
+
103
+ let global = ${TRANSFORMS_TABLE.marshalling_method_read_field('global')}(&scene_database, blade.surface);
104
+ let global_previous = ${TRANSFORMS_TABLE.marshalling_method_read_field('prev_global')}(&scene_database, blade.surface);
105
+
106
+ let blade_before = grass_blade_previous(blade);
107
+ let half = 0.5 * blade.width * grass_blade_taper(along) * across;
108
+
109
+ // how far the point has moved on its surface over the frame, in the frame and then in the world
110
+ let moved = grass_blade_point(blade, along) + side * half
111
+ - grass_blade_point(blade_before, along) - grass_blade_across(blade_before) * half;
112
+
113
+ let there = here.xyz / here.w - (frame * vec4<f32>(moved, 0.0)).xyz;
114
+
115
+ let before = view_projection_previous * (global_previous * (mat4_inverse(global) * vec4<f32>(there, 1.0)));
116
+ let before_ndc = before.xy / before.w;
117
+
118
+ out.velocity = pixel - vec2<f32>((before_ndc.x + 1.0) * 0.5 * size.x, (1.0 - before_ndc.y) * 0.5 * size.y);
119
+
120
+ return out;
121
+ }
122
+ `, [
123
+ chunk_grass_surface_frame,
124
+ chunk_grass_blade,
125
+ chunk_encode_g_buffer_normal,
126
+ chunk_encode_g_buffer_face_normal,
127
+ chunk_rgbe9995_encode,
128
+ chunk_mat4_inverse,
129
+ TRANSFORMS_TABLE.chunk_read_field('global'),
130
+ TRANSFORMS_TABLE.chunk_read_field('prev_global'),
131
+ ]);
132
+
133
+ const descriptor = ShaderDescriptor.from({ label: "Grass Blade Resolve", body, resources });
134
+
135
+ /**
136
+ * The bindings of {@link GRASS_BLADE_RESOLVE_PIPELINE}: `camera`, `scene_database`, `grass_blades` (the
137
+ * list the ids were drawn from), `grass_species`, `grass_ids` (the blade id target), `scene_depth` (the
138
+ * depth the blades were drawn into), and the two matrices of `view_velocity_matrices`.
139
+ *
140
+ * @type {ShaderResourceSetDescriptor}
141
+ */
142
+ export const GRASS_BLADE_RESOLVE_RESOURCES = resources;
143
+
144
+ /**
145
+ * Turns the blade id target into the G-buffer's surface under every pixel a blade covers, and leaves every
146
+ * other pixel as it was: a full-screen triangle (three vertices) over six targets, loaded: the four
147
+ * G-buffer targets in `G_BUFFER_COLOR_TARGETS`' order, then the visibility buffer and the velocity buffer.
148
+ *
149
+ * A blade's pixel takes its species' colour from root to tip, tinted by the blade's own seed; the normal
150
+ * of the blade's face on the view's side, turned towards the edge the pixel is nearer; no metalness, no
151
+ * emission, and an occlusion of one. A blade drawn in place of many (`thinning` under one) moves its
152
+ * normal towards the ground's and its roughness towards one by as much.
153
+ *
154
+ * The pixel's visibility word becomes `VISIBILITY_NONE`: no meshlet is the surface there, and a reader that
155
+ * decoded the word would find the ground under the blade. Its velocity is the blade point's own, in the
156
+ * velocity buffer's units: where the point was a frame ago, on the blade as it was bent then
157
+ * (`grass_blade_previous`) and on its surface where that was.
158
+ *
159
+ * @type {RenderPipelineDescriptor}
160
+ */
161
+ export const GRASS_BLADE_RESOLVE_PIPELINE = RenderPipelineDescriptor.from({
162
+ label: "Grass Blade Resolve",
163
+ layout: resources.generatePipelineLayout(GPUShaderStage.VERTEX | GPUShaderStage.FRAGMENT),
164
+ vertex: { module: { code: vertex_full_viewport_quad }, entryPoint: "main" },
165
+ fragment: {
166
+ module: { code: descriptor.source },
167
+ entryPoint: "fs_main",
168
+ targets: [
169
+ ...G_BUFFER_COLOR_TARGETS.map(target => ColorTargetState.from({ format: target.format })),
170
+ ColorTargetState.from({ format: VISIBILITY_FORMAT }),
171
+ ColorTargetState.from({ format: "rg16float" }),
172
+ ],
173
+ },
174
+ primitive: { topology: "triangle-list", cullMode: "none" },
175
+ });
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Closes a blade list for its draw: one thread, after {@link shader_grass_blade_expand}.
3
+ *
4
+ * Writes the draw's indirect arguments, a strip of `GRASS_BLADE_VERTICES` vertices an instance and an
5
+ * instance a blade the list holds, which is its count or `settings.blade_capacity` where the count passed
6
+ * it; and the two numbers of the view the draw needs into the list's own first words
7
+ * (`GRASS_BLADE_LIST_FOCAL`, `GRASS_BLADE_LIST_NARROWEST`). The list's count is left as the blades that
8
+ * asked for a place, for whoever sizes the list.
9
+ *
10
+ * @type {ComputeShader}
11
+ */
12
+ export const shader_grass_blade_draw_args: ComputeShader;
13
+ import { ComputeShader } from "../../shader/ComputeShader.js";
14
+ //# sourceMappingURL=shader_grass_blade_draw_args.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shader_grass_blade_draw_args.d.ts","sourceRoot":"","sources":["../../../../../../src/shade/renderer/grass/blade/shader_grass_blade_draw_args.js"],"names":[],"mappings":"AAgBA;;;;;;;;;;GAUG;AACH,2CAFU,aAAa,CAmBpB;8BA3C2B,+BAA+B"}
@@ -0,0 +1,45 @@
1
+ import { CodeChunk } from "../../shader/compiler/CodeChunk.js";
2
+ import { ComputeShader } from "../../shader/ComputeShader.js";
3
+ import { ShaderResourceSetDescriptor } from "../../shader/resource/ShaderResourceSetDescriptor.js";
4
+ import { WebGPUArray } from "../../shader/type/WebGPUArray.js";
5
+ import { GRASS_SURFACE_VIEW_SETTINGS } from "../surface/GRASS_SURFACE_VIEW.js";
6
+ import { GRASS_BLADE_VERTICES } from "./GRASS_BLADE.js";
7
+ import { GRASS_BLADE_LIST_STRUCT_WRITE } from "./shader_grass_blade_expand.js";
8
+
9
+ const resources = new ShaderResourceSetDescriptor();
10
+
11
+ resources.setImmediate("settings", GRASS_SURFACE_VIEW_SETTINGS);
12
+
13
+ resources.createGroup()
14
+ .addStorageBuffer("grass_blades", GRASS_BLADE_LIST_STRUCT_WRITE, true)
15
+ .addStorageBuffer("draw_args", WebGPUArray.u32, true);
16
+
17
+ /**
18
+ * Closes a blade list for its draw: one thread, after {@link shader_grass_blade_expand}.
19
+ *
20
+ * Writes the draw's indirect arguments, a strip of `GRASS_BLADE_VERTICES` vertices an instance and an
21
+ * instance a blade the list holds, which is its count or `settings.blade_capacity` where the count passed
22
+ * it; and the two numbers of the view the draw needs into the list's own first words
23
+ * (`GRASS_BLADE_LIST_FOCAL`, `GRASS_BLADE_LIST_NARROWEST`). The list's count is left as the blades that
24
+ * asked for a place, for whoever sizes the list.
25
+ *
26
+ * @type {ComputeShader}
27
+ */
28
+ export const shader_grass_blade_draw_args = ComputeShader.from({
29
+ label: "Grass Blade Draw Args",
30
+ resources,
31
+ body: CodeChunk.from(
32
+ //language=WGSL
33
+ `
34
+ @compute @workgroup_size(1)
35
+ fn main() {
36
+ grass_blades.focal = bitcast<u32>(settings.focal);
37
+ grass_blades.narrowest = bitcast<u32>(settings.narrowest_blade);
38
+
39
+ draw_args[0] = ${GRASS_BLADE_VERTICES}u;
40
+ draw_args[1] = min(atomicLoad(&grass_blades.count), settings.blade_capacity);
41
+ draw_args[2] = 0u;
42
+ draw_args[3] = 0u;
43
+ }
44
+ `),
45
+ });
@@ -0,0 +1,61 @@
1
+ /**
2
+ * A blade list as the pass that fills it sees it: `GRASS_BLADE.js` says what its first words are.
3
+ *
4
+ * @type {WebGPUStruct}
5
+ */
6
+ export const GRASS_BLADE_LIST_STRUCT_WRITE: WebGPUStruct;
7
+ /**
8
+ * A blade list as the passes that read it see it.
9
+ *
10
+ * @type {WebGPUStruct}
11
+ */
12
+ export const GRASS_BLADE_LIST_STRUCT_READ: WebGPUStruct;
13
+ /**
14
+ * The species list, a `GRASS_SPECIES_STRUCT` a species.
15
+ *
16
+ * @type {ShaderResourceDescriptor}
17
+ */
18
+ export const GRASS_SPECIES_RESOURCE: ShaderResourceDescriptor;
19
+ /**
20
+ * Makes the blades a view is shown, a thread a blade the frame's cells counted
21
+ * ({@link shader_grass_cell_count}, whose counts, summed, are `prefix_sums`), and lists the ones that are
22
+ * there in `grass_blades`.
23
+ *
24
+ * A thread finds its cell from the sums and, from its place among the cell's threads, a point of the
25
+ * surface's blade lattice (`chunk_grass_population`): the cell's points in the order of their ranks. The
26
+ * blade stands at a place of its own inside the point's square of the lattice, on the plane of the surfel
27
+ * of the column it is in. It is dropped when:
28
+ *
29
+ * - its column holds no surfel, or one too steep to stand on;
30
+ * - the member under it grows nothing;
31
+ * - its distance from the view is one another level's tile makes (the cell's ring and flags);
32
+ * - it is so far that none of its length is drawn (`grass_blade_fade`), or it is outside the view's frustum
33
+ * by more than its length;
34
+ * - its rank is not under the density the view is shown there (`grass_blade_density`), as a share of the
35
+ * lattice's own.
36
+ *
37
+ * What is left takes a place in the list (`chunk_subgroup_append_slot`: the list's count rises past
38
+ * `settings.blade_capacity`, its records do not), with a length, lean, curl and facing that are the
39
+ * blade's own, a hash of its lattice point: the same blade is the same every frame and at every level.
40
+ * Its length is cut to the open air over its surfel.
41
+ *
42
+ * The blade is then bent by the scene's wind (`chunk_grass_blade_wind`), sampled half its length above
43
+ * its root: once as the wind is and at `grass_clock`'s time, and once as the wind was a frame ago
44
+ * (`chunk_wind_field_sample_previous`) and at the clock's previous time, which is the arc the record
45
+ * keeps as the blade's previous one. In a wind and at a clock that have not changed the two are the same.
46
+ *
47
+ * And it is pushed over by whatever has pressed the ground it stands on (`chunk_grass_press`, the field
48
+ * `grass_press` under `grass_press_window`): as the field holds it now, and for the previous arc as it
49
+ * held it a frame ago. The blade the press acts on is the one that stands, its grown length cut to the
50
+ * open air over its surfel.
51
+ *
52
+ * Dispatched through `shader_prefix_sum_to_command`'s folded command. `grass_blades.count` is zero on
53
+ * entry.
54
+ *
55
+ * @type {ComputeShader}
56
+ */
57
+ export const shader_grass_blade_expand: ComputeShader;
58
+ import { WebGPUStruct } from "../../shader/type/WebGPUStruct.js";
59
+ import { ShaderResourceDescriptor } from "../../shader/resource/ShaderResourceDescriptor.js";
60
+ import { ComputeShader } from "../../shader/ComputeShader.js";
61
+ //# sourceMappingURL=shader_grass_blade_expand.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shader_grass_blade_expand.d.ts","sourceRoot":"","sources":["../../../../../../src/shade/renderer/grass/blade/shader_grass_blade_expand.js"],"names":[],"mappings":"AA0CA;;;;GAIG;AACH,4CAFU,YAAY,CAQI;AAE1B;;;;GAIG;AACH,2CAFU,YAAY,CAQG;AAEzB;;;;GAIG;AACH,qCAFU,wBAAwB,CAEoG;AAkBtI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,wCAFU,aAAa,CAoNpB;6BAlU0B,mCAAmC;yCAJvB,mDAAmD;8BAD9D,+BAA+B"}
@@ -0,0 +1,340 @@
1
+ import { CAMERA_RESOURCE } from "../../camera/CAMERA_RESOURCE.js";
2
+ import { COLLECTION_U32_STRUCT_READ } from "../../gpu_primitive/COLLECTION_U32_STRUCT_READ.js";
3
+ import { TRANSFORMS_TABLE } from "../../scene/chunk_scene_database_access.js";
4
+ import { MESH_GROUND_COVER_FLAG_GROWS } from "../../scene/MESH_GROUND_COVER_STRUCT.js";
5
+ import { SCENE_DATABASE_RESOURCE } from "../../scene/SCENE_DATABASE_RESOURCE.js";
6
+ import { SCENE_DATABASE_SPEC } from "../../scene/SCENE_DATABASE_SPEC.js";
7
+ import { chunk_folded_workgroup_index } from "../../shader/chunk/grid/chunk_folded_workgroup_index.js";
8
+ import { chunk_lower_bound_branchless } from "../../shader/chunk/math/chunk_lower_bound_branchless.js";
9
+ import { chunk_hash_lowbias32 } from "../../shader/chunk/random/chunk_hash_lowbias32.js";
10
+ import { chunk_subgroup_append_slot } from "../../shader/chunk/subgroup/chunk_subgroup_append_slot.js";
11
+ import { CodeChunk } from "../../shader/compiler/CodeChunk.js";
12
+ import { COMPUTE_SHADER_DEFAULT_GROUP_SIZE } from "../../shader/COMPUTE_SHADER_DEFAULT_GROUP_SIZE.js";
13
+ import { ComputeShader } from "../../shader/ComputeShader.js";
14
+ import { ShaderResourceDescriptor } from "../../shader/resource/ShaderResourceDescriptor.js";
15
+ import { ShaderResourceSetDescriptor } from "../../shader/resource/ShaderResourceSetDescriptor.js";
16
+ import { atomic_u32, u32 } from "../../shader/type/WEBGPU_WGSL_PRIMITIVE_TYPES.js";
17
+ import { WebGPUArray } from "../../shader/type/WebGPUArray.js";
18
+ import { WebGPUStruct } from "../../shader/type/WebGPUStruct.js";
19
+ import { chunk_wind_field_sample } from "../../wind/chunk_wind_field_sample.js";
20
+ import { chunk_wind_field_sample_previous } from "../../wind/chunk_wind_field_sample_previous.js";
21
+ import { wind_field_add_history_resources } from "../../wind/wind_field_add_resources.js";
22
+ import { chunk_grass_population } from "../population/chunk_grass_population.js";
23
+ import { chunk_grass_press } from "../press/chunk_grass_press.js";
24
+ import { GRASS_PRESS_WINDOW_STRUCT } from "../press/GRASS_PRESS.js";
25
+ import { chunk_grass_surface_frame } from "../surface/chunk_grass_surface_frame.js";
26
+ import { chunk_grass_surfel } from "../surface/chunk_grass_surfel.js";
27
+ import { chunk_grass_tile } from "../surface/chunk_grass_tile.js";
28
+ import { GRASS_SURFACE_VIEW_SETTINGS } from "../surface/GRASS_SURFACE_VIEW.js";
29
+ import { chunk_grass_blade } from "./chunk_grass_blade.js";
30
+ import { chunk_grass_blade_wind, GRASS_BLADE_CLOCK_STRUCT } from "./chunk_grass_blade_wind.js";
31
+ import {
32
+ GRASS_BLADE_RECORD_WORDS,
33
+ GRASS_CELL_CHILD_MISSING,
34
+ GRASS_CELL_LATTICE_SHIFT,
35
+ GRASS_CELL_PARENT_MISSING,
36
+ GRASS_CELL_STRUCT,
37
+ GRASS_SPECIES_STRUCT
38
+ } from "./GRASS_BLADE.js";
39
+ import { GRASS_TILE_COLUMNS_LOG2 } from "./shader_grass_cell_count.js";
40
+
41
+ const MESH_GROUND_COVERS_TABLE = SCENE_DATABASE_SPEC.get('mesh_ground_covers');
42
+
43
+ /**
44
+ * A blade list as the pass that fills it sees it: `GRASS_BLADE.js` says what its first words are.
45
+ *
46
+ * @type {WebGPUStruct}
47
+ */
48
+ export const GRASS_BLADE_LIST_STRUCT_WRITE = WebGPUStruct.from({
49
+ count: atomic_u32,
50
+ focal: u32,
51
+ narrowest: u32,
52
+ unused: u32,
53
+ records: WebGPUArray.from(WebGPUArray.from(u32, GRASS_BLADE_RECORD_WORDS)),
54
+ }, "GrassBladeListWrite");
55
+
56
+ /**
57
+ * A blade list as the passes that read it see it.
58
+ *
59
+ * @type {WebGPUStruct}
60
+ */
61
+ export const GRASS_BLADE_LIST_STRUCT_READ = WebGPUStruct.from({
62
+ count: u32,
63
+ focal: u32,
64
+ narrowest: u32,
65
+ unused: u32,
66
+ records: WebGPUArray.from(WebGPUArray.from(u32, GRASS_BLADE_RECORD_WORDS)),
67
+ }, "GrassBladeListRead");
68
+
69
+ /**
70
+ * The species list, a `GRASS_SPECIES_STRUCT` a species.
71
+ *
72
+ * @type {ShaderResourceDescriptor}
73
+ */
74
+ export const GRASS_SPECIES_RESOURCE = ShaderResourceDescriptor.storageBuffer("grass_species", WebGPUArray.from(GRASS_SPECIES_STRUCT));
75
+
76
+ const resources = new ShaderResourceSetDescriptor();
77
+
78
+ resources.setImmediate("settings", GRASS_SURFACE_VIEW_SETTINGS);
79
+
80
+ wind_field_add_history_resources(resources.createGroup()
81
+ .add(CAMERA_RESOURCE)
82
+ .add(SCENE_DATABASE_RESOURCE)
83
+ .addStorageBuffer("prefix_sums", COLLECTION_U32_STRUCT_READ)
84
+ .addStorageBuffer("grass_cells", WebGPUArray.from(GRASS_CELL_STRUCT))
85
+ .add(GRASS_SPECIES_RESOURCE)
86
+ .addTexture("grass_surfels", "uint")
87
+ .addStorageBuffer("grass_blades", GRASS_BLADE_LIST_STRUCT_WRITE, true)
88
+ .addUniform("grass_clock", GRASS_BLADE_CLOCK_STRUCT)
89
+ .addStorageBuffer("grass_press", WebGPUArray.from(u32))
90
+ .addUniform("grass_press_window", GRASS_PRESS_WINDOW_STRUCT));
91
+
92
+ /**
93
+ * Makes the blades a view is shown, a thread a blade the frame's cells counted
94
+ * ({@link shader_grass_cell_count}, whose counts, summed, are `prefix_sums`), and lists the ones that are
95
+ * there in `grass_blades`.
96
+ *
97
+ * A thread finds its cell from the sums and, from its place among the cell's threads, a point of the
98
+ * surface's blade lattice (`chunk_grass_population`): the cell's points in the order of their ranks. The
99
+ * blade stands at a place of its own inside the point's square of the lattice, on the plane of the surfel
100
+ * of the column it is in. It is dropped when:
101
+ *
102
+ * - its column holds no surfel, or one too steep to stand on;
103
+ * - the member under it grows nothing;
104
+ * - its distance from the view is one another level's tile makes (the cell's ring and flags);
105
+ * - it is so far that none of its length is drawn (`grass_blade_fade`), or it is outside the view's frustum
106
+ * by more than its length;
107
+ * - its rank is not under the density the view is shown there (`grass_blade_density`), as a share of the
108
+ * lattice's own.
109
+ *
110
+ * What is left takes a place in the list (`chunk_subgroup_append_slot`: the list's count rises past
111
+ * `settings.blade_capacity`, its records do not), with a length, lean, curl and facing that are the
112
+ * blade's own, a hash of its lattice point: the same blade is the same every frame and at every level.
113
+ * Its length is cut to the open air over its surfel.
114
+ *
115
+ * The blade is then bent by the scene's wind (`chunk_grass_blade_wind`), sampled half its length above
116
+ * its root: once as the wind is and at `grass_clock`'s time, and once as the wind was a frame ago
117
+ * (`chunk_wind_field_sample_previous`) and at the clock's previous time, which is the arc the record
118
+ * keeps as the blade's previous one. In a wind and at a clock that have not changed the two are the same.
119
+ *
120
+ * And it is pushed over by whatever has pressed the ground it stands on (`chunk_grass_press`, the field
121
+ * `grass_press` under `grass_press_window`): as the field holds it now, and for the previous arc as it
122
+ * held it a frame ago. The blade the press acts on is the one that stands, its grown length cut to the
123
+ * open air over its surfel.
124
+ *
125
+ * Dispatched through `shader_prefix_sum_to_command`'s folded command. `grass_blades.count` is zero on
126
+ * entry.
127
+ *
128
+ * @type {ComputeShader}
129
+ */
130
+ export const shader_grass_blade_expand = ComputeShader.from({
131
+ label: "Grass Blade Expand",
132
+ resources,
133
+ body: CodeChunk.from(
134
+ //language=WGSL
135
+ `
136
+ // a number in [0, 1) from a word
137
+ fn grass_blade_unit(h: u32) -> f32 {
138
+ return f32(h >> 8u) / 16777216.0;
139
+ }
140
+
141
+ fn grass_blade_make(cell: ${GRASS_CELL_STRUCT.wgsl_ref}, slot: u32, place: u32, blade: ptr<function, GrassBlade>) -> bool {
142
+ let level = cell.level_layer & 0xFFu;
143
+ let layer = cell.level_layer >> 8u;
144
+ let lattice_bits = (cell.flags >> ${GRASS_CELL_LATTICE_SHIFT}u) & 0xFFu;
145
+
146
+ let block_level = ${GRASS_TILE_COLUMNS_LOG2}u + lattice_bits + level;
147
+
148
+ let point = grass_population_point(block_level, cell.tile, place, cell.surface);
149
+
150
+ // the blade's own numbers: of its point, its surface and its layer
151
+ var h = hash_lowbias32(cell.surface ^ (layer * 0x85EBCA6Bu));
152
+
153
+ h = hash_lowbias32(h ^ bitcast<u32>(point.x));
154
+ h = hash_lowbias32(h ^ bitcast<u32>(point.y));
155
+
156
+ let h_x = h;
157
+ let h_z = hash_lowbias32(h_x);
158
+ let h_facing = hash_lowbias32(h_z);
159
+ let h_lean = hash_lowbias32(h_facing);
160
+ let h_curl = hash_lowbias32(h_lean);
161
+ let h_length = hash_lowbias32(h_curl);
162
+
163
+ // a place inside the point's square of the lattice
164
+ let pitch = ldexp(settings.finest_spacing, -i32(lattice_bits));
165
+ let xz = (vec2<f32>(point) + vec2<f32>(grass_blade_unit(h_x), grass_blade_unit(h_z))) * pitch;
166
+
167
+ // the column that square lies in
168
+ let column = vec2<u32>((point >> vec2<u32>(lattice_bits + level)) - cell.tile * i32(GRASS_TILE_COLUMNS));
169
+
170
+ let texel = textureLoad(grass_surfels, grass_slot_texel(slot, column, textureDimensions(grass_surfels).x), 0);
171
+
172
+ if (!grass_surfel_exists(texel)) {
173
+ return false;
174
+ }
175
+
176
+ let surfel = grass_surfel_unpack(texel);
177
+
178
+ if (surfel.normal.y <= 1e-3) {
179
+ return false;
180
+ }
181
+
182
+ let cover = ${MESH_GROUND_COVERS_TABLE.marshalling_method_read}(&scene_database, surfel.member);
183
+
184
+ if ((cover.flags & ${MESH_GROUND_COVER_FLAG_GROWS}u) == 0u) {
185
+ return false;
186
+ }
187
+
188
+ // on the surfel's plane
189
+ let spacing = grass_level_spacing(settings.finest_spacing, level);
190
+ let centre = grass_tile_column_position(cell.tile, column, spacing);
191
+
192
+ let root = vec3<f32>(xz.x, surfel.height - dot(surfel.normal.xz, xz - centre) / surfel.normal.y, xz.y);
193
+
194
+ let frame = grass_surface_frame(${TRANSFORMS_TABLE.marshalling_method_read_field('global')}(&scene_database, cell.surface));
195
+ let eye = grass_world_to_frame(frame, camera.transform[3].xyz);
196
+
197
+ let to_eye = eye - root;
198
+ let distance = length(to_eye);
199
+
200
+ // the level whose ring holds the distance makes the blade, or the cell in its place
201
+ if (distance >= cell.ring_outer && (cell.flags & ${GRASS_CELL_PARENT_MISSING}u) == 0u) {
202
+ return false;
203
+ }
204
+
205
+ let quarter = ((column.x >> ${GRASS_TILE_COLUMNS_LOG2 - 1}u) & 1u) | (((column.y >> ${GRASS_TILE_COLUMNS_LOG2 - 1}u) & 1u) << 1u);
206
+
207
+ if (distance < cell.ring_inner && (cell.flags & (${GRASS_CELL_CHILD_MISSING}u << quarter)) == 0u) {
208
+ return false;
209
+ }
210
+
211
+ let species = grass_species[cover.species];
212
+
213
+ let fade = grass_blade_fade(settings, species.shape.x, distance);
214
+
215
+ if (fade <= 0.0) {
216
+ return false;
217
+ }
218
+
219
+ // outside the frustum by more than a blade
220
+ let world = (frame * vec4<f32>(root, 1.0)).xyz;
221
+
222
+ for (var i = 0u; i < 6u; i++) {
223
+ let plane = camera.frustum[i];
224
+
225
+ if (dot(plane.xyz, world) + plane.w < -species.shape.x) {
226
+ return false;
227
+ }
228
+ }
229
+
230
+ let content = species.shape.z * surfel.density * cover.density;
231
+
232
+ if (content <= 0.0) {
233
+ return false;
234
+ }
235
+
236
+ let sin_elevation = dot(surfel.normal, to_eye) / max(distance, 1e-6);
237
+
238
+ let shown = grass_blade_density(settings, content, species.shape.y, species.shape.x, distance, sin_elevation, surfel.normal.y);
239
+
240
+ let lattice_side = f32(1u << lattice_bits) / settings.finest_spacing;
241
+ let share = shown / (lattice_side * lattice_side);
242
+
243
+ if (share < 1.0 && grass_population_rank(block_level, cell.rank, place) >= grass_population_threshold(share)) {
244
+ return false;
245
+ }
246
+
247
+ // as the blade grew, before it is cut short: what it bends and sways as
248
+ let grown = species.shape.x * (1.0 - species.root.w * grass_blade_unit(h_length));
249
+
250
+ let rest = GrassBladeBend(
251
+ grass_blade_unit(h_facing) * GRASS_BLADE_TAU,
252
+ species.tip.w * grass_blade_unit(h_lean),
253
+ species.more.x * grass_blade_unit(h_curl),
254
+ );
255
+
256
+ // the air half way up the blade, as it is and as it was a frame ago
257
+ let middle = world + frame[1].xyz * (0.5 * grown);
258
+
259
+ let wind = grass_world_direction_to_frame(frame, wind_field_sample(middle));
260
+ let wind_previous = grass_world_direction_to_frame(frame, wind_field_sample_previous(middle));
261
+
262
+ let frequency = species.wind.y / max(grown * grown, 1e-6);
263
+ let offsets = vec2<f32>(grass_blade_unit(hash_lowbias32(h_length)), grass_blade_unit(hash_lowbias32(h_length ^ 0x9E3779B9u)));
264
+
265
+ // what has pressed the ground here, on the blade as it stands
266
+ let standing = min(grown, surfel.clear_height);
267
+
268
+ // a push under half a step of the record's lean is no push
269
+ let pushed = grass_press_pushed(world, standing, species.wind.w, frame, 0.5 * GRASS_BLADE_LEAN_STEP);
270
+
271
+ let bent = grass_blade_bend(rest, grown, wind, species.wind, grass_blade_sway(frequency, grass_clock.whole, grass_clock.fraction), offsets, pushed.now);
272
+ let bent_previous = grass_blade_bend(rest, grown, wind_previous, species.wind, grass_blade_sway(frequency, grass_clock.previous_whole, grass_clock.previous_fraction), offsets, pushed.before);
273
+
274
+ (*blade).root = root;
275
+ (*blade).surface = cell.surface;
276
+ (*blade).species = cover.species;
277
+ (*blade).length = standing * fade;
278
+ (*blade).width = species.shape.y;
279
+ (*blade).facing = bent.facing;
280
+ (*blade).lean = bent.lean;
281
+ (*blade).curl = bent.curl;
282
+ (*blade).ground = surfel.normal;
283
+ (*blade).thinning = shown / content;
284
+ (*blade).seed = h_length >> 24u;
285
+ (*blade).facing_previous = bent_previous.facing;
286
+ (*blade).lean_previous = bent_previous.lean;
287
+ (*blade).curl_previous = bent_previous.curl;
288
+
289
+ return true;
290
+ }
291
+
292
+ @compute @workgroup_size(${COMPUTE_SHADER_DEFAULT_GROUP_SIZE})
293
+ fn main(
294
+ @builtin(workgroup_id) workgroup_id: vec3<u32>,
295
+ @builtin(local_invocation_index) lane: u32,
296
+ ) {
297
+ let thread = folded_workgroup_index(workgroup_id) * ${COMPUTE_SHADER_DEFAULT_GROUP_SIZE}u + lane;
298
+
299
+ // the sums are inclusive: a thread belongs to the first cell whose sum is past it
300
+ let cells = prefix_sums.count;
301
+ let index = lower_bound_branchless(&prefix_sums.elements, thread + 1u, cells);
302
+
303
+ var blade: GrassBlade;
304
+ var made = false;
305
+
306
+ if (index < cells) {
307
+ var place = thread;
308
+
309
+ if (index > 0u) {
310
+ place -= prefix_sums.elements[index - 1u];
311
+ }
312
+
313
+ made = grass_blade_make(grass_cells[index], index, place, &blade);
314
+ }
315
+
316
+ let slot = subgroup_append_slot(&grass_blades.count, made, settings.blade_capacity);
317
+
318
+ if (slot < settings.blade_capacity) {
319
+ grass_blades.records[slot] = grass_blade_pack(blade);
320
+ }
321
+ }
322
+ `, [
323
+ GRASS_CELL_STRUCT.declaration_chunk,
324
+ chunk_folded_workgroup_index,
325
+ chunk_lower_bound_branchless,
326
+ chunk_hash_lowbias32,
327
+ chunk_subgroup_append_slot,
328
+ chunk_grass_population,
329
+ chunk_grass_surface_frame,
330
+ chunk_grass_surfel,
331
+ chunk_grass_tile,
332
+ chunk_grass_blade,
333
+ chunk_grass_blade_wind,
334
+ chunk_grass_press,
335
+ chunk_wind_field_sample,
336
+ chunk_wind_field_sample_previous,
337
+ TRANSFORMS_TABLE.chunk_read_field('global'),
338
+ MESH_GROUND_COVERS_TABLE.chunk_read,
339
+ ]),
340
+ });