@zephyr3d/scene 0.6.0 → 0.7.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 (723) hide show
  1. package/README.md +1 -1
  2. package/dist/animation/animation.js +149 -27
  3. package/dist/animation/animation.js.map +1 -1
  4. package/dist/animation/animationset.js +173 -73
  5. package/dist/animation/animationset.js.map +1 -1
  6. package/dist/animation/animationtrack.js +65 -10
  7. package/dist/animation/animationtrack.js.map +1 -1
  8. package/dist/animation/eulerrotationtrack.js +41 -20
  9. package/dist/animation/eulerrotationtrack.js.map +1 -1
  10. package/dist/animation/morphtarget.js +14 -38
  11. package/dist/animation/morphtarget.js.map +1 -1
  12. package/dist/animation/morphtrack.js +59 -22
  13. package/dist/animation/morphtrack.js.map +1 -1
  14. package/dist/animation/proptrack.js +190 -0
  15. package/dist/animation/proptrack.js.map +1 -0
  16. package/dist/animation/rotationtrack.js +29 -11
  17. package/dist/animation/rotationtrack.js.map +1 -1
  18. package/dist/animation/scaletrack.js +29 -11
  19. package/dist/animation/scaletrack.js.map +1 -1
  20. package/dist/animation/skeleton.js +241 -78
  21. package/dist/animation/skeleton.js.map +1 -1
  22. package/dist/animation/translationtrack.js +30 -11
  23. package/dist/animation/translationtrack.js.map +1 -1
  24. package/dist/app/api.js +43 -0
  25. package/dist/app/api.js.map +1 -0
  26. package/dist/app/app.js +153 -0
  27. package/dist/app/app.js.map +1 -0
  28. package/dist/app/engine.js +312 -0
  29. package/dist/app/engine.js.map +1 -0
  30. package/dist/app/inputmgr.js +351 -0
  31. package/dist/app/inputmgr.js.map +1 -0
  32. package/dist/app/runtimescript.js +62 -0
  33. package/dist/app/runtimescript.js.map +1 -0
  34. package/dist/app/scriptingsystem.js +220 -0
  35. package/dist/app/scriptingsystem.js.map +1 -0
  36. package/dist/app/scriptregistry.js +432 -0
  37. package/dist/app/scriptregistry.js.map +1 -0
  38. package/dist/asset/assetmanager.js +772 -291
  39. package/dist/asset/assetmanager.js.map +1 -1
  40. package/dist/asset/builtin.js +7 -43
  41. package/dist/asset/builtin.js.map +1 -1
  42. package/dist/asset/loaders/dds/dds.js +17 -93
  43. package/dist/asset/loaders/dds/dds.js.map +1 -1
  44. package/dist/asset/loaders/dds/dds_loader.js +8 -18
  45. package/dist/asset/loaders/dds/dds_loader.js.map +1 -1
  46. package/dist/asset/loaders/gltf/gltf_loader.js +36 -42
  47. package/dist/asset/loaders/gltf/gltf_loader.js.map +1 -1
  48. package/dist/asset/loaders/gltf/helpers.js +27 -14
  49. package/dist/asset/loaders/gltf/helpers.js.map +1 -1
  50. package/dist/asset/loaders/hdr/hdr.js +17 -12
  51. package/dist/asset/loaders/hdr/hdr.js.map +1 -1
  52. package/dist/asset/loaders/image/tga_Loader.js +13 -16
  53. package/dist/asset/loaders/image/tga_Loader.js.map +1 -1
  54. package/dist/asset/loaders/image/webimage_loader.js +51 -50
  55. package/dist/asset/loaders/image/webimage_loader.js.map +1 -1
  56. package/dist/asset/loaders/loader.js.map +1 -1
  57. package/dist/asset/model.js +158 -4
  58. package/dist/asset/model.js.map +1 -1
  59. package/dist/blitter/bilateralblur.js +0 -1
  60. package/dist/blitter/bilateralblur.js.map +1 -1
  61. package/dist/blitter/blitter.js +22 -23
  62. package/dist/blitter/blitter.js.map +1 -1
  63. package/dist/blitter/box.js.map +1 -1
  64. package/dist/blitter/copy.js.map +1 -1
  65. package/dist/blitter/gaussianblur.js +23 -23
  66. package/dist/blitter/gaussianblur.js.map +1 -1
  67. package/dist/camera/base.js +141 -34
  68. package/dist/camera/base.js.map +1 -1
  69. package/dist/camera/camera.js +653 -149
  70. package/dist/camera/camera.js.map +1 -1
  71. package/dist/camera/fps.js +2 -10
  72. package/dist/camera/fps.js.map +1 -1
  73. package/dist/camera/orbit.js +132 -59
  74. package/dist/camera/orbit.js.map +1 -1
  75. package/dist/camera/orthocamera.js +37 -12
  76. package/dist/camera/orthocamera.js.map +1 -1
  77. package/dist/camera/perspectivecamera.js +37 -20
  78. package/dist/camera/perspectivecamera.js.map +1 -1
  79. package/dist/index.d.ts +18268 -6982
  80. package/dist/index.js +49 -16
  81. package/dist/index.js.map +1 -1
  82. package/dist/material/blinn.js +5 -0
  83. package/dist/material/blinn.js.map +1 -1
  84. package/dist/material/grassmaterial.js +6 -1
  85. package/dist/material/grassmaterial.js.map +1 -1
  86. package/dist/material/lambert.js +6 -1
  87. package/dist/material/lambert.js.map +1 -1
  88. package/dist/material/material.js +346 -73
  89. package/dist/material/material.js.map +1 -1
  90. package/dist/material/meshmaterial.js +498 -156
  91. package/dist/material/meshmaterial.js.map +1 -1
  92. package/dist/material/mixins/albedocolor.js +5 -1
  93. package/dist/material/mixins/albedocolor.js.map +1 -1
  94. package/dist/material/mixins/foliage.js +3 -3
  95. package/dist/material/mixins/foliage.js.map +1 -1
  96. package/dist/material/mixins/lightmodel/blinnphong.js +18 -5
  97. package/dist/material/mixins/lightmodel/blinnphong.js.map +1 -1
  98. package/dist/material/mixins/lightmodel/lambert.js +6 -6
  99. package/dist/material/mixins/lightmodel/lambert.js.map +1 -1
  100. package/dist/material/mixins/lightmodel/pbrblueprintmixin.js +235 -0
  101. package/dist/material/mixins/lightmodel/pbrblueprintmixin.js.map +1 -0
  102. package/dist/material/mixins/lightmodel/pbrmetallicroughness.js +52 -15
  103. package/dist/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -1
  104. package/dist/material/mixins/lightmodel/pbrspecularglossness.js +27 -9
  105. package/dist/material/mixins/lightmodel/pbrspecularglossness.js.map +1 -1
  106. package/dist/material/mixins/lit.js +16 -4
  107. package/dist/material/mixins/lit.js.map +1 -1
  108. package/dist/material/mixins/pbr/brdf.js +134 -0
  109. package/dist/material/mixins/pbr/brdf.js.map +1 -0
  110. package/dist/material/mixins/pbr/common.js +68 -85
  111. package/dist/material/mixins/pbr/common.js.map +1 -1
  112. package/dist/material/mixins/texture.js +98 -83
  113. package/dist/material/mixins/texture.js.map +1 -1
  114. package/dist/material/mixins/vertexcolor.js +6 -2
  115. package/dist/material/mixins/vertexcolor.js.map +1 -1
  116. package/dist/material/particle.js +272 -0
  117. package/dist/material/particle.js.map +1 -0
  118. package/dist/material/pbrblueprint.js +186 -0
  119. package/dist/material/pbrblueprint.js.map +1 -0
  120. package/dist/material/pbrmr.js +10 -0
  121. package/dist/material/pbrmr.js.map +1 -1
  122. package/dist/material/pbrsg.js +10 -0
  123. package/dist/material/pbrsg.js.map +1 -1
  124. package/dist/material/shader/helper.js +521 -287
  125. package/dist/material/shader/helper.js.map +1 -1
  126. package/dist/material/terrain-cm.js +607 -0
  127. package/dist/material/terrain-cm.js.map +1 -0
  128. package/dist/material/terrainmaterial.js +59 -54
  129. package/dist/material/terrainmaterial.js.map +1 -1
  130. package/dist/material/unlit.js +5 -0
  131. package/dist/material/unlit.js.map +1 -1
  132. package/dist/material/water.js +415 -0
  133. package/dist/material/water.js.map +1 -0
  134. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimemgr.js +38 -0
  135. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimemgr.js.map +1 -0
  136. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimescript.js +10 -0
  137. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimescript.js.map +1 -0
  138. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptingsystem.js +127 -0
  139. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptingsystem.js.map +1 -0
  140. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptregistry.js +263 -0
  141. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptregistry.js.map +1 -0
  142. package/dist/node_modules/es-module-lexer/dist/lexer.js +5 -0
  143. package/dist/node_modules/es-module-lexer/dist/lexer.js.map +1 -0
  144. package/dist/posteffect/bloom.js +39 -54
  145. package/dist/posteffect/bloom.js.map +1 -1
  146. package/dist/posteffect/compositor.js +95 -128
  147. package/dist/posteffect/compositor.js.map +1 -1
  148. package/dist/posteffect/fxaa.js +10 -18
  149. package/dist/posteffect/fxaa.js.map +1 -1
  150. package/dist/posteffect/grayscale.js +9 -17
  151. package/dist/posteffect/grayscale.js.map +1 -1
  152. package/dist/posteffect/motionblur.js +105 -0
  153. package/dist/posteffect/motionblur.js.map +1 -0
  154. package/dist/posteffect/posteffect.js +66 -35
  155. package/dist/posteffect/posteffect.js.map +1 -1
  156. package/dist/posteffect/sao.js +13 -21
  157. package/dist/posteffect/sao.js.map +1 -1
  158. package/dist/posteffect/ssr.js +60 -100
  159. package/dist/posteffect/ssr.js.map +1 -1
  160. package/dist/posteffect/taa.js +175 -0
  161. package/dist/posteffect/taa.js.map +1 -0
  162. package/dist/posteffect/tonemap.js +12 -20
  163. package/dist/posteffect/tonemap.js.map +1 -1
  164. package/dist/render/abuffer_oit.js +30 -19
  165. package/dist/render/abuffer_oit.js.map +1 -1
  166. package/dist/render/clipmap.js +429 -101
  167. package/dist/render/clipmap.js.map +1 -1
  168. package/dist/render/cluster_light.js +7 -5
  169. package/dist/render/cluster_light.js.map +1 -1
  170. package/dist/render/cull_visitor.js +43 -3
  171. package/dist/render/cull_visitor.js.map +1 -1
  172. package/dist/render/depthpass.js +14 -5
  173. package/dist/render/depthpass.js.map +1 -1
  174. package/dist/render/drawable_mixin.js +113 -40
  175. package/dist/render/drawable_mixin.js.map +1 -1
  176. package/dist/render/envlight.js +86 -141
  177. package/dist/render/envlight.js.map +1 -1
  178. package/dist/render/fbm_wavegenerator.js +234 -0
  179. package/dist/render/fbm_wavegenerator.js.map +1 -0
  180. package/dist/render/fft_wavegenerator.js +64 -50
  181. package/dist/render/fft_wavegenerator.js.map +1 -1
  182. package/dist/render/fullscreenquad.js +2 -2
  183. package/dist/render/fullscreenquad.js.map +1 -1
  184. package/dist/render/gerstner_wavegenerator.js +98 -48
  185. package/dist/render/gerstner_wavegenerator.js.map +1 -1
  186. package/dist/render/globalbindgroup_allocator.js +4 -2
  187. package/dist/render/globalbindgroup_allocator.js.map +1 -1
  188. package/dist/render/hzb.js +6 -3
  189. package/dist/render/hzb.js.map +1 -1
  190. package/dist/render/lightpass.js +19 -18
  191. package/dist/render/lightpass.js.map +1 -1
  192. package/dist/render/objectcolorpass.js +4 -4
  193. package/dist/render/objectcolorpass.js.map +1 -1
  194. package/dist/render/primitive.js +213 -104
  195. package/dist/render/primitive.js.map +1 -1
  196. package/dist/render/render_queue.js +40 -20
  197. package/dist/render/render_queue.js.map +1 -1
  198. package/dist/render/renderbundle_wrapper.js +65 -15
  199. package/dist/render/renderbundle_wrapper.js.map +1 -1
  200. package/dist/render/renderer.js +326 -185
  201. package/dist/render/renderer.js.map +1 -1
  202. package/dist/render/renderpass.js +20 -36
  203. package/dist/render/renderpass.js.map +1 -1
  204. package/dist/render/shadowmap_pass.js +3 -3
  205. package/dist/render/shadowmap_pass.js.map +1 -1
  206. package/dist/render/sky.js +864 -541
  207. package/dist/render/sky.js.map +1 -1
  208. package/dist/render/weightedblended_oit.js +13 -15
  209. package/dist/render/weightedblended_oit.js.map +1 -1
  210. package/dist/scene/batchgroup.js +18 -5
  211. package/dist/scene/batchgroup.js.map +1 -1
  212. package/dist/scene/environment.js +78 -48
  213. package/dist/scene/environment.js.map +1 -1
  214. package/dist/scene/graph_node.js +2 -3
  215. package/dist/scene/graph_node.js.map +1 -1
  216. package/dist/scene/light.js +28 -89
  217. package/dist/scene/light.js.map +1 -1
  218. package/dist/scene/mesh.js +218 -87
  219. package/dist/scene/mesh.js.map +1 -1
  220. package/dist/scene/octree.js +371 -162
  221. package/dist/scene/octree.js.map +1 -1
  222. package/dist/scene/particlesys.js +684 -0
  223. package/dist/scene/particlesys.js.map +1 -0
  224. package/dist/scene/raycast_visitor.js +34 -5
  225. package/dist/scene/raycast_visitor.js.map +1 -1
  226. package/dist/scene/scene.js +309 -85
  227. package/dist/scene/scene.js.map +1 -1
  228. package/dist/scene/scene_node.js +675 -102
  229. package/dist/scene/scene_node.js.map +1 -1
  230. package/dist/scene/terrain/grass.js +48 -49
  231. package/dist/scene/terrain/grass.js.map +1 -1
  232. package/dist/scene/terrain/heightfield.js +46 -44
  233. package/dist/scene/terrain/heightfield.js.map +1 -1
  234. package/dist/scene/terrain/patch.js +20 -29
  235. package/dist/scene/terrain/patch.js.map +1 -1
  236. package/dist/scene/terrain/quadtree.js +58 -27
  237. package/dist/scene/terrain/quadtree.js.map +1 -1
  238. package/dist/scene/terrain/terrain.js +31 -45
  239. package/dist/scene/terrain/terrain.js.map +1 -1
  240. package/dist/scene/terrain-cm/grass.js +603 -0
  241. package/dist/scene/terrain-cm/grass.js.map +1 -0
  242. package/dist/scene/terrain-cm/grassmaterial.js +160 -0
  243. package/dist/scene/terrain-cm/grassmaterial.js.map +1 -0
  244. package/dist/scene/terrain-cm/terrain-cm.js +533 -0
  245. package/dist/scene/terrain-cm/terrain-cm.js.map +1 -0
  246. package/dist/scene/water.js +378 -0
  247. package/dist/scene/water.js.map +1 -0
  248. package/dist/shaders/atmosphere.js +957 -0
  249. package/dist/shaders/atmosphere.js.map +1 -0
  250. package/dist/shaders/fog.js +116 -0
  251. package/dist/shaders/fog.js.map +1 -0
  252. package/dist/shaders/misc.js.map +1 -1
  253. package/dist/shaders/noise.js +217 -8
  254. package/dist/shaders/noise.js.map +1 -1
  255. package/dist/shaders/pbr.js.map +1 -1
  256. package/dist/shaders/shadow.js +8 -8
  257. package/dist/shaders/shadow.js.map +1 -1
  258. package/dist/shaders/ssr.js +87 -39
  259. package/dist/shaders/ssr.js.map +1 -1
  260. package/dist/shaders/temporal.js +216 -0
  261. package/dist/shaders/temporal.js.map +1 -0
  262. package/dist/shaders/water.js +42 -20
  263. package/dist/shaders/water.js.map +1 -1
  264. package/dist/shadow/esm.js +31 -13
  265. package/dist/shadow/esm.js.map +1 -1
  266. package/dist/shadow/pcf_opt.js +12 -13
  267. package/dist/shadow/pcf_opt.js.map +1 -1
  268. package/dist/shadow/pcf_pd.js +12 -13
  269. package/dist/shadow/pcf_pd.js.map +1 -1
  270. package/dist/shadow/shader.js +38 -0
  271. package/dist/shadow/shader.js.map +1 -0
  272. package/dist/shadow/shadow_impl.js.map +1 -1
  273. package/dist/shadow/shadowmapper.js +67 -26
  274. package/dist/shadow/shadowmapper.js.map +1 -1
  275. package/dist/shadow/ssm.js +15 -16
  276. package/dist/shadow/ssm.js.map +1 -1
  277. package/dist/shadow/vsm.js +33 -16
  278. package/dist/shadow/vsm.js.map +1 -1
  279. package/dist/shapes/box.js +181 -83
  280. package/dist/shapes/box.js.map +1 -1
  281. package/dist/shapes/cylinder.js +101 -43
  282. package/dist/shapes/cylinder.js.map +1 -1
  283. package/dist/shapes/plane.js +70 -29
  284. package/dist/shapes/plane.js.map +1 -1
  285. package/dist/shapes/shape.js +120 -17
  286. package/dist/shapes/shape.js.map +1 -1
  287. package/dist/shapes/sphere.js +78 -44
  288. package/dist/shapes/sphere.js.map +1 -1
  289. package/dist/shapes/tetrahedron.js +256 -0
  290. package/dist/shapes/tetrahedron.js.map +1 -0
  291. package/dist/shapes/torus.js +76 -55
  292. package/dist/shapes/torus.js.map +1 -1
  293. package/dist/src/animation/animation.js +127 -0
  294. package/dist/src/animation/animation.js.map +1 -0
  295. package/dist/src/animation/animationset.js +255 -0
  296. package/dist/src/animation/animationset.js.map +1 -0
  297. package/dist/src/animation/animationtrack.js +34 -0
  298. package/dist/src/animation/animationtrack.js.map +1 -0
  299. package/dist/src/animation/eulerrotationtrack.js +52 -0
  300. package/dist/src/animation/eulerrotationtrack.js.map +1 -0
  301. package/dist/src/animation/morphtarget.js +93 -0
  302. package/dist/src/animation/morphtarget.js.map +1 -0
  303. package/dist/src/animation/morphtrack.js +70 -0
  304. package/dist/src/animation/morphtrack.js.map +1 -0
  305. package/dist/src/animation/proptrack.js +161 -0
  306. package/dist/src/animation/proptrack.js.map +1 -0
  307. package/dist/src/animation/rotationtrack.js +51 -0
  308. package/dist/src/animation/rotationtrack.js.map +1 -0
  309. package/dist/src/animation/scaletrack.js +50 -0
  310. package/dist/src/animation/scaletrack.js.map +1 -0
  311. package/dist/src/animation/skeleton.js +204 -0
  312. package/dist/src/animation/skeleton.js.map +1 -0
  313. package/dist/src/animation/translationtrack.js +50 -0
  314. package/dist/src/animation/translationtrack.js.map +1 -0
  315. package/dist/{app.js → src/app/app.js} +18 -40
  316. package/dist/src/app/app.js.map +1 -0
  317. package/dist/{input → src/app}/inputmgr.js +41 -16
  318. package/dist/src/app/inputmgr.js.map +1 -0
  319. package/dist/src/asset/assetmanager.js +404 -0
  320. package/dist/src/asset/assetmanager.js.map +1 -0
  321. package/dist/src/asset/builtin.js +337 -0
  322. package/dist/src/asset/builtin.js.map +1 -0
  323. package/dist/src/asset/loaders/dds/dds.js +470 -0
  324. package/dist/src/asset/loaders/dds/dds.js.map +1 -0
  325. package/dist/src/asset/loaders/dds/dds_loader.js +28 -0
  326. package/dist/src/asset/loaders/dds/dds_loader.js.map +1 -0
  327. package/dist/src/asset/loaders/gltf/gltf_loader.js +1265 -0
  328. package/dist/src/asset/loaders/gltf/gltf_loader.js.map +1 -0
  329. package/dist/src/asset/loaders/gltf/helpers.js +327 -0
  330. package/dist/src/asset/loaders/gltf/helpers.js.map +1 -0
  331. package/dist/src/asset/loaders/hdr/hdr.js +180 -0
  332. package/dist/src/asset/loaders/hdr/hdr.js.map +1 -0
  333. package/dist/src/asset/loaders/image/tga_Loader.js +116 -0
  334. package/dist/src/asset/loaders/image/tga_Loader.js.map +1 -0
  335. package/dist/src/asset/loaders/image/webimage_loader.js +63 -0
  336. package/dist/src/asset/loaders/image/webimage_loader.js.map +1 -0
  337. package/dist/src/asset/loaders/loader.js +45 -0
  338. package/dist/src/asset/loaders/loader.js.map +1 -0
  339. package/dist/src/asset/model.js +414 -0
  340. package/dist/src/asset/model.js.map +1 -0
  341. package/dist/{blitter/depthlimitedgaussion.js → src/blitter/bilateralblur.js} +1 -2
  342. package/dist/src/blitter/bilateralblur.js.map +1 -0
  343. package/dist/src/blitter/blitter.js +390 -0
  344. package/dist/src/blitter/blitter.js.map +1 -0
  345. package/dist/src/blitter/box.js +118 -0
  346. package/dist/src/blitter/box.js.map +1 -0
  347. package/dist/src/blitter/copy.js +22 -0
  348. package/dist/src/blitter/copy.js.map +1 -0
  349. package/dist/src/blitter/gaussianblur.js +228 -0
  350. package/dist/src/blitter/gaussianblur.js.map +1 -0
  351. package/dist/src/camera/base.js +92 -0
  352. package/dist/src/camera/base.js.map +1 -0
  353. package/dist/src/camera/camera.js +1005 -0
  354. package/dist/src/camera/camera.js.map +1 -0
  355. package/dist/src/camera/fps.js +238 -0
  356. package/dist/src/camera/fps.js.map +1 -0
  357. package/dist/src/camera/orbit.js +245 -0
  358. package/dist/src/camera/orbit.js.map +1 -0
  359. package/dist/src/camera/orthocamera.js +167 -0
  360. package/dist/src/camera/orthocamera.js.map +1 -0
  361. package/dist/src/camera/perspectivecamera.js +141 -0
  362. package/dist/src/camera/perspectivecamera.js.map +1 -0
  363. package/dist/src/index.js +120 -0
  364. package/dist/src/index.js.map +1 -0
  365. package/dist/src/material/blinn.js +81 -0
  366. package/dist/src/material/blinn.js.map +1 -0
  367. package/dist/src/material/grassmaterial.js +113 -0
  368. package/dist/src/material/grassmaterial.js.map +1 -0
  369. package/dist/src/material/lambert.js +92 -0
  370. package/dist/src/material/lambert.js.map +1 -0
  371. package/dist/src/material/material.js +301 -0
  372. package/dist/src/material/material.js.map +1 -0
  373. package/dist/src/material/meshmaterial.js +704 -0
  374. package/dist/src/material/meshmaterial.js.map +1 -0
  375. package/dist/src/material/mixins/albedocolor.js +76 -0
  376. package/dist/src/material/mixins/albedocolor.js.map +1 -0
  377. package/dist/src/material/mixins/foliage.js +47 -0
  378. package/dist/src/material/mixins/foliage.js.map +1 -0
  379. package/dist/src/material/mixins/lightmodel/blinnphong.js +112 -0
  380. package/dist/src/material/mixins/lightmodel/blinnphong.js.map +1 -0
  381. package/dist/src/material/mixins/lightmodel/lambert.js +58 -0
  382. package/dist/src/material/mixins/lightmodel/lambert.js.map +1 -0
  383. package/dist/src/material/mixins/lightmodel/pbrmetallicroughness.js +178 -0
  384. package/dist/src/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -0
  385. package/dist/src/material/mixins/lightmodel/pbrspecularglossness.js +139 -0
  386. package/dist/src/material/mixins/lightmodel/pbrspecularglossness.js.map +1 -0
  387. package/dist/src/material/mixins/lit.js +476 -0
  388. package/dist/src/material/mixins/lit.js.map +1 -0
  389. package/dist/src/material/mixins/pbr/common.js +918 -0
  390. package/dist/src/material/mixins/pbr/common.js.map +1 -0
  391. package/dist/src/material/mixins/texture.js +172 -0
  392. package/dist/src/material/mixins/texture.js.map +1 -0
  393. package/dist/src/material/mixins/vertexcolor.js +56 -0
  394. package/dist/src/material/mixins/vertexcolor.js.map +1 -0
  395. package/dist/src/material/particle.js +178 -0
  396. package/dist/src/material/particle.js.map +1 -0
  397. package/dist/src/material/pbrmr.js +97 -0
  398. package/dist/src/material/pbrmr.js.map +1 -0
  399. package/dist/src/material/pbrsg.js +97 -0
  400. package/dist/src/material/pbrsg.js.map +1 -0
  401. package/dist/src/material/shader/helper.js +1209 -0
  402. package/dist/src/material/shader/helper.js.map +1 -0
  403. package/dist/src/material/terrain-cm.js +606 -0
  404. package/dist/src/material/terrain-cm.js.map +1 -0
  405. package/dist/src/material/terrainmaterial.js +375 -0
  406. package/dist/src/material/terrainmaterial.js.map +1 -0
  407. package/dist/src/material/unlit.js +41 -0
  408. package/dist/src/material/unlit.js.map +1 -0
  409. package/dist/src/material/water.js +417 -0
  410. package/dist/src/material/water.js.map +1 -0
  411. package/dist/src/posteffect/bloom.js +361 -0
  412. package/dist/src/posteffect/bloom.js.map +1 -0
  413. package/dist/src/posteffect/compositor.js +226 -0
  414. package/dist/src/posteffect/compositor.js.map +1 -0
  415. package/dist/src/posteffect/fxaa.js +273 -0
  416. package/dist/src/posteffect/fxaa.js.map +1 -0
  417. package/dist/src/posteffect/grayscale.js +69 -0
  418. package/dist/src/posteffect/grayscale.js.map +1 -0
  419. package/dist/src/posteffect/motionblur.js +96 -0
  420. package/dist/src/posteffect/motionblur.js.map +1 -0
  421. package/dist/src/posteffect/posteffect.js +126 -0
  422. package/dist/src/posteffect/posteffect.js.map +1 -0
  423. package/dist/src/posteffect/sao.js +324 -0
  424. package/dist/src/posteffect/sao.js.map +1 -0
  425. package/dist/src/posteffect/ssr.js +489 -0
  426. package/dist/src/posteffect/ssr.js.map +1 -0
  427. package/dist/src/posteffect/taa.js +172 -0
  428. package/dist/src/posteffect/taa.js.map +1 -0
  429. package/dist/src/posteffect/tonemap.js +94 -0
  430. package/dist/src/posteffect/tonemap.js.map +1 -0
  431. package/dist/src/render/abuffer_oit.js +361 -0
  432. package/dist/src/render/abuffer_oit.js.map +1 -0
  433. package/dist/src/render/clipmap.js +851 -0
  434. package/dist/src/render/clipmap.js.map +1 -0
  435. package/dist/src/render/cluster_light.js +333 -0
  436. package/dist/src/render/cluster_light.js.map +1 -0
  437. package/dist/src/render/cull_visitor.js +187 -0
  438. package/dist/src/render/cull_visitor.js.map +1 -0
  439. package/dist/src/render/depthpass.js +68 -0
  440. package/dist/src/render/depthpass.js.map +1 -0
  441. package/dist/src/render/drawable_mixin.js +227 -0
  442. package/dist/src/render/drawable_mixin.js.map +1 -0
  443. package/dist/src/render/envlight.js +463 -0
  444. package/dist/src/render/envlight.js.map +1 -0
  445. package/dist/src/render/fbm_wavegenerator.js +251 -0
  446. package/dist/src/render/fbm_wavegenerator.js.map +1 -0
  447. package/dist/src/render/fft_wavegenerator.js +1006 -0
  448. package/dist/src/render/fft_wavegenerator.js.map +1 -0
  449. package/dist/src/render/fullscreenquad.js +38 -0
  450. package/dist/src/render/fullscreenquad.js.map +1 -0
  451. package/dist/src/render/gerstner_wavegenerator.js +314 -0
  452. package/dist/src/render/gerstner_wavegenerator.js.map +1 -0
  453. package/dist/src/render/globalbindgroup_allocator.js +60 -0
  454. package/dist/src/render/globalbindgroup_allocator.js.map +1 -0
  455. package/dist/src/render/hzb.js +273 -0
  456. package/dist/src/render/hzb.js.map +1 -0
  457. package/dist/src/render/lightpass.js +172 -0
  458. package/dist/src/render/lightpass.js.map +1 -0
  459. package/dist/src/render/objectcolorpass.js +51 -0
  460. package/dist/src/render/objectcolorpass.js.map +1 -0
  461. package/dist/src/render/primitive.js +364 -0
  462. package/dist/src/render/primitive.js.map +1 -0
  463. package/dist/src/render/render_queue.js +467 -0
  464. package/dist/src/render/render_queue.js.map +1 -0
  465. package/dist/src/render/renderbundle_wrapper.js +152 -0
  466. package/dist/src/render/renderbundle_wrapper.js.map +1 -0
  467. package/dist/src/render/renderer.js +455 -0
  468. package/dist/src/render/renderer.js.map +1 -0
  469. package/dist/src/render/renderpass.js +200 -0
  470. package/dist/src/render/renderpass.js.map +1 -0
  471. package/dist/src/render/shadowmap_pass.js +56 -0
  472. package/dist/src/render/shadowmap_pass.js.map +1 -0
  473. package/dist/src/render/sky.js +1103 -0
  474. package/dist/src/render/sky.js.map +1 -0
  475. package/dist/src/render/weightedblended_oit.js +168 -0
  476. package/dist/src/render/weightedblended_oit.js.map +1 -0
  477. package/dist/src/scene/batchgroup.js +162 -0
  478. package/dist/src/scene/batchgroup.js.map +1 -0
  479. package/dist/src/scene/environment.js +209 -0
  480. package/dist/src/scene/environment.js.map +1 -0
  481. package/dist/src/scene/graph_node.js +72 -0
  482. package/dist/src/scene/graph_node.js.map +1 -0
  483. package/dist/src/scene/light.js +416 -0
  484. package/dist/src/scene/light.js.map +1 -0
  485. package/dist/src/scene/mesh.js +341 -0
  486. package/dist/src/scene/mesh.js.map +1 -0
  487. package/dist/src/scene/octree.js +649 -0
  488. package/dist/src/scene/octree.js.map +1 -0
  489. package/dist/src/scene/particlesys.js +738 -0
  490. package/dist/src/scene/particlesys.js.map +1 -0
  491. package/dist/src/scene/raycast_visitor.js +103 -0
  492. package/dist/src/scene/raycast_visitor.js.map +1 -0
  493. package/dist/src/scene/scene.js +284 -0
  494. package/dist/src/scene/scene.js.map +1 -0
  495. package/dist/src/scene/scene_node.js +732 -0
  496. package/dist/src/scene/scene_node.js.map +1 -0
  497. package/dist/src/scene/terrain/grass.js +278 -0
  498. package/dist/src/scene/terrain/grass.js.map +1 -0
  499. package/dist/src/scene/terrain/heightfield.js +475 -0
  500. package/dist/src/scene/terrain/heightfield.js.map +1 -0
  501. package/dist/src/scene/terrain/patch.js +530 -0
  502. package/dist/src/scene/terrain/patch.js.map +1 -0
  503. package/dist/src/scene/terrain/quadtree.js +461 -0
  504. package/dist/src/scene/terrain/quadtree.js.map +1 -0
  505. package/dist/src/scene/terrain/terrain.js +246 -0
  506. package/dist/src/scene/terrain/terrain.js.map +1 -0
  507. package/dist/src/scene/terrain-cm/grass.js +594 -0
  508. package/dist/src/scene/terrain-cm/grass.js.map +1 -0
  509. package/dist/src/scene/terrain-cm/grassmaterial.js +159 -0
  510. package/dist/src/scene/terrain-cm/grassmaterial.js.map +1 -0
  511. package/dist/src/scene/terrain-cm/terrain-cm.js +538 -0
  512. package/dist/src/scene/terrain-cm/terrain-cm.js.map +1 -0
  513. package/dist/src/scene/water.js +374 -0
  514. package/dist/src/scene/water.js.map +1 -0
  515. package/dist/src/shaders/atmosphere.js +957 -0
  516. package/dist/src/shaders/atmosphere.js.map +1 -0
  517. package/dist/src/shaders/fog.js +112 -0
  518. package/dist/src/shaders/fog.js.map +1 -0
  519. package/dist/src/shaders/misc.js +266 -0
  520. package/dist/src/shaders/misc.js.map +1 -0
  521. package/dist/src/shaders/noise.js +222 -0
  522. package/dist/src/shaders/noise.js.map +1 -0
  523. package/dist/src/shaders/pbr.js +51 -0
  524. package/dist/src/shaders/pbr.js.map +1 -0
  525. package/dist/src/shaders/shadow.js +636 -0
  526. package/dist/src/shaders/shadow.js.map +1 -0
  527. package/dist/src/shaders/ssr.js +490 -0
  528. package/dist/src/shaders/ssr.js.map +1 -0
  529. package/dist/src/shaders/temporal.js +215 -0
  530. package/dist/src/shaders/temporal.js.map +1 -0
  531. package/dist/src/shaders/water.js +756 -0
  532. package/dist/src/shaders/water.js.map +1 -0
  533. package/dist/src/shadow/esm.js +237 -0
  534. package/dist/src/shadow/esm.js.map +1 -0
  535. package/dist/src/shadow/pcf_opt.js +181 -0
  536. package/dist/src/shadow/pcf_opt.js.map +1 -0
  537. package/dist/src/shadow/pcf_pd.js +189 -0
  538. package/dist/src/shadow/pcf_pd.js.map +1 -0
  539. package/dist/src/shadow/shader.js +37 -0
  540. package/dist/src/shadow/shader.js.map +1 -0
  541. package/dist/src/shadow/shadow_impl.js +15 -0
  542. package/dist/src/shadow/shadow_impl.js.map +1 -0
  543. package/dist/src/shadow/shadowmapper.js +790 -0
  544. package/dist/src/shadow/shadowmapper.js.map +1 -0
  545. package/dist/src/shadow/ssm.js +159 -0
  546. package/dist/src/shadow/ssm.js.map +1 -0
  547. package/dist/src/shadow/vsm.js +297 -0
  548. package/dist/src/shadow/vsm.js.map +1 -0
  549. package/dist/src/shapes/box.js +386 -0
  550. package/dist/src/shapes/box.js.map +1 -0
  551. package/dist/src/shapes/cylinder.js +125 -0
  552. package/dist/src/shapes/cylinder.js.map +1 -0
  553. package/dist/src/shapes/plane.js +88 -0
  554. package/dist/src/shapes/plane.js.map +1 -0
  555. package/dist/src/shapes/shape.js +87 -0
  556. package/dist/src/shapes/shape.js.map +1 -0
  557. package/dist/src/shapes/sphere.js +114 -0
  558. package/dist/src/shapes/sphere.js.map +1 -0
  559. package/dist/src/shapes/tetrahedron.js +188 -0
  560. package/dist/src/shapes/tetrahedron.js.map +1 -0
  561. package/dist/src/shapes/torus.js +111 -0
  562. package/dist/src/shapes/torus.js.map +1 -0
  563. package/dist/src/utility/aabbtree.js +400 -0
  564. package/dist/src/utility/aabbtree.js.map +1 -0
  565. package/dist/src/utility/bounding_volume.js +29 -0
  566. package/dist/src/utility/bounding_volume.js.map +1 -0
  567. package/dist/src/utility/debug.js +28 -0
  568. package/dist/src/utility/debug.js.map +1 -0
  569. package/dist/src/utility/draco/decoder.js +116 -0
  570. package/dist/src/utility/draco/decoder.js.map +1 -0
  571. package/dist/src/utility/misc.js +105 -0
  572. package/dist/src/utility/misc.js.map +1 -0
  573. package/dist/src/utility/panorama.js +163 -0
  574. package/dist/src/utility/panorama.js.map +1 -0
  575. package/dist/src/utility/pmrem.js +354 -0
  576. package/dist/src/utility/pmrem.js.map +1 -0
  577. package/dist/src/utility/rendermipmap.js +115 -0
  578. package/dist/src/utility/rendermipmap.js.map +1 -0
  579. package/dist/src/utility/serialization/json.js +402 -0
  580. package/dist/src/utility/serialization/json.js.map +1 -0
  581. package/dist/src/utility/serialization/manager.js +623 -0
  582. package/dist/src/utility/serialization/manager.js.map +1 -0
  583. package/dist/src/utility/serialization/scene/animation.js +248 -0
  584. package/dist/src/utility/serialization/scene/animation.js.map +1 -0
  585. package/dist/src/utility/serialization/scene/batch.js +59 -0
  586. package/dist/src/utility/serialization/scene/batch.js.map +1 -0
  587. package/dist/src/utility/serialization/scene/camera.js +790 -0
  588. package/dist/src/utility/serialization/scene/camera.js.map +1 -0
  589. package/dist/src/utility/serialization/scene/common.js +222 -0
  590. package/dist/src/utility/serialization/scene/common.js.map +1 -0
  591. package/dist/src/utility/serialization/scene/light.js +575 -0
  592. package/dist/src/utility/serialization/scene/light.js.map +1 -0
  593. package/dist/src/utility/serialization/scene/material.js +1111 -0
  594. package/dist/src/utility/serialization/scene/material.js.map +1 -0
  595. package/dist/src/utility/serialization/scene/mesh.js +148 -0
  596. package/dist/src/utility/serialization/scene/mesh.js.map +1 -0
  597. package/dist/src/utility/serialization/scene/misc.js +39 -0
  598. package/dist/src/utility/serialization/scene/misc.js.map +1 -0
  599. package/dist/src/utility/serialization/scene/node.js +451 -0
  600. package/dist/src/utility/serialization/scene/node.js.map +1 -0
  601. package/dist/src/utility/serialization/scene/particle.js +425 -0
  602. package/dist/src/utility/serialization/scene/particle.js.map +1 -0
  603. package/dist/src/utility/serialization/scene/primitive.js +692 -0
  604. package/dist/src/utility/serialization/scene/primitive.js.map +1 -0
  605. package/dist/src/utility/serialization/scene/scene.js +704 -0
  606. package/dist/src/utility/serialization/scene/scene.js.map +1 -0
  607. package/dist/src/utility/serialization/scene/terrain.js +488 -0
  608. package/dist/src/utility/serialization/scene/terrain.js.map +1 -0
  609. package/dist/src/utility/serialization/scene/water.js +465 -0
  610. package/dist/src/utility/serialization/scene/water.js.map +1 -0
  611. package/dist/src/utility/shprojector.js +297 -0
  612. package/dist/src/utility/shprojector.js.map +1 -0
  613. package/dist/{material/mixins → src/utility/textures}/ggxlut.js +1 -1
  614. package/dist/src/utility/textures/ggxlut.js.map +1 -0
  615. package/dist/src/utility/textures/gradientnoise.js +62 -0
  616. package/dist/src/utility/textures/gradientnoise.js.map +1 -0
  617. package/dist/src/utility/textures/randomnoise.js +41 -0
  618. package/dist/src/utility/textures/randomnoise.js.map +1 -0
  619. package/dist/src/values.js +162 -0
  620. package/dist/src/values.js.map +1 -0
  621. package/dist/utility/aabbtree.js +15 -5
  622. package/dist/utility/aabbtree.js.map +1 -1
  623. package/dist/utility/blueprint/common/constants.js +851 -0
  624. package/dist/utility/blueprint/common/constants.js.map +1 -0
  625. package/dist/utility/blueprint/common/math.js +2045 -0
  626. package/dist/utility/blueprint/common/math.js.map +1 -0
  627. package/dist/utility/blueprint/common.js +7 -0
  628. package/dist/utility/blueprint/common.js.map +1 -0
  629. package/dist/utility/blueprint/material/common.js +7 -0
  630. package/dist/utility/blueprint/material/common.js.map +1 -0
  631. package/dist/utility/blueprint/material/func.js +521 -0
  632. package/dist/utility/blueprint/material/func.js.map +1 -0
  633. package/dist/utility/blueprint/material/inputs.js +1659 -0
  634. package/dist/utility/blueprint/material/inputs.js.map +1 -0
  635. package/dist/utility/blueprint/material/ir.js +1311 -0
  636. package/dist/utility/blueprint/material/ir.js.map +1 -0
  637. package/dist/utility/blueprint/material/pbr.js +362 -0
  638. package/dist/utility/blueprint/material/pbr.js.map +1 -0
  639. package/dist/utility/blueprint/material/texture.js +1099 -0
  640. package/dist/utility/blueprint/material/texture.js.map +1 -0
  641. package/dist/utility/blueprint/node.js +187 -0
  642. package/dist/utility/blueprint/node.js.map +1 -0
  643. package/dist/utility/bounding_volume.js +0 -1
  644. package/dist/utility/bounding_volume.js.map +1 -1
  645. package/dist/utility/debug.js +26 -0
  646. package/dist/utility/debug.js.map +1 -0
  647. package/dist/utility/draco/decoder.js +1 -1
  648. package/dist/utility/draco/decoder.js.map +1 -1
  649. package/dist/utility/misc.js +18 -6
  650. package/dist/utility/misc.js.map +1 -1
  651. package/dist/utility/panorama.js +8 -6
  652. package/dist/utility/panorama.js.map +1 -1
  653. package/dist/utility/pmrem.js +30 -18
  654. package/dist/utility/pmrem.js.map +1 -1
  655. package/dist/utility/rendermipmap.js +116 -0
  656. package/dist/utility/rendermipmap.js.map +1 -0
  657. package/dist/utility/serialization/blueprint/constants.js +255 -0
  658. package/dist/utility/serialization/blueprint/constants.js.map +1 -0
  659. package/dist/utility/serialization/blueprint/material/constants.js +203 -0
  660. package/dist/utility/serialization/blueprint/material/constants.js.map +1 -0
  661. package/dist/utility/serialization/blueprint/material/texture.js +165 -0
  662. package/dist/utility/serialization/blueprint/material/texture.js.map +1 -0
  663. package/dist/utility/serialization/json.js +402 -0
  664. package/dist/utility/serialization/json.js.map +1 -0
  665. package/dist/utility/serialization/manager.js +1176 -0
  666. package/dist/utility/serialization/manager.js.map +1 -0
  667. package/dist/utility/serialization/scene/animation.js +699 -0
  668. package/dist/utility/serialization/scene/animation.js.map +1 -0
  669. package/dist/utility/serialization/scene/batch.js +53 -0
  670. package/dist/utility/serialization/scene/batch.js.map +1 -0
  671. package/dist/utility/serialization/scene/camera.js +808 -0
  672. package/dist/utility/serialization/scene/camera.js.map +1 -0
  673. package/dist/utility/serialization/scene/common.js +224 -0
  674. package/dist/utility/serialization/scene/common.js.map +1 -0
  675. package/dist/utility/serialization/scene/light.js +589 -0
  676. package/dist/utility/serialization/scene/light.js.map +1 -0
  677. package/dist/utility/serialization/scene/material.js +942 -0
  678. package/dist/utility/serialization/scene/material.js.map +1 -0
  679. package/dist/utility/serialization/scene/mesh.js +374 -0
  680. package/dist/utility/serialization/scene/mesh.js.map +1 -0
  681. package/dist/utility/serialization/scene/misc.js +39 -0
  682. package/dist/utility/serialization/scene/misc.js.map +1 -0
  683. package/dist/utility/serialization/scene/node.js +391 -0
  684. package/dist/utility/serialization/scene/node.js.map +1 -0
  685. package/dist/utility/serialization/scene/particle.js +425 -0
  686. package/dist/utility/serialization/scene/particle.js.map +1 -0
  687. package/dist/utility/serialization/scene/primitive.js +582 -0
  688. package/dist/utility/serialization/scene/primitive.js.map +1 -0
  689. package/dist/utility/serialization/scene/scene.js +763 -0
  690. package/dist/utility/serialization/scene/scene.js.map +1 -0
  691. package/dist/utility/serialization/scene/terrain.js +495 -0
  692. package/dist/utility/serialization/scene/terrain.js.map +1 -0
  693. package/dist/utility/serialization/scene/water.js +465 -0
  694. package/dist/utility/serialization/scene/water.js.map +1 -0
  695. package/dist/utility/shprojector.js +313 -0
  696. package/dist/utility/shprojector.js.map +1 -0
  697. package/dist/utility/textures/ggxlut.js +4 -5
  698. package/dist/utility/textures/ggxlut.js.map +1 -1
  699. package/dist/utility/textures/gradientnoise.js +2 -1
  700. package/dist/utility/textures/gradientnoise.js.map +1 -1
  701. package/dist/utility/textures/randomnoise.js +1 -0
  702. package/dist/utility/textures/randomnoise.js.map +1 -1
  703. package/dist/values.js +91 -4
  704. package/dist/values.js.map +1 -1
  705. package/package.json +29 -15
  706. package/dist/app.js.map +0 -1
  707. package/dist/blitter/depthlimitedgaussion.js.map +0 -1
  708. package/dist/input/inputmgr.js.map +0 -1
  709. package/dist/material/mixins/ggxlut.js.map +0 -1
  710. package/dist/posteffect/water.js +0 -508
  711. package/dist/posteffect/water.js.map +0 -1
  712. package/dist/render/oit.js +0 -16
  713. package/dist/render/oit.js.map +0 -1
  714. package/dist/render/scatteringlut.js +0 -634
  715. package/dist/render/scatteringlut.js.map +0 -1
  716. package/dist/render/watermesh.js +0 -193
  717. package/dist/render/watermesh.js.map +0 -1
  718. package/dist/render/wavegenerator.js +0 -8
  719. package/dist/render/wavegenerator.js.map +0 -1
  720. package/dist/scene/xform.js +0 -247
  721. package/dist/scene/xform.js.map +0 -1
  722. package/dist/utility/shprojection.js +0 -442
  723. package/dist/utility/shprojection.js.map +0 -1
