@zephyr3d/scene 0.9.1 → 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 (522) hide show
  1. package/dist/animation/animationset.js +2 -0
  2. package/dist/animation/animationset.js.map +1 -1
  3. package/dist/animation/cloth/gpu_cloth_system.js +9 -1
  4. package/dist/animation/cloth/gpu_cloth_system.js.map +1 -1
  5. package/dist/animation/fixed_geometry_cache_track.js +5 -1
  6. package/dist/animation/fixed_geometry_cache_track.js.map +1 -1
  7. package/dist/animation/geometry_cache_utils.js +20 -4
  8. package/dist/animation/geometry_cache_utils.js.map +1 -1
  9. package/dist/animation/ik/ik_angle_constraint.js +2 -6
  10. package/dist/animation/ik/ik_angle_constraint.js.map +1 -1
  11. package/dist/animation/ik/ik_chain_builder.js +68 -0
  12. package/dist/animation/ik/ik_chain_builder.js.map +1 -0
  13. package/dist/animation/ik/ik_pole_constraint.js +2 -7
  14. package/dist/animation/ik/ik_pole_constraint.js.map +1 -1
  15. package/dist/animation/ik/two_bone_ik_solver.js +2 -6
  16. package/dist/animation/ik/two_bone_ik_solver.js.map +1 -1
  17. package/dist/animation/joint_dynamics/collision.js +60 -12
  18. package/dist/animation/joint_dynamics/collision.js.map +1 -1
  19. package/dist/animation/joint_dynamics/constraints.js +20 -4
  20. package/dist/animation/joint_dynamics/constraints.js.map +1 -1
  21. package/dist/animation/joint_dynamics/controller.js +94 -46
  22. package/dist/animation/joint_dynamics/controller.js.map +1 -1
  23. package/dist/animation/joint_dynamics/math.js +16 -0
  24. package/dist/animation/joint_dynamics/math.js.map +1 -0
  25. package/dist/animation/joint_dynamics/solver.js +21 -11
  26. package/dist/animation/joint_dynamics/solver.js.map +1 -1
  27. package/dist/animation/joint_dynamics/types.js +15 -3
  28. package/dist/animation/joint_dynamics/types.js.map +1 -1
  29. package/dist/animation/pca_geometry_cache_track.js +5 -1
  30. package/dist/animation/pca_geometry_cache_track.js.map +1 -1
  31. package/dist/animation/skeleton.js +2 -2
  32. package/dist/animation/skeleton.js.map +1 -1
  33. package/dist/animation/skeleton_modifier.js +2 -6
  34. package/dist/animation/skeleton_modifier.js.map +1 -1
  35. package/dist/animation/spring/spring_particle.js +4 -4
  36. package/dist/animation/spring/spring_particle.js.map +1 -1
  37. package/dist/animation/spring/spring_system.js +13 -40
  38. package/dist/animation/spring/spring_system.js.map +1 -1
  39. package/dist/animation/spring2/constraints.js.map +1 -1
  40. package/dist/animation/spring2/controller.js +64 -64
  41. package/dist/animation/spring2/controller.js.map +1 -1
  42. package/dist/animation/spring2/math.js.map +1 -1
  43. package/dist/animation/spring2/spring_system.js +8 -8
  44. package/dist/animation/spring2/spring_system.js.map +1 -1
  45. package/dist/app/app.js.map +1 -1
  46. package/dist/app/engine.js +1 -1
  47. package/dist/app/engine.js.map +1 -1
  48. package/dist/app/screen.js +4 -4
  49. package/dist/app/screen.js.map +1 -1
  50. package/dist/app/scriptingsystem.js +24 -1
  51. package/dist/app/scriptingsystem.js.map +1 -1
  52. package/dist/app/scriptregistry.js +22 -1
  53. package/dist/app/scriptregistry.js.map +1 -1
  54. package/dist/asset/assetmanager.js +2 -2
  55. package/dist/asset/assetmanager.js.map +1 -1
  56. package/dist/asset/model.js +60 -60
  57. package/dist/asset/model.js.map +1 -1
  58. package/dist/camera/camera.js +1 -1
  59. package/dist/camera/camera.js.map +1 -1
  60. package/dist/camera/orbit.js.map +1 -1
  61. package/dist/index.d.ts +795 -266
  62. package/dist/index.js +3 -2
  63. package/dist/index.js.map +1 -1
  64. package/dist/material/material.js +3 -1
  65. package/dist/material/material.js.map +1 -1
  66. package/dist/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -1
  67. package/dist/material/shader/helper.js +281 -278
  68. package/dist/material/shader/helper.js.map +1 -1
  69. package/dist/material/sprite.js +6 -6
  70. package/dist/material/sprite.js.map +1 -1
  71. package/dist/material/terrain-cm.js +2 -2
  72. package/dist/material/terrain-cm.js.map +1 -1
  73. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimemgr.js +38 -0
  74. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimemgr.js.map +1 -0
  75. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimescript.js +10 -0
  76. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimescript.js.map +1 -0
  77. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptingsystem.js +127 -0
  78. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptingsystem.js.map +1 -0
  79. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptregistry.js +263 -0
  80. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptregistry.js.map +1 -0
  81. package/dist/posteffect/taa.js +31 -39
  82. package/dist/posteffect/taa.js.map +1 -1
  83. package/dist/render/cluster_light.js +3 -4
  84. package/dist/render/cluster_light.js.map +1 -1
  85. package/dist/render/drawable.js +5 -1
  86. package/dist/render/drawable.js.map +1 -1
  87. package/dist/render/rendergraph/device_pool_allocator.js +29 -3
  88. package/dist/render/rendergraph/device_pool_allocator.js.map +1 -1
  89. package/dist/render/rendergraph/executor.js +283 -33
  90. package/dist/render/rendergraph/executor.js.map +1 -1
  91. package/dist/render/rendergraph/forward_plus_builder.js +338 -108
  92. package/dist/render/rendergraph/forward_plus_builder.js.map +1 -1
  93. package/dist/render/rendergraph/history_resource_manager.js +195 -115
  94. package/dist/render/rendergraph/history_resource_manager.js.map +1 -1
  95. package/dist/render/rendergraph/history_resources.js +10 -0
  96. package/dist/render/rendergraph/history_resources.js.map +1 -0
  97. package/dist/render/rendergraph/rendergraph.js +162 -35
  98. package/dist/render/rendergraph/rendergraph.js.map +1 -1
  99. package/dist/render/rendergraph/types.js +25 -5
  100. package/dist/render/rendergraph/types.js.map +1 -1
  101. package/dist/render/rendertarget.js +5 -1
  102. package/dist/render/rendertarget.js.map +1 -1
  103. package/dist/render/screenrendertarget.js +5 -1
  104. package/dist/render/screenrendertarget.js.map +1 -1
  105. package/dist/render/sky.js +4 -4
  106. package/dist/render/sky.js.map +1 -1
  107. package/dist/scene/basesprite.js +2 -2
  108. package/dist/scene/basesprite.js.map +1 -1
  109. package/dist/scene/graph_node.js +1 -1
  110. package/dist/scene/graph_node.js.map +1 -1
  111. package/dist/scene/mesh.js +81 -97
  112. package/dist/scene/mesh.js.map +1 -1
  113. package/dist/scene/particlesys.js +1 -1
  114. package/dist/scene/particlesys.js.map +1 -1
  115. package/dist/scene/scene_node.js +228 -228
  116. package/dist/scene/scene_node.js.map +1 -1
  117. package/dist/scene/script_attachment.js +15 -3
  118. package/dist/scene/script_attachment.js.map +1 -1
  119. package/dist/scene/terrain-cm/terrain-cm.js +3 -3
  120. package/dist/scene/terrain-cm/terrain-cm.js.map +1 -1
  121. package/dist/shadow/shadowmapper.js.map +1 -1
  122. package/dist/shapes/box.js +1 -1
  123. package/dist/shapes/box.js.map +1 -1
  124. package/dist/shapes/capsule.js +0 -3
  125. package/dist/shapes/capsule.js.map +1 -1
  126. package/dist/shapes/cylinder.js +0 -3
  127. package/dist/shapes/cylinder.js.map +1 -1
  128. package/dist/shapes/plane.js +0 -3
  129. package/dist/shapes/plane.js.map +1 -1
  130. package/dist/shapes/tetrahedron.js +3 -9
  131. package/dist/shapes/tetrahedron.js.map +1 -1
  132. package/dist/shapes/torus.js +94 -66
  133. package/dist/shapes/torus.js.map +1 -1
  134. package/dist/src/animation/animation.js +127 -0
  135. package/dist/src/animation/animation.js.map +1 -0
  136. package/dist/src/animation/animationset.js +255 -0
  137. package/dist/src/animation/animationset.js.map +1 -0
  138. package/dist/src/animation/animationtrack.js +34 -0
  139. package/dist/src/animation/animationtrack.js.map +1 -0
  140. package/dist/src/animation/eulerrotationtrack.js +52 -0
  141. package/dist/src/animation/eulerrotationtrack.js.map +1 -0
  142. package/dist/src/animation/morphtarget.js +93 -0
  143. package/dist/src/animation/morphtarget.js.map +1 -0
  144. package/dist/src/animation/morphtrack.js +70 -0
  145. package/dist/src/animation/morphtrack.js.map +1 -0
  146. package/dist/src/animation/proptrack.js +161 -0
  147. package/dist/src/animation/proptrack.js.map +1 -0
  148. package/dist/src/animation/rotationtrack.js +51 -0
  149. package/dist/src/animation/rotationtrack.js.map +1 -0
  150. package/dist/src/animation/scaletrack.js +50 -0
  151. package/dist/src/animation/scaletrack.js.map +1 -0
  152. package/dist/src/animation/skeleton.js +204 -0
  153. package/dist/src/animation/skeleton.js.map +1 -0
  154. package/dist/src/animation/translationtrack.js +50 -0
  155. package/dist/src/animation/translationtrack.js.map +1 -0
  156. package/dist/src/app/app.js +129 -0
  157. package/dist/src/app/app.js.map +1 -0
  158. package/dist/src/app/inputmgr.js +267 -0
  159. package/dist/src/app/inputmgr.js.map +1 -0
  160. package/dist/src/asset/assetmanager.js +404 -0
  161. package/dist/src/asset/assetmanager.js.map +1 -0
  162. package/dist/src/asset/builtin.js +337 -0
  163. package/dist/src/asset/builtin.js.map +1 -0
  164. package/dist/src/asset/loaders/dds/dds.js +470 -0
  165. package/dist/src/asset/loaders/dds/dds.js.map +1 -0
  166. package/dist/src/asset/loaders/dds/dds_loader.js +28 -0
  167. package/dist/src/asset/loaders/dds/dds_loader.js.map +1 -0
  168. package/dist/src/asset/loaders/gltf/gltf_loader.js +1265 -0
  169. package/dist/src/asset/loaders/gltf/gltf_loader.js.map +1 -0
  170. package/dist/src/asset/loaders/gltf/helpers.js +327 -0
  171. package/dist/src/asset/loaders/gltf/helpers.js.map +1 -0
  172. package/dist/src/asset/loaders/hdr/hdr.js +180 -0
  173. package/dist/src/asset/loaders/hdr/hdr.js.map +1 -0
  174. package/dist/src/asset/loaders/image/tga_Loader.js +116 -0
  175. package/dist/src/asset/loaders/image/tga_Loader.js.map +1 -0
  176. package/dist/src/asset/loaders/image/webimage_loader.js +63 -0
  177. package/dist/src/asset/loaders/image/webimage_loader.js.map +1 -0
  178. package/dist/src/asset/loaders/loader.js +45 -0
  179. package/dist/src/asset/loaders/loader.js.map +1 -0
  180. package/dist/src/asset/model.js +414 -0
  181. package/dist/src/asset/model.js.map +1 -0
  182. package/dist/src/blitter/bilateralblur.js +221 -0
  183. package/dist/src/blitter/bilateralblur.js.map +1 -0
  184. package/dist/src/blitter/blitter.js +390 -0
  185. package/dist/src/blitter/blitter.js.map +1 -0
  186. package/dist/src/blitter/box.js +118 -0
  187. package/dist/src/blitter/box.js.map +1 -0
  188. package/dist/src/blitter/copy.js +22 -0
  189. package/dist/src/blitter/copy.js.map +1 -0
  190. package/dist/src/blitter/gaussianblur.js +228 -0
  191. package/dist/src/blitter/gaussianblur.js.map +1 -0
  192. package/dist/src/camera/base.js +92 -0
  193. package/dist/src/camera/base.js.map +1 -0
  194. package/dist/src/camera/camera.js +1005 -0
  195. package/dist/src/camera/camera.js.map +1 -0
  196. package/dist/src/camera/fps.js +238 -0
  197. package/dist/src/camera/fps.js.map +1 -0
  198. package/dist/src/camera/orbit.js +245 -0
  199. package/dist/src/camera/orbit.js.map +1 -0
  200. package/dist/src/camera/orthocamera.js +167 -0
  201. package/dist/src/camera/orthocamera.js.map +1 -0
  202. package/dist/src/camera/perspectivecamera.js +141 -0
  203. package/dist/src/camera/perspectivecamera.js.map +1 -0
  204. package/dist/src/index.js +120 -0
  205. package/dist/src/index.js.map +1 -0
  206. package/dist/src/material/blinn.js +81 -0
  207. package/dist/src/material/blinn.js.map +1 -0
  208. package/dist/src/material/grassmaterial.js +113 -0
  209. package/dist/src/material/grassmaterial.js.map +1 -0
  210. package/dist/src/material/lambert.js +92 -0
  211. package/dist/src/material/lambert.js.map +1 -0
  212. package/dist/src/material/material.js +301 -0
  213. package/dist/src/material/material.js.map +1 -0
  214. package/dist/src/material/meshmaterial.js +704 -0
  215. package/dist/src/material/meshmaterial.js.map +1 -0
  216. package/dist/src/material/mixins/albedocolor.js +76 -0
  217. package/dist/src/material/mixins/albedocolor.js.map +1 -0
  218. package/dist/src/material/mixins/foliage.js +47 -0
  219. package/dist/src/material/mixins/foliage.js.map +1 -0
  220. package/dist/src/material/mixins/lightmodel/blinnphong.js +112 -0
  221. package/dist/src/material/mixins/lightmodel/blinnphong.js.map +1 -0
  222. package/dist/src/material/mixins/lightmodel/lambert.js +58 -0
  223. package/dist/src/material/mixins/lightmodel/lambert.js.map +1 -0
  224. package/dist/src/material/mixins/lightmodel/pbrmetallicroughness.js +178 -0
  225. package/dist/src/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -0
  226. package/dist/src/material/mixins/lightmodel/pbrspecularglossness.js +139 -0
  227. package/dist/src/material/mixins/lightmodel/pbrspecularglossness.js.map +1 -0
  228. package/dist/src/material/mixins/lit.js +476 -0
  229. package/dist/src/material/mixins/lit.js.map +1 -0
  230. package/dist/src/material/mixins/pbr/common.js +918 -0
  231. package/dist/src/material/mixins/pbr/common.js.map +1 -0
  232. package/dist/src/material/mixins/texture.js +172 -0
  233. package/dist/src/material/mixins/texture.js.map +1 -0
  234. package/dist/src/material/mixins/vertexcolor.js +56 -0
  235. package/dist/src/material/mixins/vertexcolor.js.map +1 -0
  236. package/dist/src/material/particle.js +178 -0
  237. package/dist/src/material/particle.js.map +1 -0
  238. package/dist/src/material/pbrmr.js +97 -0
  239. package/dist/src/material/pbrmr.js.map +1 -0
  240. package/dist/src/material/pbrsg.js +97 -0
  241. package/dist/src/material/pbrsg.js.map +1 -0
  242. package/dist/src/material/shader/helper.js +1209 -0
  243. package/dist/src/material/shader/helper.js.map +1 -0
  244. package/dist/src/material/terrain-cm.js +606 -0
  245. package/dist/src/material/terrain-cm.js.map +1 -0
  246. package/dist/src/material/terrainmaterial.js +375 -0
  247. package/dist/src/material/terrainmaterial.js.map +1 -0
  248. package/dist/src/material/unlit.js +41 -0
  249. package/dist/src/material/unlit.js.map +1 -0
  250. package/dist/src/material/water.js +417 -0
  251. package/dist/src/material/water.js.map +1 -0
  252. package/dist/src/posteffect/bloom.js +361 -0
  253. package/dist/src/posteffect/bloom.js.map +1 -0
  254. package/dist/src/posteffect/compositor.js +226 -0
  255. package/dist/src/posteffect/compositor.js.map +1 -0
  256. package/dist/src/posteffect/fxaa.js +273 -0
  257. package/dist/src/posteffect/fxaa.js.map +1 -0
  258. package/dist/src/posteffect/grayscale.js +69 -0
  259. package/dist/src/posteffect/grayscale.js.map +1 -0
  260. package/dist/src/posteffect/motionblur.js +96 -0
  261. package/dist/src/posteffect/motionblur.js.map +1 -0
  262. package/dist/src/posteffect/posteffect.js +126 -0
  263. package/dist/src/posteffect/posteffect.js.map +1 -0
  264. package/dist/src/posteffect/sao.js +324 -0
  265. package/dist/src/posteffect/sao.js.map +1 -0
  266. package/dist/src/posteffect/ssr.js +489 -0
  267. package/dist/src/posteffect/ssr.js.map +1 -0
  268. package/dist/src/posteffect/taa.js +172 -0
  269. package/dist/src/posteffect/taa.js.map +1 -0
  270. package/dist/src/posteffect/tonemap.js +94 -0
  271. package/dist/src/posteffect/tonemap.js.map +1 -0
  272. package/dist/src/render/abuffer_oit.js +361 -0
  273. package/dist/src/render/abuffer_oit.js.map +1 -0
  274. package/dist/src/render/clipmap.js +851 -0
  275. package/dist/src/render/clipmap.js.map +1 -0
  276. package/dist/src/render/cluster_light.js +333 -0
  277. package/dist/src/render/cluster_light.js.map +1 -0
  278. package/dist/src/render/cull_visitor.js +187 -0
  279. package/dist/src/render/cull_visitor.js.map +1 -0
  280. package/dist/src/render/depthpass.js +68 -0
  281. package/dist/src/render/depthpass.js.map +1 -0
  282. package/dist/src/render/drawable_mixin.js +227 -0
  283. package/dist/src/render/drawable_mixin.js.map +1 -0
  284. package/dist/src/render/envlight.js +463 -0
  285. package/dist/src/render/envlight.js.map +1 -0
  286. package/dist/src/render/fbm_wavegenerator.js +251 -0
  287. package/dist/src/render/fbm_wavegenerator.js.map +1 -0
  288. package/dist/src/render/fft_wavegenerator.js +1006 -0
  289. package/dist/src/render/fft_wavegenerator.js.map +1 -0
  290. package/dist/src/render/fullscreenquad.js +38 -0
  291. package/dist/src/render/fullscreenquad.js.map +1 -0
  292. package/dist/src/render/gerstner_wavegenerator.js +314 -0
  293. package/dist/src/render/gerstner_wavegenerator.js.map +1 -0
  294. package/dist/src/render/globalbindgroup_allocator.js +60 -0
  295. package/dist/src/render/globalbindgroup_allocator.js.map +1 -0
  296. package/dist/src/render/hzb.js +273 -0
  297. package/dist/src/render/hzb.js.map +1 -0
  298. package/dist/src/render/lightpass.js +172 -0
  299. package/dist/src/render/lightpass.js.map +1 -0
  300. package/dist/src/render/objectcolorpass.js +51 -0
  301. package/dist/src/render/objectcolorpass.js.map +1 -0
  302. package/dist/src/render/primitive.js +364 -0
  303. package/dist/src/render/primitive.js.map +1 -0
  304. package/dist/src/render/render_queue.js +467 -0
  305. package/dist/src/render/render_queue.js.map +1 -0
  306. package/dist/src/render/renderbundle_wrapper.js +152 -0
  307. package/dist/src/render/renderbundle_wrapper.js.map +1 -0
  308. package/dist/src/render/renderer.js +455 -0
  309. package/dist/src/render/renderer.js.map +1 -0
  310. package/dist/src/render/renderpass.js +200 -0
  311. package/dist/src/render/renderpass.js.map +1 -0
  312. package/dist/src/render/shadowmap_pass.js +56 -0
  313. package/dist/src/render/shadowmap_pass.js.map +1 -0
  314. package/dist/src/render/sky.js +1103 -0
  315. package/dist/src/render/sky.js.map +1 -0
  316. package/dist/src/render/weightedblended_oit.js +168 -0
  317. package/dist/src/render/weightedblended_oit.js.map +1 -0
  318. package/dist/src/scene/batchgroup.js +162 -0
  319. package/dist/src/scene/batchgroup.js.map +1 -0
  320. package/dist/src/scene/environment.js +209 -0
  321. package/dist/src/scene/environment.js.map +1 -0
  322. package/dist/src/scene/graph_node.js +72 -0
  323. package/dist/src/scene/graph_node.js.map +1 -0
  324. package/dist/src/scene/light.js +416 -0
  325. package/dist/src/scene/light.js.map +1 -0
  326. package/dist/src/scene/mesh.js +341 -0
  327. package/dist/src/scene/mesh.js.map +1 -0
  328. package/dist/src/scene/octree.js +649 -0
  329. package/dist/src/scene/octree.js.map +1 -0
  330. package/dist/src/scene/particlesys.js +738 -0
  331. package/dist/src/scene/particlesys.js.map +1 -0
  332. package/dist/src/scene/raycast_visitor.js +103 -0
  333. package/dist/src/scene/raycast_visitor.js.map +1 -0
  334. package/dist/src/scene/scene.js +284 -0
  335. package/dist/src/scene/scene.js.map +1 -0
  336. package/dist/src/scene/scene_node.js +732 -0
  337. package/dist/src/scene/scene_node.js.map +1 -0
  338. package/dist/src/scene/terrain/grass.js +278 -0
  339. package/dist/src/scene/terrain/grass.js.map +1 -0
  340. package/dist/src/scene/terrain/heightfield.js +475 -0
  341. package/dist/src/scene/terrain/heightfield.js.map +1 -0
  342. package/dist/src/scene/terrain/patch.js +530 -0
  343. package/dist/src/scene/terrain/patch.js.map +1 -0
  344. package/dist/src/scene/terrain/quadtree.js +461 -0
  345. package/dist/src/scene/terrain/quadtree.js.map +1 -0
  346. package/dist/src/scene/terrain/terrain.js +246 -0
  347. package/dist/src/scene/terrain/terrain.js.map +1 -0
  348. package/dist/src/scene/terrain-cm/grass.js +594 -0
  349. package/dist/src/scene/terrain-cm/grass.js.map +1 -0
  350. package/dist/src/scene/terrain-cm/grassmaterial.js +159 -0
  351. package/dist/src/scene/terrain-cm/grassmaterial.js.map +1 -0
  352. package/dist/src/scene/terrain-cm/terrain-cm.js +538 -0
  353. package/dist/src/scene/terrain-cm/terrain-cm.js.map +1 -0
  354. package/dist/src/scene/water.js +374 -0
  355. package/dist/src/scene/water.js.map +1 -0
  356. package/dist/src/shaders/atmosphere.js +957 -0
  357. package/dist/src/shaders/atmosphere.js.map +1 -0
  358. package/dist/src/shaders/fog.js +112 -0
  359. package/dist/src/shaders/fog.js.map +1 -0
  360. package/dist/src/shaders/misc.js +266 -0
  361. package/dist/src/shaders/misc.js.map +1 -0
  362. package/dist/src/shaders/noise.js +222 -0
  363. package/dist/src/shaders/noise.js.map +1 -0
  364. package/dist/src/shaders/pbr.js +51 -0
  365. package/dist/src/shaders/pbr.js.map +1 -0
  366. package/dist/src/shaders/shadow.js +636 -0
  367. package/dist/src/shaders/shadow.js.map +1 -0
  368. package/dist/src/shaders/ssr.js +490 -0
  369. package/dist/src/shaders/ssr.js.map +1 -0
  370. package/dist/src/shaders/temporal.js +215 -0
  371. package/dist/src/shaders/temporal.js.map +1 -0
  372. package/dist/src/shaders/water.js +756 -0
  373. package/dist/src/shaders/water.js.map +1 -0
  374. package/dist/src/shadow/esm.js +237 -0
  375. package/dist/src/shadow/esm.js.map +1 -0
  376. package/dist/src/shadow/pcf_opt.js +181 -0
  377. package/dist/src/shadow/pcf_opt.js.map +1 -0
  378. package/dist/src/shadow/pcf_pd.js +189 -0
  379. package/dist/src/shadow/pcf_pd.js.map +1 -0
  380. package/dist/src/shadow/shader.js +37 -0
  381. package/dist/src/shadow/shader.js.map +1 -0
  382. package/dist/src/shadow/shadow_impl.js +15 -0
  383. package/dist/src/shadow/shadow_impl.js.map +1 -0
  384. package/dist/src/shadow/shadowmapper.js +790 -0
  385. package/dist/src/shadow/shadowmapper.js.map +1 -0
  386. package/dist/src/shadow/ssm.js +159 -0
  387. package/dist/src/shadow/ssm.js.map +1 -0
  388. package/dist/src/shadow/vsm.js +297 -0
  389. package/dist/src/shadow/vsm.js.map +1 -0
  390. package/dist/src/shapes/box.js +386 -0
  391. package/dist/src/shapes/box.js.map +1 -0
  392. package/dist/src/shapes/cylinder.js +125 -0
  393. package/dist/src/shapes/cylinder.js.map +1 -0
  394. package/dist/src/shapes/plane.js +88 -0
  395. package/dist/src/shapes/plane.js.map +1 -0
  396. package/dist/src/shapes/shape.js +87 -0
  397. package/dist/src/shapes/shape.js.map +1 -0
  398. package/dist/src/shapes/sphere.js +114 -0
  399. package/dist/src/shapes/sphere.js.map +1 -0
  400. package/dist/src/shapes/tetrahedron.js +188 -0
  401. package/dist/src/shapes/tetrahedron.js.map +1 -0
  402. package/dist/src/shapes/torus.js +111 -0
  403. package/dist/src/shapes/torus.js.map +1 -0
  404. package/dist/src/utility/aabbtree.js +400 -0
  405. package/dist/src/utility/aabbtree.js.map +1 -0
  406. package/dist/src/utility/bounding_volume.js +29 -0
  407. package/dist/src/utility/bounding_volume.js.map +1 -0
  408. package/dist/src/utility/debug.js +28 -0
  409. package/dist/src/utility/debug.js.map +1 -0
  410. package/dist/src/utility/draco/decoder.js +116 -0
  411. package/dist/src/utility/draco/decoder.js.map +1 -0
  412. package/dist/src/utility/misc.js +105 -0
  413. package/dist/src/utility/misc.js.map +1 -0
  414. package/dist/src/utility/panorama.js +163 -0
  415. package/dist/src/utility/panorama.js.map +1 -0
  416. package/dist/src/utility/pmrem.js +354 -0
  417. package/dist/src/utility/pmrem.js.map +1 -0
  418. package/dist/src/utility/rendermipmap.js +115 -0
  419. package/dist/src/utility/rendermipmap.js.map +1 -0
  420. package/dist/src/utility/serialization/json.js +402 -0
  421. package/dist/src/utility/serialization/json.js.map +1 -0
  422. package/dist/src/utility/serialization/manager.js +623 -0
  423. package/dist/src/utility/serialization/manager.js.map +1 -0
  424. package/dist/src/utility/serialization/scene/animation.js +248 -0
  425. package/dist/src/utility/serialization/scene/animation.js.map +1 -0
  426. package/dist/src/utility/serialization/scene/batch.js +59 -0
  427. package/dist/src/utility/serialization/scene/batch.js.map +1 -0
  428. package/dist/src/utility/serialization/scene/camera.js +790 -0
  429. package/dist/src/utility/serialization/scene/camera.js.map +1 -0
  430. package/dist/src/utility/serialization/scene/common.js +222 -0
  431. package/dist/src/utility/serialization/scene/common.js.map +1 -0
  432. package/dist/src/utility/serialization/scene/light.js +575 -0
  433. package/dist/src/utility/serialization/scene/light.js.map +1 -0
  434. package/dist/src/utility/serialization/scene/material.js +1111 -0
  435. package/dist/src/utility/serialization/scene/material.js.map +1 -0
  436. package/dist/src/utility/serialization/scene/mesh.js +148 -0
  437. package/dist/src/utility/serialization/scene/mesh.js.map +1 -0
  438. package/dist/src/utility/serialization/scene/misc.js +39 -0
  439. package/dist/src/utility/serialization/scene/misc.js.map +1 -0
  440. package/dist/src/utility/serialization/scene/node.js +451 -0
  441. package/dist/src/utility/serialization/scene/node.js.map +1 -0
  442. package/dist/src/utility/serialization/scene/particle.js +425 -0
  443. package/dist/src/utility/serialization/scene/particle.js.map +1 -0
  444. package/dist/src/utility/serialization/scene/primitive.js +692 -0
  445. package/dist/src/utility/serialization/scene/primitive.js.map +1 -0
  446. package/dist/src/utility/serialization/scene/scene.js +704 -0
  447. package/dist/src/utility/serialization/scene/scene.js.map +1 -0
  448. package/dist/src/utility/serialization/scene/terrain.js +488 -0
  449. package/dist/src/utility/serialization/scene/terrain.js.map +1 -0
  450. package/dist/src/utility/serialization/scene/water.js +465 -0
  451. package/dist/src/utility/serialization/scene/water.js.map +1 -0
  452. package/dist/src/utility/shprojector.js +297 -0
  453. package/dist/src/utility/shprojector.js.map +1 -0
  454. package/dist/src/utility/textures/ggxlut.js +213 -0
  455. package/dist/src/utility/textures/ggxlut.js.map +1 -0
  456. package/dist/src/utility/textures/gradientnoise.js +62 -0
  457. package/dist/src/utility/textures/gradientnoise.js.map +1 -0
  458. package/dist/src/utility/textures/randomnoise.js +41 -0
  459. package/dist/src/utility/textures/randomnoise.js.map +1 -0
  460. package/dist/src/values.js +162 -0
  461. package/dist/src/values.js.map +1 -0
  462. package/dist/utility/blueprint/material/common.js +7 -0
  463. package/dist/utility/blueprint/material/common.js.map +1 -0
  464. package/dist/utility/blueprint/material/inputs.js +3 -3
  465. package/dist/utility/blueprint/material/inputs.js.map +1 -1
  466. package/dist/utility/blueprint/material/ir.js +4 -4
  467. package/dist/utility/blueprint/material/ir.js.map +1 -1
  468. package/dist/utility/serialization/blueprint/constants.js +255 -0
  469. package/dist/utility/serialization/blueprint/constants.js.map +1 -0
  470. package/dist/utility/serialization/blueprint/material/constants.js +203 -0
  471. package/dist/utility/serialization/blueprint/material/constants.js.map +1 -0
  472. package/dist/utility/serialization/blueprint/material/texture.js +165 -0
  473. package/dist/utility/serialization/blueprint/material/texture.js.map +1 -0
  474. package/dist/utility/serialization/manager.js +299 -268
  475. package/dist/utility/serialization/manager.js.map +1 -1
  476. package/dist/utility/serialization/scene/animation.js +45 -0
  477. package/dist/utility/serialization/scene/animation.js.map +1 -1
  478. package/dist/utility/serialization/scene/camera.js +53 -0
  479. package/dist/utility/serialization/scene/camera.js.map +1 -1
  480. package/dist/utility/serialization/scene/common.js +10 -0
  481. package/dist/utility/serialization/scene/common.js.map +1 -1
  482. package/dist/utility/serialization/scene/light.js +30 -0
  483. package/dist/utility/serialization/scene/light.js.map +1 -1
  484. package/dist/utility/serialization/scene/material.js +63 -0
  485. package/dist/utility/serialization/scene/material.js.map +1 -1
  486. package/dist/utility/serialization/scene/mesh.js +11 -0
  487. package/dist/utility/serialization/scene/mesh.js.map +1 -1
  488. package/dist/utility/serialization/scene/misc.js +2 -0
  489. package/dist/utility/serialization/scene/misc.js.map +1 -1
  490. package/dist/utility/serialization/scene/node.js +19 -0
  491. package/dist/utility/serialization/scene/node.js.map +1 -1
  492. package/dist/utility/serialization/scene/particle.js +22 -0
  493. package/dist/utility/serialization/scene/particle.js.map +1 -1
  494. package/dist/utility/serialization/scene/primitive.js +33 -0
  495. package/dist/utility/serialization/scene/primitive.js.map +1 -1
  496. package/dist/utility/serialization/scene/scene.js +39 -0
  497. package/dist/utility/serialization/scene/scene.js.map +1 -1
  498. package/dist/utility/serialization/scene/script.js +2 -0
  499. package/dist/utility/serialization/scene/script.js.map +1 -1
  500. package/dist/utility/serialization/scene/sprite.js +6 -0
  501. package/dist/utility/serialization/scene/sprite.js.map +1 -1
  502. package/dist/utility/serialization/scene/terrain.js +9 -0
  503. package/dist/utility/serialization/scene/terrain.js.map +1 -1
  504. package/dist/utility/serialization/scene/water.js +21 -0
  505. package/dist/utility/serialization/scene/water.js.map +1 -1
  506. package/dist/utility/serialization/types.js +5 -1
  507. package/dist/utility/serialization/types.js.map +1 -1
  508. package/dist/values.js +49 -53
  509. package/dist/values.js.map +1 -1
  510. package/package.json +2 -2
  511. package/dist/animation/joint_dynamics/vrm_spring_bone.js +0 -46
  512. package/dist/animation/joint_dynamics/vrm_spring_bone.js.map +0 -1
  513. package/dist/animation/spring/spring_bone.js +0 -240
  514. package/dist/animation/spring/spring_bone.js.map +0 -1
  515. package/dist/animation/spring/spring_bone_collider.js +0 -198
  516. package/dist/animation/spring/spring_bone_collider.js.map +0 -1
  517. package/dist/animation/spring/spring_bone_constraint.js +0 -170
  518. package/dist/animation/spring/spring_bone_constraint.js.map +0 -1
  519. package/dist/animation/spring/spring_bone_system.js +0 -328
  520. package/dist/animation/spring/spring_bone_system.js.map +0 -1
  521. package/dist/render/sky_motion_vector.js +0 -85
  522. package/dist/render/sky_motion_vector.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"taa.js","sources":["../../src/posteffect/taa.ts"],"sourcesContent":["import type { BindGroup, GPUProgram, Texture2D } from '@zephyr3d/device';\r\nimport type { DrawContext, Primitive } from '../render';\r\nimport { AbstractPostEffect, PostEffectLayer } from './posteffect';\r\nimport { linearToGamma } from '../shaders/misc';\r\nimport { fetchSampler } from '../utility/misc';\r\nimport { BoxShape } from '../shapes';\r\nimport { temporalResolve } from '../shaders/temporal';\r\nimport type { Nullable } from '@zephyr3d/base';\r\nimport { Vector2 } from '@zephyr3d/base';\r\n\r\n/** Resource names for TAA history buffers */\r\nconst TAA_RESOURCES = {\r\n COLOR: 'taaColor',\r\n MOTION_VECTOR: 'taaMotionVector'\r\n} as const;\r\n\r\n/** @internal */\r\nexport class TAA extends AbstractPostEffect {\r\n private static _resolveProgram: GPUProgram[] = [];\r\n private static _skyMotionVectorProgram: Nullable<GPUProgram> = null;\r\n private static _box: Primitive;\r\n private static readonly _texSize = new Vector2();\r\n private _bindGroup: Nullable<BindGroup>;\r\n private _skyMotionVectorBindGroup: Nullable<BindGroup>;\r\n constructor() {\r\n super();\r\n this._bindGroup = null;\r\n this._layer = PostEffectLayer.end;\r\n this._skyMotionVectorBindGroup = null;\r\n }\r\n renderSkyMotionVectors(ctx: DrawContext) {\r\n const fb = ctx.device.pool.fetchTemporalFramebuffer(\r\n false,\r\n 0,\r\n 0,\r\n ctx.motionVectorTexture!,\r\n ctx.depthTexture\r\n );\r\n const program = TAA._getSkyMotionVectorProgram(ctx);\r\n if (!this._skyMotionVectorBindGroup) {\r\n this._skyMotionVectorBindGroup = ctx.device.createBindGroup(program.bindGroupLayouts[0]);\r\n }\r\n const box = TAA._getBox(ctx);\r\n this._skyMotionVectorBindGroup.setValue('VPMatrix', ctx.camera.viewProjectionMatrix);\r\n this._skyMotionVectorBindGroup.setValue('prevVPMatrix', ctx.camera.prevVPMatrix!);\r\n this._skyMotionVectorBindGroup.setValue('cameraPos', ctx.camera.getWorldPosition());\r\n this._skyMotionVectorBindGroup.setValue('prevCameraPos', ctx.camera.prevPosition!);\r\n ctx.device.pushDeviceStates();\r\n ctx.device.setProgram(program);\r\n ctx.device.setBindGroup(0, this._skyMotionVectorBindGroup);\r\n ctx.device.setRenderStates(AbstractPostEffect.getDefaultRenderState(ctx, 'le'));\r\n ctx.device.setFramebuffer(fb);\r\n box.draw();\r\n ctx.device.popDeviceStates();\r\n ctx.device.pool.releaseFrameBuffer(fb);\r\n }\r\n apply(ctx: DrawContext, inputColorTexture: Texture2D, sceneDepthTexture: Texture2D, srgbOutput: boolean) {\r\n const historyMgr = ctx.camera.getHistoryResourceManager()!;\r\n\r\n // Check if this is the first frame (no history yet)\r\n const isFirstFrame = !historyMgr.has(TAA_RESOURCES.COLOR);\r\n\r\n if (isFirstFrame) {\r\n // First frame: just pass through\r\n this.passThrough(ctx, inputColorTexture, srgbOutput);\r\n\r\n // Register and update history resources (zero-copy)\r\n const currentColorTex = ctx.device.getFramebuffer()!.getColorAttachments()[0] as Texture2D;\r\n ctx.device.pool.retainTexture(currentColorTex);\r\n\r\n historyMgr.registerWithTexture(\r\n TAA_RESOURCES.COLOR,\r\n {\r\n format: inputColorTexture.format,\r\n sizeMode: 'absolute',\r\n width: inputColorTexture.width,\r\n height: inputColorTexture.height\r\n },\r\n { width: inputColorTexture.width, height: inputColorTexture.height },\r\n currentColorTex\r\n );\r\n\r\n ctx.device.pool.retainTexture(ctx.motionVectorTexture!);\r\n historyMgr.registerWithTexture(\r\n TAA_RESOURCES.MOTION_VECTOR,\r\n {\r\n format: ctx.motionVectorTexture!.format,\r\n sizeMode: 'absolute',\r\n width: ctx.motionVectorTexture!.width,\r\n height: ctx.motionVectorTexture!.height\r\n },\r\n { width: ctx.motionVectorTexture!.width, height: ctx.motionVectorTexture!.height },\r\n ctx.motionVectorTexture!\r\n );\r\n\r\n return;\r\n }\r\n\r\n // Get history textures\r\n const prevColorTex = historyMgr.getPrevious(TAA_RESOURCES.COLOR);\r\n\r\n // Check if resolution changed\r\n if (prevColorTex.width !== inputColorTexture.width || prevColorTex.height !== inputColorTexture.height) {\r\n // Resolution changed, unregister old resources and restart\r\n historyMgr.unregister(TAA_RESOURCES.COLOR);\r\n historyMgr.unregister(TAA_RESOURCES.MOTION_VECTOR);\r\n this.passThrough(ctx, inputColorTexture, srgbOutput);\r\n return;\r\n }\r\n\r\n const prevMotionVectorTex = historyMgr.getPrevious(TAA_RESOURCES.MOTION_VECTOR);\r\n\r\n // Render TAA\r\n let program = TAA._resolveProgram[ctx.camera.TAADebug];\r\n if (!program) {\r\n program = TAA._getResolveProgram(ctx, ctx.camera.TAADebug);\r\n TAA._resolveProgram[ctx.camera.TAADebug] = program;\r\n }\r\n if (!this._bindGroup) {\r\n this._bindGroup = ctx.device.createBindGroup(program.bindGroupLayouts[0]);\r\n }\r\n this._bindGroup.setTexture('historyColorTex', prevColorTex, fetchSampler('clamp_linear_nomip'));\r\n this._bindGroup.setTexture('currentColorTex', inputColorTexture, fetchSampler('clamp_nearest_nomip'));\r\n this._bindGroup.setTexture('currentDepthTex', sceneDepthTexture, fetchSampler('clamp_nearest_nomip'));\r\n this._bindGroup.setTexture('motionVector', ctx.motionVectorTexture!, fetchSampler('clamp_nearest_nomip'));\r\n this._bindGroup.setTexture('prevMotionVector', prevMotionVectorTex, fetchSampler('clamp_nearest_nomip'));\r\n this._bindGroup.setValue('flip', this.needFlip(ctx.device) ? 1 : 0);\r\n this._bindGroup.setValue('srgbOut', srgbOutput ? 1 : 0);\r\n TAA._texSize.setXY(sceneDepthTexture.width, sceneDepthTexture.height);\r\n this._bindGroup.setValue('texSize', TAA._texSize);\r\n\r\n ctx.device.setProgram(program);\r\n ctx.device.setBindGroup(0, this._bindGroup);\r\n this.drawFullscreenQuad();\r\n\r\n // Update history with current framebuffer output (zero-copy)\r\n const currentColorTex = ctx.device.getFramebuffer()!.getColorAttachments()[0] as Texture2D;\r\n ctx.device.pool.retainTexture(currentColorTex);\r\n historyMgr.updateCurrent(TAA_RESOURCES.COLOR, currentColorTex);\r\n\r\n ctx.device.pool.retainTexture(ctx.motionVectorTexture!);\r\n historyMgr.updateCurrent(TAA_RESOURCES.MOTION_VECTOR, ctx.motionVectorTexture!);\r\n\r\n // Note: History swap happens automatically in executeForwardPlusGraph\r\n }\r\n requireLinearDepthTexture(_ctx: DrawContext) {\r\n return true;\r\n }\r\n requireDepthAttachment(_ctx: DrawContext) {\r\n return true;\r\n }\r\n private static _getSkyMotionVectorProgram(ctx: DrawContext) {\r\n if (!this._skyMotionVectorProgram) {\r\n this._skyMotionVectorProgram = ctx.device.buildRenderProgram({\r\n vertex(pb) {\r\n this.$inputs.pos = pb.vec3().attrib('position');\r\n this.VPMatrix = pb.mat4().uniform(0);\r\n this.prevVPMatrix = pb.mat4().uniform(0);\r\n this.cameraPos = pb.vec3().uniform(0);\r\n this.prevCameraPos = pb.vec3().uniform(0);\r\n pb.main(function () {\r\n this.$l.worldPos = pb.add(this.$inputs.pos, this.cameraPos);\r\n this.$l.prevWorldPos = pb.add(this.$inputs.pos, this.prevCameraPos);\r\n this.$l.clipPos = pb.mul(this.VPMatrix, pb.vec4(this.worldPos, 1));\r\n this.$l.prevClipPos = pb.mul(this.prevVPMatrix, pb.vec4(this.prevWorldPos, 1));\r\n this.clipPos.z = this.clipPos.w;\r\n this.$builtins.position = this.clipPos;\r\n this.$outputs.currentPos = this.clipPos;\r\n this.$outputs.prevPos = this.prevClipPos;\r\n });\r\n },\r\n fragment(pb) {\r\n this.$outputs.color = pb.vec4();\r\n pb.main(function () {\r\n this.$l.motionVector = pb.mul(\r\n pb.sub(\r\n pb.div(this.$inputs.currentPos.xy, this.$inputs.currentPos.w),\r\n pb.div(this.$inputs.prevPos.xy, this.$inputs.prevPos.w)\r\n ),\r\n 0.5\r\n );\r\n this.$outputs.color = pb.vec4(this.motionVector, 0, 1);\r\n });\r\n }\r\n })!;\r\n this._skyMotionVectorProgram.name = '@TAA_SkyMotionVector';\r\n }\r\n return this._skyMotionVectorProgram;\r\n }\r\n private static _getBox(_ctx: DrawContext) {\r\n if (!this._box) {\r\n this._box = new BoxShape({\r\n size: 2,\r\n needNormal: false,\r\n needUV: false\r\n });\r\n }\r\n return this._box;\r\n }\r\n private static _getResolveProgram(ctx: DrawContext, debug: number) {\r\n const program = ctx.device.buildRenderProgram({\r\n vertex(pb) {\r\n this.flip = pb.int().uniform(0);\r\n this.$inputs.pos = pb.vec2().attrib('position');\r\n this.$outputs.uv = pb.vec2();\r\n pb.main(function () {\r\n this.$builtins.position = pb.vec4(this.$inputs.pos, 1, 1);\r\n this.$outputs.uv = pb.add(pb.mul(this.$inputs.pos.xy, 0.5), pb.vec2(0.5));\r\n this.$if(pb.notEqual(this.flip, 0), function () {\r\n this.$builtins.position.y = pb.neg(this.$builtins.position.y);\r\n });\r\n });\r\n },\r\n fragment(pb) {\r\n this.historyColorTex = pb.tex2D().uniform(0);\r\n this.currentColorTex = pb.tex2D().uniform(0);\r\n this.currentDepthTex = pb.tex2D().uniform(0);\r\n this.motionVector = pb.tex2D().uniform(0);\r\n this.prevMotionVector = pb.tex2D().uniform(0);\r\n this.texSize = pb.vec2().uniform(0);\r\n this.srgbOut = pb.int().uniform(0);\r\n this.$outputs.outColor = pb.vec4();\r\n pb.main(function () {\r\n this.$l.screenUV = pb.div(pb.vec2(this.$builtins.fragCoord.xy), this.texSize);\r\n this.$l.resolvedColor = temporalResolve(\r\n this,\r\n this.currentColorTex,\r\n this.historyColorTex,\r\n this.currentDepthTex,\r\n this.motionVector,\r\n this.prevMotionVector,\r\n this.screenUV,\r\n this.texSize,\r\n debug\r\n );\r\n this.$if(pb.equal(this.srgbOut, 0), function () {\r\n this.$outputs.outColor = pb.vec4(this.resolvedColor, 1);\r\n }).$else(function () {\r\n this.$outputs.outColor = pb.vec4(linearToGamma(this, this.resolvedColor), 1);\r\n });\r\n });\r\n }\r\n })!;\r\n program.name = '@TAA_Resolve';\r\n return program;\r\n }\r\n}\r\n"],"names":["TAA_RESOURCES","COLOR","MOTION_VECTOR","TAA","AbstractPostEffect","_resolveProgram","_skyMotionVectorProgram","_box","_texSize","Vector2","_bindGroup","_skyMotionVectorBindGroup","_layer","PostEffectLayer","end","renderSkyMotionVectors","ctx","fb","device","pool","fetchTemporalFramebuffer","motionVectorTexture","depthTexture","program","_getSkyMotionVectorProgram","createBindGroup","bindGroupLayouts","box","_getBox","setValue","camera","viewProjectionMatrix","prevVPMatrix","getWorldPosition","prevPosition","pushDeviceStates","setProgram","setBindGroup","setRenderStates","getDefaultRenderState","setFramebuffer","draw","popDeviceStates","releaseFrameBuffer","apply","inputColorTexture","sceneDepthTexture","srgbOutput","historyMgr","getHistoryResourceManager","isFirstFrame","has","passThrough","currentColorTex","getFramebuffer","getColorAttachments","retainTexture","registerWithTexture","format","sizeMode","width","height","prevColorTex","getPrevious","unregister","prevMotionVectorTex","TAADebug","_getResolveProgram","setTexture","fetchSampler","needFlip","setXY","drawFullscreenQuad","updateCurrent","requireLinearDepthTexture","_ctx","requireDepthAttachment","buildRenderProgram","vertex","pb","$inputs","pos","vec3","attrib","VPMatrix","mat4","uniform","cameraPos","prevCameraPos","main","$l","worldPos","add","prevWorldPos","clipPos","mul","vec4","prevClipPos","z","w","$builtins","position","$outputs","currentPos","prevPos","fragment","color","motionVector","sub","div","xy","name","BoxShape","size","needNormal","needUV","debug","flip","int","vec2","uv","$if","notEqual","y","neg","historyColorTex","tex2D","currentDepthTex","prevMotionVector","texSize","srgbOut","outColor","screenUV","fragCoord","resolvedColor","temporalResolve","equ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,GAAGpD,GAAGiB,IAAI,EAAA;AAChCjB,gBAAAA,EAAAA,CAAGU,IAAI,CAAC,WAAA;oBACN,IAAI,CAACC,EAAE,CAAC0C,QAAQ,GAAGrD,EAAG8B,CAAAA,GAAG,CAAC9B,EAAGwC,CAAAA,IAAI,CAAC,IAAI,CAACnB,SAAS,CAACiC,SAAS,CAACvB,EAAE,CAAA,EAAG,IAAI,CAACmB,OAAO,CAAA;AAC5E,oBAAA,IAAI,CAACvC,EAAE,CAAC4C,aAAa,GAAGC,eACtB,CAAA,IAAI,EACJ,IAAI,CAAClF,eAAe,EACpB,IAAI,CAACwE,eAAe,EACpB,IAAI,CAACE,eAAe,EACpB,IAAI,CAACpB,YAAY,EACjB,IAAI,CAACqB,gBAAgB,EACrB,IAAI,CAACI,QAAQ,EACb,IAAI,CAACH,OAAO,EACZb,KAAAA,CAAAA;oBAEF,IAAI,CAACK,GAAG,CAAC1C,EAAGyD,CAAAA,KAAK,CAAC,IAAI,CAACN,OAAO,EAAE,CAAI,CAAA,EAAA,WAAA;wBAClC,IAAI,CAAC5B,QAAQ,CAAC6B,QAAQ,GAAGpD,EAAGiB,CAAAA,IAAI,CAAC,IAAI,CAACsC,aAAa,EAAE,CAAA,CAAA;AACvD,qBAAA,CAAA,CAAGG,KAAK,CAAC,WAAA;AACP,wBAAA,IAAI,CAACnC,QAAQ,CAAC6B,QAAQ,GAAGpD,EAAGiB,CAAAA,IAAI,CAAC0C,aAAAA,CAAc,IAAI,EAAE,IAAI,CAACJ,aAAa,CAAG,EAAA,CAAA,CAAA;AAC5E,qBAAA,CAAA;AACF,iBAAA,CAAA;AACF;AACF,SAAA,CAAA;AACA/G,QAAAA,OAAAA,CAAQwF,IAAI,GAAG,cAAA;QACf,OAAOxF,OAAAA;AACT;AACF;;;;"}
