@zephyr3d/scene 0.9.27 → 0.10.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 (502) hide show
  1. package/README.md +60 -27
  2. package/dist/animation/animation_bank.js +634 -0
  3. package/dist/animation/animation_bank.js.map +1 -0
  4. package/dist/animation/animation_bank_gpu.js +256 -0
  5. package/dist/animation/animation_bank_gpu.js.map +1 -0
  6. package/dist/animation/animationset.js +54 -0
  7. package/dist/animation/animationset.js.map +1 -1
  8. package/dist/animation/cloth/gpu_cloth_component.js +406 -0
  9. package/dist/animation/cloth/gpu_cloth_component.js.map +1 -0
  10. package/dist/animation/cloth/gpu_cloth_system.js +332 -202
  11. package/dist/animation/cloth/gpu_cloth_system.js.map +1 -1
  12. package/dist/animation/gpu_animation_driver.js +289 -0
  13. package/dist/animation/gpu_animation_driver.js.map +1 -0
  14. package/dist/animation/joint_dynamics/collision.js +112 -1
  15. package/dist/animation/joint_dynamics/collision.js.map +1 -1
  16. package/dist/animation/joint_dynamics/controller.js +6 -0
  17. package/dist/animation/joint_dynamics/controller.js.map +1 -1
  18. package/dist/animation/joint_dynamics/joint_dynamics_system.js +11 -0
  19. package/dist/animation/joint_dynamics/joint_dynamics_system.js.map +1 -1
  20. package/dist/animation/joint_dynamics/solver.js +50 -12
  21. package/dist/animation/joint_dynamics/solver.js.map +1 -1
  22. package/dist/animation/joint_dynamics/types.js.map +1 -1
  23. package/dist/animation/skeleton.js +279 -55
  24. package/dist/animation/skeleton.js.map +1 -1
  25. package/dist/animation/skin_palette_atlas.js +252 -0
  26. package/dist/animation/skin_palette_atlas.js.map +1 -0
  27. package/dist/animation/spring/multi_chain_spring_system.js +298 -38
  28. package/dist/animation/spring/multi_chain_spring_system.js.map +1 -1
  29. package/dist/animation/spring/spring_chain.js +2 -0
  30. package/dist/animation/spring/spring_chain.js.map +1 -1
  31. package/dist/animation/spring/spring_collider.js +159 -21
  32. package/dist/animation/spring/spring_collider.js.map +1 -1
  33. package/dist/animation/spring/spring_particle.js +1 -0
  34. package/dist/animation/spring/spring_particle.js.map +1 -1
  35. package/dist/animation/spring/spring_solver.js +173 -0
  36. package/dist/animation/spring/spring_solver.js.map +1 -0
  37. package/dist/animation/spring/spring_system.js +249 -24
  38. package/dist/animation/spring/spring_system.js.map +1 -1
  39. package/dist/animation/spring_modifier.js +32 -1
  40. package/dist/animation/spring_modifier.js.map +1 -1
  41. package/dist/app/app.js +26 -0
  42. package/dist/app/app.js.map +1 -1
  43. package/dist/app/engine.js +86 -15
  44. package/dist/app/engine.js.map +1 -1
  45. package/dist/app/gamepad.js +191 -0
  46. package/dist/app/gamepad.js.map +1 -0
  47. package/dist/app/inputactions.js +271 -0
  48. package/dist/app/inputactions.js.map +1 -0
  49. package/dist/app/inputmgr.js +331 -22
  50. package/dist/app/inputmgr.js.map +1 -1
  51. package/dist/app/loading.js +138 -0
  52. package/dist/app/loading.js.map +1 -0
  53. package/dist/app/pipelinecache.js +209 -0
  54. package/dist/app/pipelinecache.js.map +1 -0
  55. package/dist/app/runtimescript.js +25 -0
  56. package/dist/app/runtimescript.js.map +1 -1
  57. package/dist/app/scriptingsystem.js +54 -0
  58. package/dist/app/scriptingsystem.js.map +1 -1
  59. package/dist/app/scriptregistry.js +7 -2
  60. package/dist/app/scriptregistry.js.map +1 -1
  61. package/dist/asset/asset_manifest.js +59 -0
  62. package/dist/asset/asset_manifest.js.map +1 -0
  63. package/dist/asset/asset_preload.js +258 -0
  64. package/dist/asset/asset_preload.js.map +1 -0
  65. package/dist/asset/assetmanager.js +117 -65
  66. package/dist/asset/assetmanager.js.map +1 -1
  67. package/dist/asset/loaders/ktx2/basis/LICENSE +201 -0
  68. package/dist/asset/loaders/ktx2/basis/basis_transcoder.js +2 -0
  69. package/dist/asset/loaders/ktx2/basis/basis_transcoder.wasm +0 -0
  70. package/dist/asset/loaders/ktx2/basis_location.js +17 -0
  71. package/dist/asset/loaders/ktx2/basis_location.js.map +1 -0
  72. package/dist/asset/loaders/ktx2/ktx2_loader.js +88 -0
  73. package/dist/asset/loaders/ktx2/ktx2_loader.js.map +1 -0
  74. package/dist/asset/loaders/ktx2/ktx2_targets.js +118 -0
  75. package/dist/asset/loaders/ktx2/ktx2_targets.js.map +1 -0
  76. package/dist/asset/loaders/ktx2/transcoder_pool.js +259 -0
  77. package/dist/asset/loaders/ktx2/transcoder_pool.js.map +1 -0
  78. package/dist/asset/mesh_lod_builder.js +104 -0
  79. package/dist/asset/mesh_lod_builder.js.map +1 -0
  80. package/dist/asset/mesh_settings.js +111 -0
  81. package/dist/asset/mesh_settings.js.map +1 -0
  82. package/dist/asset/meshopt_decoder.js +18 -0
  83. package/dist/asset/meshopt_decoder.js.map +1 -0
  84. package/dist/asset/meshopt_simplifier.js +26 -0
  85. package/dist/asset/meshopt_simplifier.js.map +1 -0
  86. package/dist/asset/model.js +171 -1
  87. package/dist/asset/model.js.map +1 -1
  88. package/dist/asset/texture_settings.js +231 -0
  89. package/dist/asset/texture_settings.js.map +1 -0
  90. package/dist/asset/zmsh_binary.js +131 -0
  91. package/dist/asset/zmsh_binary.js.map +1 -0
  92. package/dist/asset/zsdf_binary.js +111 -0
  93. package/dist/asset/zsdf_binary.js.map +1 -0
  94. package/dist/blitter/bilateralblur.js +1 -2
  95. package/dist/blitter/bilateralblur.js.map +1 -1
  96. package/dist/blitter/gaussianblur.js +1 -6
  97. package/dist/blitter/gaussianblur.js.map +1 -1
  98. package/dist/camera/base.js +31 -10
  99. package/dist/camera/base.js.map +1 -1
  100. package/dist/camera/camera.js +104 -178
  101. package/dist/camera/camera.js.map +1 -1
  102. package/dist/camera/follow.js +342 -0
  103. package/dist/camera/follow.js.map +1 -0
  104. package/dist/camera/fps.js +9 -7
  105. package/dist/camera/fps.js.map +1 -1
  106. package/dist/camera/orbit.js +46 -19
  107. package/dist/camera/orbit.js.map +1 -1
  108. package/dist/index.d.ts +25436 -15990
  109. package/dist/index.js +65 -11
  110. package/dist/index.js.map +1 -1
  111. package/dist/material/blinn.js +3 -0
  112. package/dist/material/blinn.js.map +1 -1
  113. package/dist/material/eye.js +1 -1
  114. package/dist/material/eye.js.map +1 -1
  115. package/dist/material/hair.js +2 -3
  116. package/dist/material/hair.js.map +1 -1
  117. package/dist/material/lambert.js +4 -1
  118. package/dist/material/lambert.js.map +1 -1
  119. package/dist/material/material.js +66 -4
  120. package/dist/material/material.js.map +1 -1
  121. package/dist/material/meshmaterial.js +118 -45
  122. package/dist/material/meshmaterial.js.map +1 -1
  123. package/dist/material/mixins/lightmodel/blinnphong.js +1 -1
  124. package/dist/material/mixins/lightmodel/blinnphong.js.map +1 -1
  125. package/dist/material/mixins/lightmodel/lambert.js +1 -1
  126. package/dist/material/mixins/lightmodel/lambert.js.map +1 -1
  127. package/dist/material/mixins/lightmodel/pbrblueprintmixin.js +34 -61
  128. package/dist/material/mixins/lightmodel/pbrblueprintmixin.js.map +1 -1
  129. package/dist/material/mixins/lightmodel/pbrmetallicroughness.js +16 -2
  130. package/dist/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -1
  131. package/dist/material/mixins/lightmodel/pbrspecularglossness.js +2 -1
  132. package/dist/material/mixins/lightmodel/pbrspecularglossness.js.map +1 -1
  133. package/dist/material/mixins/lit.js +191 -83
  134. package/dist/material/mixins/lit.js.map +1 -1
  135. package/dist/material/mixins/pbr/common.js +31 -206
  136. package/dist/material/mixins/pbr/common.js.map +1 -1
  137. package/dist/material/mtoon.js +1 -1
  138. package/dist/material/mtoon.js.map +1 -1
  139. package/dist/material/pbrmr.js +3 -0
  140. package/dist/material/pbrmr.js.map +1 -1
  141. package/dist/material/pbrsg.js +3 -0
  142. package/dist/material/pbrsg.js.map +1 -1
  143. package/dist/material/sdf_debug.js +78 -0
  144. package/dist/material/sdf_debug.js.map +1 -0
  145. package/dist/material/shader/helper.js +333 -191
  146. package/dist/material/shader/helper.js.map +1 -1
  147. package/dist/material/shader/terrain_blend.js +204 -43
  148. package/dist/material/shader/terrain_blend.js.map +1 -1
  149. package/dist/material/skin.js +331 -297
  150. package/dist/material/skin.js.map +1 -1
  151. package/dist/material/skinprofile.js +1058 -0
  152. package/dist/material/skinprofile.js.map +1 -0
  153. package/dist/material/sss.js +353 -0
  154. package/dist/material/sss.js.map +1 -0
  155. package/dist/material/sss_kernel.js +265 -0
  156. package/dist/material/sss_kernel.js.map +1 -0
  157. package/dist/material/sssprofile.js +879 -0
  158. package/dist/material/sssprofile.js.map +1 -0
  159. package/dist/material/subsurfaceprofile.js +4 -8
  160. package/dist/material/subsurfaceprofile.js.map +1 -1
  161. package/dist/material/terrain-cm.js +464 -188
  162. package/dist/material/terrain-cm.js.map +1 -1
  163. package/dist/material/unlit.js +3 -0
  164. package/dist/material/unlit.js.map +1 -1
  165. package/dist/material/water.js +1261 -1438
  166. package/dist/material/water.js.map +1 -1
  167. package/dist/node_modules/meshoptimizer/LICENSE +21 -0
  168. package/dist/node_modules/meshoptimizer/meshopt_decoder.js +197 -0
  169. package/dist/node_modules/meshoptimizer/meshopt_decoder.js.map +1 -0
  170. package/dist/node_modules/meshoptimizer/meshopt_simplifier.js +677 -0
  171. package/dist/node_modules/meshoptimizer/meshopt_simplifier.js.map +1 -0
  172. package/dist/physics/character.js +226 -0
  173. package/dist/physics/character.js.map +1 -0
  174. package/dist/physics/collider.js +209 -0
  175. package/dist/physics/collider.js.map +1 -0
  176. package/dist/physics/events.js +79 -0
  177. package/dist/physics/events.js.map +1 -0
  178. package/dist/physics/joint.js +272 -0
  179. package/dist/physics/joint.js.map +1 -0
  180. package/dist/physics/node_physics.js +234 -0
  181. package/dist/physics/node_physics.js.map +1 -0
  182. package/dist/physics/part.js +91 -0
  183. package/dist/physics/part.js.map +1 -0
  184. package/dist/physics/rigid_body.js +379 -0
  185. package/dist/physics/rigid_body.js.map +1 -0
  186. package/dist/physics/vehicle.js +335 -0
  187. package/dist/physics/vehicle.js.map +1 -0
  188. package/dist/physics/world.js +25 -0
  189. package/dist/physics/world.js.map +1 -0
  190. package/dist/posteffect/bloom.js +49 -14
  191. package/dist/posteffect/bloom.js.map +1 -1
  192. package/dist/posteffect/motionblur.js +106 -106
  193. package/dist/posteffect/motionblur.js.map +1 -1
  194. package/dist/posteffect/postsss.js +572 -0
  195. package/dist/posteffect/postsss.js.map +1 -0
  196. package/dist/posteffect/sao.js +2 -6
  197. package/dist/posteffect/sao.js.map +1 -1
  198. package/dist/posteffect/skinsss.js +605 -355
  199. package/dist/posteffect/skinsss.js.map +1 -1
  200. package/dist/posteffect/ssgi.js +91 -162
  201. package/dist/posteffect/ssgi.js.map +1 -1
  202. package/dist/posteffect/ssr.js +3 -11
  203. package/dist/posteffect/ssr.js.map +1 -1
  204. package/dist/posteffect/sss.js +4 -13
  205. package/dist/posteffect/sss.js.map +1 -1
  206. package/dist/posteffect/taa.js +1 -0
  207. package/dist/posteffect/taa.js.map +1 -1
  208. package/dist/render/abuffer_oit.js +3 -2
  209. package/dist/render/abuffer_oit.js.map +1 -1
  210. package/dist/render/clipmap.js +179 -64
  211. package/dist/render/clipmap.js.map +1 -1
  212. package/dist/render/cluster_light.js +958 -224
  213. package/dist/render/cluster_light.js.map +1 -1
  214. package/dist/render/cull_visitor.js +25 -5
  215. package/dist/render/cull_visitor.js.map +1 -1
  216. package/dist/render/debug_views.js +37 -0
  217. package/dist/render/debug_views.js.map +1 -0
  218. package/dist/render/depthpass.js +5 -1
  219. package/dist/render/depthpass.js.map +1 -1
  220. package/dist/render/drawable_mixin.js +53 -6
  221. package/dist/render/drawable_mixin.js.map +1 -1
  222. package/dist/render/dualdepthpeeling_oit.js +5 -5
  223. package/dist/render/dualdepthpeeling_oit.js.map +1 -1
  224. package/dist/render/envlight.js +196 -113
  225. package/dist/render/envlight.js.map +1 -1
  226. package/dist/render/fbm_wavegenerator.js +5 -10
  227. package/dist/render/fbm_wavegenerator.js.map +1 -1
  228. package/dist/render/fft_wavegenerator.js +247 -157
  229. package/dist/render/fft_wavegenerator.js.map +1 -1
  230. package/dist/render/gerstner_wavegenerator.js +16 -38
  231. package/dist/render/gerstner_wavegenerator.js.map +1 -1
  232. package/dist/render/gi/probe_volume.js +1334 -0
  233. package/dist/render/gi/probe_volume.js.map +1 -0
  234. package/dist/render/gi/scene_gi.js +282 -0
  235. package/dist/render/gi/scene_gi.js.map +1 -0
  236. package/dist/render/gi/voxel_atlas.js +198 -0
  237. package/dist/render/gi/voxel_atlas.js.map +1 -0
  238. package/dist/render/gi/voxel_lighting.js +652 -0
  239. package/dist/render/gi/voxel_lighting.js.map +1 -0
  240. package/dist/render/gi/voxel_scene.js +642 -0
  241. package/dist/render/gi/voxel_scene.js.map +1 -0
  242. package/dist/render/gi/voxelize_pass.js +223 -0
  243. package/dist/render/gi/voxelize_pass.js.map +1 -0
  244. package/dist/render/globalbindgroup_allocator.js +3 -2
  245. package/dist/render/globalbindgroup_allocator.js.map +1 -1
  246. package/dist/render/gpu_picking.js +9 -36
  247. package/dist/render/gpu_picking.js.map +1 -1
  248. package/dist/render/instance_culling.js +499 -0
  249. package/dist/render/instance_culling.js.map +1 -0
  250. package/dist/render/lightpass.js +19 -8
  251. package/dist/render/lightpass.js.map +1 -1
  252. package/dist/render/lod.js +46 -0
  253. package/dist/render/lod.js.map +1 -0
  254. package/dist/render/primitive.js +301 -9
  255. package/dist/render/primitive.js.map +1 -1
  256. package/dist/render/primitive_readback.js +209 -0
  257. package/dist/render/primitive_readback.js.map +1 -0
  258. package/dist/render/render_queue.js +162 -11
  259. package/dist/render/render_queue.js.map +1 -1
  260. package/dist/render/renderer.js +10 -7
  261. package/dist/render/renderer.js.map +1 -1
  262. package/dist/render/rendergraph/blackboard.js +14 -1
  263. package/dist/render/rendergraph/blackboard.js.map +1 -1
  264. package/dist/render/rendergraph/executor.js +136 -0
  265. package/dist/render/rendergraph/executor.js.map +1 -1
  266. package/dist/render/rendergraph/forward_plus_builder.js +272 -55
  267. package/dist/render/rendergraph/forward_plus_builder.js.map +1 -1
  268. package/dist/render/rendergraph/frame_graph_context.js +41 -0
  269. package/dist/render/rendergraph/frame_graph_context.js.map +1 -0
  270. package/dist/render/rendergraph/scene_render_context.js +31 -2
  271. package/dist/render/rendergraph/scene_render_context.js.map +1 -1
  272. package/dist/render/rendergraph/types.js.map +1 -1
  273. package/dist/render/renderpass.js +28 -5
  274. package/dist/render/renderpass.js.map +1 -1
  275. package/dist/render/sdf/box_allocator.js +98 -0
  276. package/dist/render/sdf/box_allocator.js.map +1 -0
  277. package/dist/render/sdf/global_sdf.js +865 -0
  278. package/dist/render/sdf/global_sdf.js.map +1 -0
  279. package/dist/render/sdf/scene_sdf.js +562 -0
  280. package/dist/render/sdf/scene_sdf.js.map +1 -0
  281. package/dist/render/sdf/sdf_atlas.js +227 -0
  282. package/dist/render/sdf/sdf_atlas.js.map +1 -0
  283. package/dist/render/sdf/sdf_programs.js +42 -0
  284. package/dist/render/sdf/sdf_programs.js.map +1 -0
  285. package/dist/render/sdf/sdf_view.js +199 -0
  286. package/dist/render/sdf/sdf_view.js.map +1 -0
  287. package/dist/render/sdf/waterline.js +610 -0
  288. package/dist/render/sdf/waterline.js.map +1 -0
  289. package/dist/render/shadow_mask_pass.js +142 -25
  290. package/dist/render/shadow_mask_pass.js.map +1 -1
  291. package/dist/render/shore_wave_generator.js +1193 -0
  292. package/dist/render/shore_wave_generator.js.map +1 -0
  293. package/dist/render/sky.js +516 -86
  294. package/dist/render/sky.js.map +1 -1
  295. package/dist/render/transmission_thickness_pass.js +477 -0
  296. package/dist/render/transmission_thickness_pass.js.map +1 -0
  297. package/dist/render/underwater.js +58 -158
  298. package/dist/render/underwater.js.map +1 -1
  299. package/dist/render/virtualtexture/virtual_texture.js +1214 -0
  300. package/dist/render/virtualtexture/virtual_texture.js.map +1 -0
  301. package/dist/render/volumetric_cloud/cloud_common.js +472 -0
  302. package/dist/render/volumetric_cloud/cloud_common.js.map +1 -0
  303. package/dist/render/volumetric_cloud/cloud_noise.js +189 -0
  304. package/dist/render/volumetric_cloud/cloud_noise.js.map +1 -0
  305. package/dist/render/volumetric_cloud/debug_view.js +131 -0
  306. package/dist/render/volumetric_cloud/debug_view.js.map +1 -0
  307. package/dist/render/volumetric_cloud/resources.js +380 -0
  308. package/dist/render/volumetric_cloud/resources.js.map +1 -0
  309. package/dist/render/volumetric_cloud/sky_cache.js +380 -0
  310. package/dist/render/volumetric_cloud/sky_cache.js.map +1 -0
  311. package/dist/render/volumetric_cloud/volumetric_cloud.js +318 -0
  312. package/dist/render/volumetric_cloud/volumetric_cloud.js.map +1 -0
  313. package/dist/render/water_caustics.js +134 -319
  314. package/dist/render/water_caustics.js.map +1 -1
  315. package/dist/render/water_foam.js +627 -0
  316. package/dist/render/water_foam.js.map +1 -0
  317. package/dist/render/water_interaction.js +1795 -0
  318. package/dist/render/water_interaction.js.map +1 -0
  319. package/dist/render/weightedblended_oit.js +3 -3
  320. package/dist/render/weightedblended_oit.js.map +1 -1
  321. package/dist/scene/basesprite.js +9 -4
  322. package/dist/scene/basesprite.js.map +1 -1
  323. package/dist/scene/batchgroup.js +108 -12
  324. package/dist/scene/batchgroup.js.map +1 -1
  325. package/dist/scene/environment.js +28 -7
  326. package/dist/scene/environment.js.map +1 -1
  327. package/dist/scene/foliage.js +1020 -0
  328. package/dist/scene/foliage.js.map +1 -0
  329. package/dist/scene/foliage_buckets.js +147 -0
  330. package/dist/scene/foliage_buckets.js.map +1 -0
  331. package/dist/scene/foliage_mask.js +358 -0
  332. package/dist/scene/foliage_mask.js.map +1 -0
  333. package/dist/scene/hair.js +15 -4
  334. package/dist/scene/hair.js.map +1 -1
  335. package/dist/scene/light.js +179 -13
  336. package/dist/scene/light.js.map +1 -1
  337. package/dist/scene/mesh.js +327 -45
  338. package/dist/scene/mesh.js.map +1 -1
  339. package/dist/scene/meshdrawable.js +6 -0
  340. package/dist/scene/meshdrawable.js.map +1 -1
  341. package/dist/scene/msdftext.js +9 -3
  342. package/dist/scene/msdftext.js.map +1 -1
  343. package/dist/scene/msdftextsprite.js +9 -3
  344. package/dist/scene/msdftextsprite.js.map +1 -1
  345. package/dist/scene/particlesys.js +8 -2
  346. package/dist/scene/particlesys.js.map +1 -1
  347. package/dist/scene/physics_settings.js +157 -0
  348. package/dist/scene/physics_settings.js.map +1 -0
  349. package/dist/scene/scene.js +190 -44
  350. package/dist/scene/scene.js.map +1 -1
  351. package/dist/scene/scene_node.js +147 -6
  352. package/dist/scene/scene_node.js.map +1 -1
  353. package/dist/scene/terrain-cm/bladegrassmaterial.js +735 -0
  354. package/dist/scene/terrain-cm/bladegrassmaterial.js.map +1 -0
  355. package/dist/scene/terrain-cm/grass.js +881 -42
  356. package/dist/scene/terrain-cm/grass.js.map +1 -1
  357. package/dist/scene/terrain-cm/grass_gpu.js +929 -0
  358. package/dist/scene/terrain-cm/grass_gpu.js.map +1 -0
  359. package/dist/scene/terrain-cm/grassmaterial.js +180 -9
  360. package/dist/scene/terrain-cm/grassmaterial.js.map +1 -1
  361. package/dist/scene/terrain-cm/terrain-cm.js +465 -36
  362. package/dist/scene/terrain-cm/terrain-cm.js.map +1 -1
  363. package/dist/scene/terrain-cm/terrain_gi_albedo.js +257 -0
  364. package/dist/scene/terrain-cm/terrain_gi_albedo.js.map +1 -0
  365. package/dist/scene/terrain-cm/terrain_rvt.js +395 -0
  366. package/dist/scene/terrain-cm/terrain_rvt.js.map +1 -0
  367. package/dist/scene/update_queue.js +54 -0
  368. package/dist/scene/update_queue.js.map +1 -0
  369. package/dist/scene/water.js +633 -268
  370. package/dist/scene/water.js.map +1 -1
  371. package/dist/scene/water_surface_sampler.js +324 -0
  372. package/dist/scene/water_surface_sampler.js.map +1 -0
  373. package/dist/scene/wind.js +317 -0
  374. package/dist/scene/wind.js.map +1 -0
  375. package/dist/shaders/atmosphere.js +388 -166
  376. package/dist/shaders/atmosphere.js.map +1 -1
  377. package/dist/shaders/fog.js +100 -32
  378. package/dist/shaders/fog.js.map +1 -1
  379. package/dist/shaders/gi.js +365 -0
  380. package/dist/shaders/gi.js.map +1 -0
  381. package/dist/shaders/ltc_rect.js +202 -0
  382. package/dist/shaders/ltc_rect.js.map +1 -0
  383. package/dist/shaders/misc.js +1 -10
  384. package/dist/shaders/misc.js.map +1 -1
  385. package/dist/shaders/noise.js +5 -1
  386. package/dist/shaders/noise.js.map +1 -1
  387. package/dist/shaders/probes.js +309 -0
  388. package/dist/shaders/probes.js.map +1 -0
  389. package/dist/shaders/sdf.js +537 -0
  390. package/dist/shaders/sdf.js.map +1 -0
  391. package/dist/shaders/shadow.js +104 -70
  392. package/dist/shaders/shadow.js.map +1 -1
  393. package/dist/shaders/skin_brdf.js +243 -0
  394. package/dist/shaders/skin_brdf.js.map +1 -0
  395. package/dist/shaders/ssgi.js +63 -0
  396. package/dist/shaders/ssgi.js.map +1 -0
  397. package/dist/shaders/ssgi_reprojection.js +118 -0
  398. package/dist/shaders/ssgi_reprojection.js.map +1 -0
  399. package/dist/shaders/ssr.js +6 -159
  400. package/dist/shaders/ssr.js.map +1 -1
  401. package/dist/shaders/temporal.js +38 -27
  402. package/dist/shaders/temporal.js.map +1 -1
  403. package/dist/shaders/water.js +32 -82
  404. package/dist/shaders/water.js.map +1 -1
  405. package/dist/shaders/water_medium.js +7 -21
  406. package/dist/shaders/water_medium.js.map +1 -1
  407. package/dist/shadow/dom.js +110 -19
  408. package/dist/shadow/dom.js.map +1 -1
  409. package/dist/shadow/esm.js +3 -3
  410. package/dist/shadow/esm.js.map +1 -1
  411. package/dist/shadow/pcf_opt.js +15 -48
  412. package/dist/shadow/pcf_opt.js.map +1 -1
  413. package/dist/shadow/pcf_pd.js +15 -53
  414. package/dist/shadow/pcf_pd.js.map +1 -1
  415. package/dist/shadow/pcss.js +34 -9
  416. package/dist/shadow/pcss.js.map +1 -1
  417. package/dist/shadow/shadow_impl.js +3 -8
  418. package/dist/shadow/shadow_impl.js.map +1 -1
  419. package/dist/shadow/shadow_region.js +40 -2
  420. package/dist/shadow/shadow_region.js.map +1 -1
  421. package/dist/shadow/shadowmapper.js +93 -53
  422. package/dist/shadow/shadowmapper.js.map +1 -1
  423. package/dist/shadow/ssm.js +18 -72
  424. package/dist/shadow/ssm.js.map +1 -1
  425. package/dist/shadow/vsm.js +3 -3
  426. package/dist/shadow/vsm.js.map +1 -1
  427. package/dist/shapes/shape.js +44 -1
  428. package/dist/shapes/shape.js.map +1 -1
  429. package/dist/utility/buoyancy.js +287 -0
  430. package/dist/utility/buoyancy.js.map +1 -0
  431. package/dist/utility/physical.js +10 -1
  432. package/dist/utility/physical.js.map +1 -1
  433. package/dist/utility/pmrem.js +17 -43
  434. package/dist/utility/pmrem.js.map +1 -1
  435. package/dist/utility/sdf/bake.js +435 -0
  436. package/dist/utility/sdf/bake.js.map +1 -0
  437. package/dist/utility/sdf/bvh.js +576 -0
  438. package/dist/utility/sdf/bvh.js.map +1 -0
  439. package/dist/utility/serialization/manager.js +34 -6
  440. package/dist/utility/serialization/manager.js.map +1 -1
  441. package/dist/utility/serialization/scene/animation.js +46 -5
  442. package/dist/utility/serialization/scene/animation.js.map +1 -1
  443. package/dist/utility/serialization/scene/batch.js +11 -4
  444. package/dist/utility/serialization/scene/batch.js.map +1 -1
  445. package/dist/utility/serialization/scene/camera.js +87 -254
  446. package/dist/utility/serialization/scene/camera.js.map +1 -1
  447. package/dist/utility/serialization/scene/cloth.js +25 -0
  448. package/dist/utility/serialization/scene/cloth.js.map +1 -0
  449. package/dist/utility/serialization/scene/common.js +14 -6
  450. package/dist/utility/serialization/scene/common.js.map +1 -1
  451. package/dist/utility/serialization/scene/foliage.js +821 -0
  452. package/dist/utility/serialization/scene/foliage.js.map +1 -0
  453. package/dist/utility/serialization/scene/hair.js +11 -4
  454. package/dist/utility/serialization/scene/hair.js.map +1 -1
  455. package/dist/utility/serialization/scene/light.js +115 -7
  456. package/dist/utility/serialization/scene/light.js.map +1 -1
  457. package/dist/utility/serialization/scene/material.js +388 -220
  458. package/dist/utility/serialization/scene/material.js.map +1 -1
  459. package/dist/utility/serialization/scene/mesh.js +69 -4
  460. package/dist/utility/serialization/scene/mesh.js.map +1 -1
  461. package/dist/utility/serialization/scene/node.js +140 -5
  462. package/dist/utility/serialization/scene/node.js.map +1 -1
  463. package/dist/utility/serialization/scene/node_physics.js +1318 -0
  464. package/dist/utility/serialization/scene/node_physics.js.map +1 -0
  465. package/dist/utility/serialization/scene/particle.js +11 -4
  466. package/dist/utility/serialization/scene/particle.js.map +1 -1
  467. package/dist/utility/serialization/scene/physics.js +120 -0
  468. package/dist/utility/serialization/scene/physics.js.map +1 -0
  469. package/dist/utility/serialization/scene/primitive.js +124 -10
  470. package/dist/utility/serialization/scene/primitive.js.map +1 -1
  471. package/dist/utility/serialization/scene/scene.js +1687 -51
  472. package/dist/utility/serialization/scene/scene.js.map +1 -1
  473. package/dist/utility/serialization/scene/sprite.js +11 -4
  474. package/dist/utility/serialization/scene/sprite.js.map +1 -1
  475. package/dist/utility/serialization/scene/terrain.js +163 -33
  476. package/dist/utility/serialization/scene/terrain.js.map +1 -1
  477. package/dist/utility/serialization/scene/text.js +11 -4
  478. package/dist/utility/serialization/scene/text.js.map +1 -1
  479. package/dist/utility/serialization/scene/water.js +1543 -264
  480. package/dist/utility/serialization/scene/water.js.map +1 -1
  481. package/dist/utility/serialization/types.js.map +1 -1
  482. package/dist/utility/shprojector.js +10 -22
  483. package/dist/utility/shprojector.js.map +1 -1
  484. package/dist/utility/textures/foam.js +170 -0
  485. package/dist/utility/textures/foam.js.map +1 -0
  486. package/dist/utility/textures/ggxlut.js +17 -43
  487. package/dist/utility/textures/ggxlut.js.map +1 -1
  488. package/dist/utility/textures/ltcdata.js +4 -4
  489. package/dist/utility/textures/ltcdata.js.map +1 -1
  490. package/dist/utility/textures/ltclut.js +16 -6
  491. package/dist/utility/textures/ltclut.js.map +1 -1
  492. package/dist/utility/unsupported.js +24 -0
  493. package/dist/utility/unsupported.js.map +1 -0
  494. package/dist/values.js +13 -1
  495. package/dist/values.js.map +1 -1
  496. package/package.json +25 -12
  497. package/src/asset/loaders/ktx2/basis/LICENSE +201 -0
  498. package/src/asset/loaders/ktx2/basis/basis_transcoder.js +2 -0
  499. package/src/asset/loaders/ktx2/basis/basis_transcoder.wasm +0 -0
  500. package/src/asset/meshoptimizer/LICENSE +21 -0
  501. package/dist/animation/joint_dynamics/convex_collider.js +0 -320
  502. package/dist/animation/joint_dynamics/convex_collider.js.map +0 -1
