@zephyr3d/scene 0.9.2 → 0.9.3

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 (420) hide show
  1. package/dist/animation/animationset.js +135 -135
  2. package/dist/animation/animationset.js.map +1 -1
  3. package/dist/animation/ik/ik_chain_builder.js +68 -0
  4. package/dist/animation/ik/ik_chain_builder.js.map +1 -0
  5. package/dist/animation/ik/ik_pole_constraint.js +2 -7
  6. package/dist/animation/ik/ik_pole_constraint.js.map +1 -1
  7. package/dist/animation/joint_dynamics/controller.js +146 -146
  8. package/dist/animation/joint_dynamics/controller.js.map +1 -1
  9. package/dist/animation/joint_dynamics/math.js +16 -0
  10. package/dist/animation/joint_dynamics/math.js.map +1 -0
  11. package/dist/animation/spring/spring_particle.js +4 -4
  12. package/dist/animation/spring/spring_particle.js.map +1 -1
  13. package/dist/animation/spring/spring_system.js +75 -75
  14. package/dist/animation/spring/spring_system.js.map +1 -1
  15. package/dist/animation/spring2/constraints.js.map +1 -1
  16. package/dist/animation/spring2/controller.js +64 -64
  17. package/dist/animation/spring2/controller.js.map +1 -1
  18. package/dist/animation/spring2/math.js.map +1 -1
  19. package/dist/animation/spring2/spring_system.js +8 -8
  20. package/dist/animation/spring2/spring_system.js.map +1 -1
  21. package/dist/asset/model.js +57 -57
  22. package/dist/asset/model.js.map +1 -1
  23. package/dist/camera/camera.js +184 -184
  24. package/dist/camera/camera.js.map +1 -1
  25. package/dist/index.d.ts +2 -6
  26. package/dist/index.js +1 -1
  27. package/dist/material/material.js +288 -288
  28. package/dist/material/material.js.map +1 -1
  29. package/dist/material/shader/helper.js +281 -278
  30. package/dist/material/shader/helper.js.map +1 -1
  31. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimemgr.js +38 -0
  32. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimemgr.js.map +1 -0
  33. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimescript.js +10 -0
  34. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimescript.js.map +1 -0
  35. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptingsystem.js +127 -0
  36. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptingsystem.js.map +1 -0
  37. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptregistry.js +263 -0
  38. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptregistry.js.map +1 -0
  39. package/dist/render/cluster_light.js +3 -4
  40. package/dist/render/cluster_light.js.map +1 -1
  41. package/dist/render/rendergraph/history_resource_manager.js +93 -93
  42. package/dist/render/rendergraph/history_resource_manager.js.map +1 -1
  43. package/dist/render/rendergraph/history_resources.js +3 -3
  44. package/dist/render/rendergraph/history_resources.js.map +1 -1
  45. package/dist/render/rendergraph/types.js +22 -22
  46. package/dist/render/rendergraph/types.js.map +1 -1
  47. package/dist/scene/mesh.js +80 -80
  48. package/dist/scene/mesh.js.map +1 -1
  49. package/dist/scene/scene_node.js +228 -228
  50. package/dist/scene/scene_node.js.map +1 -1
  51. package/dist/shapes/torus.js +90 -59
  52. package/dist/shapes/torus.js.map +1 -1
  53. package/dist/src/animation/animation.js +127 -0
  54. package/dist/src/animation/animation.js.map +1 -0
  55. package/dist/src/animation/animationset.js +255 -0
  56. package/dist/src/animation/animationset.js.map +1 -0
  57. package/dist/src/animation/animationtrack.js +34 -0
  58. package/dist/src/animation/animationtrack.js.map +1 -0
  59. package/dist/src/animation/eulerrotationtrack.js +52 -0
  60. package/dist/src/animation/eulerrotationtrack.js.map +1 -0
  61. package/dist/src/animation/morphtarget.js +93 -0
  62. package/dist/src/animation/morphtarget.js.map +1 -0
  63. package/dist/src/animation/morphtrack.js +70 -0
  64. package/dist/src/animation/morphtrack.js.map +1 -0
  65. package/dist/src/animation/proptrack.js +161 -0
  66. package/dist/src/animation/proptrack.js.map +1 -0
  67. package/dist/src/animation/rotationtrack.js +51 -0
  68. package/dist/src/animation/rotationtrack.js.map +1 -0
  69. package/dist/src/animation/scaletrack.js +50 -0
  70. package/dist/src/animation/scaletrack.js.map +1 -0
  71. package/dist/src/animation/skeleton.js +204 -0
  72. package/dist/src/animation/skeleton.js.map +1 -0
  73. package/dist/src/animation/translationtrack.js +50 -0
  74. package/dist/src/animation/translationtrack.js.map +1 -0
  75. package/dist/src/app/app.js +129 -0
  76. package/dist/src/app/app.js.map +1 -0
  77. package/dist/src/app/inputmgr.js +267 -0
  78. package/dist/src/app/inputmgr.js.map +1 -0
  79. package/dist/src/asset/assetmanager.js +404 -0
  80. package/dist/src/asset/assetmanager.js.map +1 -0
  81. package/dist/src/asset/builtin.js +337 -0
  82. package/dist/src/asset/builtin.js.map +1 -0
  83. package/dist/src/asset/loaders/dds/dds.js +470 -0
  84. package/dist/src/asset/loaders/dds/dds.js.map +1 -0
  85. package/dist/src/asset/loaders/dds/dds_loader.js +28 -0
  86. package/dist/src/asset/loaders/dds/dds_loader.js.map +1 -0
  87. package/dist/src/asset/loaders/gltf/gltf_loader.js +1265 -0
  88. package/dist/src/asset/loaders/gltf/gltf_loader.js.map +1 -0
  89. package/dist/src/asset/loaders/gltf/helpers.js +327 -0
  90. package/dist/src/asset/loaders/gltf/helpers.js.map +1 -0
  91. package/dist/src/asset/loaders/hdr/hdr.js +180 -0
  92. package/dist/src/asset/loaders/hdr/hdr.js.map +1 -0
  93. package/dist/src/asset/loaders/image/tga_Loader.js +116 -0
  94. package/dist/src/asset/loaders/image/tga_Loader.js.map +1 -0
  95. package/dist/src/asset/loaders/image/webimage_loader.js +63 -0
  96. package/dist/src/asset/loaders/image/webimage_loader.js.map +1 -0
  97. package/dist/src/asset/loaders/loader.js +45 -0
  98. package/dist/src/asset/loaders/loader.js.map +1 -0
  99. package/dist/src/asset/model.js +414 -0
  100. package/dist/src/asset/model.js.map +1 -0
  101. package/dist/src/blitter/bilateralblur.js +221 -0
  102. package/dist/src/blitter/bilateralblur.js.map +1 -0
  103. package/dist/src/blitter/blitter.js +390 -0
  104. package/dist/src/blitter/blitter.js.map +1 -0
  105. package/dist/src/blitter/box.js +118 -0
  106. package/dist/src/blitter/box.js.map +1 -0
  107. package/dist/src/blitter/copy.js +22 -0
  108. package/dist/src/blitter/copy.js.map +1 -0
  109. package/dist/src/blitter/gaussianblur.js +228 -0
  110. package/dist/src/blitter/gaussianblur.js.map +1 -0
  111. package/dist/src/camera/base.js +92 -0
  112. package/dist/src/camera/base.js.map +1 -0
  113. package/dist/src/camera/camera.js +1005 -0
  114. package/dist/src/camera/camera.js.map +1 -0
  115. package/dist/src/camera/fps.js +238 -0
  116. package/dist/src/camera/fps.js.map +1 -0
  117. package/dist/src/camera/orbit.js +245 -0
  118. package/dist/src/camera/orbit.js.map +1 -0
  119. package/dist/src/camera/orthocamera.js +167 -0
  120. package/dist/src/camera/orthocamera.js.map +1 -0
  121. package/dist/src/camera/perspectivecamera.js +141 -0
  122. package/dist/src/camera/perspectivecamera.js.map +1 -0
  123. package/dist/src/index.js +120 -0
  124. package/dist/src/index.js.map +1 -0
  125. package/dist/src/material/blinn.js +81 -0
  126. package/dist/src/material/blinn.js.map +1 -0
  127. package/dist/src/material/grassmaterial.js +113 -0
  128. package/dist/src/material/grassmaterial.js.map +1 -0
  129. package/dist/src/material/lambert.js +92 -0
  130. package/dist/src/material/lambert.js.map +1 -0
  131. package/dist/src/material/material.js +301 -0
  132. package/dist/src/material/material.js.map +1 -0
  133. package/dist/src/material/meshmaterial.js +704 -0
  134. package/dist/src/material/meshmaterial.js.map +1 -0
  135. package/dist/src/material/mixins/albedocolor.js +76 -0
  136. package/dist/src/material/mixins/albedocolor.js.map +1 -0
  137. package/dist/src/material/mixins/foliage.js +47 -0
  138. package/dist/src/material/mixins/foliage.js.map +1 -0
  139. package/dist/src/material/mixins/lightmodel/blinnphong.js +112 -0
  140. package/dist/src/material/mixins/lightmodel/blinnphong.js.map +1 -0
  141. package/dist/src/material/mixins/lightmodel/lambert.js +58 -0
  142. package/dist/src/material/mixins/lightmodel/lambert.js.map +1 -0
  143. package/dist/src/material/mixins/lightmodel/pbrmetallicroughness.js +178 -0
  144. package/dist/src/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -0
  145. package/dist/src/material/mixins/lightmodel/pbrspecularglossness.js +139 -0
  146. package/dist/src/material/mixins/lightmodel/pbrspecularglossness.js.map +1 -0
  147. package/dist/src/material/mixins/lit.js +476 -0
  148. package/dist/src/material/mixins/lit.js.map +1 -0
  149. package/dist/src/material/mixins/pbr/common.js +918 -0
  150. package/dist/src/material/mixins/pbr/common.js.map +1 -0
  151. package/dist/src/material/mixins/texture.js +172 -0
  152. package/dist/src/material/mixins/texture.js.map +1 -0
  153. package/dist/src/material/mixins/vertexcolor.js +56 -0
  154. package/dist/src/material/mixins/vertexcolor.js.map +1 -0
  155. package/dist/src/material/particle.js +178 -0
  156. package/dist/src/material/particle.js.map +1 -0
  157. package/dist/src/material/pbrmr.js +97 -0
  158. package/dist/src/material/pbrmr.js.map +1 -0
  159. package/dist/src/material/pbrsg.js +97 -0
  160. package/dist/src/material/pbrsg.js.map +1 -0
  161. package/dist/src/material/shader/helper.js +1209 -0
  162. package/dist/src/material/shader/helper.js.map +1 -0
  163. package/dist/src/material/terrain-cm.js +606 -0
  164. package/dist/src/material/terrain-cm.js.map +1 -0
  165. package/dist/src/material/terrainmaterial.js +375 -0
  166. package/dist/src/material/terrainmaterial.js.map +1 -0
  167. package/dist/src/material/unlit.js +41 -0
  168. package/dist/src/material/unlit.js.map +1 -0
  169. package/dist/src/material/water.js +417 -0
  170. package/dist/src/material/water.js.map +1 -0
  171. package/dist/src/posteffect/bloom.js +361 -0
  172. package/dist/src/posteffect/bloom.js.map +1 -0
  173. package/dist/src/posteffect/compositor.js +226 -0
  174. package/dist/src/posteffect/compositor.js.map +1 -0
  175. package/dist/src/posteffect/fxaa.js +273 -0
  176. package/dist/src/posteffect/fxaa.js.map +1 -0
  177. package/dist/src/posteffect/grayscale.js +69 -0
  178. package/dist/src/posteffect/grayscale.js.map +1 -0
  179. package/dist/src/posteffect/motionblur.js +96 -0
  180. package/dist/src/posteffect/motionblur.js.map +1 -0
  181. package/dist/src/posteffect/posteffect.js +126 -0
  182. package/dist/src/posteffect/posteffect.js.map +1 -0
  183. package/dist/src/posteffect/sao.js +324 -0
  184. package/dist/src/posteffect/sao.js.map +1 -0
  185. package/dist/src/posteffect/ssr.js +489 -0
  186. package/dist/src/posteffect/ssr.js.map +1 -0
  187. package/dist/src/posteffect/taa.js +172 -0
  188. package/dist/src/posteffect/taa.js.map +1 -0
  189. package/dist/src/posteffect/tonemap.js +94 -0
  190. package/dist/src/posteffect/tonemap.js.map +1 -0
  191. package/dist/src/render/abuffer_oit.js +361 -0
  192. package/dist/src/render/abuffer_oit.js.map +1 -0
  193. package/dist/src/render/clipmap.js +851 -0
  194. package/dist/src/render/clipmap.js.map +1 -0
  195. package/dist/src/render/cluster_light.js +333 -0
  196. package/dist/src/render/cluster_light.js.map +1 -0
  197. package/dist/src/render/cull_visitor.js +187 -0
  198. package/dist/src/render/cull_visitor.js.map +1 -0
  199. package/dist/src/render/depthpass.js +68 -0
  200. package/dist/src/render/depthpass.js.map +1 -0
  201. package/dist/src/render/drawable_mixin.js +227 -0
  202. package/dist/src/render/drawable_mixin.js.map +1 -0
  203. package/dist/src/render/envlight.js +463 -0
  204. package/dist/src/render/envlight.js.map +1 -0
  205. package/dist/src/render/fbm_wavegenerator.js +251 -0
  206. package/dist/src/render/fbm_wavegenerator.js.map +1 -0
  207. package/dist/src/render/fft_wavegenerator.js +1006 -0
  208. package/dist/src/render/fft_wavegenerator.js.map +1 -0
  209. package/dist/src/render/fullscreenquad.js +38 -0
  210. package/dist/src/render/fullscreenquad.js.map +1 -0
  211. package/dist/src/render/gerstner_wavegenerator.js +314 -0
  212. package/dist/src/render/gerstner_wavegenerator.js.map +1 -0
  213. package/dist/src/render/globalbindgroup_allocator.js +60 -0
  214. package/dist/src/render/globalbindgroup_allocator.js.map +1 -0
  215. package/dist/src/render/hzb.js +273 -0
  216. package/dist/src/render/hzb.js.map +1 -0
  217. package/dist/src/render/lightpass.js +172 -0
  218. package/dist/src/render/lightpass.js.map +1 -0
  219. package/dist/src/render/objectcolorpass.js +51 -0
  220. package/dist/src/render/objectcolorpass.js.map +1 -0
  221. package/dist/src/render/primitive.js +364 -0
  222. package/dist/src/render/primitive.js.map +1 -0
  223. package/dist/src/render/render_queue.js +467 -0
  224. package/dist/src/render/render_queue.js.map +1 -0
  225. package/dist/src/render/renderbundle_wrapper.js +152 -0
  226. package/dist/src/render/renderbundle_wrapper.js.map +1 -0
  227. package/dist/src/render/renderer.js +455 -0
  228. package/dist/src/render/renderer.js.map +1 -0
  229. package/dist/src/render/renderpass.js +200 -0
  230. package/dist/src/render/renderpass.js.map +1 -0
  231. package/dist/src/render/shadowmap_pass.js +56 -0
  232. package/dist/src/render/shadowmap_pass.js.map +1 -0
  233. package/dist/src/render/sky.js +1103 -0
  234. package/dist/src/render/sky.js.map +1 -0
  235. package/dist/src/render/weightedblended_oit.js +168 -0
  236. package/dist/src/render/weightedblended_oit.js.map +1 -0
  237. package/dist/src/scene/batchgroup.js +162 -0
  238. package/dist/src/scene/batchgroup.js.map +1 -0
  239. package/dist/src/scene/environment.js +209 -0
  240. package/dist/src/scene/environment.js.map +1 -0
  241. package/dist/src/scene/graph_node.js +72 -0
  242. package/dist/src/scene/graph_node.js.map +1 -0
  243. package/dist/src/scene/light.js +416 -0
  244. package/dist/src/scene/light.js.map +1 -0
  245. package/dist/src/scene/mesh.js +341 -0
  246. package/dist/src/scene/mesh.js.map +1 -0
  247. package/dist/src/scene/octree.js +649 -0
  248. package/dist/src/scene/octree.js.map +1 -0
  249. package/dist/src/scene/particlesys.js +738 -0
  250. package/dist/src/scene/particlesys.js.map +1 -0
  251. package/dist/src/scene/raycast_visitor.js +103 -0
  252. package/dist/src/scene/raycast_visitor.js.map +1 -0
  253. package/dist/src/scene/scene.js +284 -0
  254. package/dist/src/scene/scene.js.map +1 -0
  255. package/dist/src/scene/scene_node.js +732 -0
  256. package/dist/src/scene/scene_node.js.map +1 -0
  257. package/dist/src/scene/terrain/grass.js +278 -0
  258. package/dist/src/scene/terrain/grass.js.map +1 -0
  259. package/dist/src/scene/terrain/heightfield.js +475 -0
  260. package/dist/src/scene/terrain/heightfield.js.map +1 -0
  261. package/dist/src/scene/terrain/patch.js +530 -0
  262. package/dist/src/scene/terrain/patch.js.map +1 -0
  263. package/dist/src/scene/terrain/quadtree.js +461 -0
  264. package/dist/src/scene/terrain/quadtree.js.map +1 -0
  265. package/dist/src/scene/terrain/terrain.js +246 -0
  266. package/dist/src/scene/terrain/terrain.js.map +1 -0
  267. package/dist/src/scene/terrain-cm/grass.js +594 -0
  268. package/dist/src/scene/terrain-cm/grass.js.map +1 -0
  269. package/dist/src/scene/terrain-cm/grassmaterial.js +159 -0
  270. package/dist/src/scene/terrain-cm/grassmaterial.js.map +1 -0
  271. package/dist/src/scene/terrain-cm/terrain-cm.js +538 -0
  272. package/dist/src/scene/terrain-cm/terrain-cm.js.map +1 -0
  273. package/dist/src/scene/water.js +374 -0
  274. package/dist/src/scene/water.js.map +1 -0
  275. package/dist/src/shaders/atmosphere.js +957 -0
  276. package/dist/src/shaders/atmosphere.js.map +1 -0
  277. package/dist/src/shaders/fog.js +112 -0
  278. package/dist/src/shaders/fog.js.map +1 -0
  279. package/dist/src/shaders/misc.js +266 -0
  280. package/dist/src/shaders/misc.js.map +1 -0
  281. package/dist/src/shaders/noise.js +222 -0
  282. package/dist/src/shaders/noise.js.map +1 -0
  283. package/dist/src/shaders/pbr.js +51 -0
  284. package/dist/src/shaders/pbr.js.map +1 -0
  285. package/dist/src/shaders/shadow.js +636 -0
  286. package/dist/src/shaders/shadow.js.map +1 -0
  287. package/dist/src/shaders/ssr.js +490 -0
  288. package/dist/src/shaders/ssr.js.map +1 -0
  289. package/dist/src/shaders/temporal.js +215 -0
  290. package/dist/src/shaders/temporal.js.map +1 -0
  291. package/dist/src/shaders/water.js +756 -0
  292. package/dist/src/shaders/water.js.map +1 -0
  293. package/dist/src/shadow/esm.js +237 -0
  294. package/dist/src/shadow/esm.js.map +1 -0
  295. package/dist/src/shadow/pcf_opt.js +181 -0
  296. package/dist/src/shadow/pcf_opt.js.map +1 -0
  297. package/dist/src/shadow/pcf_pd.js +189 -0
  298. package/dist/src/shadow/pcf_pd.js.map +1 -0
  299. package/dist/src/shadow/shader.js +37 -0
  300. package/dist/src/shadow/shader.js.map +1 -0
  301. package/dist/src/shadow/shadow_impl.js +15 -0
  302. package/dist/src/shadow/shadow_impl.js.map +1 -0
  303. package/dist/src/shadow/shadowmapper.js +790 -0
  304. package/dist/src/shadow/shadowmapper.js.map +1 -0
  305. package/dist/src/shadow/ssm.js +159 -0
  306. package/dist/src/shadow/ssm.js.map +1 -0
  307. package/dist/src/shadow/vsm.js +297 -0
  308. package/dist/src/shadow/vsm.js.map +1 -0
  309. package/dist/src/shapes/box.js +386 -0
  310. package/dist/src/shapes/box.js.map +1 -0
  311. package/dist/src/shapes/cylinder.js +125 -0
  312. package/dist/src/shapes/cylinder.js.map +1 -0
  313. package/dist/src/shapes/plane.js +88 -0
  314. package/dist/src/shapes/plane.js.map +1 -0
  315. package/dist/src/shapes/shape.js +87 -0
  316. package/dist/src/shapes/shape.js.map +1 -0
  317. package/dist/src/shapes/sphere.js +114 -0
  318. package/dist/src/shapes/sphere.js.map +1 -0
  319. package/dist/src/shapes/tetrahedron.js +188 -0
  320. package/dist/src/shapes/tetrahedron.js.map +1 -0
  321. package/dist/src/shapes/torus.js +111 -0
  322. package/dist/src/shapes/torus.js.map +1 -0
  323. package/dist/src/utility/aabbtree.js +400 -0
  324. package/dist/src/utility/aabbtree.js.map +1 -0
  325. package/dist/src/utility/bounding_volume.js +29 -0
  326. package/dist/src/utility/bounding_volume.js.map +1 -0
  327. package/dist/src/utility/debug.js +28 -0
  328. package/dist/src/utility/debug.js.map +1 -0
  329. package/dist/src/utility/draco/decoder.js +116 -0
  330. package/dist/src/utility/draco/decoder.js.map +1 -0
  331. package/dist/src/utility/misc.js +105 -0
  332. package/dist/src/utility/misc.js.map +1 -0
  333. package/dist/src/utility/panorama.js +163 -0
  334. package/dist/src/utility/panorama.js.map +1 -0
  335. package/dist/src/utility/pmrem.js +354 -0
  336. package/dist/src/utility/pmrem.js.map +1 -0
  337. package/dist/src/utility/rendermipmap.js +115 -0
  338. package/dist/src/utility/rendermipmap.js.map +1 -0
  339. package/dist/src/utility/serialization/json.js +402 -0
  340. package/dist/src/utility/serialization/json.js.map +1 -0
  341. package/dist/src/utility/serialization/manager.js +623 -0
  342. package/dist/src/utility/serialization/manager.js.map +1 -0
  343. package/dist/src/utility/serialization/scene/animation.js +248 -0
  344. package/dist/src/utility/serialization/scene/animation.js.map +1 -0
  345. package/dist/src/utility/serialization/scene/batch.js +59 -0
  346. package/dist/src/utility/serialization/scene/batch.js.map +1 -0
  347. package/dist/src/utility/serialization/scene/camera.js +790 -0
  348. package/dist/src/utility/serialization/scene/camera.js.map +1 -0
  349. package/dist/src/utility/serialization/scene/common.js +222 -0
  350. package/dist/src/utility/serialization/scene/common.js.map +1 -0
  351. package/dist/src/utility/serialization/scene/light.js +575 -0
  352. package/dist/src/utility/serialization/scene/light.js.map +1 -0
  353. package/dist/src/utility/serialization/scene/material.js +1111 -0
  354. package/dist/src/utility/serialization/scene/material.js.map +1 -0
  355. package/dist/src/utility/serialization/scene/mesh.js +148 -0
  356. package/dist/src/utility/serialization/scene/mesh.js.map +1 -0
  357. package/dist/src/utility/serialization/scene/misc.js +39 -0
  358. package/dist/src/utility/serialization/scene/misc.js.map +1 -0
  359. package/dist/src/utility/serialization/scene/node.js +451 -0
  360. package/dist/src/utility/serialization/scene/node.js.map +1 -0
  361. package/dist/src/utility/serialization/scene/particle.js +425 -0
  362. package/dist/src/utility/serialization/scene/particle.js.map +1 -0
  363. package/dist/src/utility/serialization/scene/primitive.js +692 -0
  364. package/dist/src/utility/serialization/scene/primitive.js.map +1 -0
  365. package/dist/src/utility/serialization/scene/scene.js +704 -0
  366. package/dist/src/utility/serialization/scene/scene.js.map +1 -0
  367. package/dist/src/utility/serialization/scene/terrain.js +488 -0
  368. package/dist/src/utility/serialization/scene/terrain.js.map +1 -0
  369. package/dist/src/utility/serialization/scene/water.js +465 -0
  370. package/dist/src/utility/serialization/scene/water.js.map +1 -0
  371. package/dist/src/utility/shprojector.js +297 -0
  372. package/dist/src/utility/shprojector.js.map +1 -0
  373. package/dist/src/utility/textures/ggxlut.js +213 -0
  374. package/dist/src/utility/textures/ggxlut.js.map +1 -0
  375. package/dist/src/utility/textures/gradientnoise.js +62 -0
  376. package/dist/src/utility/textures/gradientnoise.js.map +1 -0
  377. package/dist/src/utility/textures/randomnoise.js +41 -0
  378. package/dist/src/utility/textures/randomnoise.js.map +1 -0
  379. package/dist/src/values.js +162 -0
  380. package/dist/src/values.js.map +1 -0
  381. package/dist/utility/blueprint/material/common.js +7 -0
  382. package/dist/utility/blueprint/material/common.js.map +1 -0
  383. package/dist/utility/blueprint/material/ir.js +489 -489
  384. package/dist/utility/blueprint/material/ir.js.map +1 -1
  385. package/dist/utility/serialization/blueprint/constants.js +255 -0
  386. package/dist/utility/serialization/blueprint/constants.js.map +1 -0
  387. package/dist/utility/serialization/blueprint/material/constants.js +203 -0
  388. package/dist/utility/serialization/blueprint/material/constants.js.map +1 -0
  389. package/dist/utility/serialization/blueprint/material/texture.js +165 -0
  390. package/dist/utility/serialization/blueprint/material/texture.js.map +1 -0
  391. package/dist/utility/serialization/manager.js +271 -271
  392. package/dist/utility/serialization/manager.js.map +1 -1
  393. package/dist/utility/serialization/scene/animation.js.map +1 -1
  394. package/dist/utility/serialization/scene/camera.js.map +1 -1
  395. package/dist/utility/serialization/scene/common.js.map +1 -1
  396. package/dist/utility/serialization/scene/light.js.map +1 -1
  397. package/dist/utility/serialization/scene/material.js.map +1 -1
  398. package/dist/utility/serialization/scene/mesh.js.map +1 -1
  399. package/dist/utility/serialization/scene/node.js.map +1 -1
  400. package/dist/utility/serialization/scene/particle.js.map +1 -1
  401. package/dist/utility/serialization/scene/primitive.js.map +1 -1
  402. package/dist/utility/serialization/scene/scene.js.map +1 -1
  403. package/dist/utility/serialization/scene/terrain.js.map +1 -1
  404. package/dist/utility/serialization/types.js +4 -4
  405. package/dist/utility/serialization/types.js.map +1 -1
  406. package/dist/values.js +49 -53
  407. package/dist/values.js.map +1 -1
  408. package/package.json +1 -1
  409. package/dist/animation/joint_dynamics/vrm_spring_bone.js +0 -46
  410. package/dist/animation/joint_dynamics/vrm_spring_bone.js.map +0 -1
  411. package/dist/animation/spring/spring_bone.js +0 -240
  412. package/dist/animation/spring/spring_bone.js.map +0 -1
  413. package/dist/animation/spring/spring_bone_collider.js +0 -198
  414. package/dist/animation/spring/spring_bone_collider.js.map +0 -1
  415. package/dist/animation/spring/spring_bone_constraint.js +0 -170
  416. package/dist/animation/spring/spring_bone_constraint.js.map +0 -1
  417. package/dist/animation/spring/spring_bone_system.js +0 -328
  418. package/dist/animation/spring/spring_bone_system.js.map +0 -1
  419. package/dist/render/sky_motion_vector.js +0 -85
  420. package/dist/render/sky_motion_vector.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"cluster_light.js","sources":["../../src/render/cluster_light.ts"],"sourcesContent":["import type { Nullable } from '@zephyr3d/base';\r\nimport { Vector4 } from '@zephyr3d/base';\r\nimport { MAX_CLUSTERED_LIGHTS } from '../values';\r\nimport type {\r\n AbstractDevice,\r\n BindGroup,\r\n FrameBuffer,\r\n GPUProgram,\r\n PBStructTypeInfo,\r\n RenderStateSet,\r\n StructuredBuffer,\r\n Texture2D,\r\n VertexLayout\r\n} from '@zephyr3d/device';\r\nimport type { Camera } from '../camera/camera';\r\nimport type { RenderQueue } from './render_queue';\r\nimport { ShaderHelper } from '../material/shader/helper';\r\nimport { getDevice } from '../app/api';\r\n\r\nexport class ClusteredLight {\r\n private readonly _tileCountX: number;\r\n private readonly _tileCountY: number;\r\n private readonly _tileCountZ: number;\r\n private readonly _lights: Float32Array<ArrayBuffer>;\r\n private _lightIndexTexture: Nullable<Texture2D>;\r\n private _lightIndexFramebuffer: Nullable<FrameBuffer>;\r\n private _lightIndexProgram: Nullable<GPUProgram>;\r\n private _bindGroup: Nullable<BindGroup>;\r\n private _lightIndexVertexLayout: Nullable<VertexLayout>;\r\n private _lightIndexRenderStates: Nullable<RenderStateSet>;\r\n private _lightBuffer: Nullable<StructuredBuffer>;\r\n private readonly _sizeParam: Vector4;\r\n private _countParam: Int32Array<ArrayBuffer>;\r\n private readonly _clusterParam: Vector4;\r\n constructor() {\r\n this._tileCountX = 16;\r\n this._tileCountY = 16;\r\n this._tileCountZ = 32;\r\n this._lights = new Float32Array(16 * (MAX_CLUSTERED_LIGHTS + 1));\r\n this._lightIndexTexture = null;\r\n this._lightIndexFramebuffer = null;\r\n this._lightIndexProgram = null;\r\n this._lightBuffer = null;\r\n this._bindGroup = null;\r\n this._lightIndexVertexLayout = null;\r\n this._lightIndexRenderStates = null;\r\n this._sizeParam = new Vector4();\r\n this._countParam = new Int32Array(4);\r\n this._clusterParam = new Vector4();\r\n }\r\n get lightBuffer() {\r\n return this._lightBuffer;\r\n }\r\n get clusterParam() {\r\n return this._clusterParam;\r\n }\r\n get countParam() {\r\n return this._countParam;\r\n }\r\n get lightIndexTexture() {\r\n return this._lightIndexTexture;\r\n }\r\n private createVertexLayout(device: AbstractDevice, textureWidth: number, textureHeight: number) {\r\n let vb: StructuredBuffer;\r\n if (device.type === 'webgl') {\r\n const vertices = new Float32Array(this._tileCountX * this._tileCountY * this._tileCountZ * 3);\r\n for (let i = 0; i < vertices.length; i++) {\r\n const ix = i % textureWidth;\r\n const iy = Math.floor(i / textureWidth);\r\n vertices[i * 3 + 0] = (2 * (ix + 0.5)) / textureWidth - 1;\r\n vertices[i * 3 + 1] = (2 * (iy + 0.5)) / textureHeight - 1;\r\n vertices[i * 3 + 2] = i;\r\n }\r\n vb = device.createVertexBuffer('position_f32x3', vertices)!;\r\n } else {\r\n const vertices = new Float32Array(this._tileCountX * this._tileCountY * this._tileCountZ * 2);\r\n for (let i = 0; i < vertices.length; i++) {\r\n const ix = i % textureWidth;\r\n const iy = Math.floor(i / textureWidth);\r\n vertices[i * 2 + 0] = (2 * (ix + 0.5)) / textureWidth - 1;\r\n vertices[i * 2 + 1] = (2 * (iy + 0.5)) / textureHeight - 1;\r\n }\r\n vb = device.createVertexBuffer('position_f32x2', vertices)!;\r\n }\r\n this._lightIndexVertexLayout = device.createVertexLayout({\r\n vertexBuffers: [{ buffer: vb }]\r\n });\r\n }\r\n private createRenderState(device: AbstractDevice) {\r\n this._lightIndexRenderStates = device.createRenderStateSet();\r\n this._lightIndexRenderStates.useDepthState().enableTest(false).enableWrite(false);\r\n this._lightIndexRenderStates.useRasterizerState().setCullMode('none');\r\n }\r\n private createProgram(device: AbstractDevice) {\r\n const webgl1 = device.type === 'webgl';\r\n this._lightIndexProgram = device.buildRenderProgram({\r\n vertex(pb) {\r\n this.$inputs.pos = (webgl1 ? pb.vec3() : pb.vec2()).attrib('position');\r\n this.$outputs.value = webgl1 ? pb.vec4() : pb.uvec4();\r\n this.invProjMatrix = pb.mat4().uniform(0);\r\n this.viewMatrix = pb.mat4().uniform(0);\r\n this.sizeParam = pb.vec4().uniform(0);\r\n this.countParam = pb.ivec4().uniform(0);\r\n this[ShaderHelper.getLightBufferUniformName()] =\r\n pb.vec4[(MAX_CLUSTERED_LIGHTS + 1) * 4]().uniformBuffer(0);\r\n pb.func('lineIntersectionToZPlane', [pb.vec3('a'), pb.vec3('b'), pb.float('zDistance')], function () {\r\n this.$l.normal = pb.vec3(0, 0, 1);\r\n this.$l.ab = pb.sub(this.b, this.a);\r\n this.$l.t = pb.div(\r\n pb.sub(this.zDistance, pb.dot(this.normal, this.a)),\r\n pb.dot(this.normal, this.ab)\r\n );\r\n this.$return(pb.add(this.a, pb.mul(this.t, this.ab)));\r\n });\r\n pb.func('clipToView', [pb.vec4('clip')], function () {\r\n this.$l.view = pb.mul(this.invProjMatrix, this.clip);\r\n this.$return(pb.div(this.view, this.view.w));\r\n });\r\n pb.func('screenToView', [pb.vec4('screen')], function () {\r\n this.$l.texCoord = pb.div(this.screen.xy, this.sizeParam.xy);\r\n this.$l.clip = pb.vec4(\r\n pb.sub(pb.mul(pb.vec2(this.texCoord.x, pb.sub(1, this.texCoord.y)), 2), pb.vec2(1)),\r\n this.screen.z,\r\n this.screen.w\r\n );\r\n this.$return(this.clipToView(this.clip));\r\n });\r\n pb.func(\r\n 'sphereIntersectsAABB',\r\n [pb.vec4('sphere'), pb.vec3('aabbMin'), pb.vec3('aabbMax')],\r\n function () {\r\n this.$l.dmin = pb.float(0);\r\n this.$if(pb.lessThanEqual(this.sphere.w, 0), function () {\r\n this.$return(true);\r\n });\r\n this.$for(pb.int('i'), 0, 3, function () {\r\n this.$if(pb.lessThan(this.sphere.at(this.i), this.aabbMin.at(this.i)), function () {\r\n this.$l.delta = pb.sub(this.sphere.at(this.i), this.aabbMin.at(this.i));\r\n this.dmin = pb.add(this.dmin, pb.mul(this.delta, this.delta));\r\n }).$elseif(pb.greaterThan(this.sphere.at(this.i), this.aabbMax.at(this.i)), function () {\r\n this.$l.delta = pb.sub(this.sphere.at(this.i), this.aabbMax.at(this.i));\r\n this.dmin = pb.add(this.dmin, pb.mul(this.delta, this.delta));\r\n });\r\n });\r\n this.$if(pb.lessThanEqual(this.dmin, pb.mul(this.sphere.w, this.sphere.w)), function () {\r\n this.$return(true);\r\n });\r\n this.$return(false);\r\n }\r\n );\r\n pb.main(function () {\r\n if (pb.getDevice().type !== 'webgpu') {\r\n this.$builtins.pointSize = 1;\r\n }\r\n this.$builtins.position = pb.vec4(this.$inputs.pos.xy, 0, 1);\r\n if (pb.getDevice().type === 'webgpu') {\r\n this.$builtins.position = pb.mul(this.$builtins.position, pb.vec4(1, -1, 1, 1));\r\n }\r\n this.$l.tileIndex = webgl1 ? pb.int(this.$inputs.pos.z) : pb.int(this.$builtins.vertexIndex);\r\n this.$l.tileSize = pb.div(this.sizeParam.xy, pb.vec2(this.countParam.xy));\r\n this.$l.zIndex = pb.div(this.tileIndex, pb.mul(this.countParam.x, this.countParam.y));\r\n this.$l.yIndex = pb.div(\r\n pb.sub(this.tileIndex, pb.mul(this.zIndex, this.countParam.x, this.countParam.y)),\r\n this.countParam.x\r\n );\r\n this.$l.xIndex = pb.sub(\r\n this.tileIndex,\r\n pb.add(\r\n pb.mul(this.zIndex, this.countParam.x, this.countParam.y),\r\n pb.mul(this.yIndex, this.countParam.x)\r\n )\r\n );\r\n this.$l.maxPoint_sS = pb.vec4(\r\n pb.mul(\r\n pb.vec2(pb.float(pb.add(this.xIndex, 1)), pb.float(pb.add(this.yIndex, 1))),\r\n this.tileSize\r\n ),\r\n 0.0,\r\n 1.0\r\n );\r\n this.$l.minPoint_sS = pb.vec4(\r\n pb.mul(pb.vec2(pb.float(this.xIndex), pb.float(this.yIndex)), this.tileSize),\r\n 0.0,\r\n 1.0\r\n );\r\n this.$l.maxPoint_vS = this.screenToView(this.maxPoint_sS).xyz;\r\n this.$l.minPoint_vS = this.screenToView(this.minPoint_sS).xyz;\r\n this.$l.tileNear = pb.mul(\r\n pb.neg(this.sizeParam.z),\r\n pb.pow(\r\n pb.div(this.sizeParam.w, this.sizeParam.z),\r\n pb.div(pb.float(this.zIndex), pb.float(this.countParam.z))\r\n )\r\n );\r\n this.$l.tileFar = pb.mul(\r\n pb.neg(this.sizeParam.z),\r\n pb.pow(\r\n pb.div(this.sizeParam.w, this.sizeParam.z),\r\n pb.div(pb.add(pb.float(this.zIndex), 1), pb.float(this.countParam.z))\r\n )\r\n );\r\n this.$l.eyePos = pb.vec3(0);\r\n this.$l.minPointNear = this.lineIntersectionToZPlane(this.eyePos, this.minPoint_vS, this.tileNear);\r\n this.$l.minPointFar = this.lineIntersectionToZPlane(this.eyePos, this.minPoint_vS, this.tileFar);\r\n this.$l.maxPointNear = this.lineIntersectionToZPlane(this.eyePos, this.maxPoint_vS, this.tileNear);\r\n this.$l.maxPointFar = this.lineIntersectionToZPlane(this.eyePos, this.maxPoint_vS, this.tileFar);\r\n this.$l.aabbMin = pb.min(\r\n pb.min(this.minPointNear, this.minPointFar),\r\n pb.min(this.maxPointNear, this.maxPointFar)\r\n );\r\n this.$l.aabbMax = pb.max(\r\n pb.max(this.minPointNear, this.minPointFar),\r\n pb.max(this.maxPointNear, this.maxPointFar)\r\n );\r\n this.$l.n = pb.int(0);\r\n if (webgl1) {\r\n this.$l.lightIndices = pb.float[8]();\r\n this.$for(pb.int('i'), 0, 8, function () {\r\n this.lightIndices.setAt(this.i, 0);\r\n });\r\n this.$for(pb.int('i'), 1, 256, function () {\r\n this.$if(pb.equal(this.i, this.countParam.w), function () {\r\n this.$break();\r\n });\r\n this.$l.light = this[ShaderHelper.getLightBufferUniformName()].at(pb.mul(this.i, 4));\r\n this.$l.lightPos = pb.mul(this.viewMatrix, pb.vec4(this.light.xyz, 1));\r\n this.$l.lightPos.w = this.light.w;\r\n this.$if(this.sphereIntersectsAABB(this.lightPos, this.aabbMin, this.aabbMax), function () {\r\n this.$for(pb.int('j'), 0, 8, function () {\r\n this.$if(pb.equal(this.j, this.n), function () {\r\n this.lightIndices.setAt(this.j, pb.float(this.i));\r\n this.n = pb.add(this.n, 1);\r\n this.$break();\r\n });\r\n });\r\n this.$if(pb.equal(this.n, 8), function () {\r\n this.$break();\r\n });\r\n });\r\n });\r\n this.$outputs.value.r = pb.add(pb.mul(this.lightIndices[0], 256), this.lightIndices[1]);\r\n this.$outputs.value.g = pb.add(pb.mul(this.lightIndices[2], 256), this.lightIndices[3]);\r\n this.$outputs.value.b = pb.add(pb.mul(this.lightIndices[4], 256), this.lightIndices[5]);\r\n this.$outputs.value.a = pb.add(pb.mul(this.lightIndices[6], 256), this.lightIndices[7]);\r\n } else {\r\n this.$l.lightIndex = [\r\n pb.uint(0),\r\n pb.uint(0),\r\n pb.uint(0),\r\n pb.uint(0),\r\n pb.uint(0),\r\n pb.uint(0),\r\n pb.uint(0),\r\n pb.uint(0),\r\n pb.uint(0),\r\n pb.uint(0),\r\n pb.uint(0),\r\n pb.uint(0),\r\n pb.uint(0),\r\n pb.uint(0),\r\n pb.uint(0),\r\n pb.uint(0)\r\n ];\r\n this.$for(pb.uint('i'), 1, pb.uint(this.countParam.w), function () {\r\n this.$l.light = this[ShaderHelper.getLightBufferUniformName()].at(pb.mul(this.i, 4));\r\n this.$l.lightPos = pb.mul(this.viewMatrix, pb.vec4(this.light.xyz, 1));\r\n this.$l.lightPos.w = this.light.w;\r\n this.$if(this.sphereIntersectsAABB(this.lightPos, this.aabbMin, this.aabbMax), function () {\r\n this.lightIndex.setAt(this.n, this.i);\r\n this.n = pb.add(this.n, 1);\r\n this.$if(pb.equal(this.n, 16), function () {\r\n this.$break();\r\n });\r\n });\r\n });\r\n this.$l.r = pb.add(\r\n pb.sal(this.lightIndex[0], 24),\r\n pb.sal(this.lightIndex[1], 16),\r\n pb.sal(this.lightIndex[2], 8),\r\n this.lightIndex[3]\r\n );\r\n this.$l.g = pb.add(\r\n pb.sal(this.lightIndex[4], 24),\r\n pb.sal(this.lightIndex[5], 16),\r\n pb.sal(this.lightIndex[6], 8),\r\n this.lightIndex[7]\r\n );\r\n this.$l.b = pb.add(\r\n pb.sal(this.lightIndex[8], 24),\r\n pb.sal(this.lightIndex[9], 16),\r\n pb.sal(this.lightIndex[10], 8),\r\n this.lightIndex[11]\r\n );\r\n this.$l.a = pb.add(\r\n pb.sal(this.lightIndex[12], 24),\r\n pb.sal(this.lightIndex[13], 16),\r\n pb.sal(this.lightIndex[14], 8),\r\n this.lightIndex[15]\r\n );\r\n this.$outputs.value = pb.uvec4(this.r, this.g, this.b, this.a);\r\n }\r\n });\r\n },\r\n fragment(pb) {\r\n this.$outputs.color = webgl1 ? pb.vec4() : pb.uvec4();\r\n pb.main(function () {\r\n this.$outputs.color = this.$inputs.value;\r\n });\r\n }\r\n })!;\r\n this._lightIndexProgram.name = '@ClusteredLight_Index';\r\n this._bindGroup = device.createBindGroup(this._lightIndexProgram.bindGroupLayouts[0]);\r\n this._lightBuffer?.dispose();\r\n const lightBufferType = this._lightIndexProgram.getBindingInfo(\r\n ShaderHelper.getLightBufferUniformName()!\r\n )!.type;\r\n this._lightBuffer = device.createStructuredBuffer(lightBufferType as PBStructTypeInfo, {\r\n usage: 'uniform'\r\n });\r\n }\r\n private createLightIndexTexture(device: AbstractDevice) {\r\n const exp = Math.log2(this._tileCountX * this._tileCountY * this._tileCountZ);\r\n const a = (exp + 1) >>> 1;\r\n const b = exp - a;\r\n const textureWidth = 2 << (a - 1);\r\n const textureHeight = 2 << (b - 1);\r\n if (textureWidth * textureHeight !== this._tileCountX * this._tileCountY * this._tileCountZ) {\r\n throw new Error('Internal error');\r\n }\r\n this._lightIndexTexture = device.createTexture2D(\r\n device.type === 'webgl' ? 'rgba32f' : 'rgba32ui',\r\n textureWidth,\r\n textureHeight,\r\n { mipmapping: false }\r\n )!;\r\n this._lightIndexTexture.name = 'ClusterLightIndex';\r\n this._lightIndexFramebuffer?.dispose();\r\n this._lightIndexFramebuffer = device.createFrameBuffer([this._lightIndexTexture], null);\r\n }\r\n calculateLightIndex(camera: Camera, renderQueue: RenderQueue) {\r\n const numLights = this.getVisibleLights(renderQueue, this._lights);\r\n const device = getDevice();\r\n if (!this._lightIndexTexture) {\r\n this.createLightIndexTexture(device);\r\n }\r\n if (!this._lightIndexProgram) {\r\n this.createProgram(device);\r\n }\r\n if (!this._lightIndexVertexLayout) {\r\n this.createVertexLayout(device, this._lightIndexTexture!.width, this._lightIndexTexture!.height);\r\n }\r\n if (!this._lightIndexRenderStates) {\r\n this.createRenderState(device);\r\n }\r\n const viewport = device.getViewport();\r\n const vw = device.screenXToDevice(viewport.width);\r\n const vh = device.screenYToDevice(viewport.height);\r\n const scale = this._tileCountZ / Math.log2(camera.getFarPlane() / camera.getNearPlane());\r\n const bias = -(\r\n (this._tileCountZ * Math.log2(camera.getNearPlane())) /\r\n Math.log2(camera.getFarPlane() / camera.getNearPlane())\r\n );\r\n this._clusterParam.setXYZW(vw, vh, scale, bias);\r\n this._sizeParam.setXYZW(vw, vh, camera.getNearPlane(), camera.getFarPlane());\r\n this._countParam[0] = this._tileCountX;\r\n this._countParam[1] = this._tileCountY;\r\n this._countParam[2] = this._tileCountZ;\r\n // countParam.w stores light count + 1 because clustered indices start from 1.\r\n // Keep it valid even when there are no unshadowed punctual lights so deferred\r\n // passes can still evaluate emissive / env lighting without invalid cluster math.\r\n this._countParam[3] = numLights + 1;\r\n device.pushDeviceStates();\r\n device.setFramebuffer(this._lightIndexFramebuffer);\r\n if (numLights > 0) {\r\n if (this._lightBuffer!.disposed) {\r\n this._lightBuffer!.reload();\r\n }\r\n this._lightBuffer!.bufferSubData(0, this._lights);\r\n this._bindGroup!.setValue('invProjMatrix', camera.getInvProjectionMatrix());\r\n this._bindGroup!.setValue('viewMatrix', camera.viewMatrix);\r\n this._bindGroup!.setValue('sizeParam', this._sizeParam);\r\n this._bindGroup!.setValue('countParam', this._countParam);\r\n this._bindGroup!.setBuffer(ShaderHelper.getLightBufferUniformName(), this._lightBuffer!);\r\n device.setProgram(this._lightIndexProgram);\r\n device.setVertexLayout(this._lightIndexVertexLayout);\r\n device.setBindGroup(0, this._bindGroup!);\r\n const savedRS = device.getRenderStates();\r\n device.setRenderStates(this._lightIndexRenderStates);\r\n device.draw('point-list', 0, this._tileCountX * this._tileCountY * this._tileCountZ);\r\n device.setRenderStates(savedRS);\r\n } else {\r\n device.clearFrameBuffer(new Vector4(0, 0, 0, 0), 1, 0);\r\n }\r\n device.popDeviceStates();\r\n }\r\n private getVisibleLights(renderQueue: RenderQueue, lights: Float32Array) {\r\n const numLights = Math.min(renderQueue.unshadowedLights.length, MAX_CLUSTERED_LIGHTS);\r\n for (let i = 1; i <= numLights; i++) {\r\n const light = renderQueue.unshadowedLights[i - 1];\r\n const offset = i * 16;\r\n lights.set(light.positionAndRange, offset);\r\n lights.set(light.directionAndCutoff, offset + 4);\r\n lights.set(light.diffuseAndIntensity, offset + 8);\r\n lights.set(light.extraParams, offset + 12);\r\n }\r\n return numLights;\r\n }\r\n}\r\n"],"names":["ClusteredLight","_tileCountX","_tileCountY","_tileCountZ","_lights","_lightIndexTexture","_lightIndexFramebuffer","_lightIndexProgram","_bindGroup","_lightIndexVertexLayout","_lightIndexRenderStates","_lightBuffer","_sizeParam","_countParam","_clusterParam","Float32Array","MAX_CLUSTERED_LIGHTS","Vector4","Int32Array","lightBuffer","clusterParam","countParam","lightIndexTexture","createVertexLayout","device","textureWidth","textureHeight","vb","type","vertices","i","length","ix","iy","Math","floor","createVertexBuffer","vertexBuffers","buffer","createRenderState","createRenderStateSet","useDepthState","enableTest","enableWrite","useRasterizerState","setCullMode","createProgram","webgl1","buildRenderProgram","vertex","pb","$inputs","pos","vec3","vec2","attrib","$outputs","value","vec4","uvec4","invProjMatrix","mat4","uniform","viewMatrix","sizeParam","ivec4","ShaderHelper","getLightBufferUniformName","uniformBuffer","func","float","$l","normal","ab","sub","b","a","t","div","zDistance","dot","$return","add","mul","view","clip","w","texCoord","screen","xy","x","y","z","clipToView","dmin","$if","lessThanEqual","sphere","$for","int","lessThan","at","aabbMin","delta","$elseif","greaterThan","aabbMax","main","getDevice","$builtins","pointSize","position","tileIndex","vertexIndex","tileSize","zIndex","yIndex","xIndex","maxPoint_sS","minPoint_sS","maxPoint_vS","screenToView","xyz","minPoint_vS","tileNear","neg","pow","tileFar","eyePos","minPointNear","lineIntersectionToZPlane","minPointFar","maxPointNear","maxPointFar","min","max","n","lightIndices","setAt","equal","$break","light","lightPos","sphereIntersectsAABB","j","r","g","lightIndex","uint","sal","fragment","color","name","createBindGroup","bindGroupLayouts","dispose","lightBufferType","getBindingInfo","createStructuredBuffer","usage","createLightIndexTexture","exp","log2","Error","createTexture2D","mipmapping","createFrameBuffer","calculateLightIndex","camera","renderQueue","numLights","getVisibleLights","width","height","viewport","getViewport","vw","screenXToDevice","vh","screenYToDevice","scale","getFarPlane","getNearPlane","bias","setXYZW","pushDeviceStates","setFramebuffer","disposed","reload","bufferSubData","setValue","getInvProjectionMatrix","setBuffer","setProgram","setVertexLayout","setBindGroup","savedRS","getRenderStates","setRenderStates","draw","clearFrameBuffer","popDeviceStates","lights","unshadowedLights","offset","set","positionAndRange","directionAndCutoff","diffuseAndIntensity","extraParams"],"mappings":";;;;;AAmBO,MAAMA,cAAAA,CAAAA;IACMC,WAAoB;IACpBC,WAAoB;IACpBC,WAAoB;IACpBC,OAAmC;IAC5CC,kBAAwC;IACxCC,sBAA8C;IAC9CC,kBAAyC;IACzCC,UAAgC;IAChCC,uBAAgD;IAChDC,uBAAkD;IAClDC,YAAyC;IAChCC,UAAoB;IAC7BC,WAAqC;IAC5BC,aAAuB;IACxC,WAAc,EAAA;QACZ,IAAI,CAACb,WAAW,GAAG,EAAA;QACnB,IAAI,CAACC,WAAW,GAAG,EAAA;QACnB,IAAI,CAACC,WAAW,GAAG,EAAA;QACnB,IAAI,CAACC,OAAO,GAAG,IAAIW,aAAa,EAAMC,IAAAA,uBAAuB,CAAA,CAAA,CAAA;QAC7D,IAAI,CAACX,kBAAkB,GAAG,IAAA;QAC1B,IAAI,CAACC,sBAAsB,GAAG,IAAA;QAC9B,IAAI,CAACC,kBAAkB,GAAG,IAAA;QAC1B,IAAI,CAACI,YAAY,GAAG,IAAA;QACpB,IAAI,CAACH,UAAU,GAAG,IAAA;QAClB,IAAI,CAACC,uBAAuB,GAAG,IAAA;QAC/B,IAAI,CAACC,uBAAuB,GAAG,IAAA;QAC/B,IAAI,CAACE,UAAU,GAAG,IAAIK,OAAAA,EAAAA;AACtB,QAAA,IAAI,CAACJ,WAAW,GAAG,IAAIK,UAAW,CAAA,CAAA,CAAA;QAClC,IAAI,CAACJ,aAAa,GAAG,IAAIG,OAAAA,EAAAA;AAC3B;AACA,IAAA,IAAIE,WAAc,GAAA;QAChB,OAAO,IAAI,CAACR,YAAY;AAC1B;AACA,IAAA,IAAIS,YAAe,GAAA;QACjB,OAAO,IAAI,CAACN,aAAa;AAC3B;AACA,IAAA,IAAIO,UAAa,GAAA;QACf,OAAO,IAA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AOiL,eAAe,EAAA;AACxB;IACQ9B,gBAAiBF,CAAAA,WAAwB,EAAEiC,MAAoB,EAAE;QACvE,MAAMhC,SAAAA,GAAYxI,KAAKoG,GAAG,CAACmC,YAAYkC,gBAAgB,CAAC5K,MAAM,EAAEf,oBAAAA,CAAAA;AAChE,QAAA,IAAK,IAAIc,CAAAA,GAAI,CAAGA,EAAAA,CAAAA,IAAK4I,WAAW5I,CAAK,EAAA,CAAA;AACnC,YAAA,MAAM+G,KAAQ4B,GAAAA,WAAAA,CAAYkC,gBAAgB,CAAC7K,IAAI,CAAE,CAAA;AACjD,YAAA,MAAM8K,SAAS9K,CAAI,GAAA,EAAA;AACnB4K,YAAAA,MAAAA,CAAOG,GAAG,CAAChE,KAAMiE,CAAAA,gBAAgB,EAAEF,MAAAA,CAAAA;AACnCF,YAAAA,MAAAA,CAAOG,GAAG,CAAChE,KAAMkE,CAAAA,kBAAkB,EAAEH,MAAS,GAAA,CAAA,CAAA;AAC9CF,YAAAA,MAAAA,CAAOG,GAAG,CAAChE,KAAMmE,CAAAA,mBAAmB,EAAEJ,MAAS,GAAA,CAAA,CAAA;AAC/CF,YAAAA,MAAAA,CAAOG,GAAG,CAAChE,KAAMoE,CAAAA,WAAW,EAAEL,MAAS,GAAA,EAAA,CAAA;AACzC;QACA,OAAOlC,SAAAA;AACT;AACF;;;;"}