@@ -1,101 +1,143 @@
1
- import { Application } from '../app.js';
2
- import { decodeNormalizedFloatFromRGBA, linearToGamma } from '../shaders/misc.js';
1
+ import { linearToGamma } from '../shaders/misc.js';
3
2
  import { smoothNoise3D } from '../shaders/noise.js';
4
- import { Matrix4x4, Vector4, Vector2, Vector3, CubeFace } from '@zephyr3d/base';
5
- import '@zephyr3d/device';
3
+ import { getDevice, getEngine } from '../app/api.js';
4
+ import { getDefaultAtmosphereParams, getAerialPerspectiveLut, renderAtmosphereLUTs, getAtmosphereParamsStruct, createTransmittanceLutProgram, createMultiScatteringLutProgram, createSkyViewLutProgram, createAPLutProgram, skyBox, atmosphereLUTRendered, getTransmittanceLut, getSkyViewLut } from '../shaders/atmosphere.js';
5
+ import { Matrix4x4, Disposable, DRef, Vector4, Vector2, Vector3, CubeFace } from '@zephyr3d/base';
6
+ import { Primitive } from './primitive.js';
6
7
  import { BoxShape } from '../shapes/box.js';
7
- import { ScatteringLut } from './scatteringlut.js';
8
+ import '../shapes/cylinder.js';
9
+ import '../shapes/torus.js';
10
+ import '../shapes/plane.js';
11
+ import '../shapes/sphere.js';
12
+ import '../shapes/tetrahedron.js';
8
13
  import { Camera } from '../camera/camera.js';