@@ -0,0 +1,652 @@
1
+ import { Vector4 } from '@zephyr3d/base';
2
+ import { getDevice } from '../../app/api.js';
3
+ import { buildSDFProgram } from '../sdf/sdf_programs.js';
4
+ import { drawFullscreenQuad } from '../fullscreenquad.js';
5
+ import { fetchSampler } from '../../utility/misc.js';
6
+ import { getGICacheExposure } from '../../utility/physical.js';
7
+ import { LIGHT_TYPE_RECT, LIGHT_TYPE_DIRECTIONAL, LIGHT_TYPE_SPOT } from '../../values.js';
8
+ import { defineLTCEdgeFunctions } from '../../shaders/ltc_rect.js';
9
+ import { declareGlobalSDFUniforms, declareDynamicSDFUniforms, GLOBAL_SDF_LEVELS, sampleGlobalSDFWithVoxel, GLOBAL_SDF_PARAMS } from '../../shaders/sdf.js';
10
+ import { sdfConeShadow } from '../../shaders/gi.js';
11
+ import { declareProbeUniforms, sampleProbeIrradiance } from '../../shaders/probes.js';
12
+ import { getActiveProbeVolume } from './probe_volume.js';
13
+
14
+ /** Most lights the voxels are lit by, the sun aside. */ const MAX_VOXEL_LIGHTS = 64;
15
+ /**
16
+ * vec4s per packed light: (position, range), (direction, cutoff), (colour, intensity), extra,
17
+ * (shadowed, 0, 0, 0).
18
+ */ const LIGHT_VEC4S = 5;
19
+ /** Material voxels along a brick edge of the global field, whose bricks are 8³ field voxels. */ const BRICK_VOXELS = 4;
20
+ /**
21
+ * Format of the second aniso texture, two faces (-y, -z): rg8unorm where the
22
+ * device can write it from a shader (texture-formats-tier1), else rgba8unorm.
23
+ */ function aniso1Format() {
24
+ return getDevice().getDeviceCaps().textureCaps.getTextureFormatInfo('rg8unorm')?.writable ? 'rg8unorm' : 'rgba8unorm';
25
+ }
26
+ /** Most local lights whose voxel lighting is shadowed, the nearest the camera first. */ const MAX_SHADOWED_VOXEL_LIGHTS = 8;
27
+ /**
28
+ * Cone of a local light shadow ray. Lumen traces these as hard hit tests; a vanishing cone through
29
+ * {@link sdfConeShadow} is the same test with its expanded surfaces.
30
+ */ const HARD_SHADOW_TAN = 1e-4;
31
+ /** Cone tracing steps of the sun shadow and the local light shadows. */ const SHADOW_STEPS = 24;
32
+ /** The axis faces of a voxel, in the order of the aniso textures. */ const ANISO_DIRS = [
33
+ [
34
+ 1,
35
+ 0,
36
+ 0
37
+ ],
38
+ [
39
+ 0,
40
+ 1,
41
+ 0
42
+ ],
43
+ [
44
+ 0,
45
+ 0,
46
+ 1
47
+ ],
48
+ [
49
+ -1,
50
+ 0,
51
+ 0
52
+ ],
53
+ [
54
+ 0,
55
+ -1,
56
+ 0
57
+ ],
58
+ [
59
+ 0,
60
+ 0,
61
+ -1
62
+ ]
63
+ ];
64
+ /**
65
+ * Lights the voxel scene: per material voxel, the sun (cone-traced field shadow, see
66
+ * {@link sdfConeShadow}), punctual lights in range (rect lights by their one-sided
67
+ * polygon form factor per voxel face, as surfaces shade them; shadowed by one hard field ray for
68
+ * the nearest {@link MAX_SHADOWED_VOXEL_LIGHTS} local lights casting shadows) and sky irradiance,
69
+ * times albedo,
70
+ * plus emissive, into the radiance clipmap. Kept at the fixed cache exposure
71
+ * (getGICacheExposure) so probes accumulating it don't drift with camera exposure.
72
+ *
73
+ * A fragment pass, one fragment per voxel of a slab of z slices rotating through every
74
+ * level, so the scene refreshes over a few frames. Voxels without material write zero.
75
+ *
76
+ * @internal
77
+ */ class VoxelLighting {
78
+ _scene;
79
+ _radiance;
80
+ _aniso0;
81
+ _aniso1;
82
+ _resolution;
83
+ _levels;
84
+ _program;
85
+ _programKey;
86
+ _bindGroup;
87
+ _brickProgram;
88
+ _brickBindGroup;
89
+ _brickBuffer;
90
+ _renderStates;
91
+ _lightData;
92
+ _zStart;
93
+ _passes;
94
+ _sunDir;
95
+ _sunColor;
96
+ _params;
97
+ _slab;
98
+ constructor(scene){
99
+ this._scene = scene;
100
+ this._radiance = null;
101
+ this._aniso0 = null;
102
+ this._aniso1 = null;
103
+ this._resolution = 0;
104
+ this._levels = 0;
105
+ this._program = null;
106
+ this._programKey = '';
107
+ this._bindGroup = null;
108
+ this._brickProgram = null;
109
+ this._brickBindGroup = null;
110
+ this._brickBuffer = null;
111
+ this._renderStates = null;
112
+ this._lightData = new Float32Array(MAX_VOXEL_LIGHTS * LIGHT_VEC4S * 4);
113
+ this._zStart = 0;
114
+ this._passes = 0;
115
+ this._sunDir = new Vector4();
116
+ this._sunColor = new Vector4();
117
+ this._params = new Vector4();
118
+ this._slab = new Vector4();
119
+ }
120
+ /** Outgoing radiance clipmap, rgba16f, laid out like the albedo. */ get radiance() {
121
+ if (!this._radiance) {
122
+ throw new Error('VoxelLighting: no radiance before the first update');
123
+ }
124
+ return this._radiance;
125
+ }
126
+ /** Share of the radiance each voxel face carries, (+x, +y, +z, -x); see declareVoxelSceneUniforms. */ get aniso0() {
127
+ if (!this._aniso0) {
128
+ throw new Error('VoxelLighting: no radiance before the first update');
129
+ }
130
+ return this._aniso0;
131
+ }
132
+ /** Share of the radiance each voxel face carries, (-y, -z) in rg. */ get aniso1() {
133
+ if (!this._aniso1) {
134
+ throw new Error('VoxelLighting: no radiance before the first update');
135
+ }
136
+ return this._aniso1;
137
+ }
138
+ get ready() {
139
+ return !!this._radiance;
140
+ }
141
+ /** Lighting passes run so far. */ get passes() {
142
+ return this._passes;
143
+ }
144
+ /**
145
+ * Lights the next slab of every level.
146
+ * @param albedo - The albedo clipmap, `resolution`³ per level.
147
+ * @param emissive - The emissive clipmap.
148
+ */ update(global, albedo, emissive, resolution, camera, options) {
149
+ const device = getDevice();
150
+ const scene = this._scene;
151
+ if (!this._radiance || this._resolution !== resolution || this._levels !== global.levels) {
152
+ this._radiance?.dispose();
153
+ this._aniso0?.dispose();
154
+ this._aniso1?.dispose();
155
+ this._resolution = resolution;
156
+ this._levels = global.levels;
157
+ const depth = resolution * global.levels;
158
+ this._radiance = device.createTexture3D('rgba16f', resolution, resolution, depth, {
159
+ mipmapping: false,
160
+ writable: true
161
+ });
162
+ this._radiance.name = '@VoxelSceneRadiance';
163
+ this._aniso0 = device.createTexture3D('rgba8unorm', resolution, resolution, depth, {
164
+ mipmapping: false,
165
+ writable: true
166
+ });
167
+ this._aniso0.name = '@VoxelSceneAniso0';
168
+ this._aniso1 = device.createTexture3D(aniso1Format(), resolution, resolution, depth, {
169
+ mipmapping: false,
170
+ writable: true
171
+ });
172
+ this._aniso1.name = '@VoxelSceneAniso1';
173
+ this._zStart = 0;
174
+ }
175
+ const envLight = scene.env.light.envLight;
176
+ const physical = scene.lightingMode === 'physical';
177
+ // Fixed cache exposure; the sky bake uses the same exposure, so it takes the strength alone
178
+ const cacheExposure = getGICacheExposure(scene.lightingMode);
179
+ const envStrength = scene.env.light.strength ?? 0;
180
+ // No sky without an environment light (its stand-in carries only the probes)
181
+ const skyIrradiance = scene.env.light.type !== 'none' && envLight.hasIrradiance();
182
+ const probes = getActiveProbeVolume(scene);
183
+ const key = `${global.levels}:${scene.lightingMode}:${skyIrradiance ? envLight.getType() : 'none'}:${skyIrradiance ? this.envVariant() : ''}:probes${probes ? 1 : 0}`;
184
+ if (!this._program || this._programKey !== key) {
185
+ this.disposePrograms();
186
+ this._program = this.createProgram(global.levels, physical, skyIrradiance, !!probes, false);
187
+ this._programKey = key;
188
+ this._bindGroup = device.createBindGroup(this._program.bindGroupLayouts[0]);
189
+ }
190
+ const numLights = this.collectLights(camera, cacheExposure, options.localLightShadows);
191
+ const slices = Math.max(1, Math.min(resolution, Math.floor(options.slicesPerFrame)));
192
+ const tanHalf = Math.tan(Math.max(0.1, options.sunShadowConeAngle) * Math.PI / 180);
193
+ this._params.setXYZW(numLights, envStrength, tanHalf, 0);
194
+ this._slab.setXYZW(resolution, global.levels, slices, this._zStart);
195
+ const bind = (bg)=>{
196
+ global.applyBindGroup(bg);
197
+ bg.setTexture('albedoTex', albedo, fetchSampler('clamp_nearest_nomip'));
198
+ bg.setTexture('emissiveTex', emissive, fetchSampler('clamp_nearest_nomip'));
199
+ bg.setTexture('radianceOut', this._radiance);
200
+ bg.setTexture('aniso0Out', this._aniso0);
201
+ bg.setTexture('aniso1Out', this._aniso1);
202
+ bg.setValue('lights', this._lightData);
203
+ bg.setValue('sunDir', this._sunDir);
204
+ bg.setValue('sunColor', this._sunColor);
205
+ bg.setValue('params', this._params);
206
+ bg.setValue('slab', this._slab);
207
+ if (skyIrradiance) {
208
+ envLight.updateBindGroup(bg);
209
+ }
210
+ probes?.applyBindGroup(bg);
211
+ };
212
+ if (!this._renderStates) {
213
+ this._renderStates = device.createRenderStateSet();
214
+ this._renderStates.useDepthState().enableTest(false).enableWrite(false);
215
+ this._renderStates.useRasterizerState().setCullMode('none');
216
+ this._renderStates.useColorState().setColorMask(false, false, false, false);
217
+ }
218
+ const draw = (program, bg, width, height)=>{
219
+ let fb = null;
220
+ device.pushDeviceStates();
221
+ try {
222
+ fb = device.pool.fetchTemporalFramebuffer(false, width, height, 'rgba8unorm');
223
+ device.setFramebuffer(fb);
224
+ device.setViewport([
225
+ 0,
226
+ 0,
227
+ width,
228
+ height
229
+ ]);
230
+ device.setScissor([
231
+ 0,
232
+ 0,
233
+ width,
234
+ height
235
+ ]);
236
+ device.setProgram(program);
237
+ device.setBindGroup(0, bg);
238
+ drawFullscreenQuad(this._renderStates);
239
+ } finally{
240
+ device.popDeviceStates();
241
+ if (fb) {
242
+ device.pool.releaseFrameBuffer(fb);
243
+ }
244
+ }
245
+ };
246
+ bind(this._bindGroup);
247
+ draw(this._program, this._bindGroup, resolution, resolution * slices * global.levels);
248
+ // Bricks the field composited this frame hold stale radiance; light them now
249
+ // rather than up to resolution / slices frames later
250
+ const fresh = global.freshMaterialBricks;
251
+ if (fresh.count > 0) {
252
+ if (!this._brickProgram) {
253
+ this._brickProgram = this.createProgram(global.levels, physical, skyIrradiance, !!probes, true);
254
+ this._brickBindGroup = device.createBindGroup(this._brickProgram.bindGroupLayouts[0]);
255
+ }
256
+ const bytes = fresh.data.byteLength;
257
+ if (!this._brickBuffer || this._brickBuffer.byteLength < bytes) {
258
+ this._brickBuffer?.dispose();
259
+ this._brickBuffer = device.createBuffer(bytes, {
260
+ usage: 'uniform',
261
+ storage: true
262
+ });
263
+ }
264
+ this._brickBuffer.bufferSubData(0, fresh.data, 0, fresh.count * 4);
265
+ const bg = this._brickBindGroup;
266
+ bind(bg);
267
+ bg.setBuffer('bricks', this._brickBuffer);
268
+ draw(this._brickProgram, bg, BRICK_VOXELS ** 3, fresh.count);
269
+ }
270
+ this._zStart = (this._zStart + slices) % resolution;
271
+ this._passes++;
272
+ }
273
+ dispose() {
274
+ this._radiance?.dispose();
275
+ this._radiance = null;
276
+ this._aniso0?.dispose();
277
+ this._aniso0 = null;
278
+ this._aniso1?.dispose();
279
+ this._aniso1 = null;
280
+ this.disposePrograms();
281
+ this._brickBuffer?.dispose();
282
+ this._brickBuffer = null;
283
+ }
284
+ /** @internal */ disposePrograms() {
285
+ this._bindGroup?.dispose();
286
+ this._bindGroup = null;
287
+ this._program?.dispose();
288
+ this._program = null;
289
+ this._brickBindGroup?.dispose();
290
+ this._brickBindGroup = null;
291
+ this._brickProgram?.dispose();
292
+ this._brickProgram = null;
293
+ this._programKey = '';
294
+ }
295
+ /** What of the environment light's bindings the program depends on. @internal */ envVariant() {
296
+ const envLight = this._scene.env.light.envLight;
297
+ return `${envLight.irradianceSHFB ? 'fb' : envLight.irradianceSH ? 'buf' : ''}`;
298
+ }
299
+ /**
300
+ * Packs the visible punctual lights: the sun apart (the marked sun light, else the
301
+ * first directional), the rest nearest the camera first, up to {@link MAX_VOXEL_LIGHTS}.
302
+ * The first {@link MAX_SHADOWED_VOXEL_LIGHTS} local lights casting shadows are flagged for a
303
+ * shadow ray when `localShadows` is on.
304
+ * Only the intensity carries the cache exposure, as in the clustered light buffer.
305
+ * @internal
306
+ */ collectLights(camera, exposure, localShadows) {
307
+ const scene = this._scene;
308
+ const cameraPos = camera.getWorldPosition();
309
+ const found = {
310
+ sun: null
311
+ };
312
+ const others = [];
313
+ scene.rootNode.iterate((node)=>{
314
+ if (node.isPunctualLight() && !node.hidden) {
315
+ if (node.isDirectionLight()) {
316
+ // The marked sun light wins; else the first directional light
317
+ if (!found.sun || node.sunLight) {
318
+ if (found.sun) {
319
+ others.push({
320
+ light: found.sun,
321
+ d: 0
322
+ });
323
+ }
324
+ found.sun = node;
325
+ } else {
326
+ others.push({
327
+ light: node,
328
+ d: 0
329
+ });
330
+ }
331
+ } else {
332
+ const p = node.positionAndRange;
333
+ others.push({
334
+ light: node,
335
+ d: Math.hypot(p.x - cameraPos.x, p.y - cameraPos.y, p.z - cameraPos.z)
336
+ });
337
+ }
338
+ }
339
+ return false;
340
+ });
341
+ const sunLight = found.sun;
342
+ if (sunLight) {
343
+ const dir = sunLight.directionAndCutoff;
344
+ const c = sunLight.diffuseAndIntensity;
345
+ this._sunDir.setXYZW(dir.x, dir.y, dir.z, 1);
346
+ this._sunColor.setXYZW(c.x * c.w * exposure, c.y * c.w * exposure, c.z * c.w * exposure, 0);
347
+ } else {
348
+ this._sunDir.setXYZW(0, -1, 0, 0);
349
+ this._sunColor.setXYZW(0, 0, 0, 0);
350
+ }
351
+ others.sort((a, b)=>a.d - b.d);
352
+ const count = Math.min(others.length, MAX_VOXEL_LIGHTS);
353
+ const data = this._lightData;
354
+ let shadowedCount = 0;
355
+ for(let i = 0; i < count; i++){
356
+ const light = others[i].light;
357
+ const o = i * LIGHT_VEC4S * 4;
358
+ data.set(light.positionAndRange, o);
359
+ data.set(light.directionAndCutoff, o + 4);
360
+ const c = light.diffuseAndIntensity;
361
+ data[o + 8] = c.x;
362
+ data[o + 9] = c.y;
363
+ data[o + 10] = c.z;
364
+ data[o + 11] = c.w * exposure;
365
+ data.set(light.extraParams, o + 12);
366
+ // Local lights only; a directional light besides the sun stays unshadowed
367
+ const shadowed = localShadows && shadowedCount < MAX_SHADOWED_VOXEL_LIGHTS && !light.isDirectionLight() && light.castShadow;
368
+ if (shadowed) {
369
+ shadowedCount++;
370
+ }
371
+ data[o + 16] = shadowed ? 1 : 0;
372
+ data[o + 17] = 0;
373
+ data[o + 18] = 0;
374
+ data[o + 19] = 0;
375
+ }
376
+ return count;
377
+ }
378
+ /**
379
+ * The lighting program: one fragment per voxel of the slab, or with `bricks`
380
+ * a row of {@link BRICK_VOXELS}³ fragments per listed brick.
381
+ * @internal
382
+ */ createProgram(levels, physical, skyIrradiance, useProbes, bricks) {
383
+ const scene = this._scene;
384
+ const envLight = scene.env.light.envLight;
385
+ return buildSDFProgram({
386
+ label: bricks ? 'VoxelLightingBricks' : 'VoxelLighting',
387
+ vertex (pb) {
388
+ this.$inputs.pos = pb.vec2().attrib('position');
389
+ pb.main(function() {
390
+ this.$builtins.position = pb.vec4(this.$inputs.pos, 0, 1);
391
+ });
392
+ },
393
+ fragment (pb) {
394
+ this.$outputs.color = pb.vec4();
395
+ declareGlobalSDFUniforms(this, 0, levels);
396
+ // Bound by the field alongside the global uniforms, unused here
397
+ declareDynamicSDFUniforms(this, 0);
398
+ this.albedoTex = pb.tex3D().sampleType('unfilterable-float').uniform(0);
399
+ this.emissiveTex = pb.tex3D().sampleType('unfilterable-float').uniform(0);
400
+ this.radianceOut = pb.texStorage3D.rgba16float().storage(0);
401
+ this.aniso0Out = pb.texStorage3D.rgba8unorm().storage(0);
402
+ this.aniso1Out = aniso1Format() === 'rg8unorm' ? pb.texStorage3D.rg8unorm().storage(0) : pb.texStorage3D.rgba8unorm().storage(0);
403
+ this.lights = pb.vec4[MAX_VOXEL_LIGHTS * LIGHT_VEC4S]().uniform(0);
404
+ // (direction the light travels, 1 when there is a sun)
405
+ this.sunDir = pb.vec4().uniform(0);
406
+ this.sunColor = pb.vec4().uniform(0);
407
+ // (light count, environment strength, tan of the shadow cone half angle, 0)
408
+ this.params = pb.vec4().uniform(0);
409
+ // (resolution, levels, slices per pass, first slice)
410
+ this.slab = pb.vec4().uniform(0);
411
+ if (bricks) {
412
+ // Per brick: (first material voxel within its level, level)
413
+ this.bricks = pb.vec4[0]().storageBufferReadonly(0);
414
+ }
415
+ if (skyIrradiance) {
416
+ envLight.initShaderBindings(pb);
417
+ }
418
+ if (useProbes) {
419
+ declareProbeUniforms(this, 0);
420
+ }
421
+ pb.func('Z_pointAttenuation', [
422
+ pb.vec3('p'),
423
+ pb.vec4('posRange')
424
+ ], function() {
425
+ this.$l.d = pb.sub(this.p, this.posRange.xyz);
426
+ this.$l.dist2 = pb.dot(this.d, this.d);
427
+ this.$l.atten = pb.div(1, pb.max(this.dist2, 0.0001));
428
+ this.$l.range2 = pb.mul(this.posRange.w, this.posRange.w);
429
+ this.$l.f = pb.div(this.dist2, pb.max(this.range2, 0.0001));
430
+ this.$l.f2 = pb.clamp(pb.sub(1, pb.mul(this.f, this.f)), 0, 1);
431
+ this.$return(pb.mul(this.atten, this.f2, this.f2));
432
+ });
433
+ // Rect lights as the surfaces shade their diffuse part (see evaluateLTCRectLightTerms):
434
+ // the polygon form factor clipped to the horizon (LTC with the identity matrix, Heitz et
435
+ // al. 2016), one-sided about the light plane, with the same range window
436
+ defineLTCEdgeFunctions(this);
437
+ pb.func('Z_rectFormFactor', [
438
+ pb.vec3('p'),
439
+ pb.vec3('N'),
440
+ pb.vec3('V'),
441
+ pb.vec4('posRange'),
442
+ pb.vec3('ax'),
443
+ pb.vec3('ay')
444
+ ], function() {
445
+ this.$l.lightNormal = pb.neg(pb.normalize(pb.cross(this.ax, this.ay)));
446
+ this.$l.toPoint = pb.sub(this.p, this.posRange.xyz);
447
+ this.$if(pb.lessThanEqual(pb.dot(this.lightNormal, this.toPoint), 0), function() {
448
+ this.$return(pb.float(0));
449
+ });
450
+ this.$l.falloff = pb.float(1);
451
+ this.$if(pb.greaterThan(this.posRange.w, 0), function() {
452
+ this.falloff = pb.sub(1, pb.smoothStep(pb.mul(this.posRange.w, 0.9), this.posRange.w, pb.length(this.toPoint)));
453
+ });
454
+ this.$l.c = this.posRange.xyz;
455
+ this.$l.ff = this.Z_LTCEvaluateRect(this.N, this.V, this.p, pb.mat3(pb.vec3(1, 0, 0), pb.vec3(0, 1, 0), pb.vec3(0, 0, 1)), pb.sub(pb.sub(this.c, this.ax), this.ay), pb.add(pb.sub(this.c, this.ay), this.ax), pb.add(pb.add(this.c, this.ax), this.ay), pb.add(pb.sub(this.c, this.ax), this.ay)).x;
456
+ this.$return(pb.mul(this.ff, this.falloff));
457
+ });
458
+ pb.func('Z_spotAttenuation', [
459
+ pb.vec3('p'),
460
+ pb.vec4('posRange'),
461
+ pb.vec4('dirCutoff'),
462
+ pb.vec2('angleScaleOffset')
463
+ ], function() {
464
+ // The point light's distance falloff in both modes, as the surfaces light them
465
+ this.$l.falloff = this.Z_pointAttenuation(this.p, this.posRange);
466
+ this.$l.cd = pb.dot(pb.normalize(pb.sub(this.p, this.posRange.xyz)), this.dirCutoff.xyz);
467
+ if (physical) {
468
+ this.$l.spot = pb.clamp(pb.add(pb.mul(this.cd, this.angleScaleOffset.x), this.angleScaleOffset.y), 0, 1);
469
+ this.spot = pb.mul(this.spot, this.spot);
470
+ } else {
471
+ this.$l.spot = pb.smoothStep(this.dirCutoff.w, pb.mix(this.dirCutoff.w, 1, 0.5), this.cd);
472
+ }
473
+ this.$return(pb.mul(this.spot, this.falloff));
474
+ });
475
+ pb.main(function() {
476
+ this.$l.res = pb.int(this.slab.x);
477
+ this.$l.fc = pb.ivec2(pb.floor(this.$builtins.fragCoord.xy));
478
+ if (bricks) {
479
+ this.$l.brick = this.bricks.at(this.fc.y);
480
+ this.$l.level = pb.int(this.brick.w);
481
+ this.$l.t = pb.add(pb.ivec3(this.brick.xyz), pb.ivec3(pb.mod(this.fc.x, BRICK_VOXELS), pb.mod(pb.div(this.fc.x, BRICK_VOXELS), BRICK_VOXELS), pb.div(this.fc.x, BRICK_VOXELS * BRICK_VOXELS)));
482
+ } else {
483
+ this.$l.slices = pb.int(this.slab.z);
484
+ this.$l.rowsPerLevel = pb.mul(this.res, this.slices);
485
+ this.$l.level = pb.div(this.fc.y, this.rowsPerLevel);
486
+ this.$l.rem = pb.sub(this.fc.y, pb.mul(this.level, this.rowsPerLevel));
487
+ this.$l.z = pb.add(pb.int(this.slab.w), pb.div(this.rem, this.res));
488
+ this.$l.t = pb.ivec3(this.fc.x, pb.sub(this.rem, pb.mul(pb.div(this.rem, this.res), this.res)), this.z);
489
+ }
490
+ this.$l.tz = pb.add(this.t.z, pb.mul(this.level, this.res));
491
+ this.$l.texel = pb.ivec3(this.t.x, this.t.y, this.tz);
492
+ this.$l.radiance = pb.vec3(0);
493
+ this.$l.aniso0 = pb.vec4(0);
494
+ this.$l.aniso1 = pb.vec4(0);
495
+ this.$l.a = pb.textureLoad(this.albedoTex, this.texel, 0);
496
+ this.$if(pb.greaterThan(this.a.a, 0), function() {
497
+ // World voxel of the texel: the one in the level's window with this toroidal address
498
+ this.$l.info = pb.vec4(0);
499
+ this.$l.fineVs = pb.float(0);
500
+ for(let i = 0; i < levels; i++){
501
+ this.$if(pb.equal(this.level, i), function() {
502
+ this.info = this[GLOBAL_SDF_LEVELS].at(i);
503
+ });
504
+ }
505
+ this.$l.originC = pb.ivec3(pb.floor(pb.div(this.info.xyz, 2)));
506
+ this.$l.resV = pb.ivec3(this.res);
507
+ this.$l.w = pb.add(this.originC, pb.mod(pb.add(pb.mod(pb.sub(this.t, this.originC), this.resV), this.resV), this.resV));
508
+ this.$l.vs = pb.mul(this.info.w, 2);
509
+ this.$l.p = pb.mul(pb.add(pb.vec3(this.w), pb.vec3(0.5)), this.vs);
510
+ // Light per axis face of the voxel, so a floor thinner than the voxel is lit
511
+ // on top and dark below. A face counts as open where the field at its centre
512
+ // is outside the solid.
513
+ this.$l.half = pb.mul(this.vs, 0.5);
514
+ // Read from the voxel's own level on: a finer level resolves more geometry
515
+ for(let k = 0; k < 6; k++){
516
+ this.$l[`open${k}`] = pb.greaterThan(sampleGlobalSDFWithVoxel(this, pb.add(this.p, pb.mul(pb.vec3(...ANISO_DIRS[k]), this.half)), levels, this.level).x, 0);
517
+ this.$l[`acc${k}`] = pb.vec3(0);
518
+ }
519
+ this.$l.albedo = this.a.rgb;
520
+ // Sun: one shadow ray for all faces, started near the voxel corner toward the
521
+ // light and offset along it
522
+ this.$if(pb.greaterThan(this.sunDir.w, 0.5), function() {
523
+ this.$l.L = pb.neg(this.sunDir.xyz);
524
+ this.$l.ps = pb.add(this.p, pb.mul(pb.sign(this.L), this.vs, 0.48), pb.mul(this.L, this.vs, 0.4));
525
+ this.$l.shadow = sdfConeShadow(this, this.ps, this.L, this.params.z, this.vs, pb.mul(this[GLOBAL_SDF_PARAMS].x, this[GLOBAL_SDF_LEVELS].at(levels - 1).w, 0.5), levels, SHADOW_STEPS, this.level);
526
+ this.$if(pb.greaterThan(this.shadow, 0), function() {
527
+ this.$l.sun = pb.mul(this.albedo, this.sunColor.rgb, this.shadow, 1 / Math.PI);
528
+ for(let k = 0; k < 6; k++){
529
+ this.$if(this[`open${k}`], function() {
530
+ this[`acc${k}`] = pb.add(this[`acc${k}`], pb.mul(this.sun, pb.max(pb.dot(pb.vec3(...ANISO_DIRS[k]), this.L), 0)));
531
+ });
532
+ }
533
+ });
534
+ });
535
+ this.$l.count = pb.int(this.params.x);
536
+ this.$for(pb.int('li'), 0, MAX_VOXEL_LIGHTS, function() {
537
+ this.$if(pb.greaterThanEqual(this.li, this.count), function() {
538
+ this.$break();
539
+ });
540
+ this.$l.base = pb.mul(this.li, LIGHT_VEC4S);
541
+ this.$l.posRange = this.lights.at(this.base);
542
+ this.$l.dirCutoff = this.lights.at(pb.add(this.base, 1));
543
+ this.$l.colorIntensity = this.lights.at(pb.add(this.base, 2));
544
+ this.$l.extra = this.lights.at(pb.add(this.base, 3));
545
+ this.$l.shadowInfo = this.lights.at(pb.add(this.base, 4));
546
+ this.$l.ltype = pb.int(this.extra.w);
547
+ // This light's share of each open face, before the shadow
548
+ for(let k = 0; k < 6; k++){
549
+ this.$l[`lf${k}`] = pb.vec3(0);
550
+ }
551
+ this.$if(pb.equal(this.ltype, LIGHT_TYPE_RECT), function() {
552
+ // Radiance times the form factor seen by each face; (dirCutoff, extra) hold the
553
+ // half-extent axes
554
+ this.$l.rc = pb.mul(this.albedo, this.colorIntensity.rgb, this.colorIntensity.w);
555
+ for(let k = 0; k < 6; k++){
556
+ this.$if(this[`open${k}`], function() {
557
+ // Any direction off the normal: the identity-matrix integral does not
558
+ // depend on the tangent frame
559
+ const v = ANISO_DIRS[k][1] !== 0 ? [
560
+ 1,
561
+ 0,
562
+ 0
563
+ ] : [
564
+ 0,
565
+ 1,
566
+ 0
567
+ ];
568
+ this[`lf${k}`] = pb.mul(this.rc, this.Z_rectFormFactor(this.p, pb.vec3(...ANISO_DIRS[k]), pb.vec3(...v), this.posRange, this.dirCutoff.xyz, this.extra.xyz));
569
+ });
570
+ }
571
+ }).$else(function() {
572
+ this.$l.atten = pb.float(0);
573
+ this.$l.Ld = pb.vec3(0, 1, 0);
574
+ this.$if(pb.equal(this.ltype, LIGHT_TYPE_DIRECTIONAL), function() {
575
+ this.atten = 1;
576
+ this.Ld = pb.neg(this.dirCutoff.xyz);
577
+ }).$elseif(pb.equal(this.ltype, LIGHT_TYPE_SPOT), function() {
578
+ this.atten = this.Z_spotAttenuation(this.p, this.posRange, this.dirCutoff, this.extra.xy);
579
+ this.Ld = pb.normalize(pb.sub(this.posRange.xyz, this.p));
580
+ }).$else(function() {
581
+ this.atten = this.Z_pointAttenuation(this.p, this.posRange);
582
+ this.Ld = pb.normalize(pb.sub(this.posRange.xyz, this.p));
583
+ });
584
+ this.$l.lc = pb.mul(this.albedo, this.colorIntensity.rgb, pb.mul(this.colorIntensity.w, this.atten, 1 / Math.PI));
585
+ for(let k = 0; k < 6; k++){
586
+ this.$if(this[`open${k}`], function() {
587
+ this[`lf${k}`] = pb.mul(this.lc, pb.max(pb.dot(pb.vec3(...ANISO_DIRS[k]), this.Ld), 0));
588
+ });
589
+ }
590
+ });
591
+ // Local light shadow, as Lumen's offscreen shadowing through the global field
592
+ // (LumenSceneDirectLightingSoftwareRayTracing.usf, TraceOffscreenShadows): one hard
593
+ // ray from the voxel to the light position, a rect light's centre included,
594
+ // stopping one field voxel short of the light so geometry right next to it does
595
+ // not shadow it (VoxelSizeRelativeRayEndBias). Traced only where it lights a face.
596
+ this.$l.lightSum = pb.add(this.lf0, this.lf1, this.lf2, this.lf3, this.lf4, this.lf5);
597
+ this.$l.lightShadow = pb.float(1);
598
+ this.$if(pb.and(pb.greaterThan(this.shadowInfo.x, 0.5), pb.greaterThan(pb.max(pb.max(this.lightSum.r, this.lightSum.g), this.lightSum.b), 0)), function() {
599
+ this.$l.toLight = pb.sub(this.posRange.xyz, this.p);
600
+ this.$l.SL = pb.normalize(this.toLight);
601
+ // Started as the sun's ray: near the voxel corner toward the light
602
+ this.$l.sps = pb.add(this.p, pb.mul(pb.sign(this.SL), this.vs, 0.48), pb.mul(this.SL, this.vs, 0.4));
603
+ this.$l.slen = pb.sub(pb.dot(pb.sub(this.posRange.xyz, this.sps), this.SL), this.info.w);
604
+ this.$if(pb.greaterThan(this.slen, 0), function() {
605
+ this.lightShadow = sdfConeShadow(this, this.sps, this.SL, pb.float(HARD_SHADOW_TAN), this.vs, this.slen, levels, SHADOW_STEPS, this.level);
606
+ });
607
+ });
608
+ for(let k = 0; k < 6; k++){
609
+ this[`acc${k}`] = pb.add(this[`acc${k}`], pb.mul(this[`lf${k}`], this.lightShadow));
610
+ }
611
+ });
612
+ // Ambient per open face: sky, or probe irradiance where covered, carrying every
613
+ // earlier bounce (Majercik et al. 2019 sec. 3.2). Albedo clamped below 1 keeps
614
+ // the feedback loop convergent. Emissive leaves every open face.
615
+ this.$l.feedback = pb.min(this.albedo, pb.vec3(0.9));
616
+ this.$l.emissive = pb.textureLoad(this.emissiveTex, this.texel, 0).rgb;
617
+ for(let k = 0; k < 6; k++){
618
+ this.$if(this[`open${k}`], function() {
619
+ this.$l.faceDir = pb.vec3(...ANISO_DIRS[k]);
620
+ this.$l.ambient = pb.vec3(0);
621
+ if (skyIrradiance) {
622
+ this.ambient = pb.mul(envLight.getIrradiance(this, this.faceDir).rgb, this.params.y);
623
+ }
624
+ if (useProbes) {
625
+ this.$l.bounce = sampleProbeIrradiance(this, pb.add(this.p, pb.mul(this.faceDir, this.half)), this.faceDir, this.faceDir, 'feedback');
626
+ this.ambient = pb.mix(this.ambient, this.bounce.rgb, this.bounce.a);
627
+ }
628
+ this[`acc${k}`] = pb.add(this[`acc${k}`], pb.mul(this.feedback, this.ambient), this.emissive);
629
+ });
630
+ }
631
+ // Stored as the sum, with the share of each face by luminance
632
+ this.radiance = pb.add(this.acc0, this.acc1, this.acc2, this.acc3, this.acc4, this.acc5);
633
+ this.$l.lumaTotal = pb.max(pb.max(this.radiance.r, this.radiance.g), this.radiance.b);
634
+ this.$l.invLuma = this.$choice(pb.greaterThan(this.lumaTotal, 0), pb.div(1, pb.max(this.lumaTotal, 1e-8)), pb.float(0));
635
+ for(let k = 0; k < 6; k++){
636
+ this.$l[`luma${k}`] = pb.mul(pb.max(pb.max(this[`acc${k}`].r, this[`acc${k}`].g), this[`acc${k}`].b), this.invLuma);
637
+ }
638
+ this.aniso0 = pb.vec4(this.luma0, this.luma1, this.luma2, this.luma3);
639
+ this.aniso1 = pb.vec4(this.luma4, this.luma5, 0, 0);
640
+ });
641
+ pb.textureStore(this.radianceOut, pb.uvec3(this.texel), pb.vec4(this.radiance, 1));
642
+ pb.textureStore(this.aniso0Out, pb.uvec3(this.texel), this.aniso0);
643
+ pb.textureStore(this.aniso1Out, pb.uvec3(this.texel), this.aniso1);
644
+ this.$outputs.color = pb.vec4(0);
645
+ });
646
+ }
647
+ });
648
+ }
649
+ }
650
+
651
+ export { MAX_SHADOWED_VOXEL_LIGHTS, MAX_VOXEL_LIGHTS, VoxelLighting };
652
+ //# sourceMappingURL=voxel_lighting.js.map