1
+ {"version":3,"file":"taa.js","sources":["../../src/posteffect/taa.ts"],"sourcesContent":["import type { BindGroup, GPUProgram, Texture2D } from '@zephyr3d/device';\r\nimport type { DrawContext, Primitive } from '../render';\r\nimport { AbstractPostEffect, PostEffectLayer } from './posteffect';\r\nimport { linearToGamma } from '../shaders/misc';\r\nimport { fetchSampler } from '../utility/misc';\r\nimport { BoxShape } from '../shapes';\r\nimport { temporalResolve } from '../shaders/temporal';\r\nimport type { Nullable } from '@zephyr3d/base';\r\nimport { Vector2 } from '@zephyr3d/base';\r\nimport { RGHistoryResources } from '../render/rendergraph/history_resources';\r\n\r\n/** @internal */\r\nexport class TAA extends AbstractPostEffect {\r\n private static _resolveProgram: GPUProgram[] = [];\r\n private static _skyMotionVectorProgram: Nullable<GPUProgram> = null;\r\n private static _box: Primitive;\r\n private static readonly _texSize = new Vector2();\r\n private _bindGroup: Nullable<BindGroup>;\r\n private _skyMotionVectorBindGroup: Nullable<BindGroup>;\r\n constructor() {\r\n super();\r\n this._bindGroup = null;\r\n this._layer = PostEffectLayer.end;\r\n this._skyMotionVectorBindGroup = null;\r\n }\r\n renderSkyMotionVectors(ctx: DrawContext) {\r\n const fb = ctx.device.pool.fetchTemporalFramebuffer(\r\n false,\r\n 0,\r\n 0,\r\n ctx.motionVectorTexture!,\r\n ctx.depthTexture\r\n );\r\n const program = TAA._getSkyMotionVectorProgram(ctx);\r\n if (!this._skyMotionVectorBindGroup) {\r\n this._skyMotionVectorBindGroup = ctx.device.createBindGroup(program.bindGroupLayouts[0]);\r\n }\r\n const box = TAA._getBox(ctx);\r\n this._skyMotionVectorBindGroup.setValue('VPMatrix', ctx.camera.viewProjectionMatrix);\r\n this._skyMotionVectorBindGroup.setValue('prevVPMatrix', ctx.camera.prevVPMatrix!);\r\n this._skyMotionVectorBindGroup.setValue('cameraPos', ctx.camera.getWorldPosition());\r\n this._skyMotionVectorBindGroup.setValue('prevCameraPos', ctx.camera.prevPosition!);\r\n ctx.device.pushDeviceStates();\r\n ctx.device.setProgram(program);\r\n ctx.device.setBindGroup(0, this._skyMotionVectorBindGroup);\r\n ctx.device.setRenderStates(AbstractPostEffect.getDefaultRenderState(ctx, 'le'));\r\n ctx.device.setFramebuffer(fb);\r\n box.draw();\r\n ctx.device.popDeviceStates();\r\n ctx.device.pool.releaseFrameBuffer(fb);\r\n }\r\n apply(ctx: DrawContext, inputColorTexture: Texture2D, sceneDepthTexture: Texture2D, srgbOutput: boolean) {\r\n const historyMgr = ctx.camera.getHistoryResourceManager()!;\r\n const colorDesc = {\r\n format: inputColorTexture.format,\r\n sizeMode: 'absolute' as const,\r\n width: inputColorTexture.width,\r\n height: inputColorTexture.height\r\n };\r\n const colorSize = { width: inputColorTexture.width, height: inputColorTexture.height };\r\n const motionVectorDesc = {\r\n format: ctx.motionVectorTexture!.format,\r\n sizeMode: 'absolute' as const,\r\n width: ctx.motionVectorTexture!.width,\r\n height: ctx.motionVectorTexture!.height\r\n };\r\n const motionVectorSize = {\r\n width: ctx.motionVectorTexture!.width,\r\n height: ctx.motionVectorTexture!.height\r\n };\r\n\r\n const hasHistory =\r\n historyMgr.isCompatible(RGHistoryResources.TAA_COLOR, colorDesc, colorSize) &&\r\n historyMgr.isCompatible(RGHistoryResources.TAA_MOTION_VECTOR, motionVectorDesc, motionVectorSize);\r\n\r\n if (!hasHistory) {\r\n // First frame: just pass through\r\n this.passThrough(ctx, inputColorTexture, srgbOutput);\r\n\r\n // Queue history resources only after retaining references from the pool.\r\n const currentColorTex = ctx.device.getFramebuffer()!.getColorAttachments()[0] as Texture2D;\r\n ctx.device.pool.retainTexture(currentColorTex);\r\n historyMgr.queueCommit(RGHistoryResources.TAA_COLOR, colorDesc, colorSize, currentColorTex);\r\n\r\n ctx.device.pool.retainTexture(ctx.motionVectorTexture!);\r\n historyMgr.queueCommit(\r\n RGHistoryResources.TAA_MOTION_VECTOR,\r\n motionVectorDesc,\r\n motionVectorSize,\r\n ctx.motionVectorTexture!\r\n );\r\n\r\n return;\r\n }\r\n\r\n // Get history textures\r\n const prevColorTex = historyMgr.getPrevious(RGHistoryResources.TAA_COLOR);\r\n const prevMotionVectorTex = historyMgr.getPrevious(RGHistoryResources.TAA_MOTION_VECTOR);\r\n\r\n // Render TAA\r\n let program = TAA._resolveProgram[ctx.camera.TAADebug];\r\n if (!program) {\r\n program = TAA._getResolveProgram(ctx, ctx.camera.TAADebug);\r\n TAA._resolveProgram[ctx.camera.TAADebug] = program;\r\n }\r\n if (!this._bindGroup) {\r\n this._bindGroup = ctx.device.createBindGroup(program.bindGroupLayouts[0]);\r\n }\r\n this._bindGroup.setTexture('historyColorTex', prevColorTex, fetchSampler('clamp_linear_nomip'));\r\n this._bindGroup.setTexture('currentColorTex', inputColorTexture, fetchSampler('clamp_nearest_nomip'));\r\n this._bindGroup.setTexture('currentDepthTex', sceneDepthTexture, fetchSampler('clamp_nearest_nomip'));\r\n this._bindGroup.setTexture('motionVector', ctx.motionVectorTexture!, fetchSampler('clamp_nearest_nomip'));\r\n this._bindGroup.setTexture('prevMotionVector', prevMotionVectorTex, fetchSampler('clamp_nearest_nomip'));\r\n this._bindGroup.setValue('flip', this.needFlip(ctx.device) ? 1 : 0);\r\n this._bindGroup.setValue('srgbOut', srgbOutput ? 1 : 0);\r\n TAA._texSize.setXY(sceneDepthTexture.width, sceneDepthTexture.height);\r\n this._bindGroup.setValue('texSize', TAA._texSize);\r\n\r\n ctx.device.setProgram(program);\r\n ctx.device.setBindGroup(0, this._bindGroup);\r\n this.drawFullscreenQuad();\r\n\r\n // Update history with current framebuffer output (zero-copy)\r\n const currentColorTex = ctx.device.getFramebuffer()!.getColorAttachments()[0] as Texture2D;\r\n ctx.device.pool.retainTexture(currentColorTex);\r\n historyMgr.queueCommit(RGHistoryResources.TAA_COLOR, colorDesc, colorSize, currentColorTex);\r\n\r\n ctx.device.pool.retainTexture(ctx.motionVectorTexture!);\r\n historyMgr.queueCommit(\r\n RGHistoryResources.TAA_MOTION_VECTOR,\r\n motionVectorDesc,\r\n motionVectorSize,\r\n ctx.motionVectorTexture!\r\n );\r\n\r\n // History commits happen after the render graph completes successfully.\r\n }\r\n requireLinearDepthTexture(_ctx: DrawContext) {\r\n return true;\r\n }\r\n requireDepthAttachment(_ctx: DrawContext) {\r\n return true;\r\n }\r\n private static _getSkyMotionVectorProgram(ctx: DrawContext) {\r\n if (!this._skyMotionVectorProgram) {\r\n this._skyMotionVectorProgram = ctx.device.buildRenderProgram({\r\n vertex(pb) {\r\n this.$inputs.pos = pb.vec3().attrib('position');\r\n this.VPMatrix = pb.mat4().uniform(0);\r\n this.prevVPMatrix = pb.mat4().uniform(0);\r\n this.cameraPos = pb.vec3().uniform(0);\r\n this.prevCameraPos = pb.vec3().uniform(0);\r\n pb.main(function () {\r\n this.$l.worldPos = pb.add(this.$inputs.pos, this.cameraPos);\r\n this.$l.prevWorldPos = pb.add(this.$inputs.pos, this.prevCameraPos);\r\n this.$l.clipPos = pb.mul(this.VPMatrix, pb.vec4(this.worldPos, 1));\r\n this.$l.prevClipPos = pb.mul(this.prevVPMatrix, pb.vec4(this.prevWorldPos, 1));\r\n this.clipPos.z = this.clipPos.w;\r\n this.$builtins.position = this.clipPos;\r\n this.$outputs.currentPos = this.clipPos;\r\n this.$outputs.prevPos = this.prevClipPos;\r\n });\r\n },\r\n fragment(pb) {\r\n this.$outputs.color = pb.vec4();\r\n pb.main(function () {\r\n this.$l.motionVector = pb.mul(\r\n pb.sub(\r\n pb.div(this.$inputs.currentPos.xy, this.$inputs.currentPos.w),\r\n pb.div(this.$inputs.prevPos.xy, this.$inputs.prevPos.w)\r\n ),\r\n 0.5\r\n );\r\n this.$outputs.color = pb.vec4(this.motionVector, 0, 1);\r\n });\r\n }\r\n })!;\r\n this._skyMotionVectorProgram.name = '@TAA_SkyMotionVector';\r\n }\r\n return this._skyMotionVectorProgram;\r\n }\r\n private static _getBox(_ctx: DrawContext) {\r\n if (!this._box) {\r\n this._box = new BoxShape({\r\n size: 2,\r\n needNormal: false,\r\n needUV: false\r\n });\r\n }\r\n return this._box;\r\n }\r\n private static _getResolveProgram(ctx: DrawContext, debug: number) {\r\n const program = ctx.device.buildRenderProgram({\r\n vertex(pb) {\r\n this.flip = pb.int().uniform(0);\r\n this.$inputs.pos = pb.vec2().attrib('position');\r\n this.$outputs.uv = pb.vec2();\r\n pb.main(function () {\r\n this.$builtins.position = pb.vec4(this.$inputs.pos, 1, 1);\r\n this.$outputs.uv = pb.add(pb.mul(this.$inputs.pos.xy, 0.5), pb.vec2(0.5));\r\n this.$if(pb.notEqual(this.flip, 0), function () {\r\n this.$builtins.position.y = pb.neg(this.$builtins.position.y);\r\n });\r\n });\r\n },\r\n fragment(pb) {\r\n this.historyColorTex = pb.tex2D().uniform(0);\r\n this.currentColorTex = pb.tex2D().uniform(0);\r\n this.currentDepthTex = pb.tex2D().uniform(0);\r\n this.motionVector = pb.tex2D().uniform(0);\r\n this.prevMotionVector = pb.tex2D().uniform(0);\r\n this.texSize = pb.vec2().uniform(0);\r\n this.srgbOut = pb.int().uniform(0);\r\n this.$outputs.outColor = pb.vec4();\r\n pb.main(function () {\r\n this.$l.screenUV = pb.div(pb.vec2(this.$builtins.fragCoord.xy), this.texSize);\r\n this.$l.resolvedColor = temporalResolve(\r\n this,\r\n this.currentColorTex,\r\n this.historyColorTex,\r\n this.currentDepthTex,\r\n this.motionVector,\r\n this.prevMotionVector,\r\n this.screenUV,\r\n this.texSize,\r\n debug\r\n );\r\n this.$if(pb.equal(this.srgbOut, 0), function () {\r\n this.$outputs.outColor = pb.vec4(this.resolvedColor, 1);\r\n }).$else(function () {\r\n this.$outputs.outColor = pb.vec4(linearToGamma(this, this.resolvedColor), 1);\r\n });\r\n });\r\n }\r\n })!;\r\n program.name = '@TAA_Resolve';\r\n return program;\r\n }\r\n}\r\n"],"names":["TAA","AbstractPostEffect","_resolveProgram","_skyMotionVectorProgram","_box","_texSize","Vector2","_bindGroup","_skyMotionVectorBindGroup","_layer","PostEffectLayer","end","renderSkyMotionVectors","ctx","fb","device","pool","fetchTemporalFramebuffer","motionVectorTexture","depthTexture","program","_getSkyMotionVectorProgram","createBindGroup","bindGroupLayouts","box","_getBox","setValue","camera","viewProjectionMatrix","prevVPMatrix","getWorldPosition","prevPosition","pushDeviceStates","setProgram","setBindGroup","setRenderStates","getDefaultRenderState","setFramebuffer","draw","popDeviceStates","releaseFrameBuffer","apply","inputColorTexture","sceneDepthTexture","srgbOutput","historyMgr","getHistoryResourceManager","colorDesc","format","sizeMode","width","height","colorSize","motionVectorDesc","motionVectorSize","hasHistory","isCompatible","RGHistoryResources","TAA_COLOR","TAA_MOTION_VECTOR","passThrough","currentColorTex","getFramebuffer","getColorAttachments","retainTexture","queueCommit","prevColorTex","getPrevious","prevMotionVectorTex","TAADebug","_getResolveProgram","setTexture","fetchSampler","needFlip","setXY","drawFullscreenQuad","requireLinearDepthTexture","_ctx","requireDepthAttachment","buildRenderProgram","vertex","pb","$inputs","pos","vec3","attrib","VPMatrix","mat4","uniform","cameraPos","prevCameraPos","main","$l","worldPos","add","prevWorldPos","clipPos","mul","vec4","prevClipPos","z","w","$builtins","position","$outputs","currentPos","prevPos","fragment","color","motionVector","sub","div","xy","name","BoxShape","size","needNormal","needUV","debug","flip","int","vec2","uv","$if","notEqual","y","neg","historyColorTex","tex2D","currentDepthTex","prevMotionVector","texSize","srgbOut","outColor","screenUV","fragCoord","resolvedColor","temporalResolve","equal","$else","linearToGamma"],"mappings":";;;;;;;;;;;;;;;AAWA,iBACO,MAAMA,GAAYC,SAAAA,kBAAAA,CAAAA;IACvB,OAAeC,eAAAA,GAAgC,EAAE;AACjD,IAAA,OAAeC,0BAAgD,IAAK;AACpE,IAAA,OAAeC,IAAgB;IAC/B,OAAwBC,QAAAA,GAAW,IAAIC,OAAU,EAAA;IACzCC,UAAgC;IAChCC,yBAA+C;IACvD,WAAc,EAAA;QACZ,KAAK,EAAA;QACL,IAAI,CAACD,UAAU,GAAG,IAAA;AAClB,QAAA,IAAI,CAACE,MAAM,GAAGC,eAAAA,CAAgBC,GAAG;QACjC,IAAI,CAACH,yBAAyB,GAAG,IAAA;AACnC;AACAI,IAAAA,sBAAAA,CAAuBC,GAAgB,EAAE;AACvC,QAAA,MAAMC,E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AAA,EAAA,WAAA;wBAClC,IAAI,CAAC5B,QAAQ,CAAC6B,QAAQ,GAAGpD,EAAGiB,CAAAA,IAAI,CAAC,IAAI,CAACsC,aAAa,EAAE,CAAA,CAAA;AACvD,qBAAA,CAAA,CAAGG,KAAK,CAAC,WAAA;AACP,wBAAA,IAAI,CAACnC,QAAQ,CAAC6B,QAAQ,GAAGpD,EAAGiB,CAAAA,IAAI,CAAC0C,aAAAA,CAAc,IAAI,EAAE,IAAI,CAACJ,aAAa,CAAG,EAAA,CAAA,CAAA;AAC5E,qBAAA,CAAA;AACF,iBAAA,CAAA;AACF;AACF,SAAA,CAAA;AACApH,QAAAA,OAAAA,CAAQ6F,IAAI,GAAG,cAAA;QACf,OAAO7F,OAAAA;AACT;AACF;;;;"}
@@ -1,5 +1,4 @@
1
1
  import { Vector4 } from '@zephyr3d/base';