9
14
  import { prefilterCubemap } from '../utility/pmrem.js';
10
- import '../utility/panorama.js';
11
- import '../utility/shprojection.js';
12
15
  import { ShaderHelper } from '../material/shader/helper.js';
13
16
  import { fetchSampler } from '../utility/misc.js';
17
+ import { CubemapSHProjector } from '../utility/shprojector.js';
18
+ import { uniformSphereSamples, Fog } from '../values.js';
19
+ import { getDefaultHeightFogParams, MAX_FOG_HEIGHT, getHeightFogParamsStruct, calculateFog } from '../shaders/fog.js';
20
+ import { drawFullscreenQuad } from './fullscreenquad.js';
21
+ import { panoramaToCubemap } from '../utility/panorama.js';
14
22
 
15
23
  const fogTypeMap = {
16
- linear: ShaderHelper.FOG_TYPE_LINEAR,
17
- exp: ShaderHelper.FOG_TYPE_EXP,
18
- exp2: ShaderHelper.FOG_TYPE_EXP2,
19
- scatter: ShaderHelper.FOG_TYPE_SCATTER,
20
- none: ShaderHelper.FOG_TYPE_NONE
24
+ height_fog: Fog.FOG_TYPE_HEIGHT,
25
+ none: Fog.FOG_TYPE_NONE
21
26
  };
22
27
  const defaultSkyWorldMatrix = Matrix4x4.identity();
