@zephyr3d/scene 0.8.0 → 0.8.2

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