2
- import { MAX_CLUSTERED_LIGHTS } from '../values.js';
3
2
  import { ShaderHelper } from '../material/shader/helper.js';
4
3
  import { getDevice } from '../app/api.js';
5
4
 
@@ -22,7 +21,7 @@ class ClusteredLight {
22
21
  this._tileCountX = 16;
23
22
  this._tileCountY = 16;
24
23
  this._tileCountZ = 32;
25
- this._lights = new Float32Array(16 * (MAX_CLUSTERED_LIGHTS + 1));
24
+ this._lights = new Float32Array(16 * (ShaderHelper.getMaxClusteredLightCount() + 1));
26
25
  this._lightIndexTexture = null;
27
26
  this._lightIndexFramebuffer = null;
28
27
  this._lightIndexProgram = null;
@@ -91,7 +90,7 @@ class ClusteredLight {
91
90
  this.viewMatrix = pb.mat4().uniform(0);
92
91
  this.sizeParam = pb.vec4().uniform(0);
93
92
  this.countParam = pb.ivec4().uniform(0);
94
- this[ShaderHelper.getLightBufferUniformName()] = pb.vec4[(MAX_CLUSTERED_LIGHTS + 1) * 4]().uniformBuffer(0);
93
+ this[ShaderHelper.getLightBufferUniformName()] = pb.vec4[(ShaderHelper.getMaxClusteredLightCount() + 1) * 4]().uniformBuffer(0);
95
94
  pb.func('lineIntersectionToZPlane', [
96
95
  pb.vec3('a'),
97
96
  pb.vec3('b'),
@@ -320,7 +319,7 @@ class ClusteredLight {
320
319
  device.popDeviceStates();
321
320
  }
322
321
  getVisibleLights(renderQueue, lights) {
323
- const numLights = Math.min(renderQueue.unshadowedLights.length, MAX_CLUSTERED_LIGHTS);
322
+ const numLights = Math.min(renderQueue.unshadowedLights.length, ShaderHelper.getMaxClusteredLightCount());
324
323
  for(let i = 1; i <= numLights; i++){
325
324
  const light = renderQueue.unshadowedLights[i - 1];
326
325
  const offset = i * 16;
@@ -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,uBA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AAYkC,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;QAC/B,IAAI,CAACC,uBAAuB,GAAG,IAAA;QAC/B,IAAI,CAACE,UAAU,GAAG,IAAIM,OAAAA,EAAAA;AACtB,QAAA,IAAI,CAACL,WAAW,GAAG,IAAIM,UAAW,CAAA,CAAA,CAAA;QAClC,IAAI,CAACL,aAAa,GAAG,IAAII,OAAAA,EAAAA;AAC3B;AACA,IAAA,IAAIE,WAAc,GAAA;QAChB,OAAO,IAAI,CAACT,YAAY;AAC1B;AACA,IAAA,IAAIU,YAAe,GAAA;QACjB,OA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gBAAgB,CAAC,IAAItL,OAAAA,CAAQ,GAAG,CAAG,EAAA,CAAA,EAAG,IAAI,CAAG,EAAA,CAAA,CAAA;AACtD;AACAO,QAAAA,MAAAA,CAAOgL,eAAe,EAAA;AACxB;IACQ9B,gBAAiBF,CAAAA,WAAwB,EAAEiC,MAAoB,EAAE;QACvE,MAAMhC,SAAAA,GAAYvI,IAAKmG,CAAAA,GAAG,CAACmC,WAAAA,CAAYkC,gBAAgB,CAAC3K,MAAM,EAAEhB,YAAAA,CAAaC,yBAAyB,EAAA,CAAA;AACtG,QAAA,IAAK,IAAIc,CAAAA,GAAI,CAAGA,EAAAA,CAAAA,IAAK2I,WAAW3I,CAAK,EAAA,CAAA;AACnC,YAAA,MAAM8G,KAAQ4B,GAAAA,WAAAA,CAAYkC,gBAAgB,CAAC5K,IAAI,CAAE,CAAA;AACjD,YAAA,MAAM6K,SAAS7K,CAAI,GAAA,EAAA;AACnB2K,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,6 +1,10 @@
1
1
  import { getDevice } from '../app/api.js';
2
2
 
3
- class RenderContext {
3
+ /**
4
+ * Minimal render context carrying target size and device information.
5
+ *
6
+ * @public
7
+ */ class RenderContext {
4
8
  device;
5
9
  renderWidth;
6
10
  renderHeight;
@@ -1 +1 @@
1
- {"version":3,"file":"drawable.js","sources":["../../src/render/drawable.ts"],"sourcesContent":["import type { DRef, Nullable, TypedArray, Vector4 } from '@zephyr3d/base';\r\nimport type {\r\n AbstractDevice,\r\n ColorState,\r\n FaceMode,\r\n FrameBuffer,\r\n GPUDataBuffer,\r\n Texture2D,\r\n TextureFormat\r\n} from '@zephyr3d/device';\r\nimport type { Camera } from '../camera/camera';\r\nimport type { Primitive, RenderPass } from '.';\r\nimport type { DrawableInstanceInfo, InstanceData, RenderQueue, RenderQueueRef } from './render_queue';\r\nimport type { ShadowMapParams } from '../shadow';\r\nimport type { Environment } from '../scene/environment';\r\nimport type { DirectionalLight, PunctualLight, Scene, SceneNode } from '../scene';\r\nimport type { Compositor } from '../posteffect';\r\nimport type { ClusteredLight } from './cluster_light';\r\nimport type { MeshMaterial } from '../material';\r\nimport type { GlobalBindGroupAllocator } from './globalbindgroup_allocator';\r\nimport type { OIT } from './oit';\r\nimport { getDevice } from '../app/api';\r\n\r\n/**\r\n * Picking result target container.\r\n *\r\n * Use to override/annotate which scene node (and optional label) a drawable should report\r\n * when GPU picking or raycast returns a hit.\r\n *\r\n * @public\r\n */\r\nexport type PickTarget = { node: SceneNode; label?: string };\r\n\r\nexport class RenderContext {\r\n public device: AbstractDevice;\r\n public renderWidth: number;\r\n public renderHeight: number;\r\n constructor(_camera: Camera, w: number, h: number) {\r\n this.device = getDevice();\r\n this.renderWidth = w;\r\n this.renderHeight = h;\r\n }\r\n}\r\n/**\r\n * Context object passed to draw calls and render helpers.\r\n *\r\n * It aggregates all per-frame, per-pass, and per-draw state derived from the engine and renderer,\r\n * including device handles, textures, passes, flags, and post-processing links.\r\n *\r\n * Notes:\r\n * - Not all textures/fields are present for every pass; check for undefined when optional.\r\n * - Values like `HiZ`, `TAA`, `SSR` signal features the renderer has activated for the current pass.\r\n *\r\n * @public\r\n */\r\nexport interface DrawContext {\r\n /** Render device used for issuing GPU commands. */\r\n readonly device: AbstractDevice;\r\n /** Framebuffer width for rendering (in pixels). */\r\n readonly renderWidth: number;\r\n /** Framebuffer height for rendering (in pixels). */\r\n readonly renderHeight: number;\r\n /** Allocator for global (frame/pass) bind groups and descriptor resources. */\r\n readonly globalBindGroupAllocator: GlobalBindGroupAllocator;\r\n /** The camera associated with the current drawing task (may differ from primaryCamera). */\r\n readonly camera: Camera;\r\n /** Order-Independent Transparency interface for transparent passes. */\r\n oit: Nullable<OIT>;\r\n /** Whether motion vectors are being written this pass (used by TAA/MotionBlur). */\r\n readonly motionVectors: boolean;\r\n /** Motion vector texture target when motion vectors are active. */\r\n motionVectorTexture?: Nullable<Texture2D>;\r\n /** Whether hierarchical depth (Hi-Z) is enabled for the current pass. */\r\n readonly HiZ: boolean;\r\n /** Hi-Z (hierarchical Z) depth texture, when generated. */\r\n HiZTexture: Nullable<Texture2D>;\r\n /** The scene currently being drawn. */\r\n readonly scene: Scene;\r\n /** The render pass to which this drawing task belongs. */\r\n renderPass: Nullable<RenderPass>;\r\n /** Stable hash for the current pass/draw state, for render bundle or pipeline cache. */\r\n renderPassHash: Nullable<string>;\r\n /** Whether the output orientation is flipped vertically (e.g., due to framebuffer conventions). */\r\n flip: boolean;\r\n /** Whether this is the base lighting pass that draws environment lighting. */\r\n drawEnvLight: boolean;\r\n /** Scene environment (sky, IBL, exposure, etc.) used for shading. */\r\n env: Nullable<Environment>;\r\n /** Current sub-queue index within the render queue (e.g., opaque, transparent). */\r\n queue: number;\r\n /** Whether the current lighting pass is blending light accumulations. */\r\n lightBlending: boolean;\r\n /** Scene (non-linear) depth texture bound for sampling. */\r\n depthTexture?: Texture2D;\r\n /** Linearized depth texture bound for sampling. */\r\n linearDepthTexture?: Texture2D;\r\n /** Scene color texture bound for sampling (previous pass or resolved color). */\r\n sceneColorTexture?: Texture2D;\r\n /** Default depth buffer format for targets created in this pass. */\r\n readonly depthFormat: TextureFormat;\r\n /** Default color buffer format for targets created in this pass. */\r\n readonly colorFormat: TextureFormat;\r\n /** Instance data buffer/metadata for the current drawing task (instanced rendering). */\r\n instanceData?: Nullable<InstanceData>;\r\n /** Compositor used to apply post-processing effects at the end of the frame/pass. */\r\n compositor?: Nullable<Compositor>;\r\n /** @internal Map of punctual lights to their shadow map parameters for this pass. */\r\n shadowMapInfo?: Nullable<Map<PunctualLight, ShadowMapParams>>;\r\n /** @internal The punctual light currently rendering shadows (shadow pass). */\r\n currentShadowLight?: Nullable<PunctualLight>;\r\n /** Sun/directional light reference for passes that need it. */\r\n sunLight?: Nullable<DirectionalLight>;\r\n /** Clustered light index/structure for lighting in forward+, clustered shading, etc. */\r\n clusteredLight?: ClusteredLight;\r\n /** Material varying bit flags that influence shader selection. */\r\n materialFlags: number;\r\n /** Force cull mode override for special passes (optional). */\r\n forceCullMode?: Nullable<FaceMode>;\r\n /** Force color mask state override for special passes (optional). */\r\n forceColorState?: Nullable<ColorState>;\r\n /** Screen-space reflections are active this frame/pass. */\r\n readonly SSR: boolean;\r\n /** Whether SSR thickness should be computed dynamically in this pass. */\r\n SSRCalcThickness: boolean;\r\n /** SSR roughness input texture. */\r\n SSRRoughnessTexture: Texture2D;\r\n /** SSR normal input texture (usually view-space or world-space normals). */\r\n SSRNormalTexture: Texture2D;\r\n /** Final framebuffer target where the last stage renders. */\r\n finalFramebuffer: Nullable<FrameBuffer>;\r\n /** Intermediate framebuffer used by the compositor or multi-pass pipelines. */\r\n intermediateFramebuffer: Nullable<FrameBuffer>;\r\n}\r\n\r\n/**\r\n * Morph Data\r\n * @public\r\n */\r\nexport type MorphData = {\r\n width: number;\r\n height: number;\r\n data: Float32Array<ArrayBuffer>;\r\n texture?: DRef<Texture2D>;\r\n};\r\n\r\n/**\r\n * Morph information\r\n * @public\r\n */\r\nexport type MorphInfo = { data: TypedArray; buffer?: DRef<GPUDataBuffer>; names: Record<string, number> };\r\n\r\n/**\r\n * Base interface for a drawable (renderable) object.\r\n *\r\n * A drawable encapsulates geometry, material, and GPU-resident data required to be rendered.\r\n * Implementations integrate with render queues, batching, and instancing.\r\n *\r\n * @public\r\n */\r\nexport interface Drawable {\r\n /** Gets the display name of the drawable object (for debugging/UI). */\r\n getName(): string;\r\n /** Unique, stable identifier for the drawable, used in caches and picking. */\r\n getDrawableId(): number;\r\n /** Returns the owning scene node (transform and hierarchy). */\r\n getNode(): SceneNode;\r\n /**\r\n * Returns the pick target override to be reported when this object is picked.\r\n *\r\n * If not set, a default target derived from the node/material may be used.\r\n */\r\n getPickTarget(): PickTarget;\r\n /** Returns the texture containing bone matrices for skinned meshes. */\r\n getBoneMatrices(): Nullable<Texture2D>;\r\n /** Returns the unique color used for GPU picking (object ID in color). */\r\n getObjectColor(): Vector4;\r\n /** Returns the morph target data texture (if morphing is used). */\r\n getMorphData(): Nullable<MorphData>;\r\n /** Returns the morph information buffer (weights, ranges, etc.). */\r\n getMorphInfo(): Nullable<MorphInfo>;\r\n /**\r\n * Computes the distance used for sorting (e.g., transparent draw order).\r\n *\r\n * @param camera - Camera from which to compute distance (usually camera -\\> object).\r\n */\r\n getSortDistance(camera: Camera): number;\r\n /** Returns the type/category of render queue this object belongs to. */\r\n getQueueType(): number;\r\n /** Whether the object requires access to the scene color buffer. */\r\n needSceneColor(): boolean;\r\n /** Whether the object requires access to the scene depth (linear or non-linear). */\r\n needSceneDepth(): boolean;\r\n /** True if shading is unlit (does not depend on scene lighting). */\r\n isUnlit(): boolean;\r\n /** Returns the bound material driving shading for this drawable. */\r\n getMaterial(): Nullable<MeshMaterial>;\r\n /** Returns the geometry primitive to be drawn. */\r\n getPrimitive(): Nullable<Primitive>;\r\n /**\r\n * Pushes a reference to the current render queue for cleanup or back-references.\r\n *\r\n * Useful for batching or deferred state application.\r\n */\r\n pushRenderQueueRef(ref: RenderQueueRef): void;\r\n /**\r\n * Applies transform-related uniforms to the active bind group or pipeline.\r\n *\r\n * @param renderQueue - The current render queue issuing this draw.\r\n */\r\n applyTransformUniforms(renderQueue: RenderQueue): void;\r\n /**\r\n * Issues draw commands for this object.\r\n *\r\n * @param ctx - Full draw context for the current pass.\r\n * @param renderQueue - The current render queue issuing this draw.\r\n * @param hash - Optional hash key for render bundle or pipeline caching.\r\n */\r\n draw(ctx: DrawContext, renderQueue: Nullable<RenderQueue>, hash?: string): void;\r\n /**\r\n * Updates internal state or GPU resources for this drawable, if needed.\r\n */\r\n updateState(): void;\r\n /**\r\n * Returns true if the object supports instanced rendering.\r\n *\r\n * When true, the object should also implement the {@link BatchDrawable} methods.\r\n */\r\n isBatchable(): this is BatchDrawable;\r\n /** Releases all GPU resources and detaches from the renderer. */\r\n dispose(): void;\r\n}\r\n\r\n/**\r\n * Interface for drawables that support hardware instancing.\r\n *\r\n * Instanced drawables supply instance-specific uniforms, offsets, and strides\r\n * to allow a single draw call to render many instances efficiently.\r\n *\r\n * @public\r\n */\r\nexport interface BatchDrawable extends Drawable {\r\n /**\r\n * Returns a stable instance ID string for use with the given render pass.\r\n *\r\n * Used to group compatible instances into batches within a pass.\r\n *\r\n * @param renderPass - The render pass to which current drawing task belongs.\r\n * @internal\r\n */\r\n getInstanceId(renderPass: RenderPass): string;\r\n /**\r\n * Returns a tightly-packed float array of instance uniforms for GPU upload.\r\n *\r\n * The returned memory should be compatible with ArrayBuffer views used by the renderer.\r\n *\r\n * @internal\r\n */\r\n getInstanceUniforms(): Float32Array<ArrayBuffer>;\r\n /**\r\n * Applies instance stride and starting offset to the active bind group.\r\n *\r\n * This informs the shader how to index into the instance buffer for this batch.\r\n *\r\n * @param renderQueue - Render queue associated with the bind group or pipeline.\r\n * @param stride - Per-instance stride in bytes or floats (renderer-defined).\r\n * @param offset - Starting instance offset within the instance buffer.\r\n * @internal\r\n */\r\n applyInstanceOffsetAndStride(renderQueue: RenderQueue, stride: number, offset: number): void;\r\n /**\r\n * Applies material uniforms for a single instance group.\r\n *\r\n * @param instanceInfo - Instance data information for this batch.\r\n * @internal\r\n */\r\n applyMaterialUniforms(instanceInfo: DrawableInstanceInfo): void;\r\n /**\r\n * Applies material uniforms across all grouped instance informations belonging to this material.\r\n *\r\n * Useful when batching merges multiple instance groups sharing the same material.\r\n *\r\n * @internal\r\n */\r\n applyMaterialUniformsAll(): void;\r\n}\r\n"],"names":["RenderContext","device","renderWidth","renderHeight","_camera","w","h","getDevice"],"mappings":";;AAiCO,MAAMA,aAAAA,CAAAA;IACJC,MAAuB;IACvBC,WAAoB;IACpBC,YAAqB;AAC5B,IAAA,WAAA,CAAYC,OAAe,EAAEC,CAAS,EAAEC,CAAS,CAAE;QACjD,IAAI,CAACL,MAAM,GAAGM,SAAAA,EAAAA;QACd,IAAI,CAACL,WAAW,GAAGG,CAAAA;QACnB,IAAI,CAACF,YAAY,GAAGG,CAAAA;AACtB;AACF;;;;"}
1
+ {"version":3,"file":"drawable.js","sources":["../../src/render/drawable.ts"],"sourcesContent":["import type { DRef, Nullable, TypedArray, Vector4 } from '@zephyr3d/base';\r\nimport type {\r\n AbstractDevice,\r\n ColorState,\r\n FaceMode,\r\n FrameBuffer,\r\n GPUDataBuffer,\r\n Texture2D,\r\n TextureFormat\r\n} from '@zephyr3d/device';\r\nimport type { Camera } from '../camera/camera';\r\nimport type { Primitive, RenderPass } from '.';\r\nimport type { DrawableInstanceInfo, InstanceData, RenderQueue, RenderQueueRef } from './render_queue';\r\nimport type { ShadowMapParams } from '../shadow';\r\nimport type { Environment } from '../scene/environment';\r\nimport type { DirectionalLight, PunctualLight, Scene, SceneNode } from '../scene';\r\nimport type { Compositor } from '../posteffect';\r\nimport type { ClusteredLight } from './cluster_light';\r\nimport type { MeshMaterial } from '../material';\r\nimport type { GlobalBindGroupAllocator } from './globalbindgroup_allocator';\r\nimport type { OIT } from './oit';\r\nimport { getDevice } from '../app/api';\r\n\r\n/**\r\n * Picking result target container.\r\n *\r\n * Use to override/annotate which scene node (and optional label) a drawable should report\r\n * when GPU picking or raycast returns a hit.\r\n *\r\n * @public\r\n */\r\nexport type PickTarget = { node: SceneNode; label?: string };\r\n\r\n/**\r\n * Minimal render context carrying target size and device information.\r\n *\r\n * @public\r\n */\r\nexport class RenderContext {\r\n public device: AbstractDevice;\r\n public renderWidth: number;\r\n public renderHeight: number;\r\n constructor(_camera: Camera, w: number, h: number) {\r\n this.device = getDevice();\r\n this.renderWidth = w;\r\n this.renderHeight = h;\r\n }\r\n}\r\n/**\r\n * Context object passed to draw calls and render helpers.\r\n *\r\n * It aggregates all per-frame, per-pass, and per-draw state derived from the engine and renderer,\r\n * including device handles, textures, passes, flags, and post-processing links.\r\n *\r\n * Notes:\r\n * - Not all textures/fields are present for every pass; check for undefined when optional.\r\n * - Values like `HiZ`, `TAA`, `SSR` signal features the renderer has activated for the current pass.\r\n *\r\n * @public\r\n */\r\nexport interface DrawContext {\r\n /** Render device used for issuing GPU commands. */\r\n readonly device: AbstractDevice;\r\n /** Framebuffer width for rendering (in pixels). */\r\n readonly renderWidth: number;\r\n /** Framebuffer height for rendering (in pixels). */\r\n readonly renderHeight: number;\r\n /** Allocator for global (frame/pass) bind groups and descriptor resources. */\r\n readonly globalBindGroupAllocator: GlobalBindGroupAllocator;\r\n /** The camera associated with the current drawing task (may differ from primaryCamera). */\r\n readonly camera: Camera;\r\n /** Order-Independent Transparency interface for transparent passes. */\r\n oit: Nullable<OIT>;\r\n /** Whether motion vectors are being written this pass (used by TAA/MotionBlur). */\r\n readonly motionVectors: boolean;\r\n /** Motion vector texture target when motion vectors are active. */\r\n motionVectorTexture?: Nullable<Texture2D>;\r\n /** Whether hierarchical depth (Hi-Z) is enabled for the current pass. */\r\n readonly HiZ: boolean;\r\n /** Hi-Z (hierarchical Z) depth texture, when generated. */\r\n HiZTexture: Nullable<Texture2D>;\r\n /** The scene currently being drawn. */\r\n readonly scene: Scene;\r\n /** The render pass to which this drawing task belongs. */\r\n renderPass: Nullable<RenderPass>;\r\n /** Stable hash for the current pass/draw state, for render bundle or pipeline cache. */\r\n renderPassHash: Nullable<string>;\r\n /** Whether the output orientation is flipped vertically (e.g., due to framebuffer conventions). */\r\n flip: boolean;\r\n /** Whether this is the base lighting pass that draws environment lighting. */\r\n drawEnvLight: boolean;\r\n /** Scene environment (sky, IBL, exposure, etc.) used for shading. */\r\n env: Nullable<Environment>;\r\n /** Current sub-queue index within the render queue (e.g., opaque, transparent). */\r\n queue: number;\r\n /** Whether the current lighting pass is blending light accumulations. */\r\n lightBlending: boolean;\r\n /** Scene (non-linear) depth texture bound for sampling. */\r\n depthTexture?: Texture2D;\r\n /** Linearized depth texture bound for sampling. */\r\n linearDepthTexture?: Texture2D;\r\n /** Scene color texture bound for sampling (previous pass or resolved color). */\r\n sceneColorTexture?: Texture2D;\r\n /** Default depth buffer format for targets created in this pass. */\r\n readonly depthFormat: TextureFormat;\r\n /** Default color buffer format for targets created in this pass. */\r\n readonly colorFormat: TextureFormat;\r\n /** Instance data buffer/metadata for the current drawing task (instanced rendering). */\r\n instanceData?: Nullable<InstanceData>;\r\n /** Compositor used to apply post-processing effects at the end of the frame/pass. */\r\n compositor?: Nullable<Compositor>;\r\n /** @internal Map of punctual lights to their shadow map parameters for this pass. */\r\n shadowMapInfo?: Nullable<Map<PunctualLight, ShadowMapParams>>;\r\n /** @internal The punctual light currently rendering shadows (shadow pass). */\r\n currentShadowLight?: Nullable<PunctualLight>;\r\n /** Sun/directional light reference for passes that need it. */\r\n sunLight?: Nullable<DirectionalLight>;\r\n /** Clustered light index/structure for lighting in forward+, clustered shading, etc. */\r\n clusteredLight?: ClusteredLight;\r\n /** Material varying bit flags that influence shader selection. */\r\n materialFlags: number;\r\n /** Force cull mode override for special passes (optional). */\r\n forceCullMode?: Nullable<FaceMode>;\r\n /** Force color mask state override for special passes (optional). */\r\n forceColorState?: Nullable<ColorState>;\r\n /** Screen-space reflections are active this frame/pass. */\r\n readonly SSR: boolean;\r\n /** Whether SSR thickness should be computed dynamically in this pass. */\r\n SSRCalcThickness: boolean;\r\n /** SSR roughness input texture. */\r\n SSRRoughnessTexture: Texture2D;\r\n /** SSR normal input texture (usually view-space or world-space normals). */\r\n SSRNormalTexture: Texture2D;\r\n /** Final framebuffer target where the last stage renders. */\r\n finalFramebuffer: Nullable<FrameBuffer>;\r\n /** Intermediate framebuffer used by the compositor or multi-pass pipelines. */\r\n intermediateFramebuffer: Nullable<FrameBuffer>;\r\n}\r\n\r\n/**\r\n * Morph Data\r\n * @public\r\n */\r\nexport type MorphData = {\r\n width: number;\r\n height: number;\r\n data: Float32Array<ArrayBuffer>;\r\n texture?: DRef<Texture2D>;\r\n};\r\n\r\n/**\r\n * Morph information\r\n * @public\r\n */\r\nexport type MorphInfo = { data: TypedArray; buffer?: DRef<GPUDataBuffer>; names: Record<string, number> };\r\n\r\n/**\r\n * Base interface for a drawable (renderable) object.\r\n *\r\n * A drawable encapsulates geometry, material, and GPU-resident data required to be rendered.\r\n * Implementations integrate with render queues, batching, and instancing.\r\n *\r\n * @public\r\n */\r\nexport interface Drawable {\r\n /** Gets the display name of the drawable object (for debugging/UI). */\r\n getName(): string;\r\n /** Unique, stable identifier for the drawable, used in caches and picking. */\r\n getDrawableId(): number;\r\n /** Returns the owning scene node (transform and hierarchy). */\r\n getNode(): SceneNode;\r\n /**\r\n * Returns the pick target override to be reported when this object is picked.\r\n *\r\n * If not set, a default target derived from the node/material may be used.\r\n */\r\n getPickTarget(): PickTarget;\r\n /** Returns the texture containing bone matrices for skinned meshes. */\r\n getBoneMatrices(): Nullable<Texture2D>;\r\n /** Returns the unique color used for GPU picking (object ID in color). */\r\n getObjectColor(): Vector4;\r\n /** Returns the morph target data texture (if morphing is used). */\r\n getMorphData(): Nullable<MorphData>;\r\n /** Returns the morph information buffer (weights, ranges, etc.). */\r\n getMorphInfo(): Nullable<MorphInfo>;\r\n /**\r\n * Computes the distance used for sorting (e.g., transparent draw order).\r\n *\r\n * @param camera - Camera from which to compute distance (usually camera -\\> object).\r\n */\r\n getSortDistance(camera: Camera): number;\r\n /** Returns the type/category of render queue this object belongs to. */\r\n getQueueType(): number;\r\n /** Whether the object requires access to the scene color buffer. */\r\n needSceneColor(): boolean;\r\n /** Whether the object requires access to the scene depth (linear or non-linear). */\r\n needSceneDepth(): boolean;\r\n /** True if shading is unlit (does not depend on scene lighting). */\r\n isUnlit(): boolean;\r\n /** Returns the bound material driving shading for this drawable. */\r\n getMaterial(): Nullable<MeshMaterial>;\r\n /** Returns the geometry primitive to be drawn. */\r\n getPrimitive(): Nullable<Primitive>;\r\n /**\r\n * Pushes a reference to the current render queue for cleanup or back-references.\r\n *\r\n * Useful for batching or deferred state application.\r\n */\r\n pushRenderQueueRef(ref: RenderQueueRef): void;\r\n /**\r\n * Applies transform-related uniforms to the active bind group or pipeline.\r\n *\r\n * @param renderQueue - The current render queue issuing this draw.\r\n */\r\n applyTransformUniforms(renderQueue: RenderQueue): void;\r\n /**\r\n * Issues draw commands for this object.\r\n *\r\n * @param ctx - Full draw context for the current pass.\r\n * @param renderQueue - The current render queue issuing this draw.\r\n * @param hash - Optional hash key for render bundle or pipeline caching.\r\n */\r\n draw(ctx: DrawContext, renderQueue: Nullable<RenderQueue>, hash?: string): void;\r\n /**\r\n * Updates internal state or GPU resources for this drawable, if needed.\r\n */\r\n updateState(): void;\r\n /**\r\n * Returns true if the object supports instanced rendering.\r\n *\r\n * When true, the object should also implement the {@link BatchDrawable} methods.\r\n */\r\n isBatchable(): this is BatchDrawable;\r\n /** Releases all GPU resources and detaches from the renderer. */\r\n dispose(): void;\r\n}\r\n\r\n/**\r\n * Interface for drawables that support hardware instancing.\r\n *\r\n * Instanced drawables supply instance-specific uniforms, offsets, and strides\r\n * to allow a single draw call to render many instances efficiently.\r\n *\r\n * @public\r\n */\r\nexport interface BatchDrawable extends Drawable {\r\n /**\r\n * Returns a stable instance ID string for use with the given render pass.\r\n *\r\n * Used to group compatible instances into batches within a pass.\r\n *\r\n * @param renderPass - The render pass to which current drawing task belongs.\r\n * @internal\r\n */\r\n getInstanceId(renderPass: RenderPass): string;\r\n /**\r\n * Returns a tightly-packed float array of instance uniforms for GPU upload.\r\n *\r\n * The returned memory should be compatible with ArrayBuffer views used by the renderer.\r\n *\r\n * @internal\r\n */\r\n getInstanceUniforms(): Float32Array<ArrayBuffer>;\r\n /**\r\n * Applies instance stride and starting offset to the active bind group.\r\n *\r\n * This informs the shader how to index into the instance buffer for this batch.\r\n *\r\n * @param renderQueue - Render queue associated with the bind group or pipeline.\r\n * @param stride - Per-instance stride in bytes or floats (renderer-defined).\r\n * @param offset - Starting instance offset within the instance buffer.\r\n * @internal\r\n */\r\n applyInstanceOffsetAndStride(renderQueue: RenderQueue, stride: number, offset: number): void;\r\n /**\r\n * Applies material uniforms for a single instance group.\r\n *\r\n * @param instanceInfo - Instance data information for this batch.\r\n * @internal\r\n */\r\n applyMaterialUniforms(instanceInfo: DrawableInstanceInfo): void;\r\n /**\r\n * Applies material uniforms across all grouped instance informations belonging to this material.\r\n *\r\n * Useful when batching merges multiple instance groups sharing the same material.\r\n *\r\n * @internal\r\n */\r\n applyMaterialUniformsAll(): void;\r\n}\r\n"],"names":["RenderContext","device","renderWidth","renderHeight","_camera","w","h","getDevice"],"mappings":";;AAiCA;;;;AAIC,IACM,MAAMA,aAAAA,CAAAA;IACJC,MAAuB;IACvBC,WAAoB;IACpBC,YAAqB;AAC5B,IAAA,WAAA,CAAYC,OAAe,EAAEC,CAAS,EAAEC,CAAS,CAAE;QACjD,IAAI,CAACL,MAAM,GAAGM,SAAAA,EAAAA;QACd,IAAI,CAACL,WAAW,GAAGG,CAAAA;QACnB,IAAI,CAACF,YAAY,GAAGG,CAAAA;AACtB;AACF;;;;"}
@@ -4,8 +4,8 @@ import { getDevice } from '../../app/api.js';
4
4
  * Bridges the render graph's {@link RGTextureAllocator} interface to the
5
5
  * engine's device resource pool (`device.pool`).
6
6
  *
7
- * Transient textures are fetched from the pool on {@link allocate} and
8
- * returned to the pool on {@link release}, enabling automatic reuse
7
+ * Transient textures are fetched from the pool on `allocate()` and
8
+ * returned to the pool on `release()`, enabling automatic reuse
9
9
  * across frames without manual lifecycle management.
10
10
  *
11
11
  * Usage:
@@ -25,7 +25,12 @@ import { getDevice } from '../../app/api.js';
25
25
  */ allocate(desc, size) {
26
26
  const device = getDevice();
27
27
  const mipmapping = (desc.mipLevels ?? 1) > 1;
28
- return device.pool.fetchTemporalTexture2D(false, desc.format, size.width, size.height, mipmapping);
28
+ const texture = device.pool.fetchTemporalTexture2D(false, desc.format, size.width, size.height, mipmapping);
29
+ if (desc.mipLevels && texture.mipLevelCount < desc.mipLevels) {
30
+ device.pool.releaseTexture(texture);
31
+ throw new Error(`DevicePoolAllocator: texture "${desc.label ?? '<unnamed>'}" requested ${desc.mipLevels} ` + `mip levels, but only ${texture.mipLevelCount} were allocated.`);
32
+ }
33
+ return texture;
29
34
  }
30
35
  /**
31
36
  * Release a transient texture back to the device pool.
@@ -35,6 +40,27 @@ import { getDevice } from '../../app/api.js';
35
40
  const device = getDevice();
36
41
  device.pool.releaseTexture(texture);
37
42
  }
43
+ /**
44
+ * Allocate a temporary framebuffer from the device pool.
45
+ *
46
+ * @param desc - Framebuffer descriptor from the render graph pass.
47
+ * @returns A pooled FrameBuffer instance.
48
+ */ allocateFramebuffer(desc) {
49
+ const device = getDevice();
50
+ const colors = Array.isArray(desc.colorAttachments) ? desc.colorAttachments : desc.colorAttachments ? [
51
+ desc.colorAttachments
52
+ ] : [];
53
+ const depthAttachment = desc.depthAttachment ?? null;
54
+ return device.pool.fetchTemporalFramebuffer(false, desc.width ?? 0, desc.height ?? 0, colors, depthAttachment, desc.mipmapping ?? false, desc.sampleCount ?? 1, desc.ignoreDepthStencil ?? true, desc.attachmentMipLevel ?? 0, desc.attachmentCubeface ?? 0, desc.attachmentLayer ?? 0);
55
+ }
56
+ /**
57
+ * Release a temporary framebuffer back to the device pool.
58
+ *
59
+ * @param framebuffer - The framebuffer to release.
60
+ */ releaseFramebuffer(framebuffer) {
61
+ const device = getDevice();
62
+ device.pool.releaseFrameBuffer(framebuffer);
63
+ }
38
64
  }
39
65
 
40
66
  export { DevicePoolAllocator };
@@ -1 +1 @@
1
- {"version":3,"file":"device_pool_allocator.js","sources":["../../../src/render/rendergraph/device_pool_allocator.ts"],"sourcesContent":["import type { Texture2D } from '@zephyr3d/device';\r\nimport type { RGTextureAllocator, RGTextureDesc, RGResolvedSize } from './types';\r\nimport { getDevice } from '../../app/api';\r\n\r\n/**\r\n * Bridges the render graph's {@link RGTextureAllocator} interface to the\r\n * engine's device resource pool (`device.pool`).\r\n *\r\n * Transient textures are fetched from the pool on {@link allocate} and\r\n * returned to the pool on {@link release}, enabling automatic reuse\r\n * across frames without manual lifecycle management.\r\n *\r\n * Usage:\r\n * ```ts\r\n * const allocator = new DevicePoolAllocator();\r\n * const executor = new RenderGraphExecutor(allocator, width, height);\r\n * ```\r\n *\r\n * @public\r\n */\r\nexport class DevicePoolAllocator implements RGTextureAllocator<Texture2D> {\r\n /**\r\n * Allocate a transient texture from the device pool.\r\n *\r\n * @param desc - Texture descriptor from the render graph pass.\r\n * @param size - Resolved pixel dimensions.\r\n * @returns A pooled Texture2D instance.\r\n */\r\n allocate(desc: RGTextureDesc, size: RGResolvedSize): Texture2D {\r\n const device = getDevice();\r\n const mipmapping = (desc.mipLevels ?? 1) > 1;\r\n return device.pool.fetchTemporalTexture2D(false, desc.format, size.width, size.height, mipmapping);\r\n }\r\n\r\n /**\r\n * Release a transient texture back to the device pool.\r\n *\r\n * @param texture - The texture to release.\r\n */\r\n release(texture: Texture2D): void {\r\n const device = getDevice();\r\n device.pool.releaseTexture(texture);\r\n }\r\n}\r\n"],"names":["DevicePoolAllocator","allocate","desc","size","device","getDevice","mipmapping","mipLevels","pool","fetchTemporalTexture2D","format","width","height","release","texture","releaseTexture"],"mappings":";;AAIA;;;;;;;;;;;;;;;AAeC,IACM,MAAMA,mBAAAA,CAAAA;AACX;;;;;;AAMC,MACDC,QAASC,CAAAA,IAAmB,EAAEC,IAAoB,EAAa;AAC7D,QAAA,MAAMC,MAASC,GAAAA,SAAAA,EAAAA;AACf,QAAA,MAAMC,aAAa,CAACJ,KAAKK,SAAS,IAAI,CAAA,IAAK,CAAA;AAC3C,QAAA,OAAOH,MAAOI,CAAAA,IAAI,CAACC,sBAAsB,CAAC,KAAOP,EAAAA,IAAAA,CAAKQ,MAAM,EAAEP,IAAKQ,CAAAA,KAAK,EAAER,IAAAA,CAAKS,MAAM,EAAEN,UAAAA,CAAAA;AACzF;AAEA;;;;MAKAO,OAAAA,CAAQC,OAAkB,EAAQ;AAChC,QAAA,MAAMV,MAASC,GAAAA,SAAAA,EAAAA;QACfD,MAAOI,CAAAA,IAAI,CAACO,cAAc,CAACD,OAAAA,CAAAA;AAC7B;AACF;;;;"}
1
+ {"version":3,"file":"device_pool_allocator.js","sources":["../../../src/render/rendergraph/device_pool_allocator.ts"],"sourcesContent":["import type { FrameBuffer, Texture2D, TextureFormat } from '@zephyr3d/device';\r\nimport type { RGFramebufferDesc, RGTextureAllocator, RGTextureDesc, RGResolvedSize } from './types';\r\nimport { getDevice } from '../../app/api';\r\n\r\n/**\r\n * Bridges the render graph's {@link RGTextureAllocator} interface to the\r\n * engine's device resource pool (`device.pool`).\r\n *\r\n * Transient textures are fetched from the pool on `allocate()` and\r\n * returned to the pool on `release()`, enabling automatic reuse\r\n * across frames without manual lifecycle management.\r\n *\r\n * Usage:\r\n * ```ts\r\n * const allocator = new DevicePoolAllocator();\r\n * const executor = new RenderGraphExecutor(allocator, width, height);\r\n * ```\r\n *\r\n * @public\r\n */\r\nexport class DevicePoolAllocator implements RGTextureAllocator<Texture2D, FrameBuffer> {\r\n /**\r\n * Allocate a transient texture from the device pool.\r\n *\r\n * @param desc - Texture descriptor from the render graph pass.\r\n * @param size - Resolved pixel dimensions.\r\n * @returns A pooled Texture2D instance.\r\n */\r\n allocate(desc: RGTextureDesc, size: RGResolvedSize): Texture2D {\r\n const device = getDevice();\r\n const mipmapping = (desc.mipLevels ?? 1) > 1;\r\n const texture = device.pool.fetchTemporalTexture2D(\r\n false,\r\n desc.format,\r\n size.width,\r\n size.height,\r\n mipmapping\r\n );\r\n if (desc.mipLevels && texture.mipLevelCount < desc.mipLevels) {\r\n device.pool.releaseTexture(texture);\r\n throw new Error(\r\n `DevicePoolAllocator: texture \"${desc.label ?? '<unnamed>'}\" requested ${desc.mipLevels} ` +\r\n `mip levels, but only ${texture.mipLevelCount} were allocated.`\r\n );\r\n }\r\n return texture;\r\n }\r\n\r\n /**\r\n * Release a transient texture back to the device pool.\r\n *\r\n * @param texture - The texture to release.\r\n */\r\n release(texture: Texture2D): void {\r\n const device = getDevice();\r\n device.pool.releaseTexture(texture);\r\n }\r\n\r\n /**\r\n * Allocate a temporary framebuffer from the device pool.\r\n *\r\n * @param desc - Framebuffer descriptor from the render graph pass.\r\n * @returns A pooled FrameBuffer instance.\r\n */\r\n allocateFramebuffer(desc: RGFramebufferDesc): FrameBuffer {\r\n const device = getDevice();\r\n const colors = Array.isArray(desc.colorAttachments)\r\n ? (desc.colorAttachments as Array<Texture2D | TextureFormat>)\r\n : desc.colorAttachments\r\n ? [desc.colorAttachments as Texture2D | TextureFormat]\r\n : [];\r\n const depthAttachment = (desc.depthAttachment ?? null) as Texture2D | TextureFormat | null;\r\n return device.pool.fetchTemporalFramebuffer(\r\n false,\r\n desc.width ?? 0,\r\n desc.height ?? 0,\r\n colors,\r\n depthAttachment,\r\n desc.mipmapping ?? false,\r\n desc.sampleCount ?? 1,\r\n desc.ignoreDepthStencil ?? true,\r\n desc.attachmentMipLevel ?? 0,\r\n desc.attachmentCubeface ?? 0,\r\n desc.attachmentLayer ?? 0\r\n );\r\n }\r\n\r\n /**\r\n * Release a temporary framebuffer back to the device pool.\r\n *\r\n * @param framebuffer - The framebuffer to release.\r\n */\r\n releaseFramebuffer(framebuffer: FrameBuffer): void {\r\n const device = getDevice();\r\n device.pool.releaseFrameBuffer(framebuffer);\r\n }\r\n}\r\n"],"names":["DevicePoolAllocator","allocate","desc","size","device","getDevice","mipmapping","mipLevels","texture","pool","fetchTemporalTexture2D","format","width","height","mipLevelCount","releaseTexture","Error","label","release","allocateFramebuffer","colors","Array","isArray","colorAttachments","depthAttachment","fetchTemporalFramebuffer","sampleCount","ignoreDepthStencil","attachmentMipLevel","attachmentCubeface","attachmentLayer","releaseFramebuffer","framebuffer","releaseF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