@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
@@ -1,8 +1,13 @@
1
1
  import { Vector4, Vector3 } from '@zephyr3d/base';
2
- import { getAtmosphereParamsStruct, aerialPerspective } from './atmosphere.js';
2
+ import { getAtmosphereParamsStruct, rayIntersectSphere, aerialPerspective, AP_LUT_SLICE_SIZE, AP_LUT_DEPTH_SLICES } from './atmosphere.js';
3
3
  import { Fog } from '../values.js';
4
4
 
5
- /** @internal */ const MAX_FOG_HEIGHT = 100;
5
+ /**
6
+ * How far above the fog height the observer is clamped for the fog density at the ray origin (
7
+ * FogHeight + 65536 world units, i.e. 655.36 m).
8
+ *
9
+ * @internal
10
+ */ const MAX_FOG_HEIGHT = 655.36;
6
11
  /** @internal */ function getDefaultHeightFogParams() {
7
12
  return {
8
13
  parameter1: new Vector4(0, 0, 0, 0.1),
@@ -11,7 +16,11 @@ import { Fog } from '../values.js';
11
16
  parameter4: new Vector4(0, 0, 0, 0),
12
17
  lightDir: new Vector3(0, 1, 0),
13
18
  lightColor: new Vector3(0, 0, 0),
14
- preExposure: 1
19
+ preExposure: 1,
20
+ skyLightStrength: 0,
21
+ skyLightRoughness: 0.15,
22
+ skyLightScale: 0,
23
+ skyLightMaxLod: 0
15
24
  };
16
25
  }
17
26
  /** @internal */ function getHeightFogParamsStruct(pb) {
@@ -20,14 +29,16 @@ import { Fog } from '../values.js';
20
29
  pb.vec4('parameter2'),
21
30
  pb.vec4('parameter3'),
22
31
  pb.vec4('parameter4'),
23
- pb.float('dirInscatteringStartDistance'),
24
- pb.vec3('dirInscatteringColor'),
25
32
  pb.vec3('lightDir'),
26
33
  pb.vec3('lightColor'),
27
- pb.float('preExposure')
34
+ pb.float('preExposure'),
35
+ pb.float('skyLightStrength'),
36
+ pb.float('skyLightRoughness'),
37
+ pb.float('skyLightScale'),
38
+ pb.float('skyLightMaxLod')
28
39
  ]);
29
40
  }