1
+ {"version":3,"file":"cluster_light.js","sources":["../../src/render/cluster_light.ts"],"sourcesContent":["import type { Nullable } from '@zephyr3d/base';\nimport { Vector4 } from '@zephyr3d/base';\nimport type {\n AbstractDevice,\n BindGroup,\n FrameBuffer,\n GPUProgram,\n PBStructTypeInfo,\n RenderStateSet,\n StructuredBuffer,\n Texture2D,\n VertexLayout\n} from '@zephyr3d/device';\nimport type { Camera } from '../camera/camera';\nimport type { RenderQueue } from './render_queue';\nimport { ShaderHelper } from '../material/shader/helper';\nimport { getDevice } from '../app/api';\n\nexport class ClusteredLight {\n private readonly _tileCountX: number;\n private readonly _tileCountY: number;\n private readonly _tileCountZ: number;\n private readonly _lights: Float32Array<ArrayBuffer>;\n private _lightIndexTexture: Nullable<Texture2D>;\n private _lightIndexFramebuffer: Nullable<FrameBuffer>;\n private _lightIndexProgram: Nullable<GPUProgram>;\n private _bindGroup: Nullable<BindGroup>;\n private _lightIndexVertexLayout: Nullable<VertexLayout>;\n private _lightIndexRenderStates: Nullable<RenderStateSet>;\n private _lightBuffer: Nullable<StructuredBuffer>;\n private readonly _sizeParam: Vector4;\n private _countParam: Int32Array<ArrayBuffer>;\n private readonly _clusterParam: Vector4;\n constructor() {\n this._tileCountX = 16;\n this._tileCountY = 16;\n this._tileCountZ = 32;\n this._lights = new Float32Array(16 * (ShaderHelper.getMaxClusteredLightCount() + 1));\n this._lightIndexTexture = null;\n this._lightIndexFramebuffer = null;\n this._lightIndexProgram = null;\n this._lightBuffer = null;\n this._bindGroup = null;\n this._lightIndexVertexLayout = null;\n this._lightIndexRenderStates = null;\n this._sizeParam = new Vector4();\n this._countParam = new Int32Array(4);\n this._clusterParam = new Vector4();\n }\n get lightBuffer() {\n return this._lightBuffer;\n }\n get clusterParam() {\n return this._clusterParam;\n }\n get countParam() {\n return this._countParam;\n }\n get lightIndexTexture() {\n return this._lightIndexTexture;\n }\n private createVertexLayout(device: AbstractDevice, textureWidth: number, textureHeight: number) {\n let vb: StructuredBuffer;\n if (device.type === 'webgl') {\n const vertices = new Float32Array(this._tileCountX * this._tileCountY * this._tileCountZ * 3);\n for (let i = 0; i < vertices.length; i++) {\n const ix = i % textureWidth;\n const iy = Math.floor(i / textureWidth);\n vertices[i * 3 + 0] = (2 * (ix + 0.5)) / textureWidth - 1;\n vertices[i * 3 + 1] = (2 * (iy + 0.5)) / textureHeight - 1;\n vertices[i * 3 + 2] = i;\n }\n vb = device.createVertexBuffer('position_f32x3', vertices)!;\n } else {\n const vertices = new Float32Array(this._tileCountX * this._tileCountY * this._tileCountZ * 2);\n for (let i = 0; i < vertices.length; i++) {\n const ix = i % textureWidth;\n const iy = Math.floor(i / textureWidth);\n vertices[i * 2 + 0] = (2 * (ix + 0.5)) / textureWidth - 1;\n vertices[i * 2 + 1] = (2 * (iy + 0.5)) / textureHeight - 1;\n }\n vb = device.createVertexBuffer('position_f32x2', vertices)!;\n }\n this._lightIndexVertexLayout = device.createVertexLayout({\n vertexBuffers: [{ buffer: vb }]\n });\n }\n private createRenderState(device: AbstractDevice) {\n this._lightIndexRenderStates = device.createRenderStateSet();\n this._lightIndexRenderStates.useDepthState().enableTest(false).enableWrite(false);\n this._lightIndexRenderStates.useRasterizerState().setCullMode('none');\n }\n private createProgram(device: AbstractDevice) {\n const webgl1 = device.type === 'webgl';\n this._lightIndexProgram = device.buildRenderProgram({\n vertex(pb) {\n this.$inputs.pos = (webgl1 ? pb.vec3() : pb.vec2()).attrib('position');\n this.$outputs.value = webgl1 ? pb.vec4() : pb.uvec4();\n this.invProjMatrix = pb.mat4().uniform(0);\n this.viewMatrix = pb.mat4().uniform(0);\n this.sizeParam = pb.vec4().uniform(0);\n this.countParam = pb.ivec4().uniform(0);\n this[ShaderHelper.getLightBufferUniformName()] =\n pb.vec4[(ShaderHelper.getMaxClusteredLightCount() + 1) * 4]().uniformBuffer(0);\n pb.func('lineIntersectionToZPlane', [pb.vec3('a'), pb.vec3('b'), pb.float('zDistance')], function () {\n this.$l.normal = pb.vec3(0, 0, 1);\n this.$l.ab = pb.sub(this.b, this.a);\n this.$l.t = pb.div(\n pb.sub(this.zDistance, pb.dot(this.normal, this.a)),\n pb.dot(this.normal, this.ab)\n );\n this.$return(pb.add(this.a, pb.mul(this.t, this.ab)));\n });\n pb.func('clipToView', [pb.vec4('clip')], function () {\n this.$l.view = pb.mul(this.invProjMatrix, this.clip);\n this.$return(pb.div(this.view, this.view.w));\n });\n pb.func('screenToView', [pb.vec4('screen')], function () {\n this.$l.texCoord = pb.div(this.screen.xy, this.sizeParam.xy);\n this.$l.clip = pb.vec4(\n pb.sub(pb.mul(pb.vec2(this.texCoord.x, pb.sub(1, this.texCoord.y)), 2), pb.vec2(1)),\n this.screen.z,\n this.screen.w\n );\n this.$return(this.clipToView(this.clip));\n });\n pb.func(\n 'sphereIntersectsAABB',\n [pb.vec4('sphere'), pb.vec3('aabbMin'), pb.vec3('aabbMax')],\n function () {\n this.$l.dmin = pb.float(0);\n this.$if(pb.lessThanEqual(this.sphere.w, 0), function () {\n this.$return(true);\n });\n this.$for(pb.int('i'), 0, 3, function () {\n this.$if(pb.lessThan(this.sphere.at(this.i), this.aabbMin.at(this.i)), function () {\n this.$l.delta = pb.sub(this.sphere.at(this.i), this.aabbMin.at(this.i));\n this.dmin = pb.add(this.dmin, pb.mul(this.delta, this.delta));\n }).$elseif(pb.greaterThan(this.sphere.at(this.i), this.aabbMax.at(this.i)), function () {\n this.$l.delta = pb.sub(this.sphere.at(this.i), this.aabbMax.at(this.i));\n this.dmin = pb.add(this.dmin, pb.mul(this.delta, this.delta));\n });\n });\n this.$if(pb.lessThanEqual(this.dmin, pb.mul(this.sphere.w, this.sphere.w)), function () {\n this.$return(true);\n });\n this.$return(false);\n }\n );\n pb.main(function () {\n if (pb.getDevice().type !== 'webgpu') {\n this.$builtins.pointSize = 1;\n }\n this.$builtins.position = pb.vec4(this.$inputs.pos.xy, 0, 1);\n if (pb.getDevice().type === 'webgpu') {\n this.$builtins.position = pb.mul(this.$builtins.position, pb.vec4(1, -1, 1, 1));\n }\n this.$l.tileIndex = webgl1 ? pb.int(this.$inputs.pos.z) : pb.int(this.$builtins.vertexIndex);\n this.$l.tileSize = pb.div(this.sizeParam.xy, pb.vec2(this.countParam.xy));\n this.$l.zIndex = pb.div(this.tileIndex, pb.mul(this.countParam.x, this.countParam.y));\n this.$l.yIndex = pb.div(\n pb.sub(this.tileIndex, pb.mul(this.zIndex, this.countParam.x, this.countParam.y)),\n this.countParam.x\n );\n this.$l.xIndex = pb.sub(\n this.tileIndex,\n pb.add(\n pb.mul(this.zIndex, this.countParam.x, this.countParam.y),\n pb.mul(this.yIndex, this.countParam.x)\n )\n );\n this.$l.maxPoint_sS = pb.vec4(\n pb.mul(\n pb.vec2(pb.float(pb.add(this.xIndex, 1)), pb.float(pb.add(this.yIndex, 1))),\n this.tileSize\n ),\n 0.0,\n 1.0\n );\n this.$l.minPoint_sS = pb.vec4(\n pb.mul(pb.vec2(pb.float(this.xIndex), pb.float(this.yIndex)), this.tileSize),\n 0.0,\n 1.0\n );\n this.$l.maxPoint_vS = this.screenToView(this.maxPoint_sS).xyz;\n this.$l.minPoint_vS = this.screenToView(this.minPoint_sS).xyz;\n this.$l.tileNear = pb.mul(\n pb.neg(this.sizeParam.z),\n pb.pow(\n pb.div(this.sizeParam.w, this.sizeParam.z),\n pb.div(pb.float(this.zIndex), pb.float(this.countParam.z))\n )\n );\n this.$l.tileFar = pb.mul(\n pb.neg(this.sizeParam.z),\n pb.pow(\n pb.div(this.sizeParam.w, this.sizeParam.z),\n pb.div(pb.add(pb.float(this.zIndex), 1), pb.float(this.countParam.z))\n )\n );\n this.$l.eyePos = pb.vec3(0);\n this.$l.minPointNear = this.lineIntersectionToZPlane(this.eyePos, this.minPoint_vS, this.tileNear);\n this.$l.minPointFar = this.lineIntersectionToZPlane(this.eyePos, this.minPoint_vS, this.tileFar);\n this.$l.maxPointNear = this.lineIntersectionToZPlane(this.eyePos, this.maxPoint_vS, this.tileNear);\n this.$l.maxPointFar = this.lineIntersectionToZPlane(this.eyePos, this.maxPoint_vS, this.tileFar);\n this.$l.aabbMin = pb.min(\n pb.min(this.minPointNear, this.minPointFar),\n pb.min(this.maxPointNear, this.maxPointFar)\n );\n this.$l.aabbMax = pb.max(\n pb.max(this.minPointNear, this.minPointFar),\n pb.max(this.maxPointNear, this.maxPointFar)\n );\n this.$l.n = pb.int(0);\n if (webgl1) {\n this.$l.lightIndices = pb.float[8]();\n this.$for(pb.int('i'), 0, 8, function () {\n this.lightIndices.setAt(this.i, 0);\n });\n this.$for(pb.int('i'), 1, 256, function () {\n this.$if(pb.equal(this.i, this.countParam.w), function () {\n this.$break();\n });\n this.$l.light = this[ShaderHelper.getLightBufferUniformName()].at(pb.mul(this.i, 4));\n this.$l.lightPos = pb.mul(this.viewMatrix, pb.vec4(this.light.xyz, 1));\n this.$l.lightPos.w = this.light.w;\n this.$if(this.sphereIntersectsAABB(this.lightPos, this.aabbMin, this.aabbMax), function () {\n this.$for(pb.int('j'), 0, 8, function () {\n this.$if(pb.equal(this.j, this.n), function () {\n this.lightIndices.setAt(this.j, pb.float(this.i));\n this.n = pb.add(this.n, 1);\n this.$break();\n });\n });\n this.$if(pb.equal(this.n, 8), function () {\n this.$break();\n });\n });\n });\n this.$outputs.value.r = pb.add(pb.mul(this.lightIndices[0], 256), this.lightIndices[1]);\n this.$outputs.value.g = pb.add(pb.mul(this.lightIndices[2], 256), this.lightIndices[3]);\n this.$outputs.value.b = pb.add(pb.mul(this.lightIndices[4], 256), this.lightIndices[5]);\n this.$outputs.value.a = pb.add(pb.mul(this.lightIndices[6], 256), this.lightIndices[7]);\n } else {\n this.$l.lightIndex = [\n pb.uint(0),\n pb.uint(0),\n pb.uint(0),\n pb.uint(0),\n pb.uint(0),\n pb.uint(0),\n pb.uint(0),\n pb.uint(0),\n pb.uint(0),\n pb.uint(0),\n pb.uint(0),\n pb.uint(0),\n pb.uint(0),\n pb.uint(0),\n pb.uint(0),\n pb.uint(0)\n ];\n this.$for(pb.uint('i'), 1, pb.uint(this.countParam.w), function () {\n this.$l.light = this[ShaderHelper.getLightBufferUniformName()].at(pb.mul(this.i, 4));\n this.$l.lightPos = pb.mul(this.viewMatrix, pb.vec4(this.light.xyz, 1));\n this.$l.lightPos.w = this.light.w;\n this.$if(this.sphereIntersectsAABB(this.lightPos, this.aabbMin, this.aabbMax), function () {\n this.lightIndex.setAt(this.n, this.i);\n this.n = pb.add(this.n, 1);\n this.$if(pb.equal(this.n, 16), function () {\n this.$break();\n });\n });\n });\n this.$l.r = pb.add(\n pb.sal(this.lightIndex[0], 24),\n pb.sal(this.lightIndex[1], 16),\n pb.sal(this.lightIndex[2], 8),\n this.lightIndex[3]\n );\n this.$l.g = pb.add(\n pb.sal(this.lightIndex[4], 24),\n pb.sal(this.lightIndex[5], 16),\n pb.sal(this.lightIndex[6], 8),\n this.lightIndex[7]\n );\n this.$l.b = pb.add(\n pb.sal(this.lightIndex[8], 24),\n pb.sal(this.lightIndex[9], 16),\n pb.sal(this.lightIndex[10], 8),\n this.lightIndex[11]\n );\n this.$l.a = pb.add(\n pb.sal(this.lightIndex[12], 24),\n pb.sal(this.lightIndex[13], 16),\n pb.sal(this.lightIndex[14], 8),\n this.lightIndex[15]\n );\n this.$outputs.value = pb.uvec4(this.r, this.g, this.b, this.a);\n }\n });\n },\n fragment(pb) {\n this.$outputs.color = webgl1 ? pb.vec4() : pb.uvec4();\n pb.main(function () {\n this.$outputs.color = this.$inputs.value;\n });\n }\n })!;\n this._lightIndexProgram.name = '@ClusteredLight_Index';\n this._bindGroup = device.createBindGroup(this._lightIndexProgram.bindGroupLayouts[0]);\n this._lightBuffer?.dispose();\n const lightBufferType = this._lightIndexProgram.getBindingInfo(\n ShaderHelper.getLightBufferUniformName()!\n )!.type;\n this._lightBuffer = device.createStructuredBuffer(lightBufferType as PBStructTypeInfo, {\n usage: 'uniform'\n });\n }\n private createLightIndexTexture(device: AbstractDevice) {\n const exp = Math.log2(this._tileCountX * this._tileCountY * this._tileCountZ);\n const a = (exp + 1) >>> 1;\n const b = exp - a;\n const textureWidth = 2 << (a - 1);\n const textureHeight = 2 << (b - 1);\n if (textureWidth * textureHeight !== this._tileCountX * this._tileCountY * this._tileCountZ) {\n throw new Error('Internal error');\n }\n this._lightIndexTexture = device.createTexture2D(\n device.type === 'webgl' ? 'rgba32f' : 'rgba32ui',\n textureWidth,\n textureHeight,\n { mipmapping: false }\n )!;\n this._lightIndexTexture.name = 'ClusterLightIndex';\n this._lightIndexFramebuffer?.dispose();\n this._lightIndexFramebuffer = device.createFrameBuffer([this._lightIndexTexture], null);\n }\n calculateLightIndex(camera: Camera, renderQueue: RenderQueue) {\n const numLights = this.getVisibleLights(renderQueue, this._lights);\n const device = getDevice();\n if (!this._lightIndexTexture) {\n this.createLightIndexTexture(device);\n }\n if (!this._lightIndexProgram) {\n this.createProgram(device);\n }\n if (!this._lightIndexVertexLayout) {\n this.createVertexLayout(device, this._lightIndexTexture!.width, this._lightIndexTexture!.height);\n }\n if (!this._lightIndexRenderStates) {\n this.createRenderState(device);\n }\n const viewport = device.getViewport();\n const vw = device.screenXToDevice(viewport.width);\n const vh = device.screenYToDevice(viewport.height);\n const scale = this._tileCountZ / Math.log2(camera.getFarPlane() / camera.getNearPlane());\n const bias = -(\n (this._tileCountZ * Math.log2(camera.getNearPlane())) /\n Math.log2(camera.getFarPlane() / camera.getNearPlane())\n );\n this._clusterParam.setXYZW(vw, vh, scale, bias);\n this._sizeParam.setXYZW(vw, vh, camera.getNearPlane(), camera.getFarPlane());\n this._countParam[0] = this._tileCountX;\n this._countParam[1] = this._tileCountY;\n this._countParam[2] = this._tileCountZ;\n // countParam.w stores light count + 1 because clustered indices start from 1.\n // Keep it valid even when there are no unshadowed punctual lights so deferred\n // passes can still evaluate emissive / env lighting without invalid cluster math.\n this._countParam[3] = numLights + 1;\n device.pushDeviceStates();\n device.setFramebuffer(this._lightIndexFramebuffer);\n if (numLights > 0) {\n if (this._lightBuffer!.disposed) {\n this._lightBuffer!.reload();\n }\n this._lightBuffer!.bufferSubData(0, this._lights);\n this._bindGroup!.setValue('invProjMatrix', camera.getInvProjectionMatrix());\n this._bindGroup!.setValue('viewMatrix', camera.viewMatrix);\n this._bindGroup!.setValue('sizeParam', this._sizeParam);\n this._bindGroup!.setValue('countParam', this._countParam);\n this._bindGroup!.setBuffer(ShaderHelper.getLightBufferUniformName(), this._lightBuffer!);\n device.setProgram(this._lightIndexProgram);\n device.setVertexLayout(this._lightIndexVertexLayout);\n device.setBindGroup(0, this._bindGroup!);\n const savedRS = device.getRenderStates();\n device.setRenderStates(this._lightIndexRenderStates);\n device.draw('point-list', 0, this._tileCountX * this._tileCountY * this._tileCountZ);\n device.setRenderStates(savedRS);\n } else {\n device.clearFrameBuffer(new Vector4(0, 0, 0, 0), 1, 0);\n }\n device.popDeviceStates();\n }\n private getVisibleLights(renderQueue: RenderQueue, lights: Float32Array) {\n const numLights = Math.min(renderQueue.unshadowedLights.length, ShaderHelper.getMaxClusteredLightCount());\n for (let i = 1; i <= numLights; i++) {\n const light = renderQueue.unshadowedLights[i - 1];\n const offset = i * 16;\n lights.set(light.positionAndRange, offset);\n lights.set(light.directionAndCutoff, offset + 4);\n lights.set(light.diffuseAndIntensity, offset + 8);\n lights.set(light.extraParams, offset + 12);\n }\n return numLights;\n }\n}\n"],"names":["ClusteredLight","_tileCountX","_tileCountY","_tileCountZ","_lights","_lightIndexTexture","_lightIndexFramebuffer","_lightIndexProgram","_bindGroup","_lightIndexVertexLayout","_lightIndexRenderStates","_lightBuffer","_sizeParam","_countParam","_clusterParam","Float32Array","ShaderHelper","getMaxClusteredLightCount","Vector4","Int32Array","lightBuffer","clusterParam","countParam","lightIndexTexture","createVertexLayout","device","textureWidth","textureHeight","vb","type","vertices","i","length","ix","iy","Math","floor","createVertexBuffer","vertexBuffers","buffer","createRenderState","createRenderStateSet","useDepthState","enableTest","enableWrite","useRasterizerState","setCullMode","createProgram","webgl1","buildRenderProgram","vertex","pb","$inputs","pos","vec3","vec2","attrib","$outputs","value","vec4","uvec4","invProjMatrix","mat4","uniform","viewMatrix","sizeParam","ivec4","getLightBufferUniformName","uniformBuffer","func","float","$l","normal","ab","sub","b","a","t","div","zDistance","dot","$return","add","mul","view","clip","w","texCoord","screen","xy","x","y","z","clipToView","dmin","$if","lessThanEqual","sphere","$for","int","lessThan","at","aabbMin","delta","$elseif","greaterThan","aabbMax","main","getDevice","$builtins","pointSize","position","tileIndex","vertexIndex","tileSize","zIndex","yIndex","xIndex","maxPoint_sS","minPoint_sS","maxPoint_vS","screenToView","xyz","minPoint_vS","tileNear","neg","pow","tileFar","eyePos","minPointNear","lineIntersectionToZPlane","minPointFar","maxPointNear","maxPointFar","min","max","n","lightIndices","setAt","equal","$break","light","lightPos","sphereIntersectsAABB","j","r","g","lightIndex","uint","sal","fragment","color","name","createBindGroup","bindGroupLayouts","dispose","lightBufferType","getBindingInfo","createStructuredBuffer","usage","createLightIndexTexture","exp","log2","Error","createTexture2D","mipmapping","createFrameBuffer","calculateLightIndex","camera","renderQueue","numLights","getVisibleLights","width","height","viewport","getViewport","vw","screenXToDevice","vh","screenYToDevice","scale","getFarPlane","getNearPlane","bias","setXYZW","pushDeviceStates","setFramebuffer","disposed","reload","bufferSubData","setValue","getInvProjectionMatrix","setBuffer","setProgram","setVertexLayout","setBindGroup","savedRS","getRenderStates","setRenderStates","draw","clearFrameBuffer","popDeviceStates","lights","unshadowedLights","offset","set","positionAndRange","directionAndCutoff","diffuseAndIntensity","extraParams"],"mappings":";;;;AAkBO,MAAMA,cAAAA,CAAAA;IACMC,WAAoB;IACpBC,WAAoB;IACpBC,WAAoB;IACpBC,OAAmC;IAC5CC,kBAAwC;IACxCC,sBAA8C;IAC9CC,kBAAyC;IACzCC,UAAgC;IAChCC,uBAAgD;IAChDC,uBAAkD;IAClDC,YAAyC;IAChCC,UAAoB;IAC7BC,WAAqC;IAC5BC,aAAuB;IACxC,WAAc,EAAA;QACZ,IAAI,CAACb,WAAW,GAAG,EAAA;QACnB,IAAI,CAACC,WAAW,GAAG,EAAA;QACnB,IAAI,CAACC,WAAW,GAAG,EAAA;QACnB,IAAI,CAACC,OAAO,GAAG,IAAIW,YAAAA,CAAa,MAAMC,YAAAA,CAAaC,yBAAyB,EAAA,GAAK,CAAA,CAAA,CAAA;QACjF,IAAI,CAACZ,kBAAkB,GAAG,IAAA;QAC1B,IAAI,CAACC,sBAAsB,GAAG,IAAA;QAC9B,IAAI,CAACC,kBAAkB,GAAG,IAAA;QAC1B,IAAI,CAACI,YAAY,GAAG,IAAA;QACpB,IAAI,CAACH,UAAU,GAAG,IAAA;QAClB,IAAI,CAACC,uBAAuB,GAAG,IAAA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MoE,CAAAA,WAAW,EAAEL,MAAS,GAAA,EAAA,CAAA;AACzC;QACA,OAAOlC,SAAAA;AACT;AACF;;;;"}
@@ -1,47 +1,47 @@
1
- /**
2
- * Manages cross-frame history resources that can be imported into a render graph.
3
- *
4
- * History resources are textures that persist across frames for temporal effects
5
- * like TAA, motion blur, or temporal upscaling. Previous-frame textures can be
6
- * imported into a {@link RenderGraph}, and current-frame textures are committed
7
- * only after graph execution succeeds.
8
- *
9
- * Usage:
10
- * ```ts
11
- * const historyMgr = new HistoryResourceManager(allocator);
12
- * historyMgr.beginFrame();
13
- * const prev = historyMgr.importPrevious(graph, 'taaColor');
14
- * // declare builder.read(prev) if non-null
15
- * historyMgr.bindImportedTextures(executor);
16
- * // after successful execution:
17
- * historyMgr.commitFrame();
18
- * ```
19
- *
20
- * @typeParam TTexture - The concrete texture type (e.g. `Texture2D`).
21
- * @public
1
+ /**
2
+ * Manages cross-frame history resources that can be imported into a render graph.
3
+ *
4
+ * History resources are textures that persist across frames for temporal effects
5
+ * like TAA, motion blur, or temporal upscaling. Previous-frame textures can be
6
+ * imported into a {@link RenderGraph}, and current-frame textures are committed
7
+ * only after graph execution succeeds.
8
+ *
9
+ * Usage:
10
+ * ```ts
11
+ * const historyMgr = new HistoryResourceManager(allocator);
12
+ * historyMgr.beginFrame();
13
+ * const prev = historyMgr.importPrevious(graph, 'taaColor');
14
+ * // declare builder.read(prev) if non-null
15
+ * historyMgr.bindImportedTextures(executor);
16
+ * // after successful execution:
17
+ * historyMgr.commitFrame();
18
+ * ```
19
+ *
20
+ * @typeParam TTexture - The concrete texture type (e.g. `Texture2D`).
21
+ * @public
22
22
  */ class HistoryResourceManager {
23
23
  _resources = new Map();
24
24
  _allocator;
25
25
  _pendingImports = new Map();
26
26
  _pendingCommits = new Map();
27
27
  _readScopeStack = [];
28
- /**
29
- * Create a new history resource manager.
30
- *
31
- * @param allocator - Texture allocator for creating history textures.
28
+ /**
29
+ * Create a new history resource manager.
30
+ *
31
+ * @param allocator - Texture allocator for creating history textures.
32
32
  */ constructor(allocator){
33
33
  this._allocator = allocator;
34
34
  }
35
- /**
36
- * Get the previous-frame texture resolved by the current render graph pass.
37
- *
38
- * The resource must have been imported with {@link HistoryResourceManager.importPrevious} or
39
- * {@link HistoryResourceManager.importPreviousIfCompatible}, declared as a pass read, and bound with
40
- * {@link HistoryResourceManager.beginReadScope} before this method is called.
41
- *
42
- * @param name - Name of the history resource.
43
- * @returns The graph-resolved previous-frame texture.
44
- * @throws If no read scope is active for the resource.
35
+ /**
36
+ * Get the previous-frame texture resolved by the current render graph pass.
37
+ *
38
+ * The resource must have been imported with {@link HistoryResourceManager.importPrevious} or
39
+ * {@link HistoryResourceManager.importPreviousIfCompatible}, declared as a pass read, and bound with
40
+ * {@link HistoryResourceManager.beginReadScope} before this method is called.
41
+ *
42
+ * @param name - Name of the history resource.
43
+ * @returns The graph-resolved previous-frame texture.
44
+ * @throws If no read scope is active for the resource.
45
45
  */ getPrevious(name) {
46
46
  const scoped = this._getScopedRead(name);
47
47
  if (scoped) {
@@ -49,32 +49,32 @@
49
49
  }
50
50
  throw new Error(`History resource '${name}' is not available in the current render graph read scope. ` + `Import it and declare a pass read before accessing it.`);
51
51
  }
52
- /**
53
- * Check whether a valid history resource exists and matches the descriptor.
54
- *
55
- * @param name - Name of the history resource.
56
- * @param desc - Expected texture descriptor.
57
- * @param size - Expected resolved size.
58
- * @returns True if the resource exists, is valid, and matches.
52
+ /**
53
+ * Check whether a valid history resource exists and matches the descriptor.
54
+ *
55
+ * @param name - Name of the history resource.
56
+ * @param desc - Expected texture descriptor.
57
+ * @param size - Expected resolved size.
58
+ * @returns True if the resource exists, is valid, and matches.
59
59
  */ isCompatible(name, desc, size) {
60
60
  const resource = this._resources.get(name);
61
61
  return !!resource?.valid && this._matches(resource, desc, size);
62
62
  }
63
- /**
64
- * Start collecting graph imports and deferred commits for a new frame.
63
+ /**
64
+ * Start collecting graph imports and deferred commits for a new frame.
65
65
  */ beginFrame() {
66
66
  this.discardFrame();
67
67
  this._pendingImports.clear();
68
68
  this._readScopeStack.length = 0;
69
69
  }
70
- /**
71
- * Import the latest committed texture for a history resource into the graph.
72
- *
73
- * Returns null when the resource has no valid previous frame.
74
- *
75
- * @param graph - Render graph to import into.
76
- * @param name - History resource name.
77
- * @returns Imported graph handle, or null when no valid previous texture exists.
70
+ /**
71
+ * Import the latest committed texture for a history resource into the graph.
72
+ *
73
+ * Returns null when the resource has no valid previous frame.
74
+ *
75
+ * @param graph - Render graph to import into.
76
+ * @param name - History resource name.
77
+ * @returns Imported graph handle, or null when no valid previous texture exists.
78
78
  */ importPrevious(graph, name) {
79
79
  const resource = this._resources.get(name);
80
80
  const texture = resource?.valid ? resource.textures[resource.currentIndex] : null;
@@ -85,34 +85,34 @@
85
85
  this._pendingImports.set(handle, texture);
86
86
  return handle;
87
87
  }
88
- /**
89
- * Import the latest committed texture only when it matches the expected shape.
90
- *
91
- * This is the preferred API for effects that can declare their history reads
92
- * while building the graph: incompatible history is treated as absent, so the
93
- * pass does not declare stale reads after resize or format changes.
94
- *
95
- * @param graph - Render graph to import into.
96
- * @param name - History resource name.
97
- * @param desc - Expected texture descriptor.
98
- * @param size - Expected resolved size.
99
- * @returns Imported graph handle, or null when no compatible history exists.
88
+ /**
89
+ * Import the latest committed texture only when it matches the expected shape.
90
+ *
91
+ * This is the preferred API for effects that can declare their history reads
92
+ * while building the graph: incompatible history is treated as absent, so the
93
+ * pass does not declare stale reads after resize or format changes.
94
+ *
95
+ * @param graph - Render graph to import into.
96
+ * @param name - History resource name.
97
+ * @param desc - Expected texture descriptor.
98
+ * @param size - Expected resolved size.
99
+ * @returns Imported graph handle, or null when no compatible history exists.
100
100
  */ importPreviousIfCompatible(graph, name, desc, size) {
101
101
  return this.isCompatible(name, desc, size) ? this.importPrevious(graph, name) : null;
102
102
  }
103
- /**
104
- * Bind all history imports created for this frame to the executor.
105
- *
106
- * @param executor - Render graph executor for the current frame.
103
+ /**
104
+ * Bind all history imports created for this frame to the executor.
105
+ *
106
+ * @param executor - Render graph executor for the current frame.
107
107
  */ bindImportedTextures(executor) {
108
108
  for (const [handle, texture] of this._pendingImports){
109
109
  executor.setImportedTexture(handle, texture);
110
110
  }
111
111
  }
112
- /**
113
- * Make resolved history textures available to code executing inside a pass.
114
- *
115
- * @param bindings - History name to resolved texture bindings.
112
+ /**
113
+ * Make resolved history textures available to code executing inside a pass.
114
+ *
115
+ * @param bindings - History name to resolved texture bindings.
116
116
  */ beginReadScope(bindings) {
117
117
  const scope = new Map();
118
118
  for (const binding of bindings){
@@ -120,22 +120,22 @@
120
120
  }
121
121
  this._readScopeStack.push(scope);
122
122
  }
123
- /**
124
- * End the most recent history read scope.
123
+ /**
124
+ * End the most recent history read scope.
125
125
  */ endReadScope() {
126
126
  this._readScopeStack.pop();
127
127
  }
128
- /**
129
- * Queue a current-frame texture to become the next previous-frame history.
130
- *
131
- * The texture is committed only when {@link HistoryResourceManager.commitFrame} is called. If the
132
- * frame fails, {@link HistoryResourceManager.discardFrame} releases owned pending textures instead.
133
- *
134
- * @param name - History resource name.
135
- * @param desc - Texture descriptor.
136
- * @param size - Resolved texture size.
137
- * @param texture - Texture produced by the current frame.
138
- * @param ownsTexture - Whether this manager should release the texture later.
128
+ /**
129
+ * Queue a current-frame texture to become the next previous-frame history.
130
+ *
131
+ * The texture is committed only when {@link HistoryResourceManager.commitFrame} is called. If the
132
+ * frame fails, {@link HistoryResourceManager.discardFrame} releases owned pending textures instead.
133
+ *
134
+ * @param name - History resource name.
135
+ * @param desc - Texture descriptor.
136
+ * @param size - Resolved texture size.
137
+ * @param texture - Texture produced by the current frame.
138
+ * @param ownsTexture - Whether this manager should release the texture later.
139
139
  */ queueCommit(name, desc, size, texture, ownsTexture = true) {
140
140
  const existing = this._pendingCommits.get(name);
141
141
  if (existing?.ownsTexture) {
@@ -152,8 +152,8 @@
152
152
  ownsTexture
153
153
  });
154
154
  }
