@zephyr3d/scene 0.8.0 → 0.8.1

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 (387) hide show
  1. package/dist/animation/animationset.js +198 -1
  2. package/dist/animation/animationset.js.map +1 -1
  3. package/dist/animation/ik/ccd_solver.js +3 -4
  4. package/dist/animation/ik/ccd_solver.js.map +1 -1
  5. package/dist/animation/ik/fabrik_solver.js +3 -4
  6. package/dist/animation/ik/fabrik_solver.js.map +1 -1
  7. package/dist/animation/ik/ik_pole_constraint.js +7 -2
  8. package/dist/animation/ik/ik_pole_constraint.js.map +1 -1
  9. package/dist/animation/ik/ik_utils.js +0 -79
  10. package/dist/animation/ik/ik_utils.js.map +1 -1
  11. package/dist/animation/ik/two_bone_ik_solver.js +3 -4
  12. package/dist/animation/ik/two_bone_ik_solver.js.map +1 -1
  13. package/dist/animation/spring/spring_bone.js +240 -0
  14. package/dist/animation/spring/spring_bone.js.map +1 -0
  15. package/dist/animation/spring/spring_bone_collider.js +198 -0
  16. package/dist/animation/spring/spring_bone_collider.js.map +1 -0
  17. package/dist/animation/spring/spring_bone_constraint.js +170 -0
  18. package/dist/animation/spring/spring_bone_constraint.js.map +1 -0
  19. package/dist/animation/spring/spring_bone_system.js +328 -0
  20. package/dist/animation/spring/spring_bone_system.js.map +1 -0
  21. package/dist/asset/model.js +2 -2
  22. package/dist/index.d.ts +15 -0
  23. package/dist/material/mixins/pbr/common.js +20 -17
  24. package/dist/material/mixins/pbr/common.js.map +1 -1
  25. package/dist/render/gpu_picking.js +100 -0
  26. package/dist/render/gpu_picking.js.map +1 -0
  27. package/dist/render/rendergraph/device_pool_allocator.js +41 -0
  28. package/dist/render/rendergraph/device_pool_allocator.js.map +1 -0
  29. package/dist/render/rendergraph/executor.js +146 -0
  30. package/dist/render/rendergraph/executor.js.map +1 -0
  31. package/dist/render/rendergraph/forward_plus_builder.js +414 -0
  32. package/dist/render/rendergraph/forward_plus_builder.js.map +1 -0
  33. package/dist/render/rendergraph/rendergraph.js +306 -0
  34. package/dist/render/rendergraph/rendergraph.js.map +1 -0
  35. package/dist/render/rendergraph/types.js +57 -0
  36. package/dist/render/rendergraph/types.js.map +1 -0
  37. package/dist/render/sky_motion_vector.js +85 -0
  38. package/dist/render/sky_motion_vector.js.map +1 -0
  39. package/dist/utility/serialization/scene/animation.js +3 -3
  40. package/dist/utility/serialization/scene/node.js +1 -1
  41. package/package.json +2 -2
  42. package/dist/animation/ik/ik_chain_builder.js +0 -68
  43. package/dist/animation/ik/ik_chain_builder.js.map +0 -1
  44. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimemgr.js +0 -38
  45. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimemgr.js.map +0 -1
  46. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimescript.js +0 -10
  47. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimescript.js.map +0 -1
  48. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptingsystem.js +0 -127
  49. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptingsystem.js.map +0 -1
  50. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptregistry.js +0 -263
  51. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptregistry.js.map +0 -1
  52. package/dist/src/animation/animation.js +0 -127
  53. package/dist/src/animation/animation.js.map +0 -1
  54. package/dist/src/animation/animationset.js +0 -255
  55. package/dist/src/animation/animationset.js.map +0 -1
  56. package/dist/src/animation/animationtrack.js +0 -34
  57. package/dist/src/animation/animationtrack.js.map +0 -1
  58. package/dist/src/animation/eulerrotationtrack.js +0 -52
  59. package/dist/src/animation/eulerrotationtrack.js.map +0 -1
  60. package/dist/src/animation/morphtarget.js +0 -93
  61. package/dist/src/animation/morphtarget.js.map +0 -1
  62. package/dist/src/animation/morphtrack.js +0 -70
  63. package/dist/src/animation/morphtrack.js.map +0 -1
  64. package/dist/src/animation/proptrack.js +0 -161
  65. package/dist/src/animation/proptrack.js.map +0 -1
  66. package/dist/src/animation/rotationtrack.js +0 -51
  67. package/dist/src/animation/rotationtrack.js.map +0 -1
  68. package/dist/src/animation/scaletrack.js +0 -50
  69. package/dist/src/animation/scaletrack.js.map +0 -1
  70. package/dist/src/animation/skeleton.js +0 -204
  71. package/dist/src/animation/skeleton.js.map +0 -1
  72. package/dist/src/animation/translationtrack.js +0 -50
  73. package/dist/src/animation/translationtrack.js.map +0 -1
  74. package/dist/src/app/app.js +0 -129
  75. package/dist/src/app/app.js.map +0 -1
  76. package/dist/src/app/inputmgr.js +0 -267
  77. package/dist/src/app/inputmgr.js.map +0 -1
  78. package/dist/src/asset/assetmanager.js +0 -404
  79. package/dist/src/asset/assetmanager.js.map +0 -1
  80. package/dist/src/asset/builtin.js +0 -337
  81. package/dist/src/asset/builtin.js.map +0 -1
  82. package/dist/src/asset/loaders/dds/dds.js +0 -470
  83. package/dist/src/asset/loaders/dds/dds.js.map +0 -1
  84. package/dist/src/asset/loaders/dds/dds_loader.js +0 -28
  85. package/dist/src/asset/loaders/dds/dds_loader.js.map +0 -1
  86. package/dist/src/asset/loaders/gltf/gltf_loader.js +0 -1265
  87. package/dist/src/asset/loaders/gltf/gltf_loader.js.map +0 -1
  88. package/dist/src/asset/loaders/gltf/helpers.js +0 -327
  89. package/dist/src/asset/loaders/gltf/helpers.js.map +0 -1
  90. package/dist/src/asset/loaders/hdr/hdr.js +0 -180
  91. package/dist/src/asset/loaders/hdr/hdr.js.map +0 -1
  92. package/dist/src/asset/loaders/image/tga_Loader.js +0 -116
  93. package/dist/src/asset/loaders/image/tga_Loader.js.map +0 -1
  94. package/dist/src/asset/loaders/image/webimage_loader.js +0 -63
  95. package/dist/src/asset/loaders/image/webimage_loader.js.map +0 -1
  96. package/dist/src/asset/loaders/loader.js +0 -45
  97. package/dist/src/asset/loaders/loader.js.map +0 -1
  98. package/dist/src/asset/model.js +0 -414
  99. package/dist/src/asset/model.js.map +0 -1
  100. package/dist/src/blitter/bilateralblur.js +0 -221
  101. package/dist/src/blitter/bilateralblur.js.map +0 -1
  102. package/dist/src/blitter/blitter.js +0 -390
  103. package/dist/src/blitter/blitter.js.map +0 -1
  104. package/dist/src/blitter/box.js +0 -118
  105. package/dist/src/blitter/box.js.map +0 -1
  106. package/dist/src/blitter/copy.js +0 -22
  107. package/dist/src/blitter/copy.js.map +0 -1
  108. package/dist/src/blitter/gaussianblur.js +0 -228
  109. package/dist/src/blitter/gaussianblur.js.map +0 -1
  110. package/dist/src/camera/base.js +0 -92
  111. package/dist/src/camera/base.js.map +0 -1
  112. package/dist/src/camera/camera.js +0 -1005
  113. package/dist/src/camera/camera.js.map +0 -1
  114. package/dist/src/camera/fps.js +0 -238
  115. package/dist/src/camera/fps.js.map +0 -1
  116. package/dist/src/camera/orbit.js +0 -245
  117. package/dist/src/camera/orbit.js.map +0 -1
  118. package/dist/src/camera/orthocamera.js +0 -167
  119. package/dist/src/camera/orthocamera.js.map +0 -1
  120. package/dist/src/camera/perspectivecamera.js +0 -141
  121. package/dist/src/camera/perspectivecamera.js.map +0 -1
  122. package/dist/src/index.js +0 -120
  123. package/dist/src/index.js.map +0 -1
  124. package/dist/src/material/blinn.js +0 -81
  125. package/dist/src/material/blinn.js.map +0 -1
  126. package/dist/src/material/grassmaterial.js +0 -113
  127. package/dist/src/material/grassmaterial.js.map +0 -1
  128. package/dist/src/material/lambert.js +0 -92
  129. package/dist/src/material/lambert.js.map +0 -1
  130. package/dist/src/material/material.js +0 -301
  131. package/dist/src/material/material.js.map +0 -1
  132. package/dist/src/material/meshmaterial.js +0 -704
  133. package/dist/src/material/meshmaterial.js.map +0 -1
  134. package/dist/src/material/mixins/albedocolor.js +0 -76
  135. package/dist/src/material/mixins/albedocolor.js.map +0 -1
  136. package/dist/src/material/mixins/foliage.js +0 -47
  137. package/dist/src/material/mixins/foliage.js.map +0 -1
  138. package/dist/src/material/mixins/lightmodel/blinnphong.js +0 -112
  139. package/dist/src/material/mixins/lightmodel/blinnphong.js.map +0 -1
  140. package/dist/src/material/mixins/lightmodel/lambert.js +0 -58
  141. package/dist/src/material/mixins/lightmodel/lambert.js.map +0 -1
  142. package/dist/src/material/mixins/lightmodel/pbrmetallicroughness.js +0 -178
  143. package/dist/src/material/mixins/lightmodel/pbrmetallicroughness.js.map +0 -1
  144. package/dist/src/material/mixins/lightmodel/pbrspecularglossness.js +0 -139
  145. package/dist/src/material/mixins/lightmodel/pbrspecularglossness.js.map +0 -1
  146. package/dist/src/material/mixins/lit.js +0 -476
  147. package/dist/src/material/mixins/lit.js.map +0 -1
  148. package/dist/src/material/mixins/pbr/common.js +0 -918
  149. package/dist/src/material/mixins/pbr/common.js.map +0 -1
  150. package/dist/src/material/mixins/texture.js +0 -172
  151. package/dist/src/material/mixins/texture.js.map +0 -1
  152. package/dist/src/material/mixins/vertexcolor.js +0 -56
  153. package/dist/src/material/mixins/vertexcolor.js.map +0 -1
  154. package/dist/src/material/particle.js +0 -178
  155. package/dist/src/material/particle.js.map +0 -1
  156. package/dist/src/material/pbrmr.js +0 -97
  157. package/dist/src/material/pbrmr.js.map +0 -1
  158. package/dist/src/material/pbrsg.js +0 -97
  159. package/dist/src/material/pbrsg.js.map +0 -1
  160. package/dist/src/material/shader/helper.js +0 -1209
  161. package/dist/src/material/shader/helper.js.map +0 -1
  162. package/dist/src/material/terrain-cm.js +0 -606
  163. package/dist/src/material/terrain-cm.js.map +0 -1
  164. package/dist/src/material/terrainmaterial.js +0 -375
  165. package/dist/src/material/terrainmaterial.js.map +0 -1
  166. package/dist/src/material/unlit.js +0 -41
  167. package/dist/src/material/unlit.js.map +0 -1
  168. package/dist/src/material/water.js +0 -417
  169. package/dist/src/material/water.js.map +0 -1
  170. package/dist/src/posteffect/bloom.js +0 -361
  171. package/dist/src/posteffect/bloom.js.map +0 -1
  172. package/dist/src/posteffect/compositor.js +0 -226
  173. package/dist/src/posteffect/compositor.js.map +0 -1
  174. package/dist/src/posteffect/fxaa.js +0 -273
  175. package/dist/src/posteffect/fxaa.js.map +0 -1
  176. package/dist/src/posteffect/grayscale.js +0 -69
  177. package/dist/src/posteffect/grayscale.js.map +0 -1
  178. package/dist/src/posteffect/motionblur.js +0 -96
  179. package/dist/src/posteffect/motionblur.js.map +0 -1
  180. package/dist/src/posteffect/posteffect.js +0 -126
  181. package/dist/src/posteffect/posteffect.js.map +0 -1
  182. package/dist/src/posteffect/sao.js +0 -324
  183. package/dist/src/posteffect/sao.js.map +0 -1
  184. package/dist/src/posteffect/ssr.js +0 -489
  185. package/dist/src/posteffect/ssr.js.map +0 -1
  186. package/dist/src/posteffect/taa.js +0 -172
  187. package/dist/src/posteffect/taa.js.map +0 -1
  188. package/dist/src/posteffect/tonemap.js +0 -94
  189. package/dist/src/posteffect/tonemap.js.map +0 -1
  190. package/dist/src/render/abuffer_oit.js +0 -361
  191. package/dist/src/render/abuffer_oit.js.map +0 -1
  192. package/dist/src/render/clipmap.js +0 -851
  193. package/dist/src/render/clipmap.js.map +0 -1
  194. package/dist/src/render/cluster_light.js +0 -333
  195. package/dist/src/render/cluster_light.js.map +0 -1
  196. package/dist/src/render/cull_visitor.js +0 -187
  197. package/dist/src/render/cull_visitor.js.map +0 -1
  198. package/dist/src/render/depthpass.js +0 -68
  199. package/dist/src/render/depthpass.js.map +0 -1
  200. package/dist/src/render/drawable_mixin.js +0 -227
  201. package/dist/src/render/drawable_mixin.js.map +0 -1
  202. package/dist/src/render/envlight.js +0 -463
  203. package/dist/src/render/envlight.js.map +0 -1
  204. package/dist/src/render/fbm_wavegenerator.js +0 -251
  205. package/dist/src/render/fbm_wavegenerator.js.map +0 -1
  206. package/dist/src/render/fft_wavegenerator.js +0 -1006
  207. package/dist/src/render/fft_wavegenerator.js.map +0 -1
  208. package/dist/src/render/fullscreenquad.js +0 -38
  209. package/dist/src/render/fullscreenquad.js.map +0 -1
  210. package/dist/src/render/gerstner_wavegenerator.js +0 -314
  211. package/dist/src/render/gerstner_wavegenerator.js.map +0 -1
  212. package/dist/src/render/globalbindgroup_allocator.js +0 -60
  213. package/dist/src/render/globalbindgroup_allocator.js.map +0 -1
  214. package/dist/src/render/hzb.js +0 -273
  215. package/dist/src/render/hzb.js.map +0 -1
  216. package/dist/src/render/lightpass.js +0 -172
  217. package/dist/src/render/lightpass.js.map +0 -1
  218. package/dist/src/render/objectcolorpass.js +0 -51
  219. package/dist/src/render/objectcolorpass.js.map +0 -1
  220. package/dist/src/render/primitive.js +0 -364
  221. package/dist/src/render/primitive.js.map +0 -1
  222. package/dist/src/render/render_queue.js +0 -467
  223. package/dist/src/render/render_queue.js.map +0 -1
  224. package/dist/src/render/renderbundle_wrapper.js +0 -152
  225. package/dist/src/render/renderbundle_wrapper.js.map +0 -1
  226. package/dist/src/render/renderer.js +0 -455
  227. package/dist/src/render/renderer.js.map +0 -1
  228. package/dist/src/render/renderpass.js +0 -200
  229. package/dist/src/render/renderpass.js.map +0 -1
  230. package/dist/src/render/shadowmap_pass.js +0 -56
  231. package/dist/src/render/shadowmap_pass.js.map +0 -1
  232. package/dist/src/render/sky.js +0 -1103
  233. package/dist/src/render/sky.js.map +0 -1
  234. package/dist/src/render/weightedblended_oit.js +0 -168
  235. package/dist/src/render/weightedblended_oit.js.map +0 -1
  236. package/dist/src/scene/batchgroup.js +0 -162
  237. package/dist/src/scene/batchgroup.js.map +0 -1
  238. package/dist/src/scene/environment.js +0 -209
  239. package/dist/src/scene/environment.js.map +0 -1
  240. package/dist/src/scene/graph_node.js +0 -72
  241. package/dist/src/scene/graph_node.js.map +0 -1
  242. package/dist/src/scene/light.js +0 -416
  243. package/dist/src/scene/light.js.map +0 -1
  244. package/dist/src/scene/mesh.js +0 -341
  245. package/dist/src/scene/mesh.js.map +0 -1
  246. package/dist/src/scene/octree.js +0 -649
  247. package/dist/src/scene/octree.js.map +0 -1
  248. package/dist/src/scene/particlesys.js +0 -738
  249. package/dist/src/scene/particlesys.js.map +0 -1
  250. package/dist/src/scene/raycast_visitor.js +0 -103
  251. package/dist/src/scene/raycast_visitor.js.map +0 -1
  252. package/dist/src/scene/scene.js +0 -284
  253. package/dist/src/scene/scene.js.map +0 -1
  254. package/dist/src/scene/scene_node.js +0 -732
  255. package/dist/src/scene/scene_node.js.map +0 -1
  256. package/dist/src/scene/terrain/grass.js +0 -278
  257. package/dist/src/scene/terrain/grass.js.map +0 -1
  258. package/dist/src/scene/terrain/heightfield.js +0 -475
  259. package/dist/src/scene/terrain/heightfield.js.map +0 -1
  260. package/dist/src/scene/terrain/patch.js +0 -530
  261. package/dist/src/scene/terrain/patch.js.map +0 -1
  262. package/dist/src/scene/terrain/quadtree.js +0 -461
  263. package/dist/src/scene/terrain/quadtree.js.map +0 -1
  264. package/dist/src/scene/terrain/terrain.js +0 -246
  265. package/dist/src/scene/terrain/terrain.js.map +0 -1
  266. package/dist/src/scene/terrain-cm/grass.js +0 -594
  267. package/dist/src/scene/terrain-cm/grass.js.map +0 -1
  268. package/dist/src/scene/terrain-cm/grassmaterial.js +0 -159
  269. package/dist/src/scene/terrain-cm/grassmaterial.js.map +0 -1
  270. package/dist/src/scene/terrain-cm/terrain-cm.js +0 -538
  271. package/dist/src/scene/terrain-cm/terrain-cm.js.map +0 -1
  272. package/dist/src/scene/water.js +0 -374
  273. package/dist/src/scene/water.js.map +0 -1
  274. package/dist/src/shaders/atmosphere.js +0 -957
  275. package/dist/src/shaders/atmosphere.js.map +0 -1
  276. package/dist/src/shaders/fog.js +0 -112
  277. package/dist/src/shaders/fog.js.map +0 -1
  278. package/dist/src/shaders/misc.js +0 -266
  279. package/dist/src/shaders/misc.js.map +0 -1
  280. package/dist/src/shaders/noise.js +0 -222
  281. package/dist/src/shaders/noise.js.map +0 -1
  282. package/dist/src/shaders/pbr.js +0 -51
  283. package/dist/src/shaders/pbr.js.map +0 -1
  284. package/dist/src/shaders/shadow.js +0 -636
  285. package/dist/src/shaders/shadow.js.map +0 -1
  286. package/dist/src/shaders/ssr.js +0 -490
  287. package/dist/src/shaders/ssr.js.map +0 -1
  288. package/dist/src/shaders/temporal.js +0 -215
  289. package/dist/src/shaders/temporal.js.map +0 -1
  290. package/dist/src/shaders/water.js +0 -756
  291. package/dist/src/shaders/water.js.map +0 -1
  292. package/dist/src/shadow/esm.js +0 -237
  293. package/dist/src/shadow/esm.js.map +0 -1
  294. package/dist/src/shadow/pcf_opt.js +0 -181
  295. package/dist/src/shadow/pcf_opt.js.map +0 -1
  296. package/dist/src/shadow/pcf_pd.js +0 -189
  297. package/dist/src/shadow/pcf_pd.js.map +0 -1
  298. package/dist/src/shadow/shader.js +0 -37
  299. package/dist/src/shadow/shader.js.map +0 -1
  300. package/dist/src/shadow/shadow_impl.js +0 -15
  301. package/dist/src/shadow/shadow_impl.js.map +0 -1
  302. package/dist/src/shadow/shadowmapper.js +0 -790
  303. package/dist/src/shadow/shadowmapper.js.map +0 -1
  304. package/dist/src/shadow/ssm.js +0 -159
  305. package/dist/src/shadow/ssm.js.map +0 -1
  306. package/dist/src/shadow/vsm.js +0 -297
  307. package/dist/src/shadow/vsm.js.map +0 -1
  308. package/dist/src/shapes/box.js +0 -386
  309. package/dist/src/shapes/box.js.map +0 -1
  310. package/dist/src/shapes/cylinder.js +0 -125
  311. package/dist/src/shapes/cylinder.js.map +0 -1
  312. package/dist/src/shapes/plane.js +0 -88
  313. package/dist/src/shapes/plane.js.map +0 -1
  314. package/dist/src/shapes/shape.js +0 -87
  315. package/dist/src/shapes/shape.js.map +0 -1
  316. package/dist/src/shapes/sphere.js +0 -114
  317. package/dist/src/shapes/sphere.js.map +0 -1
  318. package/dist/src/shapes/tetrahedron.js +0 -188
  319. package/dist/src/shapes/tetrahedron.js.map +0 -1
  320. package/dist/src/shapes/torus.js +0 -111
  321. package/dist/src/shapes/torus.js.map +0 -1
  322. package/dist/src/utility/aabbtree.js +0 -400
  323. package/dist/src/utility/aabbtree.js.map +0 -1
  324. package/dist/src/utility/bounding_volume.js +0 -29
  325. package/dist/src/utility/bounding_volume.js.map +0 -1
  326. package/dist/src/utility/debug.js +0 -28
  327. package/dist/src/utility/debug.js.map +0 -1
  328. package/dist/src/utility/draco/decoder.js +0 -116
  329. package/dist/src/utility/draco/decoder.js.map +0 -1
  330. package/dist/src/utility/misc.js +0 -105
  331. package/dist/src/utility/misc.js.map +0 -1
  332. package/dist/src/utility/panorama.js +0 -163
  333. package/dist/src/utility/panorama.js.map +0 -1
  334. package/dist/src/utility/pmrem.js +0 -354
  335. package/dist/src/utility/pmrem.js.map +0 -1
  336. package/dist/src/utility/rendermipmap.js +0 -115
  337. package/dist/src/utility/rendermipmap.js.map +0 -1
  338. package/dist/src/utility/serialization/json.js +0 -402
  339. package/dist/src/utility/serialization/json.js.map +0 -1
  340. package/dist/src/utility/serialization/manager.js +0 -623
  341. package/dist/src/utility/serialization/manager.js.map +0 -1
  342. package/dist/src/utility/serialization/scene/animation.js +0 -248
  343. package/dist/src/utility/serialization/scene/animation.js.map +0 -1
  344. package/dist/src/utility/serialization/scene/batch.js +0 -59
  345. package/dist/src/utility/serialization/scene/batch.js.map +0 -1
  346. package/dist/src/utility/serialization/scene/camera.js +0 -790
  347. package/dist/src/utility/serialization/scene/camera.js.map +0 -1
  348. package/dist/src/utility/serialization/scene/common.js +0 -222
  349. package/dist/src/utility/serialization/scene/common.js.map +0 -1
  350. package/dist/src/utility/serialization/scene/light.js +0 -575
  351. package/dist/src/utility/serialization/scene/light.js.map +0 -1
  352. package/dist/src/utility/serialization/scene/material.js +0 -1111
  353. package/dist/src/utility/serialization/scene/material.js.map +0 -1
  354. package/dist/src/utility/serialization/scene/mesh.js +0 -148
  355. package/dist/src/utility/serialization/scene/mesh.js.map +0 -1
  356. package/dist/src/utility/serialization/scene/misc.js +0 -39
  357. package/dist/src/utility/serialization/scene/misc.js.map +0 -1
  358. package/dist/src/utility/serialization/scene/node.js +0 -451
  359. package/dist/src/utility/serialization/scene/node.js.map +0 -1
  360. package/dist/src/utility/serialization/scene/particle.js +0 -425
  361. package/dist/src/utility/serialization/scene/particle.js.map +0 -1
  362. package/dist/src/utility/serialization/scene/primitive.js +0 -692
  363. package/dist/src/utility/serialization/scene/primitive.js.map +0 -1
  364. package/dist/src/utility/serialization/scene/scene.js +0 -704
  365. package/dist/src/utility/serialization/scene/scene.js.map +0 -1
  366. package/dist/src/utility/serialization/scene/terrain.js +0 -488
  367. package/dist/src/utility/serialization/scene/terrain.js.map +0 -1
  368. package/dist/src/utility/serialization/scene/water.js +0 -465
  369. package/dist/src/utility/serialization/scene/water.js.map +0 -1
  370. package/dist/src/utility/shprojector.js +0 -297
  371. package/dist/src/utility/shprojector.js.map +0 -1
  372. package/dist/src/utility/textures/ggxlut.js +0 -213
  373. package/dist/src/utility/textures/ggxlut.js.map +0 -1
  374. package/dist/src/utility/textures/gradientnoise.js +0 -62
  375. package/dist/src/utility/textures/gradientnoise.js.map +0 -1
  376. package/dist/src/utility/textures/randomnoise.js +0 -41
  377. package/dist/src/utility/textures/randomnoise.js.map +0 -1
  378. package/dist/src/values.js +0 -162
  379. package/dist/src/values.js.map +0 -1
  380. package/dist/utility/blueprint/material/common.js +0 -7
  381. package/dist/utility/blueprint/material/common.js.map +0 -1
  382. package/dist/utility/serialization/blueprint/constants.js +0 -255
  383. package/dist/utility/serialization/blueprint/constants.js.map +0 -1
  384. package/dist/utility/serialization/blueprint/material/constants.js +0 -203
  385. package/dist/utility/serialization/blueprint/material/constants.js.map +0 -1
  386. package/dist/utility/serialization/blueprint/material/texture.js +0 -165
  387. package/dist/utility/serialization/blueprint/material/texture.js.map +0 -1