30
- function calculateFog(scope, aerialperspective, fogType, atmosphereParams, heightFogParams, uv, isSky, cameraPos, worldPos, additive, apLut, distantLightLut) {
41
+ function calculateFog(scope, aerialperspective, fogType, atmosphereParams, heightFogParams, uv, isSky, cameraPos, worldPos, additive, apLut, distantLightLut, skyLightCubemap) {
31
42
  const pb = scope.$builder;
32
43
  const funcName = 'Z_calculateFog';
33
44
  const AtmosphereParams = getAtmosphereParamsStruct(pb);
@@ -45,10 +56,19 @@ function calculateFog(scope, aerialperspective, fogType, atmosphereParams, heigh
45
56
  ], function() {
46
57
  this.$l.fogging = pb.vec4(0, 0, 0, 1);
47
58
  this.$if(pb.equal(this.fogType, Fog.FOG_TYPE_HEIGHT), function() {
48
- this.fogging = calculateHeightFog(this, this.heightFogParams, this.cameraPos, this.worldPos, this.isSky, distantLightLut);
59
+ this.$l.skyGroundDistance = pb.float(-1);
60
+ this.$l.skyGroundBlend = pb.smoothStep(pb.mul(this.atmosphereParams.atmosphereHeight, 0.1), this.atmosphereParams.atmosphereHeight, this.atmosphereParams.observerAltitude);
61
+ this.$if(pb.and(pb.and(this.isSky, pb.notEqual(this.withAerialPerspective, 0)), pb.greaterThan(this.skyGroundBlend, 0)), function() {
62
+ this.$l.localDir = pb.normalize(pb.mul(this.atmosphereParams.skyViewReferential, pb.vec4(pb.sub(this.worldPos, this.cameraPos), 0)).xyz);
63
+ this.$l.tGround = rayIntersectSphere(this, pb.vec3(0), this.atmosphereParams.plantRadius, pb.vec3(0, pb.add(this.atmosphereParams.plantRadius, this.atmosphereParams.observerAltitude), 0), this.localDir);
64
+ this.$if(pb.greaterThan(this.tGround, 0), function() {
65
+ this.skyGroundDistance = pb.div(this.tGround, this.atmosphereParams.cameraHeightScale);
66
+ });
67
+ });
68
+ this.fogging = calculateHeightFog(this, this.heightFogParams, this.cameraPos, this.worldPos, this.isSky, distantLightLut, skyLightCubemap, this.skyGroundDistance, this.skyGroundBlend);
49
69
  });
50
70
  this.$if(pb.and(pb.notEqual(this.withAerialPerspective, 0), pb.not(this.isSky)), function() {
51
- this.$l.atmosphericFogging = aerialPerspective(this, this.uv, this.atmosphereParams, this.cameraPos, this.worldPos, pb.vec3(32), apLut);
71
+ this.$l.atmosphericFogging = aerialPerspective(this, this.uv, this.atmosphereParams, this.cameraPos, this.worldPos, pb.vec3(AP_LUT_SLICE_SIZE, AP_LUT_SLICE_SIZE, AP_LUT_DEPTH_SLICES), apLut);
52
72
  // rgb is inscattered radiance from the exposure-independent AP LUT, so it takes the camera
53
73
  // pre-exposure; alpha is transmittance and must stay unscaled.
54
74
  this.atmosphericFogging = pb.vec4(pb.mul(this.atmosphericFogging.rgb, this.heightFogParams.preExposure), this.atmosphericFogging.a);
@@ -78,7 +98,11 @@ function combineAerialPerspectiveFog(scope, fogging, aerialPerspectiveFog) {
78
98
  });
79
99
  return scope[funcName](fogging, aerialPerspectiveFog);
80
100
  }
81
- function calculateHeightFog(scope, params, cameraPos, worldPos, isSky, skyDistantColorLut) {
101
+ /**
102
+ * Exponential height fog calculation.
103
+ *
104
+ * Returns the in-scattered radiance in rgb and the transmittance in a.
105
+ */ function calculateHeightFog(scope, params, cameraPos, worldPos, isSky, skyDistantColorLut, skyLightCubemap, skyGroundDistance = -1, skyGroundBlend = 0) {
82
106
  const pb = scope.$builder;
83
107
  const funcName = 'Z_calcHeightFog';
84
108
  const Params = getHeightFogParamsStruct(pb);
@@ -86,25 +110,60 @@ function calculateHeightFog(scope, params, cameraPos, worldPos, isSky, skyDistan
86
110
  Params('params'),
87
111
  pb.vec3('cameraPosition'),
88
112
  pb.vec3('worldPosition'),
89
- pb.bool('isSky')
113
+ pb.bool('isSky'),
114
+ pb.float('skyGroundDistance'),
115
+ pb.float('skyGroundBlend')
90
116
  ], function() {
91
- this.$l.cameraPos = this.$choice(this.isSky, this.cameraPosition, pb.vec3(this.cameraPosition.x, pb.min(this.cameraPosition.y, pb.add(this.params.parameter2.y, MAX_FOG_HEIGHT)), this.cameraPosition.z));
92
- this.$l.ray = pb.sub(this.worldPosition, this.cameraPos);
93
- this.$l.d = pb.length(this.ray);
94
- this.$l.rayNorm = pb.div(this.ray, this.d);
95
- this.$l.origin = pb.add(this.cameraPos, pb.mul(this.rayNorm, this.params.parameter2.z));
96
- this.$l.term = this.params.parameter3.z;
97
- this.$l.worldPos = this.$choice(this.isSky, pb.add(this.cameraPosition, pb.mul(this.rayNorm, 1e8)), this.worldPosition);
98
- this.$l.falloff = pb.clamp(pb.mul(this.params.parameter1.w, pb.sub(this.worldPos.y, this.origin.y)), -125, 126);
99
- this.$l.fading = this.$choice(this.isSky, pb.smoothStep(5e6, 0, this.worldPos.y), 0);
100
- this.$l.factor = this.$choice(pb.greaterThan(pb.abs(this.falloff), 0.01), pb.div(pb.sub(1, pb.exp2(pb.neg(this.falloff))), this.falloff), pb.sub(Math.log(2), pb.mul(0.5 * Math.log(2) * Math.log(2), this.falloff)));
101
- this.$l.worldDistance = pb.dot(pb.sub(this.worldPos, this.origin), this.rayNorm);
102
- this.$l.lineIntegral = pb.mul(this.term, this.factor, pb.max(0, this.worldDistance));
103
- this.$l.directionalInscattering = pb.mul(pb.add(this.params.parameter4.rgb, pb.mul(this.params.lightColor, this.params.parameter3.y)), pb.pow(pb.clamp(pb.dot(this.rayNorm, this.params.lightDir), 0, 1), this.params.parameter3.w));
104
- this.$l.fogFactor = pb.sub(1, pb.clamp(pb.exp2(pb.neg(this.lineIntegral)), 0, 1));
105
- this.$l.distanceFactor = pb.clamp(pb.div(this.worldDistance, this.params.parameter2.w), 0, 1);
106
- this.fogFactor = pb.mul(this.fogFactor, pb.sub(1, this.distanceFactor));
107
- this.$l.directionalInscattering = pb.mul(this.$l.directionalInscattering, pb.max(this.fogFactor, this.fading));
117
+ // A sky pixel that sees the virtual planet ground (skyGroundDistance > 0) is fogged like a
118
+ // surface at that distance, with the forced horizon fog of sky pixels faded out by
119
+ // skyGroundBlend.
120
+ this.$l.skyHitsGround = pb.and(this.isSky, pb.greaterThan(this.skyGroundDistance, 0));
121
+ this.$l.falloff = this.params.parameter1.w;
122
+ this.$l.density = this.params.parameter2.x;
123
+ this.$l.fogHeight = this.params.parameter2.y;
124
+ this.$l.startDistance = this.params.parameter2.z;
125
+ this.$l.endDistance = this.params.parameter2.w;
126
+ this.$l.maxOpacity = this.params.parameter3.x;
127
+ // Sky pixels have no depth: put them far away along the view ray, or on the virtual ground.
128
+ this.$l.skyDir = pb.normalize(pb.sub(this.worldPosition, this.cameraPosition));
129
+ this.$l.receiver = this.$choice(this.isSky, pb.add(this.cameraPosition, pb.mul(this.skyDir, this.$choice(this.skyHitsGround, this.skyGroundDistance, pb.float(1e8)))), this.worldPosition);
130
+ // The density at the observer (rayOriginTerm, see SkyRenderer.update) is evaluated at a height
131
+ // clamped to MAX_FOG_HEIGHT above the fog, so the ray starts from that clamped observer.
132
+ this.$l.observerY = pb.min(this.cameraPosition.y, pb.add(this.fogHeight, MAX_FOG_HEIGHT));
133
+ this.$l.cameraToReceiver = pb.sub(this.receiver, this.cameraPosition);
134
+ // End distance: fog stops accumulating beyond this horizontal distance.
135
+ this.$l.lenXZSqr = pb.dot(this.cameraToReceiver.xz, this.cameraToReceiver.xz);
136
+ this.$if(pb.and(pb.greaterThan(this.endDistance, 0), pb.greaterThan(this.lenXZSqr, pb.mul(this.endDistance, this.endDistance))), function() {
137
+ this.cameraToReceiver = pb.mul(this.cameraToReceiver, pb.div(this.endDistance, pb.sqrt(pb.max(1, this.lenXZSqr))));
138
+ });
139
+ // Compensate for the clamped observer height.
140
+ this.cameraToReceiver.y = pb.add(this.cameraToReceiver.y, pb.sub(this.cameraPosition.y, this.observerY));
141
+ this.$l.cameraToReceiverLength = pb.max(pb.length(this.cameraToReceiver), 1e-4);
142
+ this.$l.cameraToReceiverNorm = pb.div(this.cameraToReceiver, this.cameraToReceiverLength);
143
+ this.$l.rayOriginTerms = this.params.parameter3.z;
144
+ this.$l.rayLength = this.cameraToReceiverLength;
145
+ this.$l.rayDirectionY = this.cameraToReceiver.y;
146
+ // Start distance: integrate from the exclusion point, with the density re-evaluated at its height.
147
+ this.$if(pb.greaterThan(this.startDistance, 0), function() {
148
+ this.$l.excludeIntersectionTime = pb.div(this.startDistance, this.cameraToReceiverLength);
149
+ this.$l.cameraToExclusionY = pb.mul(this.excludeIntersectionTime, this.cameraToReceiver.y);
150
+ this.$l.exclusionY = pb.add(this.observerY, this.cameraToExclusionY);
151
+ this.rayLength = pb.mul(pb.sub(1, this.excludeIntersectionTime), this.cameraToReceiverLength);
152
+ this.rayDirectionY = pb.sub(this.cameraToReceiver.y, this.cameraToExclusionY);
153
+ this.$l.exponent = pb.max(-127, pb.mul(this.falloff, pb.sub(this.exclusionY, this.fogHeight)));
154
+ this.rayOriginTerms = pb.mul(this.density, pb.exp2(pb.neg(this.exponent)));
155
+ });
156
+ // Line integral of density * exp2(-falloff * y) along the ray, divided by the ray length.
157
+ this.$l.falloffTerm = pb.max(-127, pb.mul(this.falloff, this.rayDirectionY));
158
+ this.$l.lineIntegralShared = pb.mul(this.rayOriginTerms, this.$choice(pb.greaterThan(pb.abs(this.falloffTerm), 0.01), pb.div(pb.sub(1, pb.exp2(pb.neg(this.falloffTerm))), this.falloffTerm), pb.sub(Math.log(2), pb.mul(0.5 * Math.log(2) * Math.log(2), this.falloffTerm))));
159
+ this.$l.lineIntegral = pb.mul(this.lineIntegralShared, this.rayLength);
160
+ // Ad hoc horizon blend for sky pixels: fully fogged below the horizon.
161
+ this.$l.fading = this.$choice(pb.and(this.isSky, pb.not(this.skyHitsGround)), pb.smoothStep(5e6, 0, this.receiver.y), this.$choice(this.skyHitsGround, pb.sub(1, pb.clamp(this.skyGroundBlend, 0, 1)), pb.float(0)));
162
+ // Directional inscattering: a lobe around the light approximating in-scattering from the
163
+ // directional light off the haze. It has its own opacity, unaffected by maxOpacity.
164
+ this.$l.directionalLight = pb.mul(pb.add(this.params.parameter4.rgb, pb.mul(this.params.lightColor, this.params.parameter3.y)), pb.pow(pb.clamp(pb.dot(this.cameraToReceiverNorm, this.params.lightDir), 0, 1), this.params.parameter3.w));
165
+ this.$l.dirFogOpacity = pb.sub(1, pb.clamp(pb.exp2(pb.neg(pb.mul(this.lineIntegralShared, pb.max(this.rayLength, 0)))), 0, 1));
166
+ this.$l.directionalInscattering = pb.mul(this.directionalLight, pb.max(this.dirFogOpacity, this.fading));
108
167
  this.$l.fogColor = this.params.parameter1.rgb;
109
168
  this.$if(pb.greaterThan(this.params.parameter3.y, 0), function() {
110
169
  // The distant-sky LUT is baked exposure-independently (it feeds the cached IBL), so the
@@ -112,11 +171,20 @@ function calculateHeightFog(scope, params, cameraPos, worldPos, isSky, skyDistan
112
171
  this.$l.skyContrib = pb.mul(pb.textureSampleLevel(skyDistantColorLut, pb.vec2(0.5), 0).rgb, this.params.preExposure);
113
172
  this.fogColor = pb.add(this.fogColor, pb.mul(this.skyContrib, this.params.parameter3.y));
114
173
  });
115
- this.$l.fogFactor = pb.max(pb.min(this.fogFactor, this.params.parameter3.x), this.fading);
116
- this.$l.fogColor = pb.add(pb.mul(this.fogColor, this.fogFactor), this.directionalInscattering);
117
- this.$return(pb.vec4(this.fogColor, pb.sub(1, this.fogFactor)));
174
+ this.$l.skyLightStrength = this.$choice(pb.greaterThan(this.params.skyLightScale, 0), pb.clamp(this.params.skyLightStrength, 0, 1), pb.float(0));
175
+ this.$if(pb.greaterThan(this.skyLightStrength, 0), function() {
176
+ this.$l.skyLightLod = pb.mul(pb.clamp(this.params.skyLightRoughness, 0, 1), this.params.skyLightMaxLod);
177
+ this.$l.minElevation = pb.min(pb.mul(Math.PI / 2, pb.exp2(pb.sub(this.skyLightLod, this.params.skyLightMaxLod))), Math.PI / 2);
178
+ this.$l.skyLightDir = pb.vec3(this.cameraToReceiverNorm.x, pb.max(pb.abs(this.cameraToReceiverNorm.y), pb.sin(this.minElevation)), this.cameraToReceiverNorm.z);
179
+ this.$l.skyLightInscattering = pb.mul(pb.textureSampleLevel(skyLightCubemap, pb.normalize(this.skyLightDir), this.skyLightLod).rgb, this.params.skyLightScale);
180
+ this.directionalInscattering = pb.mul(this.directionalInscattering, pb.sub(1, this.skyLightStrength));
181
+ this.fogColor = pb.mix(this.fogColor, this.skyLightInscattering, this.skyLightStrength);
182
+ });
183
+ this.$l.fogOpacity = pb.min(pb.sub(1, pb.clamp(pb.exp2(pb.neg(this.lineIntegral)), 0, 1)), this.maxOpacity);
184
+ this.fogOpacity = pb.max(this.fogOpacity, this.fading);
185
+ this.$return(pb.vec4(pb.add(pb.mul(this.fogColor, this.fogOpacity), this.directionalInscattering), pb.sub(1, this.fogOpacity)));
118
186
  });
119
- return scope[funcName](params, cameraPos, worldPos, isSky);
187
+ return scope[funcName](params, cameraPos, worldPos, isSky, skyGroundDistance, skyGroundBlend);
120
188
  }
121
189
 
122
190
  export { MAX_FOG_HEIGHT, calculateFog, calculateHeightFog, combineAerialPerspectiveFog, getDefaultHeightFogParams, getHeightFogParamsStruct };
@@ -1 +1 @@
1
- {"version":3,"file":"fog.js","sources":["../../src/shaders/fog.ts"],"sourcesContent":["import { Vector3, Vector4 } from '@zephyr3d/base';\r\nimport type { PBInsideFunctionScope, PBShaderExp, ProgramBuilder } from '@zephyr3d/device';\r\nimport { aerialPerspective, getAtmosphereParamsStruct } from './atmosphere';\r\nimport { Fog } from '../values';\r\n\r\n/** @internal */\r\nexport const MAX_FOG_HEIGHT = 100;\r\n\r\n/** @internal */\r\nexport type HeightFogParams = {\r\n parameter1: Vector4; // [rgb=fogColor a=heightFalloff]\r\n parameter2: Vector4; // [r=density g=startHeight b=startDistance a=maxHeight]\r\n parameter3: Vector4; // [r=maxOpacity g=atmosphereStrength b=rayOriginTerm a=dirInscatteringExponent]\r\n parameter4: Vector4; // [rgb=directionalInscatteringColor a=UNUSED]\r\n lightDir: Vector3;\r\n lightColor: Vector3;\r\n /**\r\n * Camera pre-exposure applied to the atmosphere-derived LUT samples (distant sky, aerial\r\n * perspective). Those LUTs are baked exposure-independently, unlike the authored fog colors which\r\n * are already pre-exposed on upload. 1 in legacy.\r\n */\r\n preExposure: number;\r\n};\r\n\r\n/** @internal */\r\nexport function getDefaultHeightFogParams() {\r\n return {\r\n parameter1: new Vector4(0, 0, 0, 0.1),\r\n parameter2: new Vector4(0.01, 0, 0, 10000),\r\n parameter3: new Vector4(0.8, 1, 0, 4),\r\n parameter4: new Vector4(0, 0, 0, 0),\r\n lightDir: new Vector3(0, 1, 0),\r\n lightColor: new Vector3(0, 0, 0),\r\n preExposure: 1\r\n } as HeightFogParams;\r\n}\r\n\r\n/** @internal */\r\nexport function getHeightFogParamsStruct(pb: ProgramBuilder) {\r\n return pb.defineStruct([\r\n pb.vec4('parameter1'),\r\n pb.vec4('parameter2'),\r\n pb.vec4('parameter3'),\r\n pb.vec4('parameter4'),\r\n pb.float('dirInscatteringStartDistance'),\r\n pb.vec3('dirInscatteringColor'),\r\n pb.vec3('lightDir'),\r\n pb.vec3('lightColor'),\r\n pb.float('preExposure')\r\n ]);\r\n}\r\n\r\nexport function calculateFog(\r\n scope: PBInsideFunctionScope,\r\n aerialperspective: PBShaderExp,\r\n fogType: PBShaderExp,\r\n atmosphereParams: PBShaderExp,\r\n heightFogParams: PBShaderExp,\r\n uv: PBShaderExp,\r\n isSky: PBShaderExp | boolean,\r\n cameraPos: PBShaderExp,\r\n worldPos: PBShaderExp,\r\n additive: PBShaderExp | number,\r\n apLut: PBShaderExp,\r\n distantLightLut: PBShaderExp\r\n) {\r\n const pb = scope.$builder;\r\n const funcName = 'Z_calculateFog';\r\n const AtmosphereParams = getAtmosphereParamsStruct(pb);\r\n const HeightFogParams = getHeightFogParamsStruct(pb);\r\n pb.func(\r\n funcName,\r\n [\r\n pb.int('withAerialPerspective'),\r\n pb.int('fogType'),\r\n AtmosphereParams('atmosphereParams'),\r\n HeightFogParams('heightFogParams'),\r\n pb.bool('isSky'),\r\n pb.vec2('uv'),\r\n pb.vec3('cameraPos'),\r\n pb.vec3('worldPos'),\r\n pb.int('additive')\r\n ],\r\n function () {\r\n this.$l.fogging = pb.vec4(0, 0, 0, 1);\r\n this.$if(pb.equal(this.fogType, Fog.FOG_TYPE_HEIGHT), function () {\r\n this.fogging = calculateHeightFog(\r\n this,\r\n this.heightFogParams,\r\n this.cameraPos,\r\n this.worldPos,\r\n this.isSky,\r\n distantLightLut\r\n );\r\n });\r\n this.$if(pb.and(pb.notEqual(this.withAerialPerspective, 0), pb.not(this.isSky)), function () {\r\n this.$l.atmosphericFogging = aerialPerspective(\r\n this,\r\n this.uv,\r\n this.atmosphereParams,\r\n this.cameraPos,\r\n this.worldPos,\r\n pb.vec3(32),\r\n apLut\r\n );\r\n // rgb is inscattered radiance from the exposure-independent AP LUT, so it takes the camera\r\n // pre-exposure; alpha is transmittance and must stay unscaled.\r\n this.atmosphericFogging = pb.vec4(\r\n pb.mul(this.atmosphericFogging.rgb, this.heightFogParams.preExposure),\r\n this.atmosphericFogging.a\r\n );\r\n this.$if(pb.notEqual(this.fogType, Fog.FOG_TYPE_NONE), function () {\r\n this.fogging = combineAerialPerspectiveFog(this, this.fogging, this.atmosphericFogging);\r\n }).$else(function () {\r\n this.fogging = this.atmosphericFogging;\r\n });\r\n });\r\n this.$if(pb.notEqual(this.additive, 0), function () {\r\n this.fogging = pb.vec4(pb.vec3(0), this.fogging.a);\r\n });\r\n this.$return(this.fogging);\r\n }\r\n );\r\n return scope[funcName](\r\n aerialperspective,\r\n fogType,\r\n atmosphereParams,\r\n heightFogParams,\r\n isSky,\r\n uv,\r\n cameraPos,\r\n worldPos,\r\n additive\r\n );\r\n}\r\n\r\nexport function combineAerialPerspectiveFog(\r\n scope: PBInsideFunctionScope,\r\n fogging: PBShaderExp,\r\n aerialPerspectiveFog: PBShaderExp\r\n) {\r\n const pb = scope.$builder;\r\n const funcName = 'Z_combineAerialPerspectiveFog';\r\n pb.func(funcName, [pb.vec4('fogging'), pb.vec4('aerialPerspectiveFog')], function () {\r\n this.$l.rgb = pb.add(this.fogging.rgb, pb.mul(this.aerialPerspectiveFog.rgb, this.fogging.a));\r\n this.$l.a = pb.mul(this.fogging.a, this.aerialPerspectiveFog.a);\r\n this.$return(pb.vec4(this.rgb, this.a));\r\n });\r\n return scope[funcName](fogging, aerialPerspectiveFog);\r\n}\r\n\r\nexport function calculateHeightFog(\r\n scope: PBInsideFunctionScope,\r\n params: PBShaderExp,\r\n cameraPos: PBShaderExp,\r\n worldPos: PBShaderExp,\r\n isSky: PBShaderExp | boolean,\r\n skyDistantColorLut: PBShaderExp\r\n) {\r\n const pb = scope.$builder;\r\n const funcName = 'Z_calcHeightFog';\r\n const Params = getHeightFogParamsStruct(pb);\r\n pb.func(\r\n funcName,\r\n [Params('params'), pb.vec3('cameraPosition'), pb.vec3('worldPosition'), pb.bool('isSky')],\r\n function () {\r\n this.$l.cameraPos = this.$choice(\r\n this.isSky,\r\n this.cameraPosition,\r\n pb.vec3(\r\n this.cameraPosition.x,\r\n pb.min(this.cameraPosition.y, pb.add(this.params.parameter2.y, MAX_FOG_HEIGHT)),\r\n this.cameraPosition.z\r\n )\r\n );\r\n this.$l.ray = pb.sub(this.worldPosition, this.cameraPos);\r\n this.$l.d = pb.length(this.ray);\r\n this.$l.rayNorm = pb.div(this.ray, this.d);\r\n this.$l.origin = pb.add(this.cameraPos, pb.mul(this.rayNorm, this.params.parameter2.z));\r\n this.$l.term = this.params.parameter3.z;\r\n this.$l.worldPos = this.$choice(\r\n this.isSky,\r\n pb.add(this.cameraPosition, pb.mul(this.rayNorm, 1e8)),\r\n this.worldPosition\r\n );\r\n this.$l.falloff = pb.clamp(\r\n pb.mul(this.params.parameter1.w, pb.sub(this.worldPos.y, this.origin.y)),\r\n -125,\r\n 126\r\n );\r\n this.$l.fading = this.$choice(this.isSky, pb.smoothStep(5e6, 0, this.worldPos.y), 0);\r\n this.$l.factor = this.$choice(\r\n pb.greaterThan(pb.abs(this.falloff), 0.01),\r\n pb.div(pb.sub(1, pb.exp2(pb.neg(this.falloff))), this.falloff),\r\n pb.sub(Math.log(2), pb.mul(0.5 * Math.log(2) * Math.log(2), this.falloff))\r\n );\r\n this.$l.worldDistance = pb.dot(pb.sub(this.worldPos, this.origin), this.rayNorm);\r\n this.$l.lineIntegral = pb.mul(\r\n this.term,\r\n this.factor,\r\n pb.max(0, this.worldDistance) /*pb.distance(this.origin, this.worldPos)*/\r\n );\r\n\r\n this.$l.directionalInscattering = pb.mul(\r\n pb.add(this.params.parameter4.rgb, pb.mul(this.params.lightColor, this.params.parameter3.y)),\r\n pb.pow(pb.clamp(pb.dot(this.rayNorm, this.params.lightDir), 0, 1), this.params.parameter3.w)\r\n );\r\n this.$l.fogFactor = pb.sub(1, pb.clamp(pb.exp2(pb.neg(this.lineIntegral)), 0, 1));\r\n this.$l.distanceFactor = pb.clamp(pb.div(this.worldDistance, this.params.parameter2.w), 0, 1);\r\n this.fogFactor = pb.mul(this.fogFactor, pb.sub(1, this.distanceFactor));\r\n this.$l.directionalInscattering = pb.mul(\r\n this.$l.directionalInscattering,\r\n pb.max(this.fogFactor, this.fading)\r\n );\r\n\r\n this.$l.fogColor = this.params.parameter1.rgb;\r\n this.$if(pb.greaterThan(this.params.parameter3.y, 0), function () {\r\n // The distant-sky LUT is baked exposure-independently (it feeds the cached IBL), so the\r\n // camera pre-exposure is applied here. The authored fogColor above is already pre-exposed.\r\n this.$l.skyContrib = pb.mul(\r\n pb.textureSampleLevel(skyDistantColorLut, pb.vec2(0.5), 0).rgb,\r\n this.params.preExposure\r\n );\r\n this.fogColor = pb.add(this.fogColor, pb.mul(this.skyContrib, this.params.parameter3.y));\r\n });\r\n this.$l.fogFactor = pb.max(pb.min(this.fogFactor, this.params.parameter3.x), this.fading);\r\n this.$l.fogColor = pb.add(pb.mul(this.fogColor, this.fogFactor), this.directionalInscattering);\r\n this.$return(pb.vec4(this.fogColor, pb.sub(1, this.fogFactor)));\r\n }\r\n );\r\n return scope[funcName](params, cameraPos, worldPos, isSky);\r\n}\r\n"],"names":["MAX_FOG_HEIGHT","getDefaultHeightFogParams","parameter1","Vector4","parameter2","parameter3","parameter4","lightDir","Vector3","lightColor","preExposure","getHeightFogParamsStruct","pb","defineStruct","vec4","float","vec3","calculateFog","scope","aerialperspective","fogType","atmosphereParams","heightFogParams","uv","isSky","cameraPos","worldPos","additive","apLut","distantLightLut","$builder","funcName","AtmosphereParams","getAtmosphereParamsStruct","HeightFogParams","func","int","bool","vec2","$l","fogging","$if","equal","Fog","FOG_TYPE_HEIGHT","calculateHeightFog","and","notEqual","withAerialPerspective","not","atmosphericFogging","aerialPerspective","mul","rgb","a","FOG_TYPE_NONE","combineAerialPerspectiveFog","$else","$return","aerialPerspectiveFog","add","params","skyDistantColorLut","Params","$choice","cameraPosition","x","min","y","z","ray","sub","worldPosition","d","length","rayNorm","div","origin","term","falloff","clamp","w","fading","smoothStep","factor","greaterThan","abs","exp2","neg","Math","log","worldDistance","dot","lineIntegral","max","directionalInscattering","pow","fogFactor","distanceFactor","fogColor","skyContrib","textureSampleLevel"],"mappings":";;;;AAKA,iBACaA,MAAAA,cAAAA,GAAiB;AAkB9B,iBACO,SAASC,yBAAAA,GAAAA;IACd,OAAO;AACLC,QAAAA,UAAAA,EAAY,IAAIC,OAAAA,CAAQ,CAAG,EAAA,CAAA,EAAG,CAAG,EAAA,GAAA,CAAA;AACjCC,QAAAA,UAAAA,EAAY,IAAID,OAAAA,CAAQ,IAAM,EAAA,CAAA,EAAG,CAAG,EAAA,KAAA,CAAA;AACpCE,QAAAA,UAAAA,EAAY,IAAIF,OAAAA,CAAQ,GAAK,EAAA,CAAA,EAAG,CAAG,EAAA,CAAA,CAAA;AACnCG,QAAAA,UAAAA,EAAY,IAAIH,OAAAA,CAAQ,CAAG,EAAA,CAAA,EAAG,CAAG,EAAA,CAAA,CAAA;QACjCI,QAAU,EAAA,IAAIC,OAAQ,CAAA,CAAA,EAAG,CAAG,EAAA,CAAA,CAAA;QAC5BC,UAAY,EAAA,IAAID,OAAQ,CAAA,CAAA,EAAG,CAAG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xD,UAAU,CAAC+D,CAAC,CAAA,CAAA;AACxF,SAAA,CAAA;QACA,IAAI,CAAC7B,EAAE,CAAC0D,SAAS,GAAGrF,GAAGkF,GAAG,CAAClF,EAAGuD,CAAAA,GAAG,CAAC,IAAI,CAAC8B,SAAS,EAAE,IAAI,CAACpC,MAAM,CAACxD,UAAU,CAAC6D,CAAC,CAAA,EAAG,IAAI,CAACgB,MAAM,CAAA;QACxF,IAAI,CAAC3C,EAAE,CAAC4D,QAAQ,GAAGvF,EAAGgD,CAAAA,GAAG,CAAChD,EAAGwC,CAAAA,GAAG,CAAC,IAAI,CAAC+C,QAAQ,EAAE,IAAI,CAACF,SAAS,CAAA,EAAG,IAAI,CAACF,uBAAuB,CAAA;AAC7F,QAAA,IAAI,CAACrC,OAAO,CAAC9C,EAAGE,CAAAA,IAAI,CAAC,IAAI,CAACqF,QAAQ,EAAEvF,GAAG2D,GAAG,CAAC,CAAG,EAAA,IAAI,CAAC0B,SAAS,CAAA,CAAA,CAAA;AAC9D,KAAA,CAAA;AAEF,IAAA,OAAO/E,KAAK,CAACa,QAAAA,CAAS,CAAC8B,MAAAA,EAAQpC,WAAWC,QAAUF,EAAAA,KAAAA,CAAAA;AACtD;;;;"}
1
+ {"version":3,"file":"fog.js","sources":["../../src/shaders/fog.ts"],"sourcesContent":["import { Vector3, Vector4 } from '@zephyr3d/base';\r\nimport type { PBInsideFunctionScope, PBShaderExp, ProgramBuilder } from '@zephyr3d/device';\r\nimport {\r\n AP_LUT_DEPTH_SLICES,\r\n AP_LUT_SLICE_SIZE,\r\n aerialPerspective,\r\n getAtmosphereParamsStruct,\r\n rayIntersectSphere\r\n} from './atmosphere';\r\nimport { Fog } from '../values';\r\n\r\n/**\r\n * How far above the fog height the observer is clamped for the fog density at the ray origin (\r\n * FogHeight + 65536 world units, i.e. 655.36 m).\r\n *\r\n * @internal\r\n */\r\nexport const MAX_FOG_HEIGHT = 655.36;\r\n\r\n/** @internal */\r\nexport type HeightFogParams = {\r\n parameter1: Vector4; // [rgb=fogColor a=heightFalloff]\r\n parameter2: Vector4; // [r=density g=startHeight b=startDistance a=endDistance]\r\n parameter3: Vector4; // [r=maxOpacity g=atmosphereStrength b=rayOriginTerm a=dirInscatteringExponent]\r\n parameter4: Vector4; // [rgb=directionalInscatteringColor a=UNUSED]\r\n lightDir: Vector3;\r\n lightColor: Vector3;\r\n /**\r\n * Camera pre-exposure applied to the atmosphere-derived LUT samples (distant sky, aerial\r\n * perspective). Those LUTs are baked exposure-independently, unlike the authored fog colors which\r\n * are already pre-exposed on upload. 1 in legacy.\r\n */\r\n preExposure: number;\r\n /**\r\n * How much the in-scattering color is replaced by the environment radiance map sampled along the\r\n * view ray. 0 disables it.\r\n */\r\n skyLightStrength: number;\r\n /** Roughness selecting the radiance map mip. */\r\n skyLightRoughness: number;\r\n /**\r\n * Converts radiance map samples to pre-exposed radiance, 0 when no radiance map is available.\r\n * Updated every frame by SkyRenderer.\r\n */\r\n skyLightScale: number;\r\n /** Max LOD of the radiance map. Updated every frame by SkyRenderer. */\r\n skyLightMaxLod: number;\r\n};\r\n\r\n/** @internal */\r\nexport function getDefaultHeightFogParams() {\r\n return {\r\n parameter1: new Vector4(0, 0, 0, 0.1),\r\n parameter2: new Vector4(0.01, 0, 0, 10000),\r\n parameter3: new Vector4(0.8, 1, 0, 4),\r\n parameter4: new Vector4(0, 0, 0, 0),\r\n lightDir: new Vector3(0, 1, 0),\r\n lightColor: new Vector3(0, 0, 0),\r\n preExposure: 1,\r\n skyLightStrength: 0,\r\n skyLightRoughness: 0.15,\r\n skyLightScale: 0,\r\n skyLightMaxLod: 0\r\n } as HeightFogParams;\r\n}\r\n\r\n/** @internal */\r\nexport function getHeightFogParamsStruct(pb: ProgramBuilder) {\r\n return pb.defineStruct([\r\n pb.vec4('parameter1'),\r\n pb.vec4('parameter2'),\r\n pb.vec4('parameter3'),\r\n pb.vec4('parameter4'),\r\n pb.vec3('lightDir'),\r\n pb.vec3('lightColor'),\r\n pb.float('preExposure'),\r\n pb.float('skyLightStrength'),\r\n pb.float('skyLightRoughness'),\r\n pb.float('skyLightScale'),\r\n pb.float('skyLightMaxLod')\r\n ]);\r\n}\r\n\r\nexport function calculateFog(\r\n scope: PBInsideFunctionScope,\r\n aerialperspective: PBShaderExp,\r\n fogType: PBShaderExp,\r\n atmosphereParams: PBShaderExp,\r\n heightFogParams: PBShaderExp,\r\n uv: PBShaderExp,\r\n isSky: PBShaderExp | boolean,\r\n cameraPos: PBShaderExp,\r\n worldPos: PBShaderExp,\r\n additive: PBShaderExp | number,\r\n apLut: PBShaderExp,\r\n distantLightLut: PBShaderExp,\r\n skyLightCubemap: PBShaderExp\r\n) {\r\n const pb = scope.$builder;\r\n const funcName = 'Z_calculateFog';\r\n const AtmosphereParams = getAtmosphereParamsStruct(pb);\r\n const HeightFogParams = getHeightFogParamsStruct(pb);\r\n pb.func(\r\n funcName,\r\n [\r\n pb.int('withAerialPerspective'),\r\n pb.int('fogType'),\r\n AtmosphereParams('atmosphereParams'),\r\n HeightFogParams('heightFogParams'),\r\n pb.bool('isSky'),\r\n pb.vec2('uv'),\r\n pb.vec3('cameraPos'),\r\n pb.vec3('worldPos'),\r\n pb.int('additive')\r\n ],\r\n function () {\r\n this.$l.fogging = pb.vec4(0, 0, 0, 1);\r\n this.$if(pb.equal(this.fogType, Fog.FOG_TYPE_HEIGHT), function () {\r\n this.$l.skyGroundDistance = pb.float(-1);\r\n this.$l.skyGroundBlend = pb.smoothStep(\r\n pb.mul(this.atmosphereParams.atmosphereHeight, 0.1),\r\n this.atmosphereParams.atmosphereHeight,\r\n this.atmosphereParams.observerAltitude\r\n );\r\n this.$if(\r\n pb.and(\r\n pb.and(this.isSky, pb.notEqual(this.withAerialPerspective, 0)),\r\n pb.greaterThan(this.skyGroundBlend, 0)\r\n ),\r\n function () {\r\n this.$l.localDir = pb.normalize(\r\n pb.mul(\r\n this.atmosphereParams.skyViewReferential,\r\n pb.vec4(pb.sub(this.worldPos, this.cameraPos), 0)\r\n ).xyz\r\n );\r\n this.$l.tGround = rayIntersectSphere(\r\n this,\r\n pb.vec3(0),\r\n this.atmosphereParams.plantRadius,\r\n pb.vec3(\r\n 0,\r\n pb.add(this.atmosphereParams.plantRadius, this.atmosphereParams.observerAltitude),\r\n 0\r\n ),\r\n this.localDir\r\n );\r\n this.$if(pb.greaterThan(this.tGround, 0), function () {\r\n this.skyGroundDistance = pb.div(this.tGround, this.atmosphereParams.cameraHeightScale);\r\n });\r\n }\r\n );\r\n this.fogging = calculateHeightFog(\r\n this,\r\n this.heightFogParams,\r\n this.cameraPos,\r\n this.worldPos,\r\n this.isSky,\r\n distantLightLut,\r\n skyLightCubemap,\r\n this.skyGroundDistance,\r\n this.skyGroundBlend\r\n );\r\n });\r\n this.$if(pb.and(pb.notEqual(this.withAerialPerspective, 0), pb.not(this.isSky)), function () {\r\n this.$l.atmosphericFogging = aerialPerspective(\r\n this,\r\n this.uv,\r\n this.atmosphereParams,\r\n this.cameraPos,\r\n this.worldPos,\r\n pb.vec3(AP_LUT_SLICE_SIZE, AP_LUT_SLICE_SIZE, AP_LUT_DEPTH_SLICES),\r\n apLut\r\n );\r\n // rgb is inscattered radiance from the exposure-independent AP LUT, so it takes the camera\r\n // pre-exposure; alpha is transmittance and must stay unscaled.\r\n this.atmosphericFogging = pb.vec4(\r\n pb.mul(this.atmosphericFogging.rgb, this.heightFogParams.preExposure),\r\n this.atmosphericFogging.a\r\n );\r\n this.$if(pb.notEqual(this.fogType, Fog.FOG_TYPE_NONE), function () {\r\n this.fogging = combineAerialPerspectiveFog(this, this.fogging, this.atmosphericFogging);\r\n }).$else(function () {\r\n this.fogging = this.atmosphericFogging;\r\n });\r\n });\r\n this.$if(pb.notEqual(this.additive, 0), function () {\r\n this.fogging = pb.vec4(pb.vec3(0), this.fogging.a);\r\n });\r\n this.$return(this.fogging);\r\n }\r\n );\r\n return scope[funcName](\r\n aerialperspective,\r\n fogType,\r\n atmosphereParams,\r\n heightFogParams,\r\n isSky,\r\n uv,\r\n cameraPos,\r\n worldPos,\r\n additive\r\n );\r\n}\r\n\r\nexport function combineAerialPerspectiveFog(\r\n scope: PBInsideFunctionScope,\r\n fogging: PBShaderExp,\r\n aerialPerspectiveFog: PBShaderExp\r\n) {\r\n const pb = scope.$builder;\r\n const funcName = 'Z_combineAerialPerspectiveFog';\r\n pb.func(funcName, [pb.vec4('fogging'), pb.vec4('aerialPerspectiveFog')], function () {\r\n this.$l.rgb = pb.add(this.fogging.rgb, pb.mul(this.aerialPerspectiveFog.rgb, this.fogging.a));\r\n this.$l.a = pb.mul(this.fogging.a, this.aerialPerspectiveFog.a);\r\n this.$return(pb.vec4(this.rgb, this.a));\r\n });\r\n return scope[funcName](fogging, aerialPerspectiveFog);\r\n}\r\n\r\n/**\r\n * Exponential height fog calculation.\r\n *\r\n * Returns the in-scattered radiance in rgb and the transmittance in a.\r\n */\r\nexport function calculateHeightFog(\r\n scope: PBInsideFunctionScope,\r\n params: PBShaderExp,\r\n cameraPos: PBShaderExp,\r\n worldPos: PBShaderExp,\r\n isSky: PBShaderExp | boolean,\r\n skyDistantColorLut: PBShaderExp,\r\n skyLightCubemap: PBShaderExp,\r\n skyGroundDistance: PBShaderExp | number = -1,\r\n skyGroundBlend: PBShaderExp | number = 0\r\n) {\r\n const pb = scope.$builder;\r\n const funcName = 'Z_calcHeightFog';\r\n const Params = getHeightFogParamsStruct(pb);\r\n pb.func(\r\n funcName,\r\n [\r\n Params('params'),\r\n pb.vec3('cameraPosition'),\r\n pb.vec3('worldPosition'),\r\n pb.bool('isSky'),\r\n pb.float('skyGroundDistance'),\r\n pb.float('skyGroundBlend')\r\n ],\r\n function () {\r\n // A sky pixel that sees the virtual planet ground (skyGroundDistance > 0) is fogged like a\r\n // surface at that distance, with the forced horizon fog of sky pixels faded out by\r\n // skyGroundBlend.\r\n this.$l.skyHitsGround = pb.and(this.isSky, pb.greaterThan(this.skyGroundDistance, 0));\r\n this.$l.falloff = this.params.parameter1.w;\r\n this.$l.density = this.params.parameter2.x;\r\n this.$l.fogHeight = this.params.parameter2.y;\r\n this.$l.startDistance = this.params.parameter2.z;\r\n this.$l.endDistance = this.params.parameter2.w;\r\n this.$l.maxOpacity = this.params.parameter3.x;\r\n // Sky pixels have no depth: put them far away along the view ray, or on the virtual ground.\r\n this.$l.skyDir = pb.normalize(pb.sub(this.worldPosition, this.cameraPosition));\r\n this.$l.receiver = this.$choice(\r\n this.isSky,\r\n pb.add(\r\n this.cameraPosition,\r\n pb.mul(this.skyDir, this.$choice(this.skyHitsGround, this.skyGroundDistance, pb.float(1e8)))\r\n ),\r\n this.worldPosition\r\n );\r\n // The density at the observer (rayOriginTerm, see SkyRenderer.update) is evaluated at a height\r\n // clamped to MAX_FOG_HEIGHT above the fog, so the ray starts from that clamped observer.\r\n this.$l.observerY = pb.min(this.cameraPosition.y, pb.add(this.fogHeight, MAX_FOG_HEIGHT));\r\n this.$l.cameraToReceiver = pb.sub(this.receiver, this.cameraPosition);\r\n // End distance: fog stops accumulating beyond this horizontal distance.\r\n this.$l.lenXZSqr = pb.dot(this.cameraToReceiver.xz, this.cameraToReceiver.xz);\r\n this.$if(\r\n pb.and(\r\n pb.greaterThan(this.endDistance, 0),\r\n pb.greaterThan(this.lenXZSqr, pb.mul(this.endDistance, this.endDistance))\r\n ),\r\n function () {\r\n this.cameraToReceiver = pb.mul(\r\n this.cameraToReceiver,\r\n pb.div(this.endDistance, pb.sqrt(pb.max(1, this.lenXZSqr)))\r\n );\r\n }\r\n );\r\n // Compensate for the clamped observer height.\r\n this.cameraToReceiver.y = pb.add(\r\n this.cameraToReceiver.y,\r\n pb.sub(this.cameraPosition.y, this.observerY)\r\n );\r\n this.$l.cameraToReceiverLength = pb.max(pb.length(this.cameraToReceiver), 1e-4);\r\n this.$l.cameraToReceiverNorm = pb.div(this.cameraToReceiver, this.cameraToReceiverLength);\r\n this.$l.rayOriginTerms = this.params.parameter3.z;\r\n this.$l.rayLength = this.cameraToReceiverLength;\r\n this.$l.rayDirectionY = this.cameraToReceiver.y;\r\n // Start distance: integrate from the exclusion point, with the density re-evaluated at its height.\r\n this.$if(pb.greaterThan(this.startDistance, 0), function () {\r\n this.$l.excludeIntersectionTime = pb.div(this.startDistance, this.cameraToReceiverLength);\r\n this.$l.cameraToExclusionY = pb.mul(this.excludeIntersectionTime, this.cameraToReceiver.y);\r\n this.$l.exclusionY = pb.add(this.observerY, this.cameraToExclusionY);\r\n this.rayLength = pb.mul(pb.sub(1, this.excludeIntersectionTime), this.cameraToReceiverLength);\r\n this.rayDirectionY = pb.sub(this.cameraToReceiver.y, this.cameraToExclusionY);\r\n this.$l.exponent = pb.max(-127, pb.mul(this.falloff, pb.sub(this.exclusionY, this.fogHeight)));\r\n this.rayOriginTerms = pb.mul(this.density, pb.exp2(pb.neg(this.exponent)));\r\n });\r\n // Line integral of density * exp2(-falloff * y) along the ray, divided by the ray length.\r\n this.$l.falloffTerm = pb.max(-127, pb.mul(this.falloff, this.rayDirectionY));\r\n this.$l.lineIntegralShared = pb.mul(\r\n this.rayOriginTerms,\r\n this.$choice(\r\n pb.greaterThan(pb.abs(this.falloffTerm), 0.01),\r\n pb.div(pb.sub(1, pb.exp2(pb.neg(this.falloffTerm))), this.falloffTerm),\r\n pb.sub(Math.log(2), pb.mul(0.5 * Math.log(2) * Math.log(2), this.falloffTerm))\r\n )\r\n );\r\n this.$l.lineIntegral = pb.mul(this.lineIntegralShared, this.rayLength);\r\n // Ad hoc horizon blend for sky pixels: fully fogged below the horizon.\r\n this.$l.fading = this.$choice(\r\n pb.and(this.isSky, pb.not(this.skyHitsGround)),\r\n pb.smoothStep(5e6, 0, this.receiver.y),\r\n this.$choice(this.skyHitsGround, pb.sub(1, pb.clamp(this.skyGroundBlend, 0, 1)), pb.float(0))\r\n );\r\n\r\n // Directional inscattering: a lobe around the light approximating in-scattering from the\r\n // directional light off the haze. It has its own opacity, unaffected by maxOpacity.\r\n this.$l.directionalLight = pb.mul(\r\n pb.add(this.params.parameter4.rgb, pb.mul(this.params.lightColor, this.params.parameter3.y)),\r\n pb.pow(\r\n pb.clamp(pb.dot(this.cameraToReceiverNorm, this.params.lightDir), 0, 1),\r\n this.params.parameter3.w\r\n )\r\n );\r\n this.$l.dirFogOpacity = pb.sub(\r\n 1,\r\n pb.clamp(pb.exp2(pb.neg(pb.mul(this.lineIntegralShared, pb.max(this.rayLength, 0)))), 0, 1)\r\n );\r\n this.$l.directionalInscattering = pb.mul(\r\n this.directionalLight,\r\n pb.max(this.dirFogOpacity, this.fading)\r\n );\r\n\r\n this.$l.fogColor = this.params.parameter1.rgb;\r\n this.$if(pb.greaterThan(this.params.parameter3.y, 0), function () {\r\n // The distant-sky LUT is baked exposure-independently (it feeds the cached IBL), so the\r\n // camera pre-exposure is applied here. The authored fogColor above is already pre-exposed.\r\n this.$l.skyContrib = pb.mul(\r\n pb.textureSampleLevel(skyDistantColorLut, pb.vec2(0.5), 0).rgb,\r\n this.params.preExposure\r\n );\r\n this.fogColor = pb.add(this.fogColor, pb.mul(this.skyContrib, this.params.parameter3.y));\r\n });\r\n this.$l.skyLightStrength = this.$choice(\r\n pb.greaterThan(this.params.skyLightScale, 0),\r\n pb.clamp(this.params.skyLightStrength, 0, 1),\r\n pb.float(0)\r\n );\r\n this.$if(pb.greaterThan(this.skyLightStrength, 0), function () {\r\n this.$l.skyLightLod = pb.mul(\r\n pb.clamp(this.params.skyLightRoughness, 0, 1),\r\n this.params.skyLightMaxLod\r\n );\r\n this.$l.minElevation = pb.min(\r\n pb.mul(Math.PI / 2, pb.exp2(pb.sub(this.skyLightLod, this.params.skyLightMaxLod))),\r\n Math.PI / 2\r\n );\r\n this.$l.skyLightDir = pb.vec3(\r\n this.cameraToReceiverNorm.x,\r\n pb.max(pb.abs(this.cameraToReceiverNorm.y), pb.sin(this.minElevation)),\r\n this.cameraToReceiverNorm.z\r\n );\r\n this.$l.skyLightInscattering = pb.mul(\r\n pb.textureSampleLevel(skyLightCubemap, pb.normalize(this.skyLightDir), this.skyLightLod).rgb,\r\n this.params.skyLightScale\r\n );\r\n this.directionalInscattering = pb.mul(this.directionalInscattering, pb.sub(1, this.skyLightStrength));\r\n this.fogColor = pb.mix(this.fogColor, this.skyLightInscattering, this.skyLightStrength);\r\n });\r\n this.$l.fogOpacity = pb.min(\r\n pb.sub(1, pb.clamp(pb.exp2(pb.neg(this.lineIntegral)), 0, 1)),\r\n this.maxOpacity\r\n );\r\n this.fogOpacity = pb.max(this.fogOpacity, this.fading);\r\n this.$return(\r\n pb.vec4(\r\n pb.add(pb.mul(this.fogColor, this.fogOpacity), this.directionalInscattering),\r\n pb.sub(1, this.fogOpacity)\r\n )\r\n );\r\n }\r\n );\r\n return scope[funcName](params, cameraPos, worldPos, isSky, skyGroundDistance, skyGroundBlend);\r\n}\r\n"],"names":["MAX_FOG_HEIGHT","getDefaultHeightFogParams","parameter1","Vector4","parameter2","parameter3","parameter4","lightDir","Vector3","lightColor","preExposure","skyLightStrength","skyLightRoughness","skyLightScale","skyLightMaxLod","getHeightFogParamsStruct","pb","defineStruct","vec4","vec3","float","calculateFog","scope","aerialperspective","fogType","atmosphereParams","heightFogParams","uv","isSky","cameraPos","worldPos","additive","apLut","distantLightLut","skyLightCubemap","$builder","funcName","AtmosphereParams","getAtmosphereParamsStruct","HeightFogParams","func","int","bool","vec2","$l","fogging","$if","equal","Fog","FOG_TYPE_HEIGHT","skyGroundDistance","skyGroundBlend","smoothStep","mul","atmosphereHeight","observerAltitude","and","notEqual","withAerialPerspective","greaterThan","localDir","normalize","skyViewReferential","sub","xyz","tGround","rayIntersectSphere","plantRadius","add","div","cameraHeightScale","calculateHeightFog","not","atmosphericFogging","aerialPerspective","AP_LUT_SLICE_SIZE","AP_LUT_DEPTH_SLICES","rgb","a","FOG_TYPE_NONE","combineAerialPerspectiveFog","$else","$return","aerialPerspectiveFog","params","skyDistantColorLut","Params","skyHitsGround","falloff","w","density","x","fogHeight","y","startDistance","z","endDistance","maxOpacity","skyDir","worldPosition","cameraPosition","receiver","$choice","observerY","min","cameraToReceiver","lenXZSqr","dot","xz","sqrt","max","cameraToReceiverLength","length","cameraToReceiverNorm","rayOriginTerms","rayLength","rayDirectionY","excludeIntersectionTime","cameraToExclusionY","exclusionY","exponent","exp2","neg","falloffTerm","lineIntegralShared","abs","Math","log","lineIntegral","fading","clamp","directionalLight","pow","dirFogOpacity","directionalInscattering","fogColor","skyContrib","textureSampleLevel","skyLightLod","minElevation","PI","skyLightDir","sin","skyLightInscattering","mix","fogOpacity"],"mappings":";;;;AAWA;;;;;IAMaA,MAAAA,cAAAA,GAAiB;AAgC9B,iBACO,SAASC,yBAAAA,GAAAA;IACd,OAAO;AACLC,QAAAA,UAAAA,EAAY,IAAIC,OAAAA,CAAQ,CAAG,EAAA,CAAA,EAAG,CAAG,EAAA,GAAA,CAAA;AACjCC,QAAAA,UAAAA,EAAY,IAAID,OAAAA,CAAQ,IAAM,EAAA,CAAA,EAAG,CAAG,EAAA,KAAA,CAAA;AACpCE,QAAAA,UAAAA,EAAY,IAAIF,OAAAA,CAAQ,GAAK,EAAA,CAAA,EAAG,CAAG,EAAA,CAAA,CAAA;AACnCG,QAAAA,UAAAA,EAAY,IAAIH,OAAAA,CAAQ,CAAG,EAAA,CAAA,EAAG,CAAG,EAAA,CAAA,CAAA;QACjCI,QAAU,EAAA,IAAIC,OAAQ,CAAA,CAAA,EAAG,CAAG,EAAA,CAAA,CAAA;QAC5BC,UAAY,EAAA,IAAID,OAAQ,CAAA,CAAA,EAAG,CAAG,EAAA,CAAA,CAAA;QAC9BE,WAAa,EAAA,CAAA;QACbC,gBAAkB,EAAA,CAAA;QAClBC,iBAAmB,EAAA,IAAA;QACnBC,aAAe,EAAA,CAAA;QACfC,cAAgB,EAAA;AAClB,KAAA;AACF;AAEA,iBACO,SAASC,wBAAAA,CAAyBC,EAAkB,EAAA;IACzD,OAAOA,EAAAA,CAAGC,YAAY,CAAC;AACrBD,QAAAA,EAAAA,CAAGE,IAAI,CAAC,YAAA,CAAA;AACRF,QAAAA,EAAAA,CAAG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