155
- /**
156
- * Commit all current-frame history writes.
155
+ /**
156
+ * Commit all current-frame history writes.
157
157
  */ commitFrame() {
158
158
  for (const [name, pending] of this._pendingCommits){
159
159
  let resource = this._resources.get(name);
@@ -200,8 +200,8 @@
200
200
  this._pendingImports.clear();
201
201
  this._readScopeStack.length = 0;
202
202
  }
203
- /**
204
- * Discard all uncommitted frame history writes.
203
+ /**
204
+ * Discard all uncommitted frame history writes.
205
205
  */ discardFrame() {
206
206
  for (const pending of this._pendingCommits.values()){
207
207
  if (pending.ownsTexture) {
@@ -212,10 +212,10 @@
212
212
  this._pendingImports.clear();
213
213
  this._readScopeStack.length = 0;
214
214
  }
215
- /**
216
- * Release all history resources and clear the manager.
217
- *
218
- * Call this when disposing the render context or when history is no longer needed.
215
+ /**
216
+ * Release all history resources and clear the manager.
217
+ *
218
+ * Call this when disposing the render context or when history is no longer needed.
219
219
  */ dispose() {
220
220
  this.discardFrame();
221
221
  for (const resource of this._resources.values()){
@@ -1 +1 @@
1
- {"version":3,"file":"history_resource_manager.js","sources":["../../../src/render/rendergraph/history_resource_manager.ts"],"sourcesContent":["import type { Texture2D } from '@zephyr3d/device';\nimport type { RenderGraph } from './rendergraph';\nimport type { RenderGraphExecutor } from './executor';\nimport type { RGHandle, RGTextureAllocator, RGTextureDesc, RGResolvedSize } from './types';\n\ninterface HistoryResource<TTexture> {\n desc: RGTextureDesc;\n size: RGResolvedSize;\n textures: [TTexture | null, TTexture | null];\n ownsTexture: [boolean, boolean];\n currentIndex: number;\n valid: boolean;\n}\n\ninterface PendingHistoryCommit<TTexture> {\n desc: RGTextureDesc;\n size: RGResolvedSize;\n texture: TTexture;\n ownsTexture: boolean;\n}\n\n/**\n * Manages cross-frame history resources that can be imported into a render graph.\n *\n * History resources are textures that persist across frames for temporal effects\n * like TAA, motion blur, or temporal upscaling. Previous-frame textures can be\n * imported into a {@link RenderGraph}, and current-frame textures are committed\n * only after graph execution succeeds.\n *\n * Usage:\n * ```ts\n * const historyMgr = new HistoryResourceManager(allocator);\n * historyMgr.beginFrame();\n * const prev = historyMgr.importPrevious(graph, 'taaColor');\n * // declare builder.read(prev) if non-null\n * historyMgr.bindImportedTextures(executor);\n * // after successful execution:\n * historyMgr.commitFrame();\n * ```\n *\n * @typeParam TTexture - The concrete texture type (e.g. `Texture2D`).\n * @public\n */\nexport class HistoryResourceManager<TTexture = Texture2D> {\n private _resources: Map<string, HistoryResource<TTexture>> = new Map();\n private _allocator: RGTextureAllocator<TTexture>;\n private _pendingImports: Map<RGHandle, TTexture> = new Map();\n private _pendingCommits: Map<string, PendingHistoryCommit<TTexture>> = new Map();\n private _readScopeStack: Array<Map<string, TTexture>> = [];\n\n /**\n * Create a new history resource manager.\n *\n * @param allocator - Texture allocator for creating history textures.\n */\n constructor(allocator: RGTextureAllocator<TTexture>) {\n this._allocator = allocator;\n }\n\n /**\n * Get the previous-frame texture resolved by the current render graph pass.\n *\n * The resource must have been imported with {@link HistoryResourceManager.importPrevious} or\n * {@link HistoryResourceManager.importPreviousIfCompatible}, declared as a pass read, and bound with\n * {@link HistoryResourceManager.beginReadScope} before this method is called.\n *\n * @param name - Name of the history resource.\n * @returns The graph-resolved previous-frame texture.\n * @throws If no read scope is active for the resource.\n */\n getPrevious(name: string): TTexture {\n const scoped = this._getScopedRead(name);\n if (scoped) {\n return scoped;\n }\n throw new Error(\n `History resource '${name}' is not available in the current render graph read scope. ` +\n `Import it and declare a pass read before accessing it.`\n );\n }\n\n /**\n * Check whether a valid history resource exists and matches the descriptor.\n *\n * @param name - Name of the history resource.\n * @param desc - Expected texture descriptor.\n * @param size - Expected resolved size.\n * @returns True if the resource exists, is valid, and matches.\n */\n isCompatible(name: string, desc: RGTextureDesc, size: RGResolvedSize): boolean {\n const resource = this._resources.get(name);\n return !!resource?.valid && this._matches(resource, desc, size);\n }\n\n /**\n * Start collecting graph imports and deferred commits for a new frame.\n */\n beginFrame(): void {\n this.discardFrame();\n this._pendingImports.clear();\n this._readScopeStack.length = 0;\n }\n\n /**\n * Import the latest committed texture for a history resource into the graph.\n *\n * Returns null when the resource has no valid previous frame.\n *\n * @param graph - Render graph to import into.\n * @param name - History resource name.\n * @returns Imported graph handle, or null when no valid previous texture exists.\n */\n importPrevious(graph: RenderGraph, name: string): RGHandle | null {\n const resource = this._resources.get(name);\n const texture = resource?.valid ? resource.textures[resource.currentIndex] : null;\n if (!texture) {\n return null;\n }\n const handle = graph.importTexture(`history:${name}:previous`);\n this._pendingImports.set(handle, texture);\n return handle;\n }\n\n /**\n * Import the latest committed texture only when it matches the expected shape.\n *\n * This is the preferred API for effects that can declare their history reads\n * while building the graph: incompatible history is treated as absent, so the\n * pass does not declare stale reads after resize or format changes.\n *\n * @param graph - Render graph to import into.\n * @param name - History resource name.\n * @param desc - Expected texture descriptor.\n * @param size - Expected resolved size.\n * @returns Imported graph handle, or null when no compatible history exists.\n */\n importPreviousIfCompatible(\n graph: RenderGraph,\n name: string,\n desc: RGTextureDesc,\n size: RGResolvedSize\n ): RGHandle | null {\n return this.isCompatible(name, desc, size) ? this.importPrevious(graph, name) : null;\n }\n\n /**\n * Bind all history imports created for this frame to the executor.\n *\n * @param executor - Render graph executor for the current frame.\n */\n bindImportedTextures(executor: Pick<RenderGraphExecutor<TTexture>, 'setImportedTexture'>): void {\n for (const [handle, texture] of this._pendingImports) {\n executor.setImportedTexture(handle, texture);\n }\n }\n\n /**\n * Make resolved history textures available to code executing inside a pass.\n *\n * @param bindings - History name to resolved texture bindings.\n */\n beginReadScope(bindings: Array<{ name: string; texture: TTexture }>): void {\n const scope = new Map<string, TTexture>();\n for (const binding of bindings) {\n scope.set(binding.name, binding.texture);\n }\n this._readScopeStack.push(scope);\n }\n\n /**\n * End the most recent history read scope.\n */\n endReadScope(): void {\n this._readScopeStack.pop();\n }\n\n /**\n * Queue a current-frame texture to become the next previous-frame history.\n *\n * The texture is committed only when {@link HistoryResourceManager.commitFrame} is called. If the\n * frame fails, {@link HistoryResourceManager.discardFrame} releases owned pending textures instead.\n *\n * @param name - History resource name.\n * @param desc - Texture descriptor.\n * @param size - Resolved texture size.\n * @param texture - Texture produced by the current frame.\n * @param ownsTexture - Whether this manager should release the texture later.\n */\n queueCommit(\n name: string,\n desc: RGTextureDesc,\n size: RGResolvedSize,\n texture: TTexture,\n ownsTexture = true\n ): void {\n const existing = this._pendingCommits.get(name);\n if (existing?.ownsTexture) {\n this._allocator.release(existing.texture);\n }\n this._pendingCommits.set(name, {\n desc: { ...desc },\n size: { ...size },\n texture,\n ownsTexture\n });\n }\n\n /**\n * Commit all current-frame history writes.\n */\n commitFrame(): void {\n for (const [name, pending] of this._pendingCommits) {\n let resource = this._resources.get(name);\n if (resource && !this._matches(resource, pending.desc, pending.size)) {\n this._releaseResource(resource);\n this._resources.delete(name);\n resource = undefined;\n }\n if (!resource) {\n resource = {\n desc: { ...pending.desc },\n size: { ...pending.size },\n textures: [null, null],\n ownsTexture: [false, false],\n currentIndex: 0,\n valid: false\n };\n this._resources.set(name, resource);\n }\n\n const writeIndex = resource.valid ? 1 - resource.currentIndex : resource.currentIndex;\n this._releaseSlot(resource, writeIndex);\n resource.textures[writeIndex] = pending.texture;\n resource.ownsTexture[writeIndex] = pending.ownsTexture;\n resource.desc = { ...pending.desc };\n resource.size = { ...pending.size };\n resource.currentIndex = writeIndex;\n resource.valid = true;\n }\n this._pendingCommits.clear();\n this._pendingImports.clear();\n this._readScopeStack.length = 0;\n }\n\n /**\n * Discard all uncommitted frame history writes.\n */\n discardFrame(): void {\n for (const pending of this._pendingCommits.values()) {\n if (pending.ownsTexture) {\n this._allocator.release(pending.texture);\n }\n }\n this._pendingCommits.clear();\n this._pendingImports.clear();\n this._readScopeStack.length = 0;\n }\n\n /**\n * Release all history resources and clear the manager.\n *\n * Call this when disposing the render context or when history is no longer needed.\n */\n dispose(): void {\n this.discardFrame();\n for (const resource of this._resources.values()) {\n this._releaseResource(resource);\n }\n this._resources.clear();\n }\n\n /** @internal */\n private _getScopedRead(name: string): TTexture | null {\n for (let i = this._readScopeStack.length - 1; i >= 0; i--) {\n const texture = this._readScopeStack[i].get(name);\n if (texture) {\n return texture;\n }\n }\n return null;\n }\n\n /** @internal */\n private _matches(resource: HistoryResource<TTexture>, desc: RGTextureDesc, size: RGResolvedSize): boolean {\n return (\n resource.desc.format === desc.format &&\n (resource.desc.mipLevels ?? 1) === (desc.mipLevels ?? 1) &&\n resource.size.width === size.width &&\n resource.size.height === size.height\n );\n }\n\n /** @internal */\n private _releaseResource(resource: HistoryResource<TTexture>): void {\n this._releaseSlot(resource, 0);\n this._releaseSlot(resource, 1);\n resource.valid = false;\n }\n\n /** @internal */\n private _releaseSlot(resource: HistoryResource<TTexture>, index: number): void {\n const texture = resource.textures[index];\n if (!texture) {\n return;\n }\n const otherIndex = 1 - index;\n if (resource.ownsTexture[index] && resource.textures[otherIndex] !== texture) {\n this._allocator.release(texture);\n }\n resource.textures[index] = null;\n resource.ownsTexture[index] = false;\n }\n}\n"],"names":["HistoryResourceManager","_resources","Map","_allocator","_pendingImports","_pendingCommits","_readScopeStack","allocator","getPrevious","name","scoped","_getScopedRead","Error","isCompatible","desc","size","resource","get","valid","_matches","beginFrame","discardFrame","clear","length","importPrevious","graph","texture","textures","currentIndex","handle","importTexture","set","importPreviousIfCompatible","bindImportedTextures","executor","setImportedTexture","beginReadScope","bindings","scope","binding","push","endReadScope","pop","queueCommit","ownsTexture","existing","release","commitFrame","pending","_releaseResource","delete","undefined","writeIndex","_releaseSlot","values","dispose","i","format","mipLevels","width","height","index","otherIndex"],"mappings":"AAqBA;;;;;;;;;;;;;;;;;;;;;AAqBC,IACM,MAAMA,sBAAAA,CAAAA;AACHC,IAAAA,UAAAA,GAAqD,IAAIC,GAAM,EAAA;IAC/DC,UAAyC;AACzCC,IAAAA,eAAAA,GAA2C,IAAIF,GAAM,EAAA;AACrDG,IAAAA,eAAAA,GAA+D,IAAIH,GAAM,EAAA;AACzEI,IAAAA,eAAAA,GAAgD,EAAE;AAE1D;;;;MAKA,WAAA,CAAYC,SAAuC,CAAE;QACnD,IAAI,CAACJ,UAAU,GAAGI,SAAAA;AACpB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A,MAAMoC,aAAa,CAAID,GAAAA,KAAAA;QACvB,IAAI7C,QAAAA,CAAS4B,WAAW,CAACiB,KAAM,CAAA,IAAI7C,SAASW,QAAQ,CAACmC,UAAW,CAAA,KAAKpC,OAAS,EAAA;AAC5E,YAAA,IAAI,CAACvB,UAAU,CAAC2C,OAAO,CAACpB,OAAAA,CAAAA;AAC1B;QACAV,QAASW,CAAAA,QAAQ,CAACkC,KAAAA,CAAM,GAAG,IAAA;QAC3B7C,QAAS4B,CAAAA,WAAW,CAACiB,KAAAA,CAAM,GAAG,KAAA;AAChC;AACF;;;;"}
1
+ {"version":3,"file":"history_resource_manager.js","sources":["../../../src/render/rendergraph/history_resource_manager.ts"],"sourcesContent":["import type { Texture2D } from '@zephyr3d/device';\r\nimport type { RenderGraph } from './rendergraph';\r\nimport type { RenderGraphExecutor } from './executor';\r\nimport type { RGHandle, RGTextureAllocator, RGTextureDesc, RGResolvedSize } from './types';\r\n\r\ninterface HistoryResource<TTexture> {\r\n desc: RGTextureDesc;\r\n size: RGResolvedSize;\r\n textures: [TTexture | null, TTexture | null];\r\n ownsTexture: [boolean, boolean];\r\n currentIndex: number;\r\n valid: boolean;\r\n}\r\n\r\ninterface PendingHistoryCommit<TTexture> {\r\n desc: RGTextureDesc;\r\n size: RGResolvedSize;\r\n texture: TTexture;\r\n ownsTexture: boolean;\r\n}\r\n\r\n/**\r\n * Manages cross-frame history resources that can be imported into a render graph.\r\n *\r\n * History resources are textures that persist across frames for temporal effects\r\n * like TAA, motion blur, or temporal upscaling. Previous-frame textures can be\r\n * imported into a {@link RenderGraph}, and current-frame textures are committed\r\n * only after graph execution succeeds.\r\n *\r\n * Usage:\r\n * ```ts\r\n * const historyMgr = new HistoryResourceManager(allocator);\r\n * historyMgr.beginFrame();\r\n * const prev = historyMgr.importPrevious(graph, 'taaColor');\r\n * // declare builder.read(prev) if non-null\r\n * historyMgr.bindImportedTextures(executor);\r\n * // after successful execution:\r\n * historyMgr.commitFrame();\r\n * ```\r\n *\r\n * @typeParam TTexture - The concrete texture type (e.g. `Texture2D`).\r\n * @public\r\n */\r\nexport class HistoryResourceManager<TTexture = Texture2D> {\r\n private _resources: Map<string, HistoryResource<TTexture>> = new Map();\r\n private _allocator: RGTextureAllocator<TTexture>;\r\n private _pendingImports: Map<RGHandle, TTexture> = new Map();\r\n private _pendingCommits: Map<string, PendingHistoryCommit<TTexture>> = new Map();\r\n private _readScopeStack: Array<Map<string, TTexture>> = [];\r\n\r\n /**\r\n * Create a new history resource manager.\r\n *\r\n * @param allocator - Texture allocator for creating history textures.\r\n */\r\n constructor(allocator: RGTextureAllocator<TTexture>) {\r\n this._allocator = allocator;\r\n }\r\n\r\n /**\r\n * Get the previous-frame texture resolved by the current render graph pass.\r\n *\r\n * The resource must have been imported with {@link HistoryResourceManager.importPrevious} or\r\n * {@link HistoryResourceManager.importPreviousIfCompatible}, declared as a pass read, and bound with\r\n * {@link HistoryResourceManager.beginReadScope} before this method is called.\r\n *\r\n * @param name - Name of the history resource.\r\n * @returns The graph-resolved previous-frame texture.\r\n * @throws If no read scope is active for the resource.\r\n */\r\n getPrevious(name: string): TTexture {\r\n const scoped = this._getScopedRead(name);\r\n if (scoped) {\r\n return scoped;\r\n }\r\n throw new Error(\r\n `History resource '${name}' is not available in the current render graph read scope. ` +\r\n `Import it and declare a pass read before accessing it.`\r\n );\r\n }\r\n\r\n /**\r\n * Check whether a valid history resource exists and matches the descriptor.\r\n *\r\n * @param name - Name of the history resource.\r\n * @param desc - Expected texture descriptor.\r\n * @param size - Expected resolved size.\r\n * @returns True if the resource exists, is valid, and matches.\r\n */\r\n isCompatible(name: string, desc: RGTextureDesc, size: RGResolvedSize): boolean {\r\n const resource = this._resources.get(name);\r\n return !!resource?.valid && this._matches(resource, desc, size);\r\n }\r\n\r\n /**\r\n * Start collecting graph imports and deferred commits for a new frame.\r\n */\r\n beginFrame(): void {\r\n this.discardFrame();\r\n this._pendingImports.clear();\r\n this._readScopeStack.length = 0;\r\n }\r\n\r\n /**\r\n * Import the latest committed texture for a history resource into the graph.\r\n *\r\n * Returns null when the resource has no valid previous frame.\r\n *\r\n * @param graph - Render graph to import into.\r\n * @param name - History resource name.\r\n * @returns Imported graph handle, or null when no valid previous texture exists.\r\n */\r\n importPrevious(graph: RenderGraph, name: string): RGHandle | null {\r\n const resource = this._resources.get(name);\r\n const texture = resource?.valid ? resource.textures[resource.currentIndex] : null;\r\n if (!texture) {\r\n return null;\r\n }\r\n const handle = graph.importTexture(`history:${name}:previous`);\r\n this._pendingImports.set(handle, texture);\r\n return handle;\r\n }\r\n\r\n /**\r\n * Import the latest committed texture only when it matches the expected shape.\r\n *\r\n * This is the preferred API for effects that can declare their history reads\r\n * while building the graph: incompatible history is treated as absent, so the\r\n * pass does not declare stale reads after resize or format changes.\r\n *\r\n * @param graph - Render graph to import into.\r\n * @param name - History resource name.\r\n * @param desc - Expected texture descriptor.\r\n * @param size - Expected resolved size.\r\n * @returns Imported graph handle, or null when no compatible history exists.\r\n */\r\n importPreviousIfCompatible(\r\n graph: RenderGraph,\r\n name: string,\r\n desc: RGTextureDesc,\r\n size: RGResolvedSize\r\n ): RGHandle | null {\r\n return this.isCompatible(name, desc, size) ? this.importPrevious(graph, name) : null;\r\n }\r\n\r\n /**\r\n * Bind all history imports created for this frame to the executor.\r\n *\r\n * @param executor - Render graph executor for the current frame.\r\n */\r\n bindImportedTextures(executor: Pick<RenderGraphExecutor<TTexture>, 'setImportedTexture'>): void {\r\n for (const [handle, texture] of this._pendingImports) {\r\n executor.setImportedTexture(handle, texture);\r\n }\r\n }\r\n\r\n /**\r\n * Make resolved history textures available to code executing inside a pass.\r\n *\r\n * @param bindings - History name to resolved texture bindings.\r\n */\r\n beginReadScope(bindings: Array<{ name: string; texture: TTexture }>): void {\r\n const scope = new Map<string, TTexture>();\r\n for (const binding of bindings) {\r\n scope.set(binding.name, binding.texture);\r\n }\r\n this._readScopeStack.push(scope);\r\n }\r\n\r\n /**\r\n * End the most recent history read scope.\r\n */\r\n endReadScope(): void {\r\n this._readScopeStack.pop();\r\n }\r\n\r\n /**\r\n * Queue a current-frame texture to become the next previous-frame history.\r\n *\r\n * The texture is committed only when {@link HistoryResourceManager.commitFrame} is called. If the\r\n * frame fails, {@link HistoryResourceManager.discardFrame} releases owned pending textures instead.\r\n *\r\n * @param name - History resource name.\r\n * @param desc - Texture descriptor.\r\n * @param size - Resolved texture size.\r\n * @param texture - Texture produced by the current frame.\r\n * @param ownsTexture - Whether this manager should release the texture later.\r\n */\r\n queueCommit(\r\n name: string,\r\n desc: RGTextureDesc,\r\n size: RGResolvedSize,\r\n texture: TTexture,\r\n ownsTexture = true\r\n ): void {\r\n const existing = this._pendingCommits.get(name);\r\n if (existing?.ownsTexture) {\r\n this._allocator.release(existing.texture);\r\n }\r\n this._pendingCommits.set(name, {\r\n desc: { ...desc },\r\n size: { ...size },\r\n texture,\r\n ownsTexture\r\n });\r\n }\r\n\r\n /**\r\n * Commit all current-frame history writes.\r\n */\r\n commitFrame(): void {\r\n for (const [name, pending] of this._pendingCommits) {\r\n let resource = this._resources.get(name);\r\n if (resource && !this._matches(resource, pending.desc, pending.size)) {\r\n this._releaseResource(resource);\r\n this._resources.delete(name);\r\n resource = undefined;\r\n }\r\n if (!resource) {\r\n resource = {\r\n desc: { ...pending.desc },\r\n size: { ...pending.size },\r\n textures: [null, null],\r\n ownsTexture: [false, false],\r\n currentIndex: 0,\r\n valid: false\r\n };\r\n this._resources.set(name, resource);\r\n }\r\n\r\n const writeIndex = resource.valid ? 1 - resource.currentIndex : resource.currentIndex;\r\n this._releaseSlot(resource, writeIndex);\r\n resource.textures[writeIndex] = pending.texture;\r\n resource.ownsTexture[writeIndex] = pending.ownsTexture;\r\n resource.desc = { ...pending.desc };\r\n resource.size = { ...pending.size };\r\n resource.currentIndex = writeIndex;\r\n resource.valid = true;\r\n }\r\n this._pendingCommits.clear();\r\n this._pendingImports.clear();\r\n this._readScopeStack.length = 0;\r\n }\r\n\r\n /**\r\n * Discard all uncommitted frame history writes.\r\n */\r\n discardFrame(): void {\r\n for (const pending of this._pendingCommits.values()) {\r\n if (pending.ownsTexture) {\r\n this._allocator.release(pending.texture);\r\n }\r\n }\r\n this._pendingCommits.clear();\r\n this._pendingImports.clear();\r\n this._readScopeStack.length = 0;\r\n }\r\n\r\n /**\r\n * Release all history resources and clear the manager.\r\n *\r\n * Call this when disposing the render context or when history is no longer needed.\r\n */\r\n dispose(): void {\r\n this.discardFrame();\r\n for (const resource of this._resources.values()) {\r\n this._releaseResource(resource);\r\n }\r\n this._resources.clear();\r\n }\r\n\r\n /** @internal */\r\n private _getScopedRead(name: string): TTexture | null {\r\n for (let i = this._readScopeStack.length - 1; i >= 0; i--) {\r\n const texture = this._readScopeStack[i].get(name);\r\n if (texture) {\r\n return texture;\r\n }\r\n }\r\n return null;\r\n }\r\n\r\n /** @internal */\r\n private _matches(resource: HistoryResource<TTexture>, desc: RGTextureDesc, size: RGResolvedSize): boolean {\r\n return (\r\n resource.desc.format === desc.format &&\r\n (resource.desc.mipLevels ?? 1) === (desc.mipLevels ?? 1) &&\r\n resource.size.width === size.width &&\r\n resource.size.height === size.height\r\n );\r\n }\r\n\r\n /** @internal */\r\n private _releaseResource(resource: HistoryResource<TTexture>): void {\r\n this._releaseSlot(resource, 0);\r\n this._releaseSlot(resource, 1);\r\n resource.valid = false;\r\n }\r\n\r\n /** @internal */\r\n private _releaseSlot(resource: HistoryResource<TTexture>, index: number): void {\r\n const texture = resource.textures[index];\r\n if (!texture) {\r\n return;\r\n }\r\n const otherIndex = 1 - index;\r\n if (resource.ownsTexture[index] && resource.textures[otherIndex] !== texture) {\r\n this._allocator.release(texture);\r\n }\r\n resource.textures[index] = null;\r\n resource.ownsTexture[index] = false;\r\n }\r\n}\r\n"],"names":["HistoryResourceManager","_resources","Map","_allocator","_pendingImports","_pendingCommits","_readScopeStack","allocator","getPrevious","name","scoped","_getScopedRead","Error","isCompatible","desc","size","resource","get","valid","_matches","beginFrame","discardFrame","clear","length","importPrevious","graph","texture","textures","currentIndex","handle","importTexture","set","importPreviousIfCompatible","bindImportedTextures","executor","setImportedTexture","beginReadScope","bindings","scope","binding","push","endReadScope","pop","queueCommit","ownsTexture","existing","release","commitFrame","pending","_releaseResource","delete","undefined","writeIndex","_releaseSlot","values","dispose","i","format","mipLevels","width","height","index","otherIndex"],"mappings":"AAqBA;;;;;;;;;;;;;;;;;;;;;AAqBC,IACM,MAAMA,sBAAAA,CAAAA;AACHC,IAAAA,UAAAA,GAAqD,IAAIC,GAAM,EAAA;IAC/DC,UAAyC;AACzCC,IAAAA,eAAAA,GAA2C,IAAIF,GAAM,EAAA;AACrDG,IAAAA,eAAAA,GAA+D,IAAIH,GAAM,EAAA;AACzEI,IAAAA,eAAAA,GAAgD,EAAE;AAE1D;;;;MAKA,WAAA,CAAYC,SAAuC,CAAE;QACnD,IAAI,CAACJ,UAAU,GAAGI,SAAAA;AACpB;AAEA;;;;;;;;;;MAWAC,WAAAA,CAAYC,IAAY,EAAY;AAClC,QAAA,MAAMC,MAAS,GAAA,IAAI,CAACC,cAAc,CAACF,IAAAA,CAAAA;AACnC,QAAA,IAAIC,MAAQ,EAAA;YACV,OAAOA,MAAAA;AACT;QACA,MAAM,IAAIE,KACR,CAAA,CAAC,kBAAkB,EAAEH,IAAK,CAAA,2DAA2D,CAAC,GACpF,CAAC,sDAAsD,CAAC,CAAA;AAE9D;AAEA;;;;;;;AAOC,MACDI,aAAaJ,IAAY,EAAEK,IAAmB,EAAEC,IAAoB,EAAW;AAC7E,QAAA,MAAMC,WAAW,IAAI,CAACf,UAAU,CAACgB,GAAG,CAACR,IAAAA,CAAAA;QACrC,OAAO,CAAC,CAACO,QAAUE,EAAAA,KAAAA,IAAS,IAAI,CAACC,QAAQ,CAACH,QAAAA,EAAUF,IAAMC,EAAAA,IAAAA,CAAAA;AAC5D;AAEA;;AAEC,MACDK,UAAmB,GAAA;AACjB,QAAA,IAAI,CAACC,YAAY,EAAA;QACjB,IAAI,CAACjB,eAAe,CAACkB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CAAA,IACtD1C,QAASD,CAAAA,IAAI,CAAC4C,KAAK,KAAK5C,IAAK4C,CAAAA,KAAK,IAClC3C,QAASD,CAAAA,IAAI,CAAC6C,MAAM,KAAK7C,KAAK6C,MAAM;AAExC;AAEA,qBACQX,gBAAiBjC,CAAAA,QAAmC,EAAQ;QAClE,IAAI,CAACqC,YAAY,CAACrC,QAAU,EAAA,CAAA,CAAA;QAC5B,IAAI,CAACqC,YAAY,CAACrC,QAAU,EAAA,CAAA,CAAA;AAC5BA,QAAAA,QAAAA,CAASE,KAAK,GAAG,KAAA;AACnB;AAEA,qBACA,YAAQmC,CAAarC,QAAmC,EAAE6C,KAAa,EAAQ;AAC7E,QAAA,MAAMnC,OAAUV,GAAAA,QAAAA,CAASW,QAAQ,CAACkC,KAAM,CAAA;AACxC,QAAA,IAAI,CAACnC,OAAS,EAAA;AACZ,YAAA;AACF;AACA,QAAA,MAAMoC,aAAa,CAAID,GAAAA,KAAAA;QACvB,IAAI7C,QAAAA,CAAS4B,WAAW,CAACiB,KAAM,CAAA,IAAI7C,SAASW,QAAQ,CAACmC,UAAW,CAAA,KAAKpC,OAAS,EAAA;AAC5E,YAAA,IAAI,CAACvB,UAAU,CAAC2C,OAAO,CAACpB,OAAAA,CAAAA;AAC1B;QACAV,QAASW,CAAAA,QAAQ,CAACkC,KAAAA,CAAM,GAAG,IAAA;QAC3B7C,QAAS4B,CAAAA,WAAW,CAACiB,KAAAA,CAAM,GAAG,KAAA;AAChC;AACF;;;;"}
@@ -1,6 +1,6 @@
1
- /**
2
- * Resource names for render graph history resources.
3
- * @public
1
+ /**
2
+ * Resource names for render graph history resources.
3
+ * @public
4
4
  */ const RGHistoryResources = {
5
5
  TAA_COLOR: 'taaColor',
6
6
  TAA_MOTION_VECTOR: 'taaMotionVector'
@@ -1 +1 @@
1
- {"version":3,"file":"history_resources.js","sources":["../../../src/render/rendergraph/history_resources.ts"],"sourcesContent":["/**\n * Resource names for render graph history resources.\n * @public\n */\nexport const RGHistoryResources = {\n TAA_COLOR: 'taaColor',\n TAA_MOTION_VECTOR: 'taaMotionVector'\n} as const;\n"],"names":["RGHistoryResources","TAA_COLOR","TAA_MOTION_VECTOR"],"mappings":"AAAA;;;UAIaA,kBAAqB,GAAA;IAChCC,SAAW,EAAA,UAAA;IACXC,iBAAmB,EAAA;AACrB;;;;"}
1
+ {"version":3,"file":"history_resources.js","sources":["../../../src/render/rendergraph/history_resources.ts"],"sourcesContent":["/**\r\n * Resource names for render graph history resources.\r\n * @public\r\n */\r\nexport const RGHistoryResources = {\r\n TAA_COLOR: 'taaColor',\r\n TAA_MOTION_VECTOR: 'taaMotionVector'\r\n} as const;\r\n"],"names":["RGHistoryResources","TAA_COLOR","TAA_MOTION_VECTOR"],"mappings":"AAAA;;;UAIaA,kBAAqB,GAAA;IAChCC,SAAW,EAAA,UAAA;IACXC,iBAAmB,EAAA;AACrB;;;;"}