23
28
  /**
24
29
  * The sky renderer
25
30
  * @public
26
- */ class SkyRenderer {
31
+ */ class SkyRenderer extends Disposable {
32
+ static _skyCamera = (()=>{
33
+ const camera = new Camera(null);
34
+ camera.setPerspective(Math.PI / 2, 1, 1, 20);
35
+ return camera;
36
+ })();
37
+ static transmittanceLutProgram = null;
38
+ static multiScatteringLutProgram = null;
39
+ static skyViewLutProgram = null;
40
+ static APLutProgram = null;
41
+ static _programSky = {};
42
+ static _programDistantLight = null;
43
+ static _programFog = null;
44
+ static _programFogNoDepth = null;
45
+ static _vertexLayout = null;
46
+ static _primitiveSky = null;
47
+ static _primitiveDistantLight = null;
48
+ static _renderStatesSky = null;
49
+ static _renderStatesSkyNoDepthTest = null;
50
+ static _renderStatesFog = null;
51
+ static _renderStatesFogScatter = null;
52
+ static _renderStatesDistantLight = null;
53
+ static _defaultSkyImage = new DRef();
27
54
  _skyType;
28
55
  _skyColor;
56
+ _skyImage;
57
+ _bakedSkyboxDirty;
58
+ _bakedSkyboxTextureSize;
59
+ _skyboxTextureSize;
29
60
  _skyboxTexture;
30
- _updateRadianceMaps;
31
- _radianceMapDirty;
32
- _scatterSkyboxFramebuffer;
33
- _scatterSkyboxTextureWidth;
34
- _aerialPerspectiveDensity;
61
+ _bakedSkyboxTexture;
62
+ _bakedSkyboxFrameBuffer;
35
63
  _radianceMap;
64
+ _radianceFrameBuffer;
65
+ _irradianceSH;
66
+ _irradianceSHFB;
67
+ _skyDistantLightLut;
68
+ _irradianceFrameBuffer;
36
69
  _radianceMapWidth;
37
- _irradianceMap;
38
- _irradianceMapWidth;
70
+ _atmosphereParams;
71
+ _atmosphereExposure;
39
72
  _fogType;
40
- _fogColor;
41
- _fogParams;
73
+ _heightFogParams;
42
74
  _cloudy;
43
75
  _cloudIntensity;
76
+ _debugAerialPerspective;
44
77
  _wind;
45
- _programSky;
46
- _bindgroupSky;
47
- _programFog;
48
- _bindgroupFog;
49
- _programFogScatter;
50
- _bindgroupFogScatter;
51
- _vertexLayout;
52
- _primitiveSky;
53
78
  _skyWorldMatrix;
54
- _renderStatesSky;
55
- _renderStatesSkyNoDepthTest;
56
- _renderStatesFog;
57
- _renderStatesFogScatter;
58
- _drawGround;
59
79
  _lastSunDir;
80
+ _lastSunColor;
81
+ _panoramaAsset;
82
+ _shProjector;
83
+ _shWindowWeights;
84
+ _radianceConvSamples;
85
+ _irradianceConvSamples;
86
+ _bindgroupDistantLight = null;
87
+ _bindgroupSky = {};
88
+ _bindgroupFog = null;
89
+ _bindgroupFogNoDepth = null;
90
+ _format;
60
91
  /**
61
92
  * Creates an instance of SkyRenderer
62
93
  */ constructor(){
94
+ super();
63
95
  this._skyType = 'scatter';
64
- this._updateRadianceMaps = true;
65
- this._radianceMapDirty = true;
66
- this._skyColor = Vector4.zero();
67
- this._skyboxTexture = null;
68
- this._scatterSkyboxFramebuffer = null;
69
- this._scatterSkyboxTextureWidth = 256;
70
- this._aerialPerspectiveDensity = 1;
71
- this._radianceMap = null;
96
+ this._skyColor = Vector4.one();
97
+ this._skyImage = new DRef();
98
+ this._skyboxTexture = new DRef();
99
+ this._skyboxTextureSize = 1024;
100
+ this._bakedSkyboxTexture = new DRef();
101
+ this._bakedSkyboxFrameBuffer = new DRef();
102
+ this._bakedSkyboxDirty = true;
103
+ this._bakedSkyboxTextureSize = 256;
104
+ this._radianceMap = new DRef();
105
+ this._radianceFrameBuffer = new DRef();
72
106
  this._radianceMapWidth = 128;
73
- this._irradianceMap = null;
74
- this._irradianceMapWidth = 64;
75
- this._fogType = 'none';
76
- this._fogColor = Vector4.one();
77
- this._fogParams = new Vector4(1, 100, 50, 0.002);
78
- this._cloudy = 0.6;
79
- this._cloudIntensity = 40;
80
- this._wind = Vector2.zero();
81
- this._drawGround = false;
82
- this._programSky = {};
83
- this._bindgroupSky = {};
84
- this._programFog = null;
85
- this._bindgroupFog = null;
86
- this._programFogScatter = null;
87
- this._bindgroupFogScatter = null;
88
- this._vertexLayout = null;
89
- this._primitiveSky = null;
90
- this._renderStatesSky = null;
91
- this._renderStatesSkyNoDepthTest = null;
92
- this._renderStatesFog = null;
93
- this._renderStatesFogScatter = null;
107
+ this._irradianceSH = new DRef();
108
+ this._irradianceSHFB = new DRef();
109
+ this._skyDistantLightLut = new DRef();
110
+ this._irradianceFrameBuffer = new DRef();
111
+ this._atmosphereParams = getDefaultAtmosphereParams();
112
+ this._atmosphereExposure = 1;
113
+ this._debugAerialPerspective = 0;
114
+ this._fogType = 'height_fog';
115
+ this._heightFogParams = getDefaultHeightFogParams();
116
+ this._cloudy = 0.45;
117
+ this._cloudIntensity = 15;
118
+ this._wind = new Vector2(0, 0);
94
119
  this._skyWorldMatrix = defaultSkyWorldMatrix;
95
- this._lastSunDir = Vector3.zero();
120
+ this._lastSunDir = SkyRenderer._getSunDir(null);
121
+ this._lastSunColor = SkyRenderer._getSunColor(null);
122
+ this._panoramaAsset = '';
123
+ this._shProjector = new CubemapSHProjector(10000);
124
+ this._shWindowWeights = new Vector3(1, 0.8, 0.6);
125
+ this._radianceConvSamples = 64;
126
+ this._irradianceConvSamples = 256;
127
+ this._bindgroupDistantLight = new DRef();
128
+ this._bindgroupSky = {};
129
+ this._bindgroupFog = new DRef();
130
+ this._bindgroupFogNoDepth = new DRef();
131
+ const texCaps = getDevice().getDeviceCaps().textureCaps;
132
+ this._format = texCaps.getTextureFormatInfo('rg11b10uf')?.renderable ? 'rg11b10uf' : texCaps.supportHalfFloatColorBuffer && texCaps.supportLinearHalfFloatTexture ? 'rgba16f' : 'rgba32f';
96
133
  }
97
- /** @internal */ getHash(ctx) {
98
- return ctx.applyFog === 'scatter' ? '1' : ctx.applyFog ? '2' : '0';
134
+ /** @internal */ getHash(_ctx) {
135
+ return `${this.skyType}:${this.fogType}`;
136
+ }
137
+ /**
138
+ * Gets the preferred environment texture format.
139
+ */ get envTextureFormat() {
140
+ return this._format;
99
141
  }
100
142
  /** Which type of the sky should be rendered */ get skyType() {
101
143
  return this._skyType;
@@ -103,57 +145,206 @@ const defaultSkyWorldMatrix = Matrix4x4.identity();
103
145
  set skyType(val) {
104
146
  if (val !== this._skyType) {
105
147
  this._skyType = val;
106
- this.invalidateIBLMaps();
148
+ this.invalidate();
107
149
  }
108
150
  }
109
- /** Whether ground should be rendered */ get drawGround() {
110
- return this._drawGround;
151
+ /** @internal */ get panoramaTextureAsset() {
152
+ return this._panoramaAsset;
111
153
  }
112
- set drawGround(val) {
113
- this._drawGround = !!val;
114
- }
115
- /** Baked sky texture */ get bakedSkyTexture() {
116
- if (this._skyType === 'skybox' && this._skyboxTexture) {
117
- return this._skyboxTexture;
154
+ set panoramaTextureAsset(id) {
155
+ if (id !== this._panoramaAsset) {
156
+ this._panoramaAsset = id ?? '';
157
+ if (!this._panoramaAsset) {
158
+ this.skyboxTexture = null;
159
+ return;
160
+ }
161
+ this._updateSkyboxTexture();
118
162
  }
119
- if (!this._scatterSkyboxFramebuffer) {
120
- this.updateIBLMaps(this._lastSunDir);
163
+ }
164
+ /** @internal */ get skyboxTextureSize() {
165
+ return this._skyboxTextureSize;
166
+ }
167
+ set skyboxTextureSize(size) {
168
+ if (size !== this._skyboxTextureSize) {
169
+ this._skyboxTextureSize = size;
170
+ this._updateSkyboxTexture();
121
171
  }
122
- return this._scatterSkyboxFramebuffer.getColorAttachments()[0];
123
172
  }
124
- /**
125
- * Wether the IBL maps should be updated automatically.
126
- *
127
- * @remarks
128
- * If use use the sky for image-based lighting, the value shoud be set to true. default is false
129
- *
130
- */ get autoUpdateIBLMaps() {
131
- return this._updateRadianceMaps;
132
- }
133
- set autoUpdateIBLMaps(val) {
134
- if (this._updateRadianceMaps !== !!val) {
135
- this._updateRadianceMaps = !!val;
136
- if (this._updateRadianceMaps) {
137
- this.invalidateIBLMaps();
138
- }
173
+ /** Baked sky texture */ getBakedSkyTexture(ctx) {
174
+ if (this._bakedSkyboxDirty) {
175
+ this.update(ctx);
139
176
  }
177
+ return this._bakedSkyboxTexture.get();
140
178
  }
141
179
  /**
142
- * The solid sky color
180
+ * The color used when sky type is `image`
143
181
  */ get skyColor() {
144
182
  return this._skyColor;
145
183
  }
146
184
  set skyColor(val) {
147
185
  if (!val.equalsTo(this._skyColor)) {
148
186
  this._skyColor.set(val);
149
- this.invalidateIBLMaps();
187
+ this.invalidate();
150
188
  }
151
189
  }
152
- /** Aerial perspective density */ get aerialPerspectiveDensity() {
153
- return this._aerialPerspectiveDensity;
190
+ /**
191
+ * The image used when sky type is `image`
192
+ */ get skyImage() {
193
+ return this._skyImage.get();
154
194
  }
155
- set aerialPerspectiveDensity(val) {
156
- this._aerialPerspectiveDensity = val;
195
+ set skyImage(texture) {
196
+ if (texture !== this._skyImage.get()) {
197
+ this._skyImage.set(texture);
198
+ this.invalidate();
199
+ }
200
+ }
201
+ /**
202
+ * Window weights for SH projection
203
+ */ get shWindowWeights() {
204
+ return this._shWindowWeights;
205
+ }
206
+ set shWindowWeights(weights) {
207
+ this._shWindowWeights.set(weights);
208
+ this.invalidate();
209
+ }
210
+ /**
211
+ * Sample count for radiance convolution
212
+ */ get radianceConvSamples() {
213
+ return this._radianceConvSamples;
214
+ }
215
+ set radianceConvSamples(val) {
216
+ if (val !== this._radianceConvSamples) {
217
+ this._radianceConvSamples = val;
218
+ this.invalidate();
219
+ }
220
+ }
221
+ /**
222
+ * Sample count for irradiance convolution
223
+ */ get irradianceConvSamples() {
224
+ return this._irradianceConvSamples;
225
+ }
226
+ set irradianceConvSamples(val) {
227
+ if (val !== this._irradianceConvSamples) {
228
+ this._irradianceConvSamples = val;
229
+ this.invalidate();
230
+ }
231
+ }
232
+ /** Aerial perspective density */ get aerialPerspectiveDistance() {
233
+ return this._atmosphereParams.apDistance;
234
+ }
235
+ set aerialPerspectiveDistance(val) {
236
+ if (val !== this._atmosphereParams.apDistance) {
237
+ this._atmosphereParams.apDistance = val;
238
+ this.invalidate();
239
+ }
240
+ }
241
+ /** Atmosphere exposure */ get atmosphereExposure() {
242
+ return this._atmosphereExposure;
243
+ }
244
+ set atmosphereExposure(val) {
245
+ if (val !== this._atmosphereExposure) {
246
+ this._atmosphereExposure = val;
247
+ this.invalidate();
248
+ }
249
+ }
250
+ /** Aerial perspective density */ get cameraHeightScale() {
251
+ return this._atmosphereParams.cameraHeightScale;
252
+ }
253
+ set cameraHeightScale(val) {
254
+ if (val !== this._atmosphereParams.cameraHeightScale) {
255
+ this._atmosphereParams.cameraHeightScale = val;
256
+ this.invalidate();
257
+ }
258
+ }
259
+ /** Height fog color */ get heightFogColor() {
260
+ return this._heightFogParams.parameter1.xyz();
261
+ }
262
+ set heightFogColor(val) {
263
+ if (!val.equalsTo(this._heightFogParams.parameter1.xyz())) {
264
+ this._heightFogParams.parameter1.set(val);
265
+ this.invalidate();
266
+ }
267
+ }
268
+ /** Height fog density */ get heightFogDensity() {
269
+ return this._heightFogParams.parameter2.x;
270
+ }
271
+ set heightFogDensity(val) {
272
+ if (val !== this._heightFogParams.parameter2.x) {
273
+ this._heightFogParams.parameter2.x = val;
274
+ this.invalidate();
275
+ }
276
+ }
277
+ /** Height fog falloff */ get heightFogFalloff() {
278
+ return this._heightFogParams.parameter1.w;
279
+ }
280
+ set heightFogFalloff(val) {
281
+ if (val !== this._heightFogParams.parameter1.w) {
282
+ this._heightFogParams.parameter1.w = val;
283
+ this.invalidate();
284
+ }
285
+ }
286
+ /** Height fog start height */ get heightFogStartHeight() {
287
+ return this._heightFogParams.parameter2.y;
288
+ }
289
+ set heightFogStartHeight(val) {
290
+ if (val !== this._heightFogParams.parameter2.y) {
291
+ this._heightFogParams.parameter2.y = val;
292
+ this.invalidate();
293
+ }
294
+ }
295
+ /** Height fog start distance */ get heightFogStartDistance() {
296
+ return this._heightFogParams.parameter2.z;
297
+ }
298
+ set heightFogStartDistance(val) {
299
+ if (val !== this._heightFogParams.parameter2.z) {
300
+ this._heightFogParams.parameter2.z = val;
301
+ this.invalidate();
302
+ }
303
+ }
304
+ /** Height fog end distance */ get heightFogEndDistance() {
305
+ return this._heightFogParams.parameter2.w;
306
+ }
307
+ set heightFogEndDistance(val) {
308
+ if (val !== this._heightFogParams.parameter2.w) {
309
+ this._heightFogParams.parameter2.w = val;
310
+ this.invalidate();
311
+ }
312
+ }
313
+ /** Height fog maximum opacity */ get heightFogMaxOpacity() {
314
+ return this._heightFogParams.parameter3.x;
315
+ }
316
+ set heightFogMaxOpacity(val) {
317
+ if (val !== this._heightFogParams.parameter3.x) {
318
+ this._heightFogParams.parameter3.x = val;
319
+ this.invalidate();
320
+ }
321
+ }
322
+ /** Height fog atmosphere contribution strength */ get heightFogAtmosphereContribution() {
323
+ return this._heightFogParams.parameter3.y;
324
+ }
325
+ set heightFogAtmosphereContribution(val) {
326
+ if (val !== this._heightFogParams.parameter3.y) {
327
+ this._heightFogParams.parameter3.y = val;
328
+ this.invalidate();
329
+ }
330
+ }
331
+ /** Height fog directional exponent */ get heightFogDirExponent() {
332
+ return this._heightFogParams.parameter3.w;
333
+ }
334
+ set heightFogDirExponent(val) {
335
+ if (val !== this._heightFogParams.parameter3.w) {
336
+ this._heightFogParams.parameter3.w = val;
337
+ this.invalidate();
338
+ }
339
+ }
340
+ /** Height fog directional inscattering color */ get heightFogDirColor() {
341
+ return this._heightFogParams.parameter4.xyz();
342
+ }
343
+ set heightFogDirColor(val) {
344
+ if (!val.equalsTo(this._heightFogParams.parameter4.xyz())) {
345
+ this._heightFogParams.parameter4.set(val);
346
+ this.invalidate();
347
+ }
157
348
  }
158
349
  /**
159
350
  * Light density of the sky.
@@ -167,7 +358,7 @@ const defaultSkyWorldMatrix = Matrix4x4.identity();
167
358
  set cloudy(val) {
168
359
  if (val !== this._cloudy && this._skyType === 'scatter') {
169
360
  this._cloudy = val;
170
- this.invalidateIBLMaps();
361
+ this.invalidate();
171
362
  }
172
363
  }
173
364
  /**
@@ -178,7 +369,7 @@ const defaultSkyWorldMatrix = Matrix4x4.identity();
178
369
  set cloudIntensity(val) {
179
370
  if (val !== this._cloudIntensity && this._skyType === 'scatter') {
180
371
  this._cloudIntensity = val;
181
- this.invalidateIBLMaps();
372
+ this.invalidate();
182
373
  }
183
374
  }
184
375
  /**
@@ -195,35 +386,61 @@ const defaultSkyWorldMatrix = Matrix4x4.identity();
195
386
  /**
196
387
  * Radiance map of the sky.
197
388
  */ get radianceMap() {
198
- if (!this._radianceMap) {
199
- this._radianceMap = Application.instance.device.createCubeTexture('rgba16f', this._radianceMapWidth);
200
- this._radianceMap.name = 'SkyRadianceMap';
389
+ if (!this._radianceMap.get()) {
390
+ this._radianceMap.set(getDevice().createCubeTexture(this._format, this._radianceMapWidth));
391
+ this._radianceMap.get().name = 'SkyRadianceMap';
201
392
  }
202
- return this._radianceMap;
393
+ return this._radianceMap.get();
394
+ }
395
+ /** @internal */ get atmosphereParams() {
396
+ return this._atmosphereParams;
397
+ }
398
+ /** @internal */ get heightFogParams() {
399
+ return this._heightFogParams;
400
+ }
401
+ /** @internal */ get radianceFramebuffer() {
402
+ if (!this._radianceFrameBuffer.get()) {
403
+ this._radianceFrameBuffer.set(getDevice().createFrameBuffer([
404
+ this.radianceMap
405
+ ], null));
406
+ }
407
+ return this._radianceFrameBuffer.get();
203
408
  }
204
409
  /**
205
- * Irradiance map of the sky.
206
- */ get irradianceMap() {
207
- if (!this._irradianceMap) {
208
- this._irradianceMap = Application.instance.device.createCubeTexture('rgba16f', this._irradianceMapWidth, {
209
- samplerOptions: {
210
- mipFilter: 'none'
211
- }
410
+ * Irradiance SH coeffecients buffer
411
+ */ get irradianceSH() {
412
+ if (!this._irradianceSH.get()) {
413
+ const buffer = getDevice().createBuffer(4 * 4 * 9, {
414
+ usage: 'uniform'
415
+ });
416
+ this._irradianceSH.set(buffer);
417
+ }
418
+ return this._irradianceSH.get();
419
+ }
420
+ /**
421
+ * Irradiance SH coeffecients texture
422
+ */ get irradianceSHFB() {
423
+ if (!this._irradianceSHFB.get()) {
424
+ const device = getDevice();
425
+ const texture = device.createTexture2D('rgba32f', 3, 3, {
426
+ mipmapping: false
212
427
  });
213
- this._irradianceMap.name = 'SkyIrradianceMap';
428
+ this._irradianceSHFB.set(device.createFrameBuffer([
429
+ texture
430
+ ], null));
214
431
  }
215
- return this._irradianceMap;
432
+ return this._irradianceSHFB.get();
216
433
  }
217
434
  /**
218
435
  * Cube texture for skybox.
219
436
  */ get skyboxTexture() {
220
- return this._skyboxTexture;
437
+ return this._skyboxTexture.get();
221
438
  }
222
439
  set skyboxTexture(tex) {
223
- if (tex !== this._skyboxTexture) {
224
- this._skyboxTexture = tex;
440
+ if (tex !== this.skyboxTexture) {
441
+ this._skyboxTexture.set(tex);
225
442
  if (this._skyType === 'skybox') {
226
- this.invalidateIBLMaps();
443
+ this.invalidate();
227
444
  }
228
445
  }
229
446
  }
@@ -234,7 +451,7 @@ const defaultSkyWorldMatrix = Matrix4x4.identity();
234
451
  val = val ?? defaultSkyWorldMatrix;
235
452
  if (val !== this._skyWorldMatrix) {
236
453
  this._skyWorldMatrix = val;
237
- this.invalidateIBLMaps();
454
+ this.invalidate();
238
455
  }
239
456
  }
240
457
  /** @internal */ get mappedFogType() {
@@ -244,170 +461,268 @@ const defaultSkyWorldMatrix = Matrix4x4.identity();
244
461
  return this._fogType;
245
462
  }
246
463
  set fogType(val) {
247
- this._fogType = val;
248
- }
249
- /** Start distance of linear fog */ get fogStart() {
250
- return this._fogParams.x;
464
+ if (val !== this._fogType) {
465
+ this._fogType = val;
466
+ this.invalidate();
467
+ }
251
468
  }
252
- set fogStart(val) {
253
- this._fogParams.x = val;
469
+ /** @internal */ get aerialPerspectiveDebug() {
470
+ return this._debugAerialPerspective;
254
471
  }
255
- /** End distance of linear fog */ get fogEnd() {
256
- return this._fogParams.y;
472
+ set aerialPerspectiveDebug(val) {
473
+ this._debugAerialPerspective = val;
257
474
  }
258
- set fogEnd(val) {
259
- this._fogParams.y = val;
475
+ /** @internal */ get fogPresents() {
476
+ return this._skyType === 'scatter' || this._fogType !== 'none';
260
477
  }
261
- /** Top distance of fog if fog type is not scatter */ get fogTop() {
262
- return this._fogParams.z;
478
+ /**
479
+ * Force the radiance map and irradiance map to be regenerated.
480
+ */ invalidate() {
481
+ this._bakedSkyboxDirty = true;
263
482
  }
264
- set fogTop(val) {
265
- this._fogParams.z = val;
483
+ /** @internal */ drawScatteredFog(_ctx) {
484
+ return this.skyType === 'scatter';
266
485
  }
267
- /** Density of exp/exp2 fog */ get fogDensity() {
268
- return this._fogParams.w;
486
+ /** @internal */ getAerialPerspectiveLUT(_ctx) {
487
+ return getAerialPerspectiveLut();
269
488
  }
270
- set fogDensity(val) {
271
- this._fogParams.w = val;
489
+ /** @internal */ getSkyDistantLightLUT(_ctx) {
490
+ return this._skyDistantLightLut.get().getColorAttachments()[0];
272
491
  }
273
- /** The fog color if fog type is not scatter */ get fogColor() {
274
- return this._fogColor;
492
+ update(ctx) {
493
+ const useScatter = this._skyType === 'scatter';
494
+ if (useScatter || !atmosphereLUTRendered()) {
495
+ this.renderAtmosphereLUTs(ctx);
496
+ }
497
+ const oldSunLight = ctx.sunLight && useScatter ? ctx.sunLight.color : null;
498
+ const sunDir = SkyRenderer._getSunDir(ctx.sunLight);
499
+ const sunColor = SkyRenderer._getSunColor(ctx.sunLight);
500
+ if (this._skyType === 'scatter' && (this._wind.x !== 0 || this._wind.y !== 0)) {
501
+ this._bakedSkyboxDirty = true;
502
+ }
503
+ if (!this._skyDistantLightLut.get()) {
504
+ const tex = ctx.device.createTexture2D(this._format, 1, 1, {
505
+ mipmapping: false
506
+ });
507
+ tex.name = 'DistantSkyLut';
508
+ this._skyDistantLightLut.set(ctx.device.createFrameBuffer([
509
+ tex
510
+ ], null));
511
+ this._bakedSkyboxDirty = true;
512
+ }
513
+ if (!sunDir.equalsTo(this._lastSunDir) || !sunColor.equalsTo(this._lastSunColor)) {
514
+ this._lastSunDir.set(sunDir);
515
+ this._lastSunColor.set(sunColor);
516
+ this._bakedSkyboxDirty = true;
517
+ }
518
+ if (this._bakedSkyboxDirty) {
519
+ this._bakedSkyboxDirty = false;
520
+ this.updateBakedSkyMap(ctx);
521
+ this.renderSkyDistantLut(ctx, this._bakedSkyboxTexture.get());
522
+ if (ctx.scene.env.light.radianceMap && (ctx.scene.env.light.radianceMap === this.radianceMap || this._irradianceSH.get() && ctx.scene.env.light.irradianceSH === this.irradianceSH || this._irradianceSHFB.get() && ctx.scene.env.light.irradianceSHFB === this.irradianceSHFB)) {
523
+ prefilterCubemap(this._bakedSkyboxTexture.get(), 'ggx', this.radianceFramebuffer, this._radianceConvSamples);
524
+ if (ctx.device.type === 'webgl' || !ctx.device.getDeviceCaps().framebufferCaps.supportFloatBlending) {
525
+ this._shProjector.projectCubemapToTexture(this._bakedSkyboxTexture.get(), this.irradianceSHFB);
526
+ } else {
527
+ this._shProjector.projectCubemap(this._bakedSkyboxTexture.get(), this.irradianceSH);
528
+ }
529
+ ctx.scene.env.light.irradianceSH = this.irradianceSH;
530
+ ctx.scene.env.light.irradianceWindow = this._shWindowWeights;
531
+ }
532
+ }
533
+ const newSunLight = oldSunLight ? Vector3.mul(ctx.sunLight.color.xyz(), this.sunTransmittance(ctx.sunLight)) : Vector3.zero();
534
+ if (oldSunLight) {
535
+ ctx.sunLight.setColor(newSunLight);
536
+ }
537
+ // Update height fog parameters
538
+ if (this._fogType === 'height_fog') {
539
+ const cameraY = Math.min(this._heightFogParams.parameter2.y + MAX_FOG_HEIGHT, ctx.camera.getWorldPosition().y);
540
+ const p = Math.max(-125, Math.min(126, -this._heightFogParams.parameter1.w * (cameraY - this._heightFogParams.parameter2.y)));
541
+ this._heightFogParams.parameter3.z = this._heightFogParams.parameter2.x * Math.pow(2, p);
542
+ this._heightFogParams.lightColor.set(newSunLight);
543
+ this._heightFogParams.lightDir.set(SkyRenderer._getSunDir(ctx.sunLight));
544
+ }
545
+ return oldSunLight;
275
546
  }
276
- set fogColor(val) {
277
- this._fogColor.set(val);
547
+ renderAtmosphereLUTs(ctx) {
548
+ this._atmosphereParams.lightDir.set(SkyRenderer._getSunDir(ctx.sunLight));
549
+ this._atmosphereParams.lightColor.set(SkyRenderer._getSunColor(ctx.sunLight));
550
+ this._atmosphereParams.lightColor.w *= this._atmosphereExposure;
551
+ this._atmosphereParams.cameraAspect = ctx.camera.getAspect();
552
+ this._atmosphereParams.cameraWorldMatrix.set(ctx.camera.worldMatrix);
553
+ renderAtmosphereLUTs(this._atmosphereParams);
278
554
  }
279
- /** @internal */ get fogParams() {
280
- return this._fogParams;
555
+ renderSkyDistantLut(ctx, skybox) {
556
+ this._prepareSkyBox(ctx.device);
557
+ ctx.device.pushDeviceStates();
558
+ ctx.device.setRenderStates(SkyRenderer._renderStatesDistantLight);
559
+ ctx.device.setProgram(SkyRenderer._programDistantLight);
560
+ ctx.device.setFramebuffer(this._skyDistantLightLut.get());
561
+ ctx.device.clearFrameBuffer(new Vector4(0, 0, 0, 1), null, null);
562
+ this._bindgroupDistantLight.get().setTexture('skybox', skybox, fetchSampler('clamp_linear_nomip'));
563
+ ctx.device.setBindGroup(0, this._bindgroupDistantLight.get());
564
+ SkyRenderer._primitiveDistantLight.draw();
565
+ ctx.device.popDeviceStates();
281
566
  }
282
- set fogParams(val) {
283
- this._fogParams.set(val);
567
+ updateBakedSkyMap(ctx) {
568
+ const device = ctx.device;
569
+ const tex = this._bakedSkyboxTexture.get() && this._bakedSkyboxTexture.get().width === this._bakedSkyboxTextureSize ? this._bakedSkyboxTexture.get() : device.createCubeTexture(this._format, this._bakedSkyboxTextureSize, {
570
+ mipmapping: false
571
+ });
572
+ tex.name = 'BakedSkyboxTexture';
573
+ if (tex !== this._bakedSkyboxTexture.get()) {
574
+ this._bakedSkyboxFrameBuffer.set(device.createFrameBuffer([
575
+ tex
576
+ ], null));
577
+ }
578
+ const camera = SkyRenderer._skyCamera;
579
+ const saveRenderStates = device.getRenderStates();
580
+ device.pushDeviceStates();
581
+ device.setFramebuffer(this._bakedSkyboxFrameBuffer.get());
582
+ for (const face of [
583
+ CubeFace.PX,
584
+ CubeFace.NX,
585
+ CubeFace.PY,
586
+ CubeFace.NY,
587
+ CubeFace.PZ,
588
+ CubeFace.NZ
589
+ ]){
590
+ camera.lookAtCubeFace(face);
591
+ this._bakedSkyboxFrameBuffer.get().setColorAttachmentCubeFace(0, face);
592
+ this._renderSky(camera, false);
593
+ }
594
+ device.popDeviceStates();
595
+ this.renderSkyDistantLut(ctx, tex);
596
+ device.pushDeviceStates();
597
+ device.setFramebuffer(this._bakedSkyboxFrameBuffer.get());
598
+ for (const face of [
599
+ CubeFace.PX,
600
+ CubeFace.NX,
601
+ CubeFace.PY,
602
+ CubeFace.NY,
603
+ CubeFace.PZ,
604
+ CubeFace.NZ
605
+ ]){
606
+ camera.lookAtCubeFace(face);
607
+ this._bakedSkyboxFrameBuffer.get().setColorAttachmentCubeFace(0, face);
608
+ this.renderFog(camera);
609
+ }
610
+ device.popDeviceStates();
611
+ device.setRenderStates(saveRenderStates);
612
+ this._bakedSkyboxTexture.set(tex);
284
613
  }
285
- /**
286
- * Force the radiance map and irradiance map to be regenerated.
287
- */ invalidateIBLMaps() {
288
- this._radianceMapDirty = true;
289
- }
290
- /** @internal */ drawScatteredFog(ctx) {
291
- return ctx.sunLight && this._fogType === 'scatter';
292
- }
293
- /** @internal */ getAerialPerspectiveLUT(ctx) {
294
- if (this.drawScatteredFog(ctx)) {
295
- const sunDir = SkyRenderer._getSunDir(ctx.sunLight);
296
- const alpha = Math.PI / 2 - Math.acos(Math.max(-1, Math.min(1, sunDir.y)));
297
- const farPlane = ctx.camera.getFarPlane() * this._aerialPerspectiveDensity * this._aerialPerspectiveDensity;
298
- return ScatteringLut.getAerialPerspectiveLut(alpha, farPlane);
299
- } else {
300
- return null;
614
+ renderUberFog(camera, depthTexture) {
615
+ const device = getDevice();
616
+ const fogProgram = depthTexture ? SkyRenderer._programFog : SkyRenderer._programFogNoDepth;
617
+ const renderStates = SkyRenderer._renderStatesFog;
618
+ const bindgroup = depthTexture ? this._bindgroupFog.get() : this._bindgroupFogNoDepth.get();
619
+ if (depthTexture) {
620
+ bindgroup.setTexture('depthTex', depthTexture, fetchSampler('clamp_nearest_nomip'));
301
621
  }
622
+ bindgroup.setTexture('skyDistantLightLut', this._skyDistantLightLut.get().getColorAttachments()[0], fetchSampler('clamp_nearest_nomip'));
623
+ bindgroup.setTexture('apLut', getAerialPerspectiveLut(), fetchSampler('clamp_linear_nomip'));
624
+ bindgroup.setValue('rt', device.getFramebuffer() ? 1 : 0);
625
+ bindgroup.setValue('invProjViewMatrix', camera.invViewProjectionMatrix);
626
+ bindgroup.setValue('cameraNearFar', new Vector2(camera.getNearPlane(), camera.getFarPlane()));
627
+ bindgroup.setValue('cameraPosition', camera.getWorldPosition());
628
+ bindgroup.setValue('srgbOut', device.getFramebuffer() ? 0 : 1);
629
+ bindgroup.setValue('withAerialPerspective', this.skyType === 'scatter' ? 1 : 0);
630
+ bindgroup.setValue('fogType', this.mappedFogType);
631
+ bindgroup.setValue('atmosphereParams', this._atmosphereParams);
632
+ bindgroup.setValue('heightFogParams', this._heightFogParams);
633
+ device.setProgram(fogProgram);
634
+ device.setBindGroup(0, bindgroup);
635
+ device.setVertexLayout(SkyRenderer._vertexLayout);
636
+ device.setRenderStates(renderStates);
637
+ device.draw('triangle-strip', 0, 4);
302
638
  }
303
- /**
304
- * Regenerate the radiance map and irradiance map
305
- *
306
- * @param sunLight - The sun light
307
- */ updateIBLMaps(sunDir) {
308
- const device = Application.instance.device;
309
- let bakedSkyboxTexture = null;
310
- if (this._skyType === 'skybox' && this._skyboxTexture) {
311
- bakedSkyboxTexture = this._skyboxTexture;
312
- } else {
313
- if (!this._scatterSkyboxFramebuffer) {
314
- const texCaps = device.getDeviceCaps().textureCaps;
315
- const format = texCaps.supportHalfFloatColorBuffer && texCaps.supportLinearHalfFloatTexture ? 'rgba16f' : texCaps.supportFloatColorBuffer && texCaps.supportLinearFloatTexture ? 'rgba32f' : 'rgba8unorm';
316
- const tex = device.createCubeTexture(format, this._scatterSkyboxTextureWidth);
317
- tex.name = 'BakedSkyboxTexture';
318
- this._scatterSkyboxFramebuffer = device.createFrameBuffer([
319
- tex
320
- ], null);
321
- this._radianceMapDirty = true;
322
- }
323
- const camera = new Camera(null);
324
- camera.setPerspective(Math.PI / 2, 1, 1, 20);
325
- const saveRenderStates = device.getRenderStates();
639
+ /** @internal */ renderFog(camera) {
640
+ const device = getDevice();
641
+ const currentFramebuffer = device.getFramebuffer();
642
+ const depthBuffer = currentFramebuffer?.getDepthAttachment() ?? null;
643
+ const colorBuffer = currentFramebuffer?.getColorAttachments()[0] ?? null;
644
+ const fogFramebuffer = depthBuffer && colorBuffer ? device.pool.fetchTemporalFramebuffer(false, 0, 0, colorBuffer, null, false) : null;
645
+ if (fogFramebuffer) {
646
+ const vp = device.getViewport();
647
+ const scissor = device.getScissor();
326
648
  device.pushDeviceStates();
327
- device.setFramebuffer(this._scatterSkyboxFramebuffer);
328
- for (const face of [
329
- CubeFace.PX,
330
- CubeFace.NX,
331
- CubeFace.PY,
332
- CubeFace.NY,
333
- CubeFace.PZ,
334
- CubeFace.NZ
335
- ]){
336
- camera.lookAtCubeFace(face);
337
- this._scatterSkyboxFramebuffer.setColorAttachmentCubeFace(0, face);
338
- this._renderSky(camera, false, sunDir, true, false);
339
- }
340
- device.popDeviceStates();
341
- device.setRenderStates(saveRenderStates);
342
- bakedSkyboxTexture = this._scatterSkyboxFramebuffer.getColorAttachments()[0];
649
+ device.setFramebuffer(fogFramebuffer);
650
+ device.setViewport(vp);
651
+ device.setScissor(scissor);
343
652
  }
344
- prefilterCubemap(bakedSkyboxTexture, 'ggx', this.radianceMap);
345
- prefilterCubemap(bakedSkyboxTexture, 'lambertian', this.irradianceMap);
346
- }
347
- /** @internal */ renderFog(ctx) {
348
- const camera = ctx.camera;
349
- const sceneDepthTexture = ctx.linearDepthTexture;
350
- const device = ctx.device;
351
653
  const savedRenderStates = device.getRenderStates();
352
654
  this._prepareSkyBox(device);
353
- const sunLight = ctx.sunLight;
354
- if (this._fogType === 'scatter' && !sunLight) {
355
- console.error('Cannot render scattering fog without sun light');
356
- return;
357
- }
358
- const fogProgram = this._fogType === 'scatter' ? this._programFogScatter : this._programFog;
359
- const renderStates = this._fogType === 'scatter' ? this._renderStatesFogScatter : this._renderStatesFog;
360
- if (fogProgram && sceneDepthTexture) {
361
- const bindgroup = this._fogType === 'scatter' ? this._bindgroupFogScatter : this._bindgroupFog;
362
- bindgroup.setTexture('depthTex', sceneDepthTexture, fetchSampler('clamp_nearest_nomip'));
363
- bindgroup.setValue('rt', device.getFramebuffer() ? 1 : 0);
364
- bindgroup.setValue('invProjViewMatrix', camera.invViewProjectionMatrix);
365
- bindgroup.setValue('cameraNearFar', new Vector2(camera.getNearPlane(), camera.getFarPlane()));
366
- bindgroup.setValue('cameraPosition', camera.getWorldPosition());
367
- bindgroup.setValue('srgbOut', device.getFramebuffer() ? 0 : 1);
368
- if (this._fogType === 'scatter') {
369
- const sunDir = sunLight ? sunLight.directionAndCutoff.xyz().scaleBy(-1) : ShaderHelper.defaultSunDir;
370
- const alpha = Math.PI / 2 - Math.acos(Math.max(-1, Math.min(1, sunDir.y)));
371
- const scale = this._aerialPerspectiveDensity * this._aerialPerspectiveDensity;
372
- const farPlane = ctx.camera.getFarPlane() * scale;
373
- bindgroup.setTexture('apLut', ScatteringLut.getAerialPerspectiveLut(alpha, farPlane));
374
- bindgroup.setValue('sliceDist', farPlane / ScatteringLut.aerialPerspectiveSliceZ);
375
- bindgroup.setValue('sunDir', sunDir);
376
- bindgroup.setValue('worldScale', scale);
377
- } else {
378
- bindgroup.setValue('fogType', this.mappedFogType);
379
- bindgroup.setValue('fogColor', this._fogColor);
380
- bindgroup.setValue('fogParams', this._fogParams);
381
- }
382
- device.setProgram(fogProgram);
383
- device.setBindGroup(0, bindgroup);
384
- device.setVertexLayout(this._vertexLayout);
385
- device.setRenderStates(renderStates);
386
- device.draw('triangle-strip', 0, 4);
387
- device.setRenderStates(savedRenderStates);
655
+ this.renderUberFog(camera, depthBuffer);
656
+ /*
657
+ if (this._skyType === 'scatter') {
658
+ this.renderAtmosphericFog(ctx, depthBuffer);
659
+ }
660
+ */ /*
661
+ if (this._fogType === 'height_fog') {
662
+ this.renderHeightFog(ctx, depthBuffer);
663
+ }
664
+ */ device.setRenderStates(savedRenderStates);
665
+ if (fogFramebuffer) {
666
+ device.popDeviceStates();
667
+ device.pool.releaseFrameBuffer(fogFramebuffer);
388
668
  }
389
669
  }
390
670
  /** @internal */ renderSky(ctx) {
391
- const sunDir = SkyRenderer._getSunDir(ctx.sunLight);
392
- if (!sunDir.equalsTo(this._lastSunDir)) {
393
- this._radianceMapDirty = true;
394
- this._lastSunDir.set(sunDir);
671
+ let skyCamera = ctx.camera;
672
+ if (!skyCamera.isPerspective()) {
673
+ skyCamera = SkyRenderer._skyCamera;
674
+ ctx.camera.worldMatrix.decompose(null, skyCamera.rotation, null);
395
675
  }
396
- this._renderSky(ctx.camera, true, sunDir, this._drawGround, this._skyType === 'scatter' && this._cloudy > 0);
397
- if (this._radianceMapDirty && ctx.env.light.type === 'ibl') {
398
- if (ctx.env.light.radianceMap && (ctx.env.light.radianceMap === this._radianceMap || ctx.env.light.irradianceMap === this._irradianceMap)) {
399
- this._radianceMapDirty = false;
400
- this.updateIBLMaps(sunDir);
401
- }
676
+ this._renderSky(skyCamera, true);
677
+ }
678
+ /** Disposes resources of this SkyRenderer */ onDispose() {
679
+ super.onDispose();
680
+ this._skyboxTexture.dispose();
681
+ this._bakedSkyboxTexture.dispose();
682
+ this._bakedSkyboxFrameBuffer.dispose();
683
+ this._radianceMap.dispose();
684
+ this._radianceFrameBuffer.dispose();
685
+ this._irradianceSH.dispose();
686
+ this._irradianceSHFB.dispose();
687
+ this._irradianceFrameBuffer.dispose();
688
+ this._shProjector.dispose();
689
+ if (this._skyDistantLightLut.get()) {
690
+ this._skyDistantLightLut.get().getColorAttachments()[0].dispose();
691
+ this._skyDistantLightLut.dispose();
692
+ }
693
+ this._bindgroupDistantLight.dispose();
694
+ for(const k in this._bindgroupSky){
695
+ this._bindgroupSky[k].dispose();
696
+ }
697
+ this._bindgroupSky = {};
698
+ this._bindgroupFog.dispose();
699
+ this._bindgroupFogNoDepth.dispose();
700
+ }
701
+ /** @internal */ _updateSkyboxTexture() {
702
+ if (this._panoramaAsset) {
703
+ getEngine().resourceManager.fetchTexture(this._panoramaAsset).then((tex)=>{
704
+ if (!tex.isTexture2D()) {
705
+ console.error(`Invalid panorama texture asset: ${this._panoramaAsset}`);
706
+ } else {
707
+ const skyboxTexture = getDevice().createCubeTexture(this._format, this._skyboxTextureSize, {
708
+ mipmapping: false
709
+ });
710
+ panoramaToCubemap(tex, skyboxTexture);
711
+ skyboxTexture.name = 'SkyboxTexture';
712
+ this.skyboxTexture = skyboxTexture;
713
+ }
714
+ }).catch((err)=>{
715
+ console.error(`Load asset failed: ${this._panoramaAsset}: ${err}`);
716
+ });
402
717
  }
403
718
  }
404
- /** @internal */ _renderSky(camera, depthTest, sunDir, drawGround, drawCloud) {
405
- const device = Application.instance.device;
719
+ /** @internal */ _renderSky(camera, depthTest) {
720
+ const device = getDevice();
406
721
  const savedRenderStates = device.getRenderStates();
407
722
  this._prepareSkyBox(device);
408
723
  if (this._skyType === 'scatter') {
409
- this._drawScattering(camera, sunDir, depthTest, drawGround, drawCloud);
410
- } else if (this._skyType === 'skybox' && this._skyboxTexture) {
724
+ this._drawScattering(camera, depthTest);
725
+ } else if (this._skyType === 'skybox' && this.skyboxTexture) {
411
726
  this._drawSkybox(camera, depthTest);
412
727
  } else {
413
728
  this._drawSkyColor(camera, depthTest);
@@ -415,215 +730,216 @@ const defaultSkyWorldMatrix = Matrix4x4.identity();
415
730
  device.setRenderStates(savedRenderStates);
416
731
  }
417
732
  /** @internal */ _drawSkyColor(camera, depthTest) {
418
- const device = Application.instance.device;
419
- const bindgroup = this._bindgroupSky.color;
420
- bindgroup.setValue('viewProjMatrix', camera.viewProjectionMatrix);
421
- bindgroup.setValue('worldMatrix', this._skyWorldMatrix);
422
- bindgroup.setValue('cameraPos', camera.getWorldPosition());
733
+ const device = getDevice();
734
+ const bindgroup = this._bindgroupSky.image.get();
423
735
  bindgroup.setValue('color', this._skyColor);
736
+ bindgroup.setTexture('texture', this._skyImage.get() ?? SkyRenderer._defaultSkyImage.get(), fetchSampler('clamp_linear_nomip'));
737
+ bindgroup.setValue('flip', device.getFramebuffer() && device.type === 'webgpu' ? -1 : 1);
424
738
  bindgroup.setValue('srgbOut', device.getFramebuffer() ? 0 : 1);
425
- device.setProgram(this._programSky.color);
739
+ device.setProgram(SkyRenderer._programSky.image);
426
740
  device.setBindGroup(0, bindgroup);
427
- device.setRenderStates(depthTest ? this._renderStatesSky : this._renderStatesSkyNoDepthTest);
428
- this._primitiveSky.draw();
741
+ drawFullscreenQuad(depthTest ? SkyRenderer._renderStatesSky : SkyRenderer._renderStatesSkyNoDepthTest);
429
742
  }
430
743
  /** @internal */ _drawSkybox(camera, depthTest) {
431
- const device = Application.instance.device;
432
- const bindgroup = this._bindgroupSky.skybox;
433
- bindgroup.setTexture('skyCubeMap', this._skyboxTexture);
744
+ const device = getDevice();
745
+ const bindgroup = this._bindgroupSky.skybox.get();
746
+ bindgroup.setTexture('skyCubeMap', this.skyboxTexture, fetchSampler('clamp_linear_nomip'));
434
747
  bindgroup.setValue('flip', device.getFramebuffer() && device.type === 'webgpu' ? new Vector4(1, -1, 1, 1) : new Vector4(1, 1, 1, 1));
435
748
  bindgroup.setValue('viewProjMatrix', camera.viewProjectionMatrix);
436
749
  bindgroup.setValue('worldMatrix', this._skyWorldMatrix);
437
750
  bindgroup.setValue('cameraPos', camera.getWorldPosition());
438
751
  bindgroup.setValue('srgbOut', device.getFramebuffer() ? 0 : 1);
439
- device.setProgram(this._programSky.skybox);
752
+ device.setProgram(SkyRenderer._programSky.skybox);
440
753
  device.setBindGroup(0, bindgroup);
441
- device.setRenderStates(depthTest ? this._renderStatesSky : this._renderStatesSkyNoDepthTest);
442
- this._primitiveSky.draw();
443
- }
444
- /** @internal */ _drawScattering(camera, sunDir, depthTest, drawGround, drawCloud) {
445
- const device = Application.instance.device;
446
- const alpha = Math.PI / 2 - Math.acos(Math.max(-1, Math.min(1, sunDir.y)));
447
- const tLut = ScatteringLut.getTransmittanceLut();
448
- const skyLut = ScatteringLut.getSkyViewLut(alpha);
754
+ device.setRenderStates(depthTest ? SkyRenderer._renderStatesSky : SkyRenderer._renderStatesSkyNoDepthTest);
755
+ SkyRenderer._primitiveSky.draw();
756
+ }
757
+ /** @internal */ _rayIntersectSphere(radius, rayStart, rayDir) {
758
+ const OS = rayStart.magnitude;
759
+ const SH = -Vector3.dot(rayStart, rayDir);
760
+ const OH = Math.sqrt(Math.max(0, OS * OS - SH * SH));
761
+ const PH = Math.sqrt(Math.max(0, radius * radius - OH * OH));
762
+ if (OH > radius) {
763
+ return -1;
764
+ }
765
+ const t1 = SH - PH;
766
+ const t2 = SH + PH;
767
+ return t1 < 0 ? t2 : t1;
768
+ }
769
+ /** @internal */ sunTransmittance(sunLight) {
770
+ const TRANSMITTANCE_SAMPLES = 32;
771
+ const RAYLEIGH_SIGMA = [
772
+ 5.802,
773
+ 13.558,
774
+ 33.1
775
+ ];
776
+ const MIE_SIGMA = 3.996;
777
+ const MIE_ABSORPTION_SIGMA = 4.4;
778
+ const OZONE_ABSORPTION_SIGMA = [
779
+ 0.65,
780
+ 1.881,
781
+ 0.085
782
+ ];
783
+ function rayleighSc(params, fH) {
784
+ const sigma = new Vector3(RAYLEIGH_SIGMA[0] * 1e-6, RAYLEIGH_SIGMA[1] * 1e-6, RAYLEIGH_SIGMA[2] * 1e-6);
785
+ const rho_h = Math.exp(-fH / params.rayleighScatteringHeight);
786
+ return Vector3.scale(sigma, rho_h);
787
+ }
788
+ function mieSc(params, fH) {
789
+ const sigma = new Vector3(MIE_SIGMA * 1e-6, MIE_SIGMA * 1e-6, MIE_SIGMA * 1e-6);
790
+ const rho_h = Math.exp(-(fH / params.mieScatteringHeight));
791
+ return Vector3.scale(sigma, rho_h);
792
+ }
793
+ function mieAb(params, fH) {
794
+ const sigma = new Vector3(MIE_ABSORPTION_SIGMA * 1e-6, MIE_ABSORPTION_SIGMA * 1e-6, MIE_ABSORPTION_SIGMA * 1e-6);
795
+ const rho_h = Math.exp(-(fH / params.mieScatteringHeight));
796
+ return Vector3.scale(sigma, rho_h);
797
+ }
798
+ function ozoneAb(params, fH) {
799
+ const sigma = new Vector3(OZONE_ABSORPTION_SIGMA[0] * 1e-6, OZONE_ABSORPTION_SIGMA[1] * 1e-6, OZONE_ABSORPTION_SIGMA[2] * 1e-6);
800
+ const rho_h = Math.max(0, 1 - Math.abs(fH - params.ozoneCenter) * 0.5 / params.ozoneWidth);
801
+ return Vector3.scale(sigma, rho_h);
802
+ }
803
+ const eyePos = new Vector3(0, this._atmosphereParams.plantRadius + this._atmosphereParams.cameraHeightScale, 0);
804
+ const lightDir = SkyRenderer._getSunDir(sunLight);
805
+ const d = this._rayIntersectSphere(this._atmosphereParams.plantRadius + this._atmosphereParams.atmosphereHeight, eyePos, lightDir);
806
+ if (d < 0) {
807
+ return new Vector3(0, 0, 0);
808
+ }
809
+ const ds = d / TRANSMITTANCE_SAMPLES;
810
+ const sum = new Vector3(0, 0, 0);
811
+ const p = Vector3.combine(eyePos, lightDir, 1, ds * 0.5);
812
+ for(let i = 0; i < TRANSMITTANCE_SAMPLES; i++){
813
+ const h = p.magnitude - this._atmosphereParams.plantRadius;
814
+ const scattering = Vector3.add(rayleighSc(this._atmosphereParams, h), mieSc(this._atmosphereParams, h));
815
+ const absorption = Vector3.add(ozoneAb(this._atmosphereParams, h), mieAb(this._atmosphereParams, h));
816
+ const extinction = Vector3.add(scattering, absorption);
817
+ Vector3.add(sum, Vector3.scale(extinction, ds), sum);
818
+ Vector3.add(p, Vector3.scale(lightDir, ds), p);
819
+ }
820
+ return new Vector3(Math.exp(-sum.x), Math.exp(-sum.y), Math.exp(-sum.z));
821
+ }
822
+ /** @internal */ _drawScattering(camera, depthTest) {
823
+ const device = getDevice();
824
+ const tLut = getTransmittanceLut();
825
+ const skyLut = getSkyViewLut();
449
826
  //const apLut = ScatteringLut.getAerialPerspectiveLut(alpha, 8000);
450
- const program = drawCloud ? this._programSky.scatter : this._programSky['scatter-nocloud'];
451
- const bindgroup = drawCloud ? this._bindgroupSky.scatter : this._bindgroupSky['scatter-nocloud'];
452
- bindgroup.setValue('sunDir', sunDir);
827
+ const program = SkyRenderer._programSky.scatter;
828
+ const bindgroup = this._bindgroupSky.scatter.get();
453
829
  bindgroup.setValue('flip', device.getFramebuffer() && device.type === 'webgpu' ? new Vector4(1, -1, 1, 1) : new Vector4(1, 1, 1, 1));
830
+ bindgroup.setValue('params', this._atmosphereParams);
454
831
  bindgroup.setValue('viewProjMatrix', camera.viewProjectionMatrix);
455
832
  bindgroup.setValue('worldMatrix', this._skyWorldMatrix);
456
833
  bindgroup.setValue('cameraPos', camera.getWorldPosition());
457
834
  bindgroup.setValue('srgbOut', device.getFramebuffer() ? 0 : 1);
458
- bindgroup.setTexture('tLut', tLut);
459
- bindgroup.setTexture('skyLut', skyLut);
460
- if (drawCloud) {
461
- bindgroup.setValue('cloudy', this._cloudy);
462
- bindgroup.setValue('cloudIntensity', this._cloudIntensity);
463
- bindgroup.setValue('time', device.frameInfo.elapsedOverall * 0.001);
464
- bindgroup.setValue('velocity', this._wind);
465
- }
466
- bindgroup.setValue('drawGround', drawGround ? 1 : 0);
835
+ bindgroup.setTexture('tLut', tLut, fetchSampler('clamp_linear_nomip'));
836
+ bindgroup.setTexture('skyLut', skyLut, fetchSampler('clamp_linear_nomip'));
837
+ bindgroup.setValue('cloudy', this._cloudy);
838
+ bindgroup.setValue('cloudIntensity', this._cloudIntensity);
839
+ bindgroup.setValue('time', device.frameInfo.elapsedOverall * 0.001);
840
+ bindgroup.setValue('velocity', this._wind);
467
841
  device.setProgram(program);
468
842
  device.setBindGroup(0, bindgroup);
469
- device.setRenderStates(depthTest ? this._renderStatesSky : this._renderStatesSkyNoDepthTest);
470
- this._primitiveSky.draw();
843
+ device.setRenderStates(depthTest ? SkyRenderer._renderStatesSky : SkyRenderer._renderStatesSkyNoDepthTest);
844
+ SkyRenderer._primitiveSky.draw();
471
845
  }
472
846
  /** @internal */ _prepareSkyBox(device) {
473
- if (!this._programFogScatter) {
474
- this._programFogScatter = device.buildRenderProgram({
475
- label: 'FogScatter',
847
+ SkyRenderer._createAtmosphereLUTPrograms(device);
848
+ if (!SkyRenderer._defaultSkyImage.get()) {
849
+ const texture = device.createTexture2D('rgba8unorm', 1, 1, {
850
+ mipmapping: false
851
+ });
852
+ texture.update(new Uint8Array([
853
+ 255,
854
+ 255,
855
+ 255,
856
+ 255
857
+ ]), 0, 0, 1, 1);
858
+ SkyRenderer._defaultSkyImage.set(texture);
859
+ }
860
+ if (!SkyRenderer._programDistantLight) {
861
+ SkyRenderer._programDistantLight = device.buildRenderProgram({
476
862
  vertex (pb) {
477
- this.rt = pb.int().uniform(0);
478
- this.$inputs.pos = pb.vec2().attrib('position');
479
- this.$outputs.uv = pb.vec2();
863
+ this.$inputs.vector = pb.vec3().attrib('position');
480
864
  pb.main(function() {
481
- this.$builtins.position = pb.vec4(this.$inputs.pos, 1, 1);
482
- this.$outputs.uv = pb.add(pb.mul(this.$inputs.pos.xy, 0.5), pb.vec2(0.5));
483
- if (device.type === 'webgpu') {
484
- this.$if(pb.notEqual(this.rt, 0), function() {
485
- this.$builtins.position.y = pb.neg(this.$builtins.position.y);
486
- });
865
+ this.$outputs.vector = this.$inputs.vector;
866
+ this.$builtins.position = pb.vec4(0, 0, 0, 1);
867
+ if (pb.getDevice().type !== 'webgpu') {
868
+ this.$builtins.pointSize = 1;
487
869
  }
488
870
  });
489
871
  },
490
872
  fragment (pb) {
491
- this.depthTex = pb.tex2D().sampleType('unfilterable-float').uniform(0);
492
- this.invProjViewMatrix = pb.mat4().uniform(0);
493
- this.cameraNearFar = pb.vec2().uniform(0);
494
- this.cameraPosition = pb.vec3().uniform(0);
495
- this.apLut = pb.tex2D().uniform(0);
496
- this.worldScale = pb.float().uniform(0);
497
- this.sliceDist = pb.float().uniform(0);
498
- this.sunDir = pb.vec3().uniform(0);
499
- this.srgbOut = pb.int().uniform(0);
500
- this.$outputs.outColor = pb.vec4();
873
+ this.$outputs.color = pb.vec4();
874
+ this.skybox = pb.texCube().uniform(0);
501
875
  pb.main(function() {
502
- this.$l.depthValue = pb.textureSample(this.depthTex, this.$inputs.uv);
503
- if (device.type === 'webgl') {
504
- this.$l.linearDepth = decodeNormalizedFloatFromRGBA(this, this.depthValue);
505
- } else {
506
- this.$l.linearDepth = this.depthValue.r;
507
- }
508
- this.$l.nonLinearDepth = pb.div(pb.sub(pb.div(this.cameraNearFar.x, this.linearDepth), this.cameraNearFar.y), pb.sub(this.cameraNearFar.x, this.cameraNearFar.y));
509
- //this.$l.clipSpacePos = pb.vec4(pb.sub(pb.mul(this.$inputs.uv, 2), pb.vec2(1)), this.nonLinearDepth, 1);
510
- this.$l.clipSpacePos = pb.vec4(pb.sub(pb.mul(this.$inputs.uv, 2), pb.vec2(1)), pb.sub(pb.mul(this.nonLinearDepth, 2), 1), 1);
511
- this.$l.hPos = pb.mul(this.invProjViewMatrix, this.clipSpacePos);
512
- this.$l.hPos = pb.div(this.$l.hPos, this.$l.hPos.w);
513
- this.$l.viewDir = pb.sub(this.hPos.xyz, this.cameraPosition);
514
- // Assume object is above the sea level
515
- this.viewDir.y = pb.max(0, this.viewDir.y);
516
- this.$l.distance = pb.mul(pb.length(this.viewDir), this.worldScale);
517
- this.$l.slice0 = pb.floor(pb.div(this.distance, this.sliceDist));
518
- this.$l.slice1 = pb.add(this.slice0, 1);
519
- this.$l.factor = pb.sub(pb.div(this.distance, this.sliceDist), this.slice0);
520
- this.$l.viewNormal = pb.normalize(this.viewDir);
521
- this.$l.horizonAngle = pb.acos(pb.clamp(pb.dot(pb.normalize(this.sunDir.xz), pb.normalize(this.viewNormal.xz)), 0, 1));
522
- this.$l.zenithAngle = pb.asin(this.viewNormal.y);
523
- this.$l.sliceU = pb.max(pb.div(this.horizonAngle, Math.PI * 2), 0.5 / ScatteringLut.aerialPerspectiveSliceZ);
524
- this.$l.u0 = pb.div(pb.add(this.slice0, this.sliceU), ScatteringLut.aerialPerspectiveSliceZ);
525
- this.$l.u1 = pb.add(this.u0, 1 / ScatteringLut.aerialPerspectiveSliceZ);
526
- this.$l.v = pb.div(this.zenithAngle, Math.PI / 2);
527
- this.$l.t0 = pb.textureSampleLevel(this.apLut, pb.vec2(this.u0, this.v), 0);
528
- this.$l.t1 = pb.textureSampleLevel(this.apLut, pb.vec2(this.u1, this.v), 0);
529
- this.$l.t = pb.mix(this.t0, this.t1, this.factor);
530
- this.$outputs.outColor = pb.vec4(this.t.rgb, pb.sub(1, this.t.a));
876
+ this.$l.sunColor = pb.vec4();
877
+ this.$l.skyColor = pb.textureSampleLevel(this.skybox, this.$inputs.vector, 0).rgb;
878
+ this.$outputs.color = pb.vec4(pb.mul(this.skyColor, 1 / 64), 1);
531
879
  });
532
880
  }
533
881
  });
534
- this._bindgroupFogScatter = device.createBindGroup(this._programFogScatter.bindGroupLayouts[0]);
882
+ SkyRenderer._programDistantLight.name = '@SkyDistantLight';
883
+ }
884
+ if (!this._bindgroupDistantLight.get()) {
885
+ this._bindgroupDistantLight.set(device.createBindGroup(SkyRenderer._programDistantLight.bindGroupLayouts[0]));
886
+ }
887
+ if (!SkyRenderer._programFog) {
888
+ SkyRenderer._programFog = SkyRenderer._createFogProgram(device, false);
889
+ }
890
+ if (!SkyRenderer._programFogNoDepth) {
891
+ SkyRenderer._programFogNoDepth = SkyRenderer._createFogProgram(device, true);
892
+ }
893
+ if (!this._bindgroupFog.get()) {
894
+ this._bindgroupFog.set(device.createBindGroup(SkyRenderer._programFog.bindGroupLayouts[0]));
895
+ }
896
+ if (!this._bindgroupFogNoDepth.get()) {
897
+ this._bindgroupFogNoDepth.set(device.createBindGroup(SkyRenderer._programFogNoDepth.bindGroupLayouts[0]));
535
898
  }
536
- if (!this._programFog) {
537
- this._programFog = device.buildRenderProgram({
538
- label: 'Fog',
899
+ if (!SkyRenderer._programSky.image) {
900
+ SkyRenderer._programSky.image = device.buildRenderProgram({
901
+ label: 'ImageSky',
539
902
  vertex (pb) {
540
- this.rt = pb.int().uniform(0);
541
903
  this.$inputs.pos = pb.vec2().attrib('position');
542
904
  this.$outputs.uv = pb.vec2();
905
+ this.flip = pb.int().uniform(0);
543
906
  pb.main(function() {
544
907
  this.$builtins.position = pb.vec4(this.$inputs.pos, 1, 1);
545
908
  this.$outputs.uv = pb.add(pb.mul(this.$inputs.pos.xy, 0.5), pb.vec2(0.5));
546
- if (device.type === 'webgpu') {
547
- this.$if(pb.notEqual(this.rt, 0), function() {
548
- this.$builtins.position.y = pb.neg(this.$builtins.position.y);
549
- });
909
+ if (device.type !== 'webgpu') {
910
+ this.$builtins.position.y = pb.neg(this.$builtins.position.y);
550
911
  }
551
912
  });
552
913
  },
553
- fragment (pb) {
554
- this.depthTex = pb.tex2D().sampleType('unfilterable-float').uniform(0);
555
- this.invProjViewMatrix = pb.mat4().uniform(0);
556
- this.cameraNearFar = pb.vec2().uniform(0);
557
- this.cameraPosition = pb.vec3().uniform(0);
558
- this.fogType = pb.int().uniform(0);
559
- this.fogColor = pb.vec4().uniform(0);
560
- this.fogParams = pb.vec4().uniform(0);
561
- this.srgbOut = pb.int().uniform(0);
562
- this.$outputs.outColor = pb.vec4();
563
- pb.main(function() {
564
- this.$l.depthValue = pb.textureSample(this.depthTex, this.$inputs.uv);
565
- if (device.type === 'webgl') {
566
- this.$l.linearDepth = decodeNormalizedFloatFromRGBA(this, this.depthValue);
567
- } else {
568
- this.$l.linearDepth = this.depthValue.r;
569
- }
570
- this.$l.nonLinearDepth = pb.div(pb.sub(pb.div(this.cameraNearFar.x, this.linearDepth), this.cameraNearFar.y), pb.sub(this.cameraNearFar.x, this.cameraNearFar.y));
571
- //this.$l.clipSpacePos = pb.vec4(pb.sub(pb.mul(this.$inputs.uv, 2), pb.vec2(1)), this.nonLinearDepth, 1);
572
- this.$l.clipSpacePos = pb.vec4(pb.sub(pb.mul(this.$inputs.uv, 2), pb.vec2(1)), pb.sub(pb.mul(this.nonLinearDepth, 2), 1), 1);
573
- this.$l.hPos = pb.mul(this.invProjViewMatrix, this.clipSpacePos);
574
- this.$l.hPos = pb.div(this.$l.hPos, this.$l.hPos.w);
575
- this.$l.viewDir = pb.sub(this.hPos.xyz, this.cameraPosition);
576
- this.$l.fogFactor = ShaderHelper.computeFogFactor(this, this.viewDir, this.fogType, this.fogParams);
577
- this.$l.color = pb.mul(this.fogColor.rgb, this.fogFactor);
578
- this.$if(pb.equal(this.srgbOut, 0), function() {
579
- this.$outputs.outColor = pb.vec4(this.color, this.fogFactor);
580
- }).$else(function() {
581
- this.$outputs.outColor = pb.vec4(linearToGamma(this, this.color), this.fogFactor);
582
- });
583
- });
584
- }
585
- });
586
- this._bindgroupFog = device.createBindGroup(this._programFog.bindGroupLayouts[0]);
587
- }
588
- if (!this._programSky.color) {
589
- this._programSky.color = device.buildRenderProgram({
590
- label: 'SolidColorSky',
591
- vertex (pb) {
592
- this.$inputs.pos = pb.vec3().attrib('position');
593
- this.worldMatrix = pb.mat4().uniform(0);
594
- this.viewProjMatrix = pb.mat4().uniform(0);
595
- this.cameraPos = pb.vec3().uniform(0);
596
- pb.main(function() {
597
- this.$l.worldDirection = pb.mul(this.worldMatrix, pb.vec4(this.$inputs.pos, 0)).xyz;
598
- this.$builtins.position = pb.mul(this.viewProjMatrix, pb.vec4(pb.add(this.worldDirection, this.cameraPos), 1));
599
- this.$builtins.position.z = this.$builtins.position.w;
600
- });
601
- },
602
914
  fragment (pb) {
603
915
  this.$outputs.outColor = pb.vec4();
604
916
  this.color = pb.vec4().uniform(0);
917
+ this.texture = pb.tex2D().uniform(0);
605
918
  this.srgbOut = pb.int().uniform(0);
606
919
  pb.main(function() {
920
+ this.$l.sampleColor = pb.textureSampleLevel(this.texture, this.$inputs.uv, 0);
921
+ this.$l.outColor = pb.mul(this.sampleColor, this.color);
607
922
  this.$if(pb.equal(this.srgbOut, 0), function() {
608
- this.$outputs.outColor = pb.vec4(this.color.rgb, 1);
923
+ this.$outputs.outColor = pb.vec4(this.outColor.rgb, 1);
609
924
  }).$else(function() {
610
- this.$outputs.outColor = pb.vec4(linearToGamma(this, this.color.rgb), 1);
925
+ this.$outputs.outColor = pb.vec4(linearToGamma(this, this.outColor.rgb), 1);
611
926
  });
612
927
  });
613
928
  }
614
929
  });
615
- this._bindgroupSky.color = device.createBindGroup(this._programSky.color.bindGroupLayouts[0]);
930
+ SkyRenderer._programSky.image.name = '@SkyImage';
931
+ }
932
+ if (!this._bindgroupSky.image) {
933
+ this._bindgroupSky.image = new DRef(device.createBindGroup(SkyRenderer._programSky.image.bindGroupLayouts[0]));
616
934
  }
617
- if (!this._programSky.scatter) {
618
- this._programSky.scatter = SkyRenderer._createScatterProgram(device, true);
619
- this._bindgroupSky.scatter = device.createBindGroup(this._programSky.scatter.bindGroupLayouts[0]);
935
+ if (!SkyRenderer._programSky.scatter) {
936
+ SkyRenderer._programSky.scatter = SkyRenderer._createScatterProgram(device, true);
620
937
  }
621
- if (!this._programSky['scatter-nocloud']) {
622
- this._programSky['scatter-nocloud'] = SkyRenderer._createScatterProgram(device, false);
623
- this._bindgroupSky['scatter-nocloud'] = device.createBindGroup(this._programSky['scatter-nocloud'].bindGroupLayouts[0]);
938
+ if (!this._bindgroupSky.scatter) {
939
+ this._bindgroupSky.scatter = new DRef(device.createBindGroup(SkyRenderer._programSky.scatter.bindGroupLayouts[0]));
624
940
  }
625
- if (!this._programSky.skybox) {
626
- this._programSky.skybox = device.buildRenderProgram({
941
+ if (!SkyRenderer._programSky.skybox) {
942
+ SkyRenderer._programSky.skybox = device.buildRenderProgram({
627
943
  label: 'SkyBoxSky',
628
944
  vertex (pb) {
629
945
  this.$inputs.pos = pb.vec3().attrib('position');
@@ -654,32 +970,41 @@ const defaultSkyWorldMatrix = Matrix4x4.identity();
654
970
  });
655
971
  }
656
972
  });
657
- this._bindgroupSky.skybox = device.createBindGroup(this._programSky.skybox.bindGroupLayouts[0]);
658
- }
659
- if (!this._renderStatesSky) {
660
- this._renderStatesSky = device.createRenderStateSet();
661
- this._renderStatesSky.useDepthState().enableTest(true).enableWrite(false).setCompareFunc('le');
662
- this._renderStatesSky.useRasterizerState().setCullMode('none');
663
- }
664
- if (!this._renderStatesSkyNoDepthTest) {
665
- this._renderStatesSkyNoDepthTest = device.createRenderStateSet();
666
- this._renderStatesSkyNoDepthTest.useDepthState().enableTest(false).enableWrite(false);
667
- this._renderStatesSkyNoDepthTest.useRasterizerState().setCullMode('none');
668
- }
669
- if (!this._renderStatesFog) {
670
- this._renderStatesFog = device.createRenderStateSet();
671
- this._renderStatesFog.useRasterizerState().setCullMode('none');
672
- this._renderStatesFog.useBlendingState().enable(true).setBlendFunc('one', 'inv-src-alpha');
673
- this._renderStatesFog.useDepthState().enableTest(false).enableWrite(false);
674
- }
675
- if (!this._renderStatesFogScatter) {
676
- this._renderStatesFogScatter = device.createRenderStateSet();
677
- this._renderStatesFogScatter.useRasterizerState().setCullMode('none');
678
- this._renderStatesFogScatter.useBlendingState().enable(true).setBlendFunc('one', 'inv-src-alpha');
679
- this._renderStatesFogScatter.useDepthState().enableTest(true).enableWrite(false).setCompareFunc('gt');
680
- }
681
- if (!this._vertexLayout) {
682
- this._vertexLayout = device.createVertexLayout({
973
+ SkyRenderer._programSky.skybox.name = '@SkySkybox';
974
+ }
975
+ if (!this._bindgroupSky.skybox) {
976
+ this._bindgroupSky.skybox = new DRef(device.createBindGroup(SkyRenderer._programSky.skybox.bindGroupLayouts[0]));
977
+ }
978
+ if (!SkyRenderer._renderStatesSky) {
979
+ SkyRenderer._renderStatesSky = device.createRenderStateSet();
980
+ SkyRenderer._renderStatesSky.useDepthState().enableTest(true).enableWrite(false).setCompareFunc('le');
981
+ SkyRenderer._renderStatesSky.useRasterizerState().setCullMode('none');
982
+ }
983
+ if (!SkyRenderer._renderStatesSkyNoDepthTest) {
984
+ SkyRenderer._renderStatesSkyNoDepthTest = device.createRenderStateSet();
985
+ SkyRenderer._renderStatesSkyNoDepthTest.useDepthState().enableTest(false).enableWrite(false);
986
+ SkyRenderer._renderStatesSkyNoDepthTest.useRasterizerState().setCullMode('none');
987
+ }
988
+ if (!SkyRenderer._renderStatesFog) {
989
+ SkyRenderer._renderStatesFog = device.createRenderStateSet();
990
+ SkyRenderer._renderStatesFog.useRasterizerState().setCullMode('none');
991
+ SkyRenderer._renderStatesFog.useBlendingState().enable(true).setBlendFunc('one', 'src-alpha');
992
+ SkyRenderer._renderStatesFog.useDepthState().enableTest(false).enableWrite(false);
993
+ }
994
+ if (!SkyRenderer._renderStatesFogScatter) {
995
+ SkyRenderer._renderStatesFogScatter = device.createRenderStateSet();
996
+ SkyRenderer._renderStatesFogScatter.useRasterizerState().setCullMode('none');
997
+ SkyRenderer._renderStatesFogScatter.useBlendingState().enable(true).setBlendFunc('one', 'src-alpha');
998
+ SkyRenderer._renderStatesFogScatter.useDepthState().enableTest(true).enableWrite(false).setCompareFunc('gt');
999
+ }
1000
+ if (!SkyRenderer._renderStatesDistantLight) {
1001
+ SkyRenderer._renderStatesDistantLight = device.createRenderStateSet();
1002
+ SkyRenderer._renderStatesDistantLight.useDepthState().enableTest(false).enableWrite(false);
1003
+ SkyRenderer._renderStatesDistantLight.useBlendingState().enable(true).setBlendEquation('add', 'add').setBlendFuncRGB('one', 'one').setBlendFuncAlpha('zero', 'one');
1004
+ SkyRenderer._renderStatesDistantLight.useRasterizerState().setCullMode('none');
1005
+ }
1006
+ if (!SkyRenderer._vertexLayout) {
1007
+ SkyRenderer._vertexLayout = device.createVertexLayout({
683
1008
  vertexBuffers: [
684
1009
  {
685
1010
  buffer: device.createVertexBuffer('position_f32x2', new Float32Array([
@@ -696,18 +1021,102 @@ const defaultSkyWorldMatrix = Matrix4x4.identity();
696
1021
  ]
697
1022
  });
698
1023
  }
699
- if (!this._primitiveSky) {
700
- this._primitiveSky = new BoxShape({
1024
+ if (!SkyRenderer._primitiveSky) {
1025
+ SkyRenderer._primitiveSky = new BoxShape({
701
1026
  size: 8
702
1027
  });
703
1028
  }
1029
+ if (!SkyRenderer._primitiveDistantLight) {
1030
+ const data = new Float32Array(uniformSphereSamples.length * 3);
1031
+ let i = 0;
1032
+ for (const v of uniformSphereSamples){
1033
+ data[i++] = v.x;
1034
+ data[i++] = v.y;
1035
+ data[i++] = v.z;
1036
+ }
1037
+ SkyRenderer._primitiveDistantLight = new Primitive();
1038
+ SkyRenderer._primitiveDistantLight.createAndSetVertexBuffer('position_f32x3', data);
1039
+ SkyRenderer._primitiveDistantLight.indexCount = uniformSphereSamples.length;
1040
+ SkyRenderer._primitiveDistantLight.indexStart = 0;
1041
+ SkyRenderer._primitiveDistantLight.primitiveType = 'point-list';
1042
+ }
1043
+ }
1044
+ /** @internal */ static _createFogProgram(device, noDepth) {
1045
+ const program = device.buildRenderProgram({
1046
+ label: 'Fog',
1047
+ vertex (pb) {
1048
+ this.rt = pb.int().uniform(0);
1049
+ this.$inputs.pos = pb.vec2().attrib('position');
1050
+ this.$outputs.uv = pb.vec2();
1051
+ pb.main(function() {
1052
+ this.$builtins.position = pb.vec4(this.$inputs.pos, 1, 1);
1053
+ this.$outputs.uv = pb.add(pb.mul(this.$inputs.pos.xy, 0.5), pb.vec2(0.5));
1054
+ if (device.type === 'webgpu') {
1055
+ this.$if(pb.notEqual(this.rt, 0), function() {
1056
+ this.$builtins.position.y = pb.neg(this.$builtins.position.y);
1057
+ });
1058
+ }
1059
+ });
1060
+ },
1061
+ fragment (pb) {
1062
+ const AtmosphereParams = getAtmosphereParamsStruct(pb);
1063
+ const HeightFogParams = getHeightFogParamsStruct(pb);
1064
+ if (!noDepth) {
1065
+ this.depthTex = pb.tex2D().sampleType('unfilterable-float').uniform(0);
1066
+ }
1067
+ this.apLut = pb.tex2D().uniform(0);
1068
+ this.skyDistantLightLut = pb.tex2D().uniform(0);
1069
+ this.invProjViewMatrix = pb.mat4().uniform(0);
1070
+ this.cameraNearFar = pb.vec2().uniform(0);
1071
+ this.cameraPosition = pb.vec3().uniform(0);
1072
+ this.withAerialPerspective = pb.int().uniform(0);
1073
+ this.fogType = pb.int().uniform(0);
1074
+ this.atmosphereParams = AtmosphereParams().uniform(0);
1075
+ this.heightFogParams = HeightFogParams().uniform(0);
1076
+ this.srgbOut = pb.int().uniform(0);
1077
+ this.$outputs.outColor = pb.vec4();
1078
+ pb.main(function() {
1079
+ this.$l.depthValue = noDepth ? pb.float(1) : pb.textureSample(this.depthTex, this.$inputs.uv).r;
1080
+ this.$l.clipSpacePos = pb.vec4(pb.sub(pb.mul(this.$inputs.uv, 2), pb.vec2(1)), pb.sub(pb.mul(this.depthValue, 2), 1), 1);
1081
+ this.$l.hPos = pb.mul(this.invProjViewMatrix, this.clipSpacePos);
1082
+ this.$l.worldPos = pb.div(this.$l.hPos, this.$l.hPos.w).xyz;
1083
+ this.$l.isSky = pb.equal(this.$l.depthValue, 1);
1084
+ this.$l.color = calculateFog(this, this.withAerialPerspective, this.fogType, this.atmosphereParams, this.heightFogParams, this.$inputs.uv, this.isSky, this.cameraPosition, this.worldPos, 0, this.apLut, this.skyDistantLightLut);
1085
+ this.$if(pb.equal(this.srgbOut, 0), function() {
1086
+ this.$outputs.outColor = this.color;
1087
+ }).$else(function() {
1088
+ this.$outputs.outColor = pb.vec4(linearToGamma(this, this.color.rgb), this.color.a);
1089
+ });
1090
+ });
1091
+ }
1092
+ });
1093
+ program.name = noDepth ? '@FogNoDepth' : '@Fog';
1094
+ return program;
704
1095
  }
705
1096
  /** @internal */ static _getSunDir(sunLight) {
706
1097
  // TODO: reduce GC
707
1098
  return sunLight?.directionAndCutoff.xyz().scaleBy(-1) ?? ShaderHelper.defaultSunDir;
708
1099
  }
1100
+ /** @internal */ static _getSunColor(sunLight) {
1101
+ // TODO: reduce GC
1102
+ return sunLight?.diffuseAndIntensity ?? new Vector4(1, 1, 1, 10);
1103
+ }
1104
+ static _createAtmosphereLUTPrograms(device) {
1105
+ if (!this.transmittanceLutProgram) {
1106
+ this.transmittanceLutProgram = createTransmittanceLutProgram(device);
1107
+ }
1108
+ if (!this.multiScatteringLutProgram) {
1109
+ this.multiScatteringLutProgram = createMultiScatteringLutProgram(device);
1110
+ }
1111
+ if (!this.skyViewLutProgram) {
1112
+ this.skyViewLutProgram = createSkyViewLutProgram(device);
1113
+ }
1114
+ if (!this.APLutProgram) {
1115
+ this.APLutProgram = createAPLutProgram(device);
1116
+ }
1117
+ }
709
1118
  static _createScatterProgram(device, cloud) {
710
- return device.buildRenderProgram({
1119
+ const program = device.buildRenderProgram({
711
1120
  vertex (pb) {
712
1121
  this.$inputs.pos = pb.vec3().attrib('position');
713
1122
  this.worldMatrix = pb.mat4().uniform(0);
@@ -724,26 +1133,14 @@ const defaultSkyWorldMatrix = Matrix4x4.identity();
724
1133
  this.$outputs.outColor = pb.vec4();
725
1134
  this.tLut = pb.tex2D().uniform(0);
726
1135
  this.skyLut = pb.tex2D().uniform(0);
727
- this.sunDir = pb.vec3().uniform(0);
1136
+ this.params = getAtmosphereParamsStruct(pb)().uniform(0);
728
1137
  if (cloud) {
729
1138
  this.cloudy = pb.float().uniform(0);
730
1139
  this.cloudIntensity = pb.float().uniform(0);
731
1140
  this.time = pb.float().uniform(0);
732
1141
  this.velocity = pb.vec2().uniform(0);
733
1142
  }
734
- this.drawGround = pb.int().uniform(0);
735
1143
  this.srgbOut = pb.int().uniform(0);
736
- this.viewPos = pb.vec3(ScatteringLut.viewPosition.x, ScatteringLut.viewPosition.y, ScatteringLut.viewPosition.z);
737
- pb.func('getMiePhase', [
738
- pb.float('cosTheta')
739
- ], function() {
740
- this.$l.g = pb.float(0.8);
741
- this.$l.scale = pb.float(3 / (Math.PI * 8));
742
- this.$l.gg = pb.mul(this.g, this.g);
743
- this.$l.num = pb.mul(pb.sub(1, this.gg), pb.add(pb.mul(this.cosTheta, this.cosTheta), 1));
744
- this.$l.denom = pb.mul(pb.add(2, this.gg), pb.pow(pb.sub(pb.add(1, this.gg), pb.mul(this.g, this.cosTheta, 2)), 1.5));
745
- this.$return(pb.div(pb.mul(this.scale, this.num), this.denom));
746
- });
747
1144
  pb.func('noise', [
748
1145
  pb.vec3('p'),
749
1146
  pb.float('t')
@@ -764,77 +1161,12 @@ const defaultSkyWorldMatrix = Matrix4x4.identity();
764
1161
  this.f = pb.add(this.f, pb.mul(smoothNoise3D(this, this.p2), 0.015625));
765
1162
  this.$return(this.f);
766
1163
  });
767
- pb.func('getValFromSkyLUT', [
768
- pb.vec3('rayDir'),
769
- pb.vec3('sunDir')
770
- ], function() {
771
- this.$l.height = pb.length(this.viewPos);
772
- this.$l.up = pb.div(this.viewPos, this.height);
773
- this.$l.c = pb.div(pb.sqrt(pb.sub(pb.mul(this.height, this.height), pb.mul(ScatteringLut.groundRadius, ScatteringLut.groundRadius))), this.height);
774
- this.$l.horizonAngle = pb.acos(pb.clamp(this.c, -1, 1));
775
- this.$l.altitudeAngle = pb.sub(this.horizonAngle, pb.acos(pb.dot(this.rayDir, this.up)));
776
- this.$l.azimuthAngle = pb.float();
777
- this.$if(pb.greaterThan(pb.abs(this.altitudeAngle), Math.PI * 0.5 - 0.0001), function() {
778
- this.azimuthAngle = 0;
779
- }).$else(function() {
780
- this.$l.right = pb.cross(this.sunDir, this.up);
781
- this.$l.forward = pb.cross(this.up, this.right);
782
- this.$l.projectedDir = pb.normalize(pb.sub(this.rayDir, pb.mul(this.up, pb.dot(this.rayDir, this.up))));
783
- this.$l.sinTheta = pb.dot(this.projectedDir, this.right);
784
- this.$l.cosTheta = pb.dot(this.projectedDir, this.forward);
785
- this.azimuthAngle = pb.add(pb.atan2(this.sinTheta, this.cosTheta), Math.PI);
786
- });
787
- this.$l.v = pb.add(0.5, pb.mul(0.5, pb.sign(this.altitudeAngle), pb.sqrt(pb.mul(pb.abs(this.altitudeAngle), 2 / Math.PI))));
788
- this.$l.uv = pb.vec2(pb.div(this.azimuthAngle, Math.PI * 2), this.v);
789
- this.$return(pb.textureSampleLevel(this.skyLut, this.uv, 0).rgb);
790
- });
791
- pb.func('sunWithBloom', [
792
- pb.vec3('rayDir'),
793
- pb.vec3('sunDir')
794
- ], function() {
795
- this.$l.sunSolidAngle = 0.53 * Math.PI / 180;
796
- this.$l.minSunCosTheta = pb.cos(this.sunSolidAngle);
797
- this.$l.cosTheta = pb.dot(this.rayDir, this.sunDir);
798
- this.$if(pb.greaterThanEqual(this.cosTheta, this.minSunCosTheta), function() {
799
- this.$return(pb.vec3(1));
800
- });
801
- this.$l.offset = pb.sub(this.minSunCosTheta, this.cosTheta);
802
- this.$l.gaussianBloom = pb.mul(pb.exp(pb.mul(this.offset, -50000)), 0.5);
803
- this.$l.invBloom = pb.mul(pb.div(1, pb.add(0.02, pb.mul(this.offset, 300))), 0.01);
804
- this.$return(pb.vec3(pb.add(this.gaussianBloom, this.invBloom)));
805
- });
806
- pb.func('rayIntersectSphere', [
807
- pb.vec3('ro'),
808
- pb.vec3('rd'),
809
- pb.float('rad')
810
- ], function() {
811
- this.$l.b = pb.dot(this.ro, this.rd);
812
- this.$l.c = pb.sub(pb.dot(this.ro, this.ro), pb.mul(this.rad, this.rad));
813
- this.$if(pb.and(pb.greaterThan(this.c, 0), pb.greaterThan(this.b, 0)), function() {
814
- this.$return(pb.float(-1));
815
- });
816
- this.$l.bb = pb.mul(this.b, this.b);
817
- this.$l.discr = pb.sub(this.bb, this.c);
818
- this.$if(pb.lessThan(this.discr, 0), function() {
819
- this.$return(pb.float(-1));
820
- });
821
- this.$if(pb.greaterThan(this.discr, this.bb), function() {
822
- this.$return(pb.sub(pb.sqrt(this.discr), this.b));
823
- });
824
- this.$return(pb.sub(pb.neg(pb.sqrt(this.discr)), this.b));
825
- });
826
- pb.func('getValFromTLUT', [
827
- pb.vec3('pos'),
828
- pb.vec3('sunDir')
829
- ], function() {
830
- this.$l.height = pb.length(this.pos);
831
- this.$l.up = pb.div(this.pos, this.height);
832
- this.$l.sunCosZenithAngle = pb.dot(this.sunDir, this.up);
833
- this.$l.uv = pb.vec2(pb.clamp(pb.add(0.5, pb.mul(this.sunCosZenithAngle, 0.5)), 0, 1), pb.max(0, pb.min(1, pb.div(pb.sub(this.height, ScatteringLut.groundRadius), pb.sub(ScatteringLut.atmosphereRadius, ScatteringLut.groundRadius)))));
834
- this.$return(pb.textureSampleLevel(this.tLut, this.uv, 0).rgb);
835
- });
836
1164
  pb.main(function() {
1165
+ // Calculate sky color
1166
+ this.$l.sunColor = pb.vec4();
1167
+ this.$l.skyColor = skyBox(this, this.params, this.sunColor, this.$inputs.worldDirection, pb.float(0.01), this.tLut, this.skyLut).rgb;
837
1168
  this.$l.rayDir = pb.normalize(this.$inputs.worldDirection);
1169
+ this.$l.sunDir = this.params.lightDir;
838
1170
  // ad-hoc
839
1171
  this.$l.sunIntensity = pb.sqrt(pb.max(0, pb.mul(this.sunDir.y, this.rayDir.y)));
840
1172
  // compute cloud
@@ -852,33 +1184,22 @@ const defaultSkyWorldMatrix = Matrix4x4.identity();
852
1184
  this.noiseValue = pb.smoothStep(1, pb.add(1, this.cloudy), this.noiseValue);
853
1185
  });
854
1186
  // use sun color as cloud color
855
- this.$l.sunColor = pb.mul(this.getValFromSkyLUT(this.sunDir, this.sunDir), this.sunIntensity);
856
- this.$l.cloudColor = pb.mul(this.sunColor.rgb, pb.mul(this.noiseValue, this.cloudIntensity));
1187
+ /*
1188
+ this.$l.sunColor = pb.mul(
1189
+ pb.textureSampleLevel(this.skyLut, viewDirToUV(this, this.sunDir), 0),
1190
+ this.sunIntensity
1191
+ );
1192
+ */ this.$l.cloudColor = pb.mul(this.sunColor.rgb, this.sunIntensity, pb.mul(this.noiseValue, this.cloudIntensity));
857
1193
  }
858
1194
  // Compute sky color
859
- this.$l.skyRayDir = this.$choice(pb.equal(this.drawGround, 0), pb.normalize(pb.vec3(this.rayDir.x, pb.max(0, this.rayDir.y), this.rayDir.z)), this.rayDir);
860
- this.$l.lum = this.getValFromSkyLUT(this.skyRayDir, this.sunDir);
861
- this.$l.sunLum = this.sunWithBloom(this.rayDir, this.sunDir);
862
- this.sunLum = pb.smoothStep(pb.vec3(0.002), pb.vec3(1), this.sunLum);
863
- this.$if(pb.greaterThan(pb.length(this.sunLum), 0), function() {
864
- this.$if(pb.greaterThanEqual(this.rayIntersectSphere(this.viewPos, this.rayDir, ScatteringLut.groundRadius), 0), function() {
865
- this.sunLum = pb.vec3(0);
866
- }).$else(function() {
867
- this.sunLum = pb.mul(this.sunLum, this.getValFromTLUT(this.viewPos, this.sunDir));
868
- });
869
- });
870
1195
  if (cloud) {
871
- this.lum = pb.add(this.lum, this.sunLum);
872
1196
  // blend
873
1197
  this.$l.vfactor = pb.clamp(pb.div(pb.sub(this.rayDir.y, 0.01), pb.sub(0.03, 0.01)), 0, 1);
874
1198
  this.$l.factor = pb.clamp(pb.mul(this.noiseValue, this.vfactor), 0, 1);
875
- this.$l.color = pb.mix(this.lum, this.cloudColor, this.factor);
1199
+ this.$l.color = pb.mix(this.skyColor, this.cloudColor, this.factor);
876
1200
  } else {
877
- this.$l.color = this.lum;
1201
+ this.$l.color = this.skyColor;
878
1202
  }
879
- this.color = pb.mul(this.color, 8);
880
- this.color = pb.pow(this.color, pb.vec3(1.3));
881
- this.color = pb.div(this.color, pb.add(pb.mul(pb.smoothStep(0, 0.2, pb.clamp(this.sunDir.y, 0, 1)), 2), 0.15));
882
1203
  this.$if(pb.equal(this.srgbOut, 0), function() {
883
1204
  this.$outputs.outColor = pb.vec4(this.color, 1);
884
1205
  }).$else(function() {
@@ -887,6 +1208,8 @@ const defaultSkyWorldMatrix = Matrix4x4.identity();
887
1208
  });
888
1209
  }
889
1210
  });
1211
+ program.name = cloud ? '@SkyScatterCloud' : '@SkyScatter';
1212
+ return program;
890
1213
  }
891
1214
  }
892
1215