@@ -1,957 +0,0 @@
1
- import { Application } from '../app/app.js';
2
- import { drawFullscreenQuad } from '../render/fullscreenquad.js';
3
- import { fetchSampler } from '../utility/misc.js';
4
- import { Matrix4x4, Vector3, Vector4 } from '@zephyr3d/base';
5
- import { uniformSphereSamples } from '../values.js';
6
-
7
- const TRANSMITTANCE_SAMPLES = 16;
8
- const RAYLEIGH_SIGMA = [
9
- 5.802,
10
- 13.558,
11
- 33.1
12
- ];
13
- const MIE_SIGMA = 3.996;
14
- const MIE_ABSORPTION_SIGMA = 4.4;
15
- const OZONE_ABSORPTION_SIGMA = [
16
- 0.65,
17
- 1.881,
18
- 0.085
19
- ];
20
- /** @internal */ const CAMERA_POS_Y = 1;
21
- /** @internal */ function getDefaultAtmosphereParams() {
22
- return {
23
- plantRadius: 6360000,
24
- atmosphereHeight: 60000,
25
- rayleighScatteringHeight: 8000,
26
- mieScatteringHeight: 1200,
27
- mieAnstropy: 0.8,
28
- ozoneCenter: 25000,
29
- ozoneWidth: 15000,
30
- apDistance: 4000,
31
- cameraWorldMatrix: Matrix4x4.identity(),
32
- lightDir: new Vector3(1, 0, 0),
33
- lightColor: new Vector4(1, 1, 1, 10),
34
- cameraAspect: 1,
35
- cameraHeightScale: 1
36
- };
37
- }
38
- const defaultAtmosphereParams = getDefaultAtmosphereParams();
39
- let currentAtmosphereParams = null;
40
- function checkParams(other) {
41
- const result = {
42
- transmittance: false,
43
- multiScattering: false,
44
- skyView: false,
45
- aerialPerspective: false
46
- };
47
- other = {
48
- ...defaultAtmosphereParams,
49
- ...other
50
- };
51
- if (!currentAtmosphereParams) {
52
- currentAtmosphereParams = {
53
- ...defaultAtmosphereParams,
54
- lightDir: new Vector3(defaultAtmosphereParams.lightDir),
55
- lightColor: new Vector4(defaultAtmosphereParams.lightColor),
56
- cameraWorldMatrix: new Matrix4x4(defaultAtmosphereParams.cameraWorldMatrix)
57
- };
58
- result.transmittance = true;
59
- result.multiScattering = true;
60
- result.skyView = true;
61
- result.aerialPerspective = true;
62
- } else {
63
- result.transmittance = currentAtmosphereParams.plantRadius !== other.plantRadius || currentAtmosphereParams.atmosphereHeight !== other.atmosphereHeight || currentAtmosphereParams.rayleighScatteringHeight !== other.rayleighScatteringHeight || currentAtmosphereParams.mieScatteringHeight !== other.mieScatteringHeight || currentAtmosphereParams.ozoneCenter !== other.ozoneCenter || currentAtmosphereParams.ozoneWidth !== other.ozoneWidth;
64
- result.multiScattering = result.transmittance || currentAtmosphereParams.mieAnstropy !== other.mieAnstropy;
65
- result.skyView = result.transmittance || result.multiScattering || currentAtmosphereParams.cameraHeightScale !== other.cameraHeightScale || !currentAtmosphereParams.lightDir.equalsTo(other.lightDir) || !currentAtmosphereParams.lightColor.equalsTo(other.lightColor) || !currentAtmosphereParams.cameraWorldMatrix.equalsTo(other.cameraWorldMatrix);
66
- result.aerialPerspective = result.transmittance || result.multiScattering || result.skyView || currentAtmosphereParams.apDistance !== other.apDistance || currentAtmosphereParams.cameraAspect !== other.cameraAspect;
67
- }
68
- if (result.transmittance) {
69
- currentAtmosphereParams.plantRadius = other.plantRadius;
70
- currentAtmosphereParams.atmosphereHeight = other.atmosphereHeight;
71
- currentAtmosphereParams.rayleighScatteringHeight = other.rayleighScatteringHeight;
72
- currentAtmosphereParams.mieScatteringHeight = other.mieScatteringHeight;
73
- currentAtmosphereParams.ozoneCenter = other.ozoneCenter;
74
- currentAtmosphereParams.ozoneWidth = other.ozoneWidth;
75
- }
76
- if (result.multiScattering) {
77
- currentAtmosphereParams.mieAnstropy = other.mieAnstropy;
78
- }
79
- if (result.skyView) {
80
- currentAtmosphereParams.cameraHeightScale = other.cameraHeightScale;
81
- currentAtmosphereParams.lightDir.set(other.lightDir);
82
- currentAtmosphereParams.lightColor.set(other.lightColor);
83
- currentAtmosphereParams.cameraWorldMatrix.set(other.cameraWorldMatrix);
84
- }
85
- if (result.aerialPerspective) {
86
- currentAtmosphereParams.apDistance = other.apDistance;
87
- currentAtmosphereParams.cameraAspect = other.cameraAspect;
88
- }
89
- return result;
90
- }
91
- /** @internal */ function rayIntersectSphere(scope, f3Center, fRadius, f3RayStart, f3RayDir) {
92
- const pb = scope.$builder;
93
- const funcName = 'z_rayIntersectSphere';
94
- pb.func(funcName, [
95
- pb.vec3('center'),
96
- pb.float('radius'),
97
- pb.vec3('rayStart'),
98
- pb.vec3('rayDir')
99
- ], function() {
100
- this.$l.OS = pb.length(pb.sub(this.center, this.rayStart));
101
- this.$l.SH = pb.dot(pb.sub(this.center, this.rayStart), this.rayDir);
102
- this.$l.OH = pb.sqrt(pb.sub(pb.mul(this.OS, this.OS), pb.mul(this.SH, this.SH)));
103
- this.$l.PH = pb.sqrt(pb.sub(pb.mul(this.radius, this.radius), pb.mul(this.OH, this.OH)));
104
- this.$if(pb.greaterThan(this.OH, this.radius), function() {
105
- this.$return(pb.float(-1));
106
- });
107
- this.$l.t1 = pb.sub(this.SH, this.PH);
108
- this.$l.t2 = pb.add(this.SH, this.PH);
109
- this.$return(this.$choice(pb.lessThan(this.t1, 0), this.t2, this.t1));
110
- });
111
- return scope[funcName](f3Center, fRadius, f3RayStart, f3RayDir);
112
- }
113
- /** @internal */ function transmittanceToSky(scope, stParams, f3Pos, f3Dir, texLut) {
114
- const pb = scope.$builder;
115
- const funcName = 'z_transmittanceToSky';
116
- const Params = getAtmosphereParamsStruct(pb);
117
- pb.func(funcName, [
118
- Params('params'),
119
- pb.vec3('p'),
120
- pb.vec3('dir')
121
- ], function() {
122
- this.$l.bottomRadius = this.params.plantRadius;
123
- this.$l.topRadius = pb.add(this.params.plantRadius, this.params.atmosphereHeight);
124
- this.$l.upVector = pb.normalize(this.p);
125
- this.$l.cosTheta = pb.dot(this.upVector, this.dir);
126
- this.$l.r = pb.length(this.p);
127
- this.$l.uv = transmittanceLutToUV(this, this.bottomRadius, this.topRadius, this.cosTheta, this.r);
128
- this.$return(pb.textureSampleLevel(texLut, this.uv, 0).rgb);
129
- });
130
- return scope[funcName](stParams, f3Pos, f3Dir);
131
- }
132
- /** @internal */ function rayleighCoefficient(scope, fRayleighScatteringHeight, fH) {
133
- const pb = scope.$builder;
134
- const funcName = 'z_rayleighCoefficient';
135
- pb.func(funcName, [
136
- pb.float('rayleighScatteringHeight'),
137
- pb.float('h')
138
- ], function() {
139
- this.$l.sigma = pb.mul(pb.vec3(RAYLEIGH_SIGMA[0], RAYLEIGH_SIGMA[1], RAYLEIGH_SIGMA[2]), 1e-6);
140
- this.$l.rho_h = pb.exp(pb.neg(pb.div(this.h, this.rayleighScatteringHeight)));
141
- this.$return(pb.mul(this.sigma, this.rho_h));
142
- });
143
- return scope[funcName](fRayleighScatteringHeight, fH);
144
- }
145
- /** @internal */ function rayleighPhase(scope, fCosTheta) {
146
- const pb = scope.$builder;
147
- const funcName = 'z_rayleighPhase';
148
- pb.func(funcName, [
149
- pb.float('cosTheta')
150
- ], function() {
151
- this.$return(pb.mul(3 / (16 * Math.PI), pb.add(1, pb.mul(this.cosTheta, this.cosTheta))));
152
- });
153
- return scope[funcName](fCosTheta);
154
- }
155
- /** @internal */ function mieCoefficient(scope, fMieScatteringHeight, fH) {
156
- const pb = scope.$builder;
157
- const funcName = 'z_mieCoefficient';
158
- pb.func(funcName, [
159
- pb.float('mieScatteringHeight'),
160
- pb.float('h')
161
- ], function() {
162
- this.$l.sigma = pb.mul(pb.vec3(MIE_SIGMA), 1e-6);
163
- this.$l.rho_h = pb.exp(pb.neg(pb.div(this.h, this.mieScatteringHeight)));
164
- this.$return(pb.mul(this.sigma, this.rho_h));
165
- });
166
- return scope[funcName](fMieScatteringHeight, fH);
167
- }
168
- /** @internal */ function miePhase(scope, fMieAnstropy, fCosTheta) {
169
- const pb = scope.$builder;
170
- const funcName = 'z_miePhase';
171
- pb.func(funcName, [
172
- pb.float('g'),
173
- pb.float('cosTheta')
174
- ], function() {
175
- this.$l.g2 = pb.mul(this.g, this.g);
176
- this.$l.a = 3 / (8 * Math.PI);
177
- this.$l.b = pb.div(pb.sub(1, this.g2), pb.add(2, this.g2));
178
- this.$l.c = pb.add(1, pb.mul(this.cosTheta, this.cosTheta));
179
- this.$l.d = pb.pow(pb.sub(pb.add(1, this.g2), pb.mul(this.g, this.cosTheta, 2)), 1.5);
180
- this.$return(pb.div(pb.mul(this.a, this.b, this.c), this.d));
181
- });
182
- return scope[funcName](fMieAnstropy, fCosTheta);
183
- }
184
- /** @internal */ function mieAbsorption(scope, fMieScatteringHeight, fH) {
185
- const pb = scope.$builder;
186
- const funcName = 'z_mieAbsorption';
187
- pb.func(funcName, [
188
- pb.float('mieScatteringHeight'),
189
- pb.float('h')
190
- ], function() {
191
- this.$l.sigma = pb.mul(pb.vec3(MIE_ABSORPTION_SIGMA), 1e-6);
192
- this.$l.rho_h = pb.exp(pb.neg(pb.div(this.h, this.mieScatteringHeight)));
193
- this.$return(pb.mul(this.sigma, this.rho_h));
194
- });
195
- return scope[funcName](fMieScatteringHeight, fH);
196
- }
197
- /** @internal */ function ozoneAbsorption(scope, fOzoneLevelCenterHeight, fOzoneLevelWidth, fH) {
198
- const pb = scope.$builder;
199
- const funcName = 'z_ozoneAbsorption';
200
- pb.func(funcName, [
201
- pb.float('center'),
202
- pb.float('width'),
203
- pb.float('h')
204
- ], function() {
205
- this.$l.sigma = pb.mul(pb.vec3(OZONE_ABSORPTION_SIGMA[0], OZONE_ABSORPTION_SIGMA[1], OZONE_ABSORPTION_SIGMA[2]), 1e-6);
206
- this.$l.rho_h = pb.max(0, pb.sub(1, pb.div(pb.abs(pb.sub(this.h, this.center)), this.width)));
207
- this.$return(pb.mul(this.sigma, this.rho_h));
208
- });
209
- return scope[funcName](fOzoneLevelCenterHeight, fOzoneLevelWidth, fH);
210
- }
211
- /** @internal */ function getSkyView(scope, stParams, f3EyePos, f3ViewDir, fMaxDis, texTransmittanceLut, texMultiScatteringLut, withGround = true) {
212
- const pb = scope.$builder;
213
- const Params = getAtmosphereParamsStruct(pb);
214
- const funcName = 'z_getSkyView';
215
- pb.func(funcName, [
216
- Params('params'),
217
- pb.vec3('eyePos'),
218
- pb.vec3('viewDir'),
219
- pb.float('maxDis')
220
- ], function() {
221
- const N_SAMPLE = 32;
222
- this.$l.color = pb.vec3(0);
223
- this.$l.dis = rayIntersectSphere(this, pb.vec3(0), pb.add(this.params.plantRadius, this.params.atmosphereHeight), this.eyePos, this.viewDir);
224
- this.$if(pb.lessThan(this.dis, 0), function() {
225
- this.$return(pb.vec3(0));
226
- });
227
- if (withGround) {
228
- this.$l.d = rayIntersectSphere(this, pb.vec3(0), this.params.plantRadius, this.eyePos, this.viewDir);
229
- this.$if(pb.greaterThan(this.d, 0), function() {
230
- this.dis = pb.min(this.dis, this.d);
231
- });
232
- }
233
- this.$if(pb.greaterThanEqual(this.maxDis, 0), function() {
234
- this.dis = pb.min(this.dis, this.maxDis);
235
- });
236
- this.$l.ds = pb.div(this.dis, N_SAMPLE);
237
- this.$l.p = pb.add(this.eyePos, pb.mul(this.viewDir, this.ds, 0.5));
238
- this.$l.sunLuminance = pb.mul(this.params.lightColor.rgb, this.params.lightColor.a);
239
- this.$l.opticalDepth = pb.vec3(0);
240
- this.$for(pb.int('i'), 0, N_SAMPLE, function() {
241
- this.$l.h = pb.sub(pb.length(this.p), this.params.plantRadius);
242
- this.$l.extinction = pb.add(rayleighCoefficient(this, this.params.rayleighScatteringHeight, this.h), mieCoefficient(this, this.params.mieScatteringHeight, this.h), ozoneAbsorption(this, this.params.ozoneCenter, this.params.ozoneWidth, this.h), mieAbsorption(this, this.params.mieScatteringHeight, this.h));
243
- this.opticalDepth = pb.add(this.opticalDepth, pb.mul(this.extinction, this.ds));
244
- this.$l.t1 = transmittanceToSky(this, this.params, this.p, this.params.lightDir, texTransmittanceLut);
245
- this.$l.s = scattering(this, this.params, this.p, this.viewDir);
246
- this.$l.t2 = pb.exp(pb.neg(this.opticalDepth));
247
- this.$l.inScattering = pb.mul(this.t1, this.s, this.t2, this.ds, this.sunLuminance);
248
- this.color = pb.add(this.color, this.inScattering);
249
- this.$l.multiScattering = getMultiScattering(this, this.params, this.p, texMultiScatteringLut);
250
- this.color = pb.add(this.color, pb.mul(this.multiScattering, this.t2, this.ds, this.sunLuminance));
251
- this.p = pb.add(this.p, pb.mul(this.viewDir, this.ds));
252
- });
253
- this.$return(this.color);
254
- });
255
- return scope[funcName](stParams, f3EyePos, f3ViewDir, fMaxDis);
256
- }
257
- /** @internal */ function getMultiScattering(scope, stParams, f3Pos, texMultiScatteringLut) {
258
- const pb = scope.$builder;
259
- const funcName = 'z_getMultiScattering';
260
- const Params = getAtmosphereParamsStruct(pb);
261
- pb.func(funcName, [
262
- Params('params'),
263
- pb.vec3('p')
264
- ], function() {
265
- this.$l.h = pb.sub(pb.length(this.p), this.params.plantRadius);
266
- this.$l.sigma_s = pb.add(rayleighCoefficient(this, this.params.rayleighScatteringHeight, this.h), mieCoefficient(this, this.params.mieScatteringHeight, this.h));
267
- this.$l.zenithAngle = pb.dot(pb.normalize(this.p), this.params.lightDir);
268
- this.$l.uv = pb.vec2(pb.add(pb.mul(this.zenithAngle, 0.5), 0.5), pb.div(this.h, this.params.atmosphereHeight));
269
- this.$l.G_ALL = pb.textureSampleLevel(texMultiScatteringLut, this.uv, 0).rgb;
270
- this.$return(pb.mul(this.G_ALL, this.sigma_s));
271
- });
272
- return scope[funcName](stParams, f3Pos);
273
- }
274
- /** @internal */ function integralMultiScattering(scope, stParams, f3LightDir, f3SamplePoint, texTransmittanceLut) {
275
- const N_DIRECTION = 64;
276
- const N_SAMPLE = 32;
277
- const pb = scope.$builder;
278
- const Params = getAtmosphereParamsStruct(pb);
279
- const funcName = 'z_integralMultiScattering';
280
- pb.func(funcName, [
281
- Params('params'),
282
- pb.vec3('lightDir'),
283
- pb.vec3('samplePoint')
284
- ], function() {
285
- const uniformPhase = 1 / (4 * Math.PI);
286
- const sphereSolidAngle = 4 * Math.PI / N_DIRECTION;
287
- this.$l.G_2 = pb.vec3(0);
288
- this.$l.f_ms = pb.vec3(0);
289
- this.$for(pb.int('i'), 0, N_DIRECTION, function() {
290
- this.$l.viewDir = this.uniformSphereSamples.at(this.i).xyz;
291
- this.$l.dis = rayIntersectSphere(this, pb.vec3(0), pb.add(this.params.plantRadius, this.params.atmosphereHeight), this.samplePoint, this.viewDir);
292
- this.$l.d = rayIntersectSphere(this, pb.vec3(0), this.params.plantRadius, this.samplePoint, this.viewDir);
293
- this.$if(pb.greaterThan(this.d, 0), function() {
294
- this.dis = pb.min(this.dis, this.d);
295
- });
296
- this.$l.ds = pb.div(this.dis, N_SAMPLE);
297
- this.$l.p = pb.add(this.samplePoint, pb.mul(this.viewDir, this.ds, 0.5));
298
- this.$l.opticalDepth = pb.vec3(0);
299
- this.$for(pb.int('j'), 0, N_SAMPLE, function() {
300
- this.$l.h = pb.sub(pb.length(this.p), this.params.plantRadius);
301
- this.$l.sigma_s = pb.add(rayleighCoefficient(this, this.params.rayleighScatteringHeight, this.h), mieCoefficient(this, this.params.mieScatteringHeight, this.h));
302
- this.$l.sigma_a = pb.add(ozoneAbsorption(this, this.params.ozoneCenter, this.params.ozoneWidth, this.h), mieAbsorption(this, this.params.mieScatteringHeight, this.h));
303
- this.$l.sigma_t = pb.add(this.sigma_s, this.sigma_a);
304
- this.opticalDepth = pb.add(this.opticalDepth, pb.mul(this.sigma_t, this.ds));
305
- this.$l.t1 = transmittanceToSky(this, this.params, this.p, this.lightDir, texTransmittanceLut);
306
- this.$l.s = scattering(this, this.params, this.p, this.viewDir);
307
- this.$l.t2 = pb.exp(pb.neg(this.opticalDepth));
308
- this.G_2 = pb.add(this.G_2, pb.mul(this.t1, this.s, this.t2, uniformPhase, this.ds));
309
- this.f_ms = pb.add(this.f_ms, pb.mul(this.t2, this.sigma_s, uniformPhase, this.ds));
310
- this.p = pb.add(this.p, pb.mul(this.viewDir, this.ds));
311
- });
312
- });
313
- this.G_2 = pb.mul(this.G_2, sphereSolidAngle);
314
- this.f_ms = pb.mul(this.f_ms, sphereSolidAngle);
315
- this.$return(pb.div(this.G_2, pb.sub(pb.vec3(1), this.f_ms)));
316
- });
317
- return scope[funcName](stParams, f3LightDir, f3SamplePoint);
318
- }
319
- /** @internal */ function scattering(scope, stParams, f3Pos, f3ViewDir) {
320
- const pb = scope.$builder;
321
- const Params = getAtmosphereParamsStruct(pb);
322
- const funcName = 'z_scattering';
323
- pb.func(funcName, [
324
- Params('params'),
325
- pb.vec3('p'),
326
- pb.vec3('viewDir')
327
- ], function() {
328
- this.$l.cosTheta = pb.dot(this.params.lightDir, this.viewDir);
329
- this.$l.h = pb.sub(pb.length(this.p), this.params.plantRadius);
330
- this.$l.rayleigh = pb.mul(rayleighCoefficient(this, this.params.rayleighScatteringHeight, this.h), rayleighPhase(this, this.cosTheta));
331
- this.$l.mie = pb.mul(mieCoefficient(this, this.params.mieScatteringHeight, this.h), miePhase(this, this.params.mieAnstropy, this.cosTheta));
332
- this.$return(pb.add(this.rayleigh, this.mie));
333
- });
334
- return scope[funcName](stParams, f3Pos, f3ViewDir);
335
- }
336
- /** @internal */ function transmittance(scope, stParams, f3P1, f3P2) {
337
- const pb = scope.$builder;
338
- const Params = getAtmosphereParamsStruct(pb);
339
- const funcName = 'z_transmittance';
340
- pb.func(funcName, [
341
- Params('params'),
342
- pb.vec3('p1'),
343
- pb.vec3('p2')
344
- ], function() {
345
- this.$l.dir = pb.normalize(pb.sub(this.p2, this.p1));
346
- this.$l.distance = pb.length(pb.sub(this.p2, this.p1));
347
- this.$l.ds = pb.div(this.distance, TRANSMITTANCE_SAMPLES);
348
- this.$l.sum = pb.vec3(0);
349
- this.$l.p = pb.add(this.p1, pb.mul(this.dir, this.ds, 0.5));
350
- this.$for(pb.int('i'), 0, TRANSMITTANCE_SAMPLES, function() {
351
- this.$l.h = pb.sub(pb.length(this.p), this.params.plantRadius);
352
- this.$l.scattering = pb.add(rayleighCoefficient(this, this.params.rayleighScatteringHeight, this.h), mieCoefficient(this, this.params.mieScatteringHeight, this.h));
353
- this.$l.absorption = pb.add(ozoneAbsorption(this, this.params.ozoneCenter, this.params.ozoneWidth, this.h), mieAbsorption(this, this.params.mieScatteringHeight, this.h));
354
- this.$l.extinction = pb.add(this.scattering, this.absorption);
355
- this.sum = pb.add(this.sum, pb.mul(this.extinction, this.ds));
356
- this.p = pb.add(this.p, pb.mul(this.dir, this.ds));
357
- });
358
- this.$return(pb.exp(pb.neg(this.sum)));
359
- });
360
- return scope[funcName](stParams, f3P1, f3P2);
361
- }
362
- /** @internal */ function transmittanceLutToUV(scope, fBottomRadius, fTopRadius, fMu, fR) {
363
- const pb = scope.$builder;
364
- const funcName = 'z_transmittanceToUV';
365
- pb.func(funcName, [
366
- pb.float('bottomRadius'),
367
- pb.float('topRadius'),
368
- pb.float('mu'),
369
- pb.float('r')
370
- ], function() {
371
- this.$l.H = pb.sqrt(pb.max(0, pb.sub(pb.mul(this.topRadius, this.topRadius), pb.mul(this.bottomRadius, this.bottomRadius))));
372
- this.$l.rho = pb.sqrt(pb.max(0, pb.sub(pb.mul(this.r, this.r), pb.mul(this.bottomRadius, this.bottomRadius))));
373
- this.$l.discriminant = pb.add(pb.mul(this.r, this.r, pb.sub(pb.mul(this.mu, this.mu), 1)), pb.mul(this.topRadius, this.topRadius));
374
- this.$l.d = pb.max(0, pb.sub(pb.sqrt(this.discriminant), pb.mul(this.mu, this.r)));
375
- this.$l.d_min = pb.sub(this.topRadius, this.r);
376
- this.$l.d_max = pb.add(this.rho, this.H);
377
- this.$l.x_mu = pb.div(pb.sub(this.d, this.d_min), pb.sub(this.d_max, this.d_min));
378
- this.$l.x_r = pb.div(this.rho, this.H);
379
- this.$return(pb.vec2(this.x_mu, this.x_r));
380
- });
381
- return scope[funcName](fBottomRadius, fTopRadius, fMu, fR);
382
- }
383
- /** @internal */ function viewDirToUV(scope, f3ViewDir) {
384
- const pb = scope.$builder;
385
- const funcName = 'z_viewDirToUV';
386
- pb.func(funcName, [
387
- pb.vec3('viewDir')
388
- ], function() {
389
- this.$l.uv = pb.vec2(pb.atan2(this.viewDir.z, this.viewDir.x), pb.asin(this.viewDir.y));
390
- this.uv = pb.div(this.uv, pb.vec2(2 * Math.PI, Math.PI));
391
- this.uv = pb.add(this.uv, pb.vec2(0.5));
392
- this.$return(this.uv);
393
- });
394
- return scope[funcName](f3ViewDir);
395
- }
396
- /** @internal */ function uvToViewDir(scope, f2UV) {
397
- const pb = scope.$builder;
398
- const funcName = 'z_uvToViewDir';
399
- pb.func(funcName, [
400
- pb.vec2('uv')
401
- ], function() {
402
- this.$l.theta = pb.mul(pb.sub(1, this.uv.y), Math.PI);
403
- this.$l.phi = pb.mul(pb.sub(pb.mul(this.uv.x, 2), 1), Math.PI);
404
- this.$l.x = pb.mul(pb.sin(this.theta), pb.cos(this.phi));
405
- this.$l.z = pb.mul(pb.sin(this.theta), pb.sin(this.phi));
406
- this.$l.y = pb.cos(this.theta);
407
- this.$return(pb.vec3(this.x, this.y, this.z));
408
- });
409
- return scope[funcName](f2UV);
410
- }
411
- /** @internal */ function uvToTransmittanceLut(scope, f2UV, fBottomRadius, fTopRadius) {
412
- const pb = scope.$builder;
413
- const funcName = 'z_uvToTransmittanceLut';
414
- pb.func(funcName, [
415
- pb.vec2('uv'),
416
- pb.float('bottomRadius'),
417
- pb.float('topRadius')
418
- ], function() {
419
- this.$l.x_mu = this.uv.x;
420
- this.$l.x_r = this.uv.y;
421
- this.$l.H = pb.sqrt(pb.max(0, pb.sub(pb.mul(this.topRadius, this.topRadius), pb.mul(this.bottomRadius, this.bottomRadius))));
422
- this.$l.rho = pb.mul(this.H, this.x_r);
423
- this.$l.r = pb.sqrt(pb.max(0, pb.add(pb.mul(this.rho, this.rho), pb.mul(this.bottomRadius, this.bottomRadius))));
424
- this.$l.d_min = pb.sub(this.topRadius, this.r);
425
- this.$l.d_max = pb.add(this.rho, this.H);
426
- this.$l.d = pb.add(this.d_min, pb.mul(this.x_mu, pb.sub(this.d_max, this.d_min)));
427
- this.$l.mu = this.$choice(pb.equal(this.d, 0), pb.float(1), pb.div(pb.sub(pb.mul(this.H, this.H), pb.add(pb.mul(this.rho, this.rho), pb.mul(this.d, this.d))), pb.mul(this.r, this.d, 2)));
428
- this.mu = pb.clamp(this.mu, -1, 1);
429
- this.$return(pb.vec2(this.mu, this.r));
430
- });
431
- return scope[funcName](f2UV, fBottomRadius, fTopRadius);
432
- }
433
- function sunBloom(scope, f3ViewDir, f3LightDir, f4LightColorAndIntensity, fSunSolidAngle) {
434
- const pb = scope.$builder;
435
- const funcName = 'v_sunBloom';
436
- pb.func(funcName, [
437
- pb.vec3('viewDir'),
438
- pb.vec3('lightDir'),
439
- pb.vec4('sunColorAndIntensity'),
440
- pb.float('sunSolidAngle')
441
- ], function() {
442
- this.$l.minSunCosTheta = pb.cos(this.sunSolidAngle);
443
- this.$l.cosTheta = pb.dot(this.viewDir, this.lightDir);
444
- this.$l.luminance = pb.mul(this.sunColorAndIntensity.rgb, this.sunColorAndIntensity.a);
445
- this.$if(pb.lessThan(this.cosTheta, this.minSunCosTheta), function() {
446
- this.$l.offset = pb.sub(this.minSunCosTheta, this.cosTheta);
447
- this.$l.gaussianBloom = pb.mul(pb.exp(pb.mul(this.offset, -5e4)), 0.5);
448
- this.$l.invBloom = pb.mul(pb.div(1, pb.add(0.02, pb.mul(this.offset, 300))), 0.01);
449
- this.luminance = pb.mul(this.luminance, pb.add(this.gaussianBloom, this.invBloom));
450
- });
451
- this.$return(this.luminance);
452
- });
453
- return scope[funcName](f3ViewDir, f3LightDir, f4LightColorAndIntensity, fSunSolidAngle);
454
- }
455
- /** @internal */ function skyBox(scope, stParams, f4SunColor, f3SkyBoxWorldPos, fSunSolidAngle, texTransmittanceLut, texSkyViewLut) {
456
- const pb = scope.$builder;
457
- const funcName = 'v_skybox';
458
- const Params = getAtmosphereParamsStruct(pb);
459
- pb.func(funcName, [
460
- Params('params'),
461
- pb.vec4('sunColor').out(),
462
- pb.vec3('worldPos'),
463
- pb.float('sunSolidAngle')
464
- ], function() {
465
- this.$l.rgb = pb.vec3(0);
466
- this.$l.viewDir = pb.normalize(this.worldPos);
467
- this.rgb = pb.add(this.rgb, pb.textureSampleLevel(texSkyViewLut, viewDirToUV(this, this.viewDir), 0).rgb);
468
- this.$l.groundDistance = rayIntersectSphere(this, pb.vec3(0), this.params.plantRadius, pb.vec3(0, pb.add(this.params.plantRadius, pb.mul(CAMERA_POS_Y, this.params.cameraHeightScale)), 0), this.viewDir);
469
- this.$l.sunTransmittance = transmittanceToSky(this, this.params, pb.vec3(0, pb.add(this.params.cameraHeightScale, this.params.plantRadius), 0), this.params.lightDir, texTransmittanceLut);
470
- this.sunColor = pb.mul(this.params.lightColor, pb.vec4(this.sunTransmittance, 1));
471
- this.$if(pb.lessThan(this.groundDistance, 0), function() {
472
- this.rgb = pb.add(this.rgb, sunBloom(this, this.viewDir, this.params.lightDir, this.sunColor, this.sunSolidAngle));
473
- });
474
- this.$return(pb.vec4(this.rgb, 1));
475
- });
476
- return scope[funcName](stParams, f4SunColor, f3SkyBoxWorldPos, fSunSolidAngle);
477
- }
478
- /** @internal */ function aerialPerspective(scope, f2UV, stParams, f3CameraPos, f3WorldPos, f3Dim, texAerialPerspectiveLut) {
479
- const pb = scope.$builder;
480
- const Params = getAtmosphereParamsStruct(pb);
481
- const funcName = 'z_aerialPerspective';
482
- pb.func(funcName, [
483
- Params('params'),
484
- pb.vec2('uv'),
485
- pb.vec3('cameraPos'),
486
- pb.vec3('worldPos'),
487
- pb.vec3('dim')
488
- ], function() {
489
- this.$l.V = pb.sub(this.worldPos, this.cameraPos);
490
- this.$l.dis = pb.length(this.V);
491
- this.$l.viewDir = pb.normalize(this.V);
492
- this.$l.apDistance = pb.div(this.params.apDistance, this.params.cameraHeightScale);
493
- this.$l.d0 = pb.clamp(pb.div(this.dis, this.apDistance), 0, 1);
494
- this.$l.weight = pb.clamp(pb.mul(this.d0, 2), 0, 1);
495
- this.$l.dz = pb.mul(this.d0, pb.sub(this.dim.z, 1));
496
- this.$l.slice = pb.floor(this.dz);
497
- this.$l.nextSlice = pb.min(pb.add(this.slice, 1), pb.sub(this.dim.z, 1));
498
- this.$l.factor = pb.sub(this.dz, pb.floor(this.dz));
499
- this.t = pb.div(this.uv, pb.vec2(this.dim.x, 1));
500
- this.$l.uv1 = pb.add(this.t, pb.vec2(pb.div(this.slice, this.dim.z), 0));
501
- this.$l.uv2 = pb.add(this.t, pb.vec2(pb.div(this.nextSlice, this.dim.z), 0));
502
- this.$l.data1 = pb.textureSampleLevel(texAerialPerspectiveLut, this.uv1, 0);
503
- this.$l.data2 = pb.textureSampleLevel(texAerialPerspectiveLut, this.uv2, 0);
504
- this.$l.data = pb.mix(this.data1, this.data2, this.factor);
505
- this.$l.inscattering = pb.mul(this.data.rgb, this.weight);
506
- //this.$l.transmittance = pb.sub(1, pb.mul(this.weight, pb.sub(1, this.data.a)));
507
- this.$l.planetTranslate = pb.vec3(0, this.params.plantRadius, 0);
508
- this.$l.transmittance = pb.dot(transmittance(this, this.params, pb.add(this.cameraPos, this.planetTranslate), pb.add(this.worldPos, this.planetTranslate)), pb.vec3(1 / 3, 1 / 3, 1 / 3));
509
- this.$return(pb.vec4(this.inscattering, this.transmittance));
510
- });
511
- return scope[funcName](stParams, f2UV, f3CameraPos, f3WorldPos, f3Dim);
512
- }
513
- /** @internal */ function aerialPerspectiveLut(scope, stParams, f2UV, f3VoxelDim, texTransmittanceLut, texMultiScatteringLut) {
514
- const pb = scope.$builder;
515
- const Params = getAtmosphereParamsStruct(pb);
516
- const funcNameFixVoxel = 'z_fixVoxel';
517
- pb.func(funcNameFixVoxel, [
518
- Params('params'),
519
- pb.vec3('eyePos'),
520
- pb.vec3('viewDir').inout(),
521
- pb.float('maxDis'),
522
- pb.float('adjustedMaxDis').inout()
523
- ], function() {
524
- this.$l.voxelPos = pb.add(this.eyePos, pb.mul(this.viewDir, this.maxDis));
525
- this.$l.voxelHeight = pb.length(this.voxelPos);
526
- this.$l.underGround = pb.lessThan(this.voxelHeight, this.params.plantRadius);
527
- this.$l.cameraToVoxel = pb.sub(this.voxelPos, this.eyePos);
528
- this.$l.cameraToVoxelLen = pb.length(this.cameraToVoxel);
529
- this.$l.cameraToVoxelDir = pb.div(this.cameraToVoxel, this.cameraToVoxelLen);
530
- this.$l.planetNearT = rayIntersectSphere(this, pb.vec3(0), this.params.plantRadius, this.eyePos, this.cameraToVoxelDir);
531
- this.$l.belowHorizon = pb.and(pb.greaterThan(this.planetNearT, 0), pb.greaterThan(this.cameraToVoxelLen, this.planetNearT));
532
- this.$l.eyePos2 = this.eyePos;
533
- this.$if(pb.or(this.underGround, this.belowHorizon), function() {
534
- this.eyePos2 = pb.add(this.eyePos2, pb.mul(pb.normalize(this.eyePos2), 0.02));
535
- this.$if(this.belowHorizon, function() {
536
- this.$l.voxelWorldPosNorm = pb.normalize(this.voxelPos);
537
- this.$l.camProjOnGround = pb.mul(pb.normalize(this.eyePos2), this.params.plantRadius);
538
- this.$l.voxProjOnGround = pb.mul(this.voxelWorldPosNorm, this.params.plantRadius);
539
- this.$l.voxelGroundToRayStart = pb.sub(this.eyePos2, this.voxProjOnGround);
540
- this.$if(pb.lessThan(pb.dot(pb.normalize(this.voxelGroundToRayStart), this.voxelWorldPosNorm), 0.0001), function() {
541
- this.$l.middlePoint = pb.mul(pb.add(this.camProjOnGround, this.voxProjOnGround), 0.5);
542
- this.$l.middlePointOnGround = pb.mul(pb.normalize(this.middlePoint), this.params.plantRadius);
543
- this.voxelPos = pb.add(this.eyePos2, pb.mul(pb.sub(this.middlePointOnGround, this.eyePos2), 2));
544
- });
545
- }).$else(function() {
546
- this.voxelPos = pb.mul(pb.normalize(this.voxelPos), this.params.plantRadius);
547
- });
548
- this.$l.V = pb.sub(this.voxelPos, this.eyePos2);
549
- this.adjustedMaxDis = pb.length(this.V);
550
- this.viewDir = pb.div(this.V, this.adjustedMaxDis);
551
- });
552
- this.$return(this.eyePos2);
553
- });
554
- const funcName = 'z_aerialPerspectiveLut';
555
- pb.func(funcName, [
556
- Params('params'),
557
- pb.vec2('uv'),
558
- pb.vec3('dim'),
559
- pb.float('cameraPosY')
560
- ], function() {
561
- this.$l.uvw = pb.vec3(this.uv, 0);
562
- this.uvw.x = pb.mul(this.uvw.x, this.dim.x, this.dim.z);
563
- this.uvw.z = pb.div(pb.floor(pb.div(this.uvw.x, this.dim.z)), this.dim.x);
564
- this.uvw.x = pb.div(pb.mod(this.uvw.x, this.dim.z), this.dim.x);
565
- this.uvw = pb.add(this.uvw, pb.div(pb.vec3(0.5), this.dim));
566
- this.$l.slice = this.uvw.z; //pb.mul(this.uvw.z, this.uvw.z);
567
- this.$l.viewDir = pb.normalize(pb.mul(this.params.cameraWorldMatrix, pb.vec4(pb.sub(pb.mul(this.uvw.x, 2), 1), pb.div(pb.sub(pb.mul(this.uvw.y, 2), 1), this.params.cameraAspect), -1, 0)).xyz);
568
- this.$l.eyePos = pb.vec3(0, pb.add(pb.mul(this.cameraPosY, this.params.cameraHeightScale), this.params.plantRadius), 0);
569
- this.$l.maxDis = pb.mul(this.slice, this.params.apDistance);
570
- this.$l.voxelPos = pb.add(this.eyePos, pb.mul(this.viewDir, this.maxDis));
571
- this.$if(pb.lessThan(pb.length(this.voxelPos), this.params.plantRadius), function() {
572
- this.voxelPos = pb.mul(pb.normalize(this.voxelPos), this.params.plantRadius);
573
- this.maxDis = pb.length(pb.sub(this.eyePos, this.voxelPos));
574
- });
575
- this.$l.color = getSkyView(this, this.params, this.eyePos, this.viewDir, this.maxDis, texTransmittanceLut, texMultiScatteringLut);
576
- this.$l.t1 = transmittanceToSky(this, this.params, this.eyePos, this.viewDir, texTransmittanceLut);
577
- this.$l.t2 = transmittanceToSky(this, this.params, this.voxelPos, this.viewDir, texTransmittanceLut);
578
- this.$l.t = pb.clamp(pb.div(this.t1, pb.max(this.t2, pb.vec3(0.0001))), pb.vec3(0), pb.vec3(1));
579
- this.$return(pb.vec4(this.color, pb.dot(this.t, pb.vec3(1 / 3, 1 / 3, 1 / 3))));
580
- });
581
- return scope[funcName](stParams, f2UV, f3VoxelDim, CAMERA_POS_Y);
582
- }
583
- /** @internal */ function skyViewLut(scope, stParams, f2UV, texTransmittanceLut, texMultiScatteringLut) {
584
- const pb = scope.$builder;
585
- const Params = getAtmosphereParamsStruct(pb);
586
- const funcName = 'v_skyViewLut';
587
- pb.func(funcName, [
588
- Params('params'),
589
- pb.vec2('uv'),
590
- pb.float('cameraPosY')
591
- ], function() {
592
- this.$l.viewDir = uvToViewDir(this, this.uv);
593
- this.$l.h = pb.add(this.params.plantRadius, pb.mul(this.cameraPosY, this.params.cameraHeightScale));
594
- this.$l.eyePos = pb.vec3(0, this.h, 0);
595
- this.$l.rgb = getSkyView(this, this.params, this.eyePos, this.viewDir, pb.float(-1), texTransmittanceLut, texMultiScatteringLut);
596
- this.$return(pb.vec4(this.rgb, 1));
597
- });
598
- return scope[funcName](stParams, f2UV, CAMERA_POS_Y);
599
- }
600
- /** @internal */ function multiScatteringLut(scope, stParams, f2UV, texTransmittanceLut) {
601
- const pb = scope.$builder;
602
- const Params = getAtmosphereParamsStruct(pb);
603
- const funcName = 'v_multiScatteringLut';
604
- pb.func(funcName, [
605
- Params('params'),
606
- pb.vec2('uv')
607
- ], function() {
608
- this.$l.mu_s = pb.sub(pb.mul(this.uv.x, 2), 1);
609
- this.$l.r = pb.add(pb.mul(this.uv.y, this.params.atmosphereHeight), this.params.plantRadius);
610
- this.$l.cosTheta = this.mu_s;
611
- this.$l.sinTheta = pb.sqrt(pb.sub(1, pb.mul(this.cosTheta, this.cosTheta)));
612
- this.$l.lightDir = pb.vec3(this.sinTheta, this.cosTheta, 0);
613
- this.$l.p = pb.vec3(0, this.r, 0);
614
- this.$l.rgb = integralMultiScattering(this, this.params, this.lightDir, this.p, texTransmittanceLut);
615
- this.$return(pb.vec4(this.rgb, 1));
616
- });
617
- return scope[funcName](stParams, f2UV);
618
- }
619
- /** @internal */ function transmittanceLut(scope, stParams, f2UV) {
620
- const pb = scope.$builder;
621
- const Params = getAtmosphereParamsStruct(pb);
622
- const funcName = 'transmittanceLut';
623
- pb.func(funcName, [
624
- Params('params'),
625
- pb.vec2('uv')
626
- ], function() {
627
- this.$l.color = pb.vec4(0, 0, 0, 1);
628
- this.$l.bottomRadius = this.params.plantRadius;
629
- this.$l.topRadius = pb.add(this.bottomRadius, this.params.atmosphereHeight);
630
- this.$l.lutParams = uvToTransmittanceLut(this, this.uv, this.bottomRadius, this.topRadius);
631
- this.$l.cos_theta = this.lutParams.x;
632
- this.$l.r = this.lutParams.y;
633
- this.$l.sin_theta = pb.sqrt(pb.sub(1, pb.mul(this.cos_theta, this.cos_theta)));
634
- this.$l.viewDir = pb.vec3(this.sin_theta, this.cos_theta, 0);
635
- this.$l.eyePos = pb.vec3(0, this.r, 0);
636
- this.$l.dis = rayIntersectSphere(this, pb.vec3(0), this.topRadius, this.eyePos, this.viewDir);
637
- this.$l.hitPoint = pb.add(this.eyePos, pb.mul(this.viewDir, this.dis));
638
- this.$return(pb.vec4(transmittance(this, this.params, this.eyePos, this.hitPoint), 1));
639
- });
640
- return scope[funcName](stParams, f2UV);
641
- }
642
- /** @internal */ function atmosphereLUTRendered() {
643
- return !!transmittanceLUT && !!multiScatteringLUT && !!skyViewLUT && !!ApLut;
644
- }
645
- /** @internal */ function renderAtmosphereLUTs(params) {
646
- const checkResult = checkParams(params);
647
- if (checkResult.transmittance || !transmittanceLUT) {
648
- renderTransmittanceLut(currentAtmosphereParams);
649
- }
650
- {
651
- renderMultiScatteringLut(currentAtmosphereParams);
652
- }
653
- if (checkResult.skyView || !skyViewLUT) {
654
- renderSkyViewLut(currentAtmosphereParams);
655
- }
656
- if (checkResult.aerialPerspective || !ApLut) {
657
- renderAPLut(currentAtmosphereParams);
658
- }
659
- }
660
- /* For debug */ let transmittanceLutProgram = undefined;
661
- let multiScatteringLutProgram = undefined;
662
- let skyViewLutProgram = undefined;
663
- let APLutProgram = undefined;
664
- let transmittanceLutBindGroup = undefined;
665
- let transmittanceLUT = undefined;
666
- let transmittanceFramebuffer = undefined;
667
- let multiScatteringLutBindGroup = undefined;
668
- let multiScatteringLUT = undefined;
669
- let uniformSphereSampleBuffer = undefined;
670
- let multiScatteringFramebuffer = undefined;
671
- let skyViewLutBindGroup = undefined;
672
- let skyViewLUT = undefined;
673
- let skyViewFramebuffer = undefined;
674
- let APLutBindGroup = undefined;
675
- let ApLut = undefined;
676
- let APFramebuffer = undefined;
677
- /** @internal */ function getTransmittanceLut() {
678
- return transmittanceLUT;
679
- }
680
- /** @internal */ function getMultiScatteringLut() {
681
- return multiScatteringLUT;
682
- }
683
- /** @internal */ function getSkyViewLut() {
684
- return skyViewLUT;
685
- }
686
- /** @internal */ function getAerialPerspectiveLut() {
687
- return ApLut;
688
- }
689
- /** @internal */ function getAtmosphereParamsStruct(pb) {
690
- return pb.defineStruct([
691
- pb.mat4('cameraWorldMatrix'),
692
- pb.vec4('lightColor'),
693
- pb.vec3('lightDir'),
694
- pb.float('cameraAspect'),
695
- pb.float('plantRadius'),
696
- pb.float('atmosphereHeight'),
697
- pb.float('rayleighScatteringHeight'),
698
- pb.float('mieScatteringHeight'),
699
- pb.float('mieAnstropy'),
700
- pb.float('ozoneCenter'),
701
- pb.float('ozoneWidth'),
702
- pb.float('apDistance'),
703
- pb.float('cameraHeightScale')
704
- ]);
705
- }
706
- /** @internal */ function createTransmittanceLutProgram(device) {
707
- return device.buildRenderProgram({
708
- vertex (pb) {
709
- this.flip = pb.int().uniform(0);
710
- this.$inputs.pos = pb.vec2().attrib('position');
711
- this.$outputs.uv = pb.vec2();
712
- pb.main(function() {
713
- this.$builtins.position = pb.vec4(this.$inputs.pos, 0, 1);
714
- this.$outputs.uv = pb.add(pb.mul(this.$inputs.pos.xy, 0.5), pb.vec2(0.5));
715
- this.$if(pb.notEqual(this.flip, 0), function() {
716
- this.$builtins.position.y = pb.neg(this.$builtins.position.y);
717
- });
718
- });
719
- },
720
- fragment (pb) {
721
- const Params = getAtmosphereParamsStruct(pb);
722
- this.params = Params().uniform(0);
723
- this.$outputs.outColor = pb.vec4();
724
- pb.main(function() {
725
- this.$outputs.outColor = transmittanceLut(this, this.params, this.$inputs.uv);
726
- });
727
- }
728
- });
729
- }
730
- /** @internal */ function renderTransmittanceLut(params) {
731
- const device = Application.instance.device;
732
- if (transmittanceLutProgram === undefined) {
733
- try {
734
- transmittanceLutProgram = createTransmittanceLutProgram(device);
735
- transmittanceLutBindGroup = device.createBindGroup(transmittanceLutProgram.bindGroupLayouts[0]);
736
- transmittanceLUT = device.createTexture2D('rgba16f', 256, 64, {
737
- samplerOptions: {
738
- mipFilter: 'none'
739
- }
740
- });
741
- transmittanceLUT.name = 'DebugTransmittanceLut';
742
- transmittanceFramebuffer = device.createFrameBuffer([
743
- transmittanceLUT
744
- ], null);
745
- } catch (err) {
746
- console.error(err);
747
- transmittanceLutProgram = null;
748
- transmittanceLutBindGroup = null;
749
- transmittanceFramebuffer = null;
750
- }
751
- }
752
- if (transmittanceLutProgram) {
753
- transmittanceLutBindGroup.setValue('flip', device.type === 'webgpu' ? 1 : 0);
754
- transmittanceLutBindGroup.setValue('params', params);
755
- device.pushDeviceStates();
756
- device.setFramebuffer(transmittanceFramebuffer);
757
- device.setProgram(transmittanceLutProgram);
758
- device.setBindGroup(0, transmittanceLutBindGroup);
759
- drawFullscreenQuad();
760
- device.popDeviceStates();
761
- }
762
- }
763
- /** @internal */ function createMultiScatteringLutProgram(device) {
764
- return device.buildRenderProgram({
765
- vertex (pb) {
766
- this.flip = pb.int().uniform(0);
767
- this.$inputs.pos = pb.vec2().attrib('position');
768
- this.$outputs.uv = pb.vec2();
769
- pb.main(function() {
770
- this.$builtins.position = pb.vec4(this.$inputs.pos, 0, 1);
771
- this.$outputs.uv = pb.add(pb.mul(this.$inputs.pos.xy, 0.5), pb.vec2(0.5));
772
- this.$if(pb.notEqual(this.flip, 0), function() {
773
- this.$builtins.position.y = pb.neg(this.$builtins.position.y);
774
- });
775
- });
776
- },
777
- fragment (pb) {
778
- const Params = getAtmosphereParamsStruct(pb);
779
- this.params = Params().uniform(0);
780
- this.uniformSphereSamples = pb.vec4[64]().uniformBuffer(0);
781
- this.transmittanceLut = pb.tex2D().uniform(0);
782
- this.$outputs.outColor = pb.vec4();
783
- pb.main(function() {
784
- this.$outputs.outColor = multiScatteringLut(this, this.params, this.$inputs.uv, this.transmittanceLut);
785
- });
786
- }
787
- });
788
- }
789
- /** @internal */ function renderMultiScatteringLut(params) {
790
- const device = Application.instance.device;
791
- if (multiScatteringLutProgram === undefined) {
792
- try {
793
- multiScatteringLutProgram = createMultiScatteringLutProgram(device);
794
- multiScatteringLutBindGroup = device.createBindGroup(multiScatteringLutProgram.bindGroupLayouts[0]);
795
- multiScatteringLUT = device.createTexture2D('rgba16f', 32, 32, {
796
- samplerOptions: {
797
- mipFilter: 'none'
798
- }
799
- });
800
- multiScatteringLUT.name = 'DebugMultiScatteringLut';
801
- multiScatteringFramebuffer = device.createFrameBuffer([
802
- multiScatteringLUT
803
- ], null);
804
- uniformSphereSampleBuffer = multiScatteringLutBindGroup.getBuffer('uniformSphereSamples', false);
805
- const sphereSamples = new Float32Array(64 * 4);
806
- for(let i = 0; i < 64; i++){
807
- sphereSamples[i * 4 + 0] = uniformSphereSamples[i].x;
808
- sphereSamples[i * 4 + 1] = uniformSphereSamples[i].y;
809
- sphereSamples[i * 4 + 2] = uniformSphereSamples[i].z;
810
- sphereSamples[i * 4 + 3] = 0;
811
- }
812
- uniformSphereSampleBuffer.bufferSubData(0, sphereSamples);
813
- } catch (err) {
814
- console.error(err);
815
- multiScatteringLutProgram = null;
816
- multiScatteringLutBindGroup = null;
817
- multiScatteringFramebuffer = null;
818
- }
819
- }
820
- if (multiScatteringLutProgram) {
821
- multiScatteringLutBindGroup.setValue('flip', device.type === 'webgpu' ? 1 : 0);
822
- multiScatteringLutBindGroup.setValue('params', params);
823
- //multiScatteringLutBindGroup.setBuffer('uniformSphereSamples', uniformSphereSampleBuffer);
824
- multiScatteringLutBindGroup.setTexture('transmittanceLut', transmittanceLUT, fetchSampler('clamp_linear_nomip'));
825
- device.pushDeviceStates();
826
- device.setFramebuffer(multiScatteringFramebuffer);
827
- device.setProgram(multiScatteringLutProgram);
828
- device.setBindGroup(0, multiScatteringLutBindGroup);
829
- drawFullscreenQuad();
830
- device.popDeviceStates();
831
- }
832
- }
833
- /** @internal */ function createSkyViewLutProgram(device) {
834
- return device.buildRenderProgram({
835
- vertex (pb) {
836
- this.flip = pb.int().uniform(0);
837
- this.$inputs.pos = pb.vec2().attrib('position');
838
- this.$outputs.uv = pb.vec2();
839
- pb.main(function() {
840
- this.$builtins.position = pb.vec4(this.$inputs.pos, 0, 1);
841
- this.$outputs.uv = pb.add(pb.mul(this.$inputs.pos.xy, 0.5), pb.vec2(0.5));
842
- this.$if(pb.notEqual(this.flip, 0), function() {
843
- this.$builtins.position.y = pb.neg(this.$builtins.position.y);
844
- });
845
- });
846
- },
847
- fragment (pb) {
848
- const Params = getAtmosphereParamsStruct(pb);
849
- this.params = Params().uniform(0);
850
- this.transmittanceLut = pb.tex2D().uniform(0);
851
- this.multiScatteringLut = pb.tex2D().uniform(0);
852
- this.$outputs.outColor = pb.vec4();
853
- pb.main(function() {
854
- this.$outputs.outColor = skyViewLut(this, this.params, this.$inputs.uv, this.transmittanceLut, this.multiScatteringLut);
855
- });
856
- }
857
- });
858
- }
859
- /** @internal */ function renderSkyViewLut(params) {
860
- const device = Application.instance.device;
861
- if (skyViewLutProgram === undefined) {
862
- try {
863
- skyViewLutProgram = createSkyViewLutProgram(device);
864
- skyViewLutBindGroup = device.createBindGroup(skyViewLutProgram.bindGroupLayouts[0]);
865
- skyViewLUT = device.createTexture2D('rgba16f', 256, 128, {
866
- samplerOptions: {
867
- mipFilter: 'none'
868
- }
869
- });
870
- skyViewLUT.name = 'DebugSkyViewLut';
871
- skyViewFramebuffer = device.createFrameBuffer([
872
- skyViewLUT
873
- ], null);
874
- } catch (err) {
875
- console.error(err);
876
- skyViewLutProgram = null;
877
- skyViewLutBindGroup = null;
878
- skyViewFramebuffer = null;
879
- }
880
- }
881
- if (skyViewLutProgram) {
882
- skyViewLutBindGroup.setValue('flip', device.type === 'webgpu' ? 1 : 0);
883
- skyViewLutBindGroup.setValue('params', params);
884
- skyViewLutBindGroup.setTexture('transmittanceLut', transmittanceLUT, fetchSampler('clamp_linear_nomip'));
885
- skyViewLutBindGroup.setTexture('multiScatteringLut', multiScatteringLUT, fetchSampler('clamp_linear_nomip'));
886
- device.pushDeviceStates();
887
- device.setFramebuffer(skyViewFramebuffer);
888
- device.setProgram(skyViewLutProgram);
889
- device.setBindGroup(0, skyViewLutBindGroup);
890
- drawFullscreenQuad();
891
- device.popDeviceStates();
892
- }
893
- }
894
- /** @internal */ function createAPLutProgram(device) {
895
- return device.buildRenderProgram({
896
- vertex (pb) {
897
- this.flip = pb.int().uniform(0);
898
- this.$inputs.pos = pb.vec2().attrib('position');
899
- this.$outputs.uv = pb.vec2();
900
- pb.main(function() {
901
- this.$builtins.position = pb.vec4(this.$inputs.pos, 0, 1);
902
- this.$outputs.uv = pb.add(pb.mul(this.$inputs.pos.xy, 0.5), pb.vec2(0.5));
903
- this.$if(pb.notEqual(this.flip, 0), function() {
904
- this.$builtins.position.y = pb.neg(this.$builtins.position.y);
905
- });
906
- });
907
- },
908
- fragment (pb) {
909
- const Params = getAtmosphereParamsStruct(pb);
910
- this.params = Params().uniform(0);
911
- this.transmittanceLut = pb.tex2D().uniform(0);
912
- this.multiScatteringLut = pb.tex2D().uniform(0);
913
- this.$outputs.outColor = pb.vec4();
914
- pb.main(function() {
915
- this.$outputs.outColor = aerialPerspectiveLut(this, this.params, this.$inputs.uv, pb.vec3(32, 32, 32), this.transmittanceLut, this.multiScatteringLut);
916
- });
917
- }
918
- });
919
- }
920
- /** @internal */ function renderAPLut(params) {
921
- const device = Application.instance.device;
922
- if (APLutProgram === undefined) {
923
- try {
924
- APLutProgram = createAPLutProgram(device);
925
- APLutBindGroup = device.createBindGroup(APLutProgram.bindGroupLayouts[0]);
926
- ApLut = device.createTexture2D('rgba16f', 32 * 32, 32, {
927
- samplerOptions: {
928
- mipFilter: 'none'
929
- }
930
- });
931
- ApLut.name = 'DebugAPLut';
932
- APFramebuffer = device.createFrameBuffer([
933
- ApLut
934
- ], null);
935
- } catch (err) {
936
- console.error(err);
937
- APLutProgram = null;
938
- APLutBindGroup = null;
939
- APFramebuffer = null;
940
- }
941
- }
942
- if (APLutProgram) {
943
- APLutBindGroup.setValue('flip', device.type === 'webgpu' ? 1 : 0);
944
- APLutBindGroup.setValue('params', params);
945
- APLutBindGroup.setTexture('transmittanceLut', transmittanceLUT, fetchSampler('clamp_linear_nomip'));
946
- APLutBindGroup.setTexture('multiScatteringLut', multiScatteringLUT, fetchSampler('clamp_linear_nomip'));
947
- device.pushDeviceStates();
948
- device.setFramebuffer(APFramebuffer);
949
- device.setProgram(APLutProgram);
950
- device.setBindGroup(0, APLutBindGroup);
951
- drawFullscreenQuad();
952
- device.popDeviceStates();
953
- }
954
- }
955
-
956
- export { CAMERA_POS_Y, aerialPerspective, aerialPerspectiveLut, atmosphereLUTRendered, createAPLutProgram, createMultiScatteringLutProgram, createSkyViewLutProgram, createTransmittanceLutProgram, getAerialPerspectiveLut, getAtmosphereParamsStruct, getDefaultAtmosphereParams, getMultiScattering, getMultiScatteringLut, getSkyView, getSkyViewLut, getTransmittanceLut, integralMultiScattering, mieAbsorption, mieCoefficient, miePhase, multiScatteringLut, ozoneAbsorption, rayIntersectSphere, rayleighCoefficient, rayleighPhase, renderAPLut, renderAtmosphereLUTs, renderMultiScatteringLut, renderSkyViewLut, renderTransmittanceLut, scattering, skyBox, skyViewLut, transmittance, transmittanceLut, transmittanceLutToUV, transmittanceToSky, uvToTransmittanceLut, uvToViewDir, viewDirToUV };
957
- //# sourceMappingURL=atmosphere.js.map