@zephyr3d/scene 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (368) hide show
  1. package/dist/animation/animation.js +4 -33
  2. package/dist/animation/animation.js.map +1 -1
  3. package/dist/animation/animationset.js +24 -11
  4. package/dist/animation/animationset.js.map +1 -1
  5. package/dist/animation/animationtrack.js +1 -0
  6. package/dist/animation/animationtrack.js.map +1 -1
  7. package/dist/animation/eulerrotationtrack.js +0 -1
  8. package/dist/animation/eulerrotationtrack.js.map +1 -1
  9. package/dist/animation/ik/ccd_solver.js +372 -0
  10. package/dist/animation/ik/ccd_solver.js.map +1 -0
  11. package/dist/animation/ik/fabrik_solver.js +399 -0
  12. package/dist/animation/ik/fabrik_solver.js.map +1 -0
  13. package/dist/animation/ik/ik_angle_constraint.js +181 -0
  14. package/dist/animation/ik/ik_angle_constraint.js.map +1 -0
  15. package/dist/animation/ik/ik_chain.js +163 -0
  16. package/dist/animation/ik/ik_chain.js.map +1 -0
  17. package/dist/animation/ik/ik_chain_builder.js +68 -0
  18. package/dist/animation/ik/ik_chain_builder.js.map +1 -0
  19. package/dist/animation/ik/ik_constraint.js +25 -0
  20. package/dist/animation/ik/ik_constraint.js.map +1 -0
  21. package/dist/animation/ik/ik_pole_constraint.js +123 -0
  22. package/dist/animation/ik/ik_pole_constraint.js.map +1 -0
  23. package/dist/animation/ik/ik_solver.js +48 -0
  24. package/dist/animation/ik/ik_solver.js.map +1 -0
  25. package/dist/animation/ik/ik_track.js +96 -0
  26. package/dist/animation/ik/ik_track.js.map +1 -0
  27. package/dist/animation/ik/ik_utils.js +270 -0
  28. package/dist/animation/ik/ik_utils.js.map +1 -0
  29. package/dist/animation/ik/two_bone_ik_solver.js +332 -0
  30. package/dist/animation/ik/two_bone_ik_solver.js.map +1 -0
  31. package/dist/animation/ik_modifier.js +61 -0
  32. package/dist/animation/ik_modifier.js.map +1 -0
  33. package/dist/animation/ik_postprocessor.js +71 -0
  34. package/dist/animation/ik_postprocessor.js.map +1 -0
  35. package/dist/animation/manual_transform_processor.js +156 -0
  36. package/dist/animation/manual_transform_processor.js.map +1 -0
  37. package/dist/animation/morphtarget.js +7 -1
  38. package/dist/animation/morphtarget.js.map +1 -1
  39. package/dist/animation/morphtrack.js +3 -3
  40. package/dist/animation/morphtrack.js.map +1 -1
  41. package/dist/animation/proptrack.js +37 -41
  42. package/dist/animation/proptrack.js.map +1 -1
  43. package/dist/animation/rotationtrack.js +0 -1
  44. package/dist/animation/rotationtrack.js.map +1 -1
  45. package/dist/animation/scaletrack.js +0 -1
  46. package/dist/animation/scaletrack.js.map +1 -1
  47. package/dist/animation/skeleton.js +57 -60
  48. package/dist/animation/skeleton.js.map +1 -1
  49. package/dist/animation/skeleton_modifier.js +38 -0
  50. package/dist/animation/skeleton_modifier.js.map +1 -0
  51. package/dist/animation/skeleton_postprocessor.js +50 -0
  52. package/dist/animation/skeleton_postprocessor.js.map +1 -0
  53. package/dist/animation/spring/multi_chain_spring_system.js +503 -0
  54. package/dist/animation/spring/multi_chain_spring_system.js.map +1 -0
  55. package/dist/animation/spring/spring_chain.js +103 -0
  56. package/dist/animation/spring/spring_chain.js.map +1 -0
  57. package/dist/animation/spring/spring_collider.js +247 -0
  58. package/dist/animation/spring/spring_collider.js.map +1 -0
  59. package/dist/animation/spring/spring_constraint.js +21 -0
  60. package/dist/animation/spring/spring_constraint.js.map +1 -0
  61. package/dist/animation/spring/spring_particle.js +20 -0
  62. package/dist/animation/spring/spring_particle.js.map +1 -0
  63. package/dist/animation/spring/spring_system.js +526 -0
  64. package/dist/animation/spring/spring_system.js.map +1 -0
  65. package/dist/animation/spring_modifier.js +45 -0
  66. package/dist/animation/spring_modifier.js.map +1 -0
  67. package/dist/animation/spring_postprocessor.js +54 -0
  68. package/dist/animation/spring_postprocessor.js.map +1 -0
  69. package/dist/animation/translationtrack.js +0 -1
  70. package/dist/animation/translationtrack.js.map +1 -1
  71. package/dist/app/api.js +13 -4
  72. package/dist/app/api.js.map +1 -1
  73. package/dist/app/app.js +13 -1
  74. package/dist/app/app.js.map +1 -1
  75. package/dist/app/engine.js +33 -45
  76. package/dist/app/engine.js.map +1 -1
  77. package/dist/app/inputmgr.js.map +1 -1
  78. package/dist/app/runtimescript.js.map +1 -1
  79. package/dist/app/screen.js +318 -0
  80. package/dist/app/screen.js.map +1 -0
  81. package/dist/app/scriptingsystem.js +10 -6
  82. package/dist/app/scriptingsystem.js.map +1 -1
  83. package/dist/app/scriptregistry.js +11 -22
  84. package/dist/app/scriptregistry.js.map +1 -1
  85. package/dist/asset/assetmanager.js +79 -58
  86. package/dist/asset/assetmanager.js.map +1 -1
  87. package/dist/asset/builtin.js +5 -5
  88. package/dist/asset/builtin.js.map +1 -1
  89. package/dist/asset/loaders/dds/dds.js +6 -2
  90. package/dist/asset/loaders/dds/dds.js.map +1 -1
  91. package/dist/asset/loaders/dds/dds_loader.js +1 -1
  92. package/dist/asset/loaders/dds/dds_loader.js.map +1 -1
  93. package/dist/asset/loaders/gltf/gltf_loader.js +14 -6
  94. package/dist/asset/loaders/gltf/gltf_loader.js.map +1 -1
  95. package/dist/asset/loaders/gltf/helpers.js +6 -2
  96. package/dist/asset/loaders/gltf/helpers.js.map +1 -1
  97. package/dist/asset/loaders/hdr/hdr.js +22 -15
  98. package/dist/asset/loaders/hdr/hdr.js.map +1 -1
  99. package/dist/asset/loaders/image/tga_Loader.js +2 -1
  100. package/dist/asset/loaders/image/tga_Loader.js.map +1 -1
  101. package/dist/asset/loaders/image/webimage_loader.js.map +1 -1
  102. package/dist/asset/loaders/loader.js +2 -2
  103. package/dist/asset/loaders/loader.js.map +1 -1
  104. package/dist/asset/model.js +9 -5
  105. package/dist/asset/model.js.map +1 -1
  106. package/dist/blitter/bilateralblur.js.map +1 -1
  107. package/dist/blitter/blitter.js +9 -11
  108. package/dist/blitter/blitter.js.map +1 -1
  109. package/dist/blitter/box.js +0 -1
  110. package/dist/blitter/box.js.map +1 -1
  111. package/dist/blitter/copy.js.map +1 -1
  112. package/dist/blitter/gaussianblur.js.map +1 -1
  113. package/dist/camera/base.js +1 -3
  114. package/dist/camera/base.js.map +1 -1
  115. package/dist/camera/camera.js +121 -37
  116. package/dist/camera/camera.js.map +1 -1
  117. package/dist/camera/fps.js +19 -17
  118. package/dist/camera/fps.js.map +1 -1
  119. package/dist/camera/orbit.js +45 -43
  120. package/dist/camera/orbit.js.map +1 -1
  121. package/dist/camera/orthocamera.js +27 -21
  122. package/dist/camera/orthocamera.js.map +1 -1
  123. package/dist/camera/perspectivecamera.js +28 -19
  124. package/dist/camera/perspectivecamera.js.map +1 -1
  125. package/dist/index.d.ts +15802 -15577
  126. package/dist/index.js +33 -11
  127. package/dist/index.js.map +1 -1
  128. package/dist/material/blinn.js.map +1 -1
  129. package/dist/material/grassmaterial.js.map +1 -1
  130. package/dist/material/lambert.js.map +1 -1
  131. package/dist/material/material.js +11 -5
  132. package/dist/material/material.js.map +1 -1
  133. package/dist/material/meshmaterial.js +10 -9
  134. package/dist/material/meshmaterial.js.map +1 -1
  135. package/dist/material/mixins/albedocolor.js.map +1 -1
  136. package/dist/material/mixins/foliage.js.map +1 -1
  137. package/dist/material/mixins/lightmodel/blinnphong.js +66 -4
  138. package/dist/material/mixins/lightmodel/blinnphong.js.map +1 -1
  139. package/dist/material/mixins/lightmodel/lambert.js.map +1 -1
  140. package/dist/material/mixins/lightmodel/pbrblueprintmixin.js +7 -0
  141. package/dist/material/mixins/lightmodel/pbrblueprintmixin.js.map +1 -1
  142. package/dist/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -1
  143. package/dist/material/mixins/lightmodel/pbrspecularglossness.js.map +1 -1
  144. package/dist/material/mixins/lit.js +3 -3
  145. package/dist/material/mixins/lit.js.map +1 -1
  146. package/dist/material/mixins/pbr/brdf.js.map +1 -1
  147. package/dist/material/mixins/pbr/common.js.map +1 -1
  148. package/dist/material/mixins/texture.js +3 -0
  149. package/dist/material/mixins/texture.js.map +1 -1
  150. package/dist/material/mixins/vertexcolor.js.map +1 -1
  151. package/dist/material/particle.js.map +1 -1
  152. package/dist/material/pbrblueprint.js +180 -22
  153. package/dist/material/pbrblueprint.js.map +1 -1
  154. package/dist/material/pbrmr.js.map +1 -1
  155. package/dist/material/pbrsg.js.map +1 -1
  156. package/dist/material/shader/helper.js +41 -56
  157. package/dist/material/shader/helper.js.map +1 -1
  158. package/dist/material/sprite.js +301 -0
  159. package/dist/material/sprite.js.map +1 -0
  160. package/dist/material/sprite3d.js +301 -0
  161. package/dist/material/sprite3d.js.map +1 -0
  162. package/dist/material/sprite3d_std.js +116 -0
  163. package/dist/material/sprite3d_std.js.map +1 -0
  164. package/dist/material/sprite3dblueprint.js +235 -0
  165. package/dist/material/sprite3dblueprint.js.map +1 -0
  166. package/dist/material/sprite_std.js +116 -0
  167. package/dist/material/sprite_std.js.map +1 -0
  168. package/dist/material/spriteblueprint.js +235 -0
  169. package/dist/material/spriteblueprint.js.map +1 -0
  170. package/dist/material/terrain-cm.js +0 -1
  171. package/dist/material/terrain-cm.js.map +1 -1
  172. package/dist/material/unlit.js.map +1 -1
  173. package/dist/material/water.js.map +1 -1
  174. package/dist/posteffect/bloom.js.map +1 -1
  175. package/dist/posteffect/compositor.js.map +1 -1
  176. package/dist/posteffect/fxaa.js.map +1 -1
  177. package/dist/posteffect/grayscale.js.map +1 -1
  178. package/dist/posteffect/motionblur.js.map +1 -1
  179. package/dist/posteffect/posteffect.js.map +1 -1
  180. package/dist/posteffect/sao.js.map +1 -1
  181. package/dist/posteffect/ssr.js +7 -5
  182. package/dist/posteffect/ssr.js.map +1 -1
  183. package/dist/posteffect/taa.js.map +1 -1
  184. package/dist/posteffect/tonemap.js.map +1 -1
  185. package/dist/render/abuffer_oit.js +8 -6
  186. package/dist/render/abuffer_oit.js.map +1 -1
  187. package/dist/render/clipmap.js +0 -10
  188. package/dist/render/clipmap.js.map +1 -1
  189. package/dist/render/cluster_light.js +4 -4
  190. package/dist/render/cluster_light.js.map +1 -1
  191. package/dist/render/cull_visitor.js +15 -17
  192. package/dist/render/cull_visitor.js.map +1 -1
  193. package/dist/render/depthpass.js +3 -4
  194. package/dist/render/depthpass.js.map +1 -1
  195. package/dist/render/drawable.js +15 -0
  196. package/dist/render/drawable.js.map +1 -0
  197. package/dist/render/drawable_mixin.js +8 -4
  198. package/dist/render/drawable_mixin.js.map +1 -1
  199. package/dist/render/envlight.js.map +1 -1
  200. package/dist/render/fbm_wavegenerator.js +3 -1
  201. package/dist/render/fbm_wavegenerator.js.map +1 -1
  202. package/dist/render/fft_wavegenerator.js +67 -64
  203. package/dist/render/fft_wavegenerator.js.map +1 -1
  204. package/dist/render/fullscreenquad.js.map +1 -1
  205. package/dist/render/gerstner_wavegenerator.js +3 -1
  206. package/dist/render/gerstner_wavegenerator.js.map +1 -1
  207. package/dist/render/globalbindgroup_allocator.js +3 -1
  208. package/dist/render/globalbindgroup_allocator.js.map +1 -1
  209. package/dist/render/hzb.js +1 -2
  210. package/dist/render/hzb.js.map +1 -1
  211. package/dist/render/lightpass.js +13 -13
  212. package/dist/render/lightpass.js.map +1 -1
  213. package/dist/render/objectcolorpass.js +4 -7
  214. package/dist/render/objectcolorpass.js.map +1 -1
  215. package/dist/render/primitive.js +4 -5
  216. package/dist/render/primitive.js.map +1 -1
  217. package/dist/render/render_queue.js +10 -5
  218. package/dist/render/render_queue.js.map +1 -1
  219. package/dist/render/renderer.js +16 -22
  220. package/dist/render/renderer.js.map +1 -1
  221. package/dist/render/renderpass.js +27 -52
  222. package/dist/render/renderpass.js.map +1 -1
  223. package/dist/render/rendertarget.js +5 -0
  224. package/dist/render/rendertarget.js.map +1 -0
  225. package/dist/render/screenrendertarget.js +56 -0
  226. package/dist/render/screenrendertarget.js.map +1 -0
  227. package/dist/render/shadowmap_pass.js +4 -5
  228. package/dist/render/shadowmap_pass.js.map +1 -1
  229. package/dist/render/sky.js +16 -14
  230. package/dist/render/sky.js.map +1 -1
  231. package/dist/render/weightedblended_oit.js.map +1 -1
  232. package/dist/scene/basesprite.js +296 -0
  233. package/dist/scene/basesprite.js.map +1 -0
  234. package/dist/scene/batchgroup.js +4 -2
  235. package/dist/scene/batchgroup.js.map +1 -1
  236. package/dist/scene/environment.js +9 -10
  237. package/dist/scene/environment.js.map +1 -1
  238. package/dist/scene/graph_node.js.map +1 -1
  239. package/dist/scene/light.js +22 -4
  240. package/dist/scene/light.js.map +1 -1
  241. package/dist/scene/mesh.js +96 -26
  242. package/dist/scene/mesh.js.map +1 -1
  243. package/dist/scene/octree.js.map +1 -1
  244. package/dist/scene/particlesys.js +25 -22
  245. package/dist/scene/particlesys.js.map +1 -1
  246. package/dist/scene/raycast_visitor.js +0 -16
  247. package/dist/scene/raycast_visitor.js.map +1 -1
  248. package/dist/scene/scene.js +7 -4
  249. package/dist/scene/scene.js.map +1 -1
  250. package/dist/scene/scene_node.js +20 -35
  251. package/dist/scene/scene_node.js.map +1 -1
  252. package/dist/scene/sprite.js +18 -0
  253. package/dist/scene/sprite.js.map +1 -0
  254. package/dist/scene/sprite3d.js +18 -0
  255. package/dist/scene/sprite3d.js.map +1 -0
  256. package/dist/scene/terrain-cm/grass.js +5 -4
  257. package/dist/scene/terrain-cm/grass.js.map +1 -1
  258. package/dist/scene/terrain-cm/grassmaterial.js +3 -1
  259. package/dist/scene/terrain-cm/grassmaterial.js.map +1 -1
  260. package/dist/scene/terrain-cm/terrain-cm.js +65 -48
  261. package/dist/scene/terrain-cm/terrain-cm.js.map +1 -1
  262. package/dist/scene/water.js +35 -30
  263. package/dist/scene/water.js.map +1 -1
  264. package/dist/shaders/atmosphere.js +17 -29
  265. package/dist/shaders/atmosphere.js.map +1 -1
  266. package/dist/shaders/fog.js.map +1 -1
  267. package/dist/shaders/misc.js.map +1 -1
  268. package/dist/shaders/noise.js.map +1 -1
  269. package/dist/shaders/pbr.js.map +1 -1
  270. package/dist/shaders/shadow.js.map +1 -1
  271. package/dist/shaders/ssr.js.map +1 -1
  272. package/dist/shaders/temporal.js.map +1 -1
  273. package/dist/shaders/water.js.map +1 -1
  274. package/dist/shadow/esm.js +1 -1
  275. package/dist/shadow/esm.js.map +1 -1
  276. package/dist/shadow/pcf_opt.js.map +1 -1
  277. package/dist/shadow/pcf_pd.js.map +1 -1
  278. package/dist/shadow/shader.js +3 -1
  279. package/dist/shadow/shader.js.map +1 -1
  280. package/dist/shadow/shadow_impl.js.map +1 -1
  281. package/dist/shadow/shadowmapper.js +6 -18
  282. package/dist/shadow/shadowmapper.js.map +1 -1
  283. package/dist/shadow/ssm.js.map +1 -1
  284. package/dist/shadow/vsm.js.map +1 -1
  285. package/dist/shapes/box.js +9 -3
  286. package/dist/shapes/box.js.map +1 -1
  287. package/dist/shapes/cylinder.js +2 -2
  288. package/dist/shapes/cylinder.js.map +1 -1
  289. package/dist/shapes/plane.js +2 -2
  290. package/dist/shapes/plane.js.map +1 -1
  291. package/dist/shapes/shape.js +2 -1
  292. package/dist/shapes/shape.js.map +1 -1
  293. package/dist/shapes/sphere.js +2 -2
  294. package/dist/shapes/sphere.js.map +1 -1
  295. package/dist/shapes/tetrahedron.js +5 -6
  296. package/dist/shapes/tetrahedron.js.map +1 -1
  297. package/dist/shapes/torus.js +2 -2
  298. package/dist/shapes/torus.js.map +1 -1
  299. package/dist/utility/aabbtree.js +1 -1
  300. package/dist/utility/aabbtree.js.map +1 -1
  301. package/dist/utility/blueprint/common/constants.js +578 -104
  302. package/dist/utility/blueprint/common/constants.js.map +1 -1
  303. package/dist/utility/blueprint/common/math.js +471 -9
  304. package/dist/utility/blueprint/common/math.js.map +1 -1
  305. package/dist/utility/blueprint/common.js +1 -1
  306. package/dist/utility/blueprint/common.js.map +1 -1
  307. package/dist/utility/blueprint/material/func.js +9 -5
  308. package/dist/utility/blueprint/material/func.js.map +1 -1
  309. package/dist/utility/blueprint/material/inputs.js.map +1 -1
  310. package/dist/utility/blueprint/material/ir.js +288 -80
  311. package/dist/utility/blueprint/material/ir.js.map +1 -1
  312. package/dist/utility/blueprint/material/pbr.js +92 -4
  313. package/dist/utility/blueprint/material/pbr.js.map +1 -1
  314. package/dist/utility/blueprint/material/texture.js +62 -45
  315. package/dist/utility/blueprint/material/texture.js.map +1 -1
  316. package/dist/utility/blueprint/node.js +28 -1
  317. package/dist/utility/blueprint/node.js.map +1 -1
  318. package/dist/utility/bounding_volume.js.map +1 -1
  319. package/dist/utility/debug.js.map +1 -1
  320. package/dist/utility/draco/decoder.js.map +1 -1
  321. package/dist/utility/misc.js +1 -1
  322. package/dist/utility/misc.js.map +1 -1
  323. package/dist/utility/panorama.js.map +1 -1
  324. package/dist/utility/pmrem.js.map +1 -1
  325. package/dist/utility/rendermipmap.js.map +1 -1
  326. package/dist/utility/serialization/json.js +19 -15
  327. package/dist/utility/serialization/json.js.map +1 -1
  328. package/dist/utility/serialization/manager.js +89 -22
  329. package/dist/utility/serialization/manager.js.map +1 -1
  330. package/dist/utility/serialization/scene/animation.js +44 -41
  331. package/dist/utility/serialization/scene/animation.js.map +1 -1
  332. package/dist/utility/serialization/scene/batch.js +4 -3
  333. package/dist/utility/serialization/scene/batch.js.map +1 -1
  334. package/dist/utility/serialization/scene/camera.js +97 -9
  335. package/dist/utility/serialization/scene/camera.js.map +1 -1
  336. package/dist/utility/serialization/scene/common.js +102 -28
  337. package/dist/utility/serialization/scene/common.js.map +1 -1
  338. package/dist/utility/serialization/scene/light.js +14 -12
  339. package/dist/utility/serialization/scene/light.js.map +1 -1
  340. package/dist/utility/serialization/scene/material.js +216 -26
  341. package/dist/utility/serialization/scene/material.js.map +1 -1
  342. package/dist/utility/serialization/scene/mesh.js +71 -100
  343. package/dist/utility/serialization/scene/mesh.js.map +1 -1
  344. package/dist/utility/serialization/scene/misc.js +3 -2
  345. package/dist/utility/serialization/scene/misc.js.map +1 -1
  346. package/dist/utility/serialization/scene/node.js +42 -9
  347. package/dist/utility/serialization/scene/node.js.map +1 -1
  348. package/dist/utility/serialization/scene/particle.js +7 -5
  349. package/dist/utility/serialization/scene/particle.js.map +1 -1
  350. package/dist/utility/serialization/scene/primitive.js +18 -15
  351. package/dist/utility/serialization/scene/primitive.js.map +1 -1
  352. package/dist/utility/serialization/scene/scene.js +3 -2
  353. package/dist/utility/serialization/scene/scene.js.map +1 -1
  354. package/dist/utility/serialization/scene/sprite.js +164 -0
  355. package/dist/utility/serialization/scene/sprite.js.map +1 -0
  356. package/dist/utility/serialization/scene/terrain.js +8 -6
  357. package/dist/utility/serialization/scene/terrain.js.map +1 -1
  358. package/dist/utility/serialization/scene/water.js +11 -9
  359. package/dist/utility/serialization/scene/water.js.map +1 -1
  360. package/dist/utility/serialization/types.js +6 -0
  361. package/dist/utility/serialization/types.js.map +1 -0
  362. package/dist/utility/shprojector.js.map +1 -1
  363. package/dist/utility/textures/ggxlut.js.map +1 -1
  364. package/dist/utility/textures/gradientnoise.js.map +1 -1
  365. package/dist/utility/textures/randomnoise.js.map +1 -1
  366. package/dist/values.js +14 -14
  367. package/dist/values.js.map +1 -1
  368. package/package.json +80 -80
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sprite3d.js","sources":["../../src/material/sprite3d.ts"],"sourcesContent":["import { MeshMaterial } from './meshmaterial';\r\nimport type { BindGroup, PBFunctionScope, PBInsideFunctionScope } from '@zephyr3d/device';\r\nimport { ShaderHelper } from './shader/helper';\r\nimport { MaterialVaryingFlags } from '../values';\r\nimport type { Clonable, Immutable, Vector2 } from '@zephyr3d/base';\r\nimport { Vector4 } from '@zephyr3d/base';\r\nimport type { DrawContext } from '../render';\r\n\r\n/**\r\n * Sprite3D material base class.\r\n *\r\n * @remarks\r\n * This material renders a camera-facing quad (billboard) in 3D space,\r\n * using UV information and an anchor point to control how the sprite\r\n * is positioned and textured.\r\n *\r\n * Derived classes can override {@link internalSetupUniforms},\r\n * {@link internalApplyUniforms} and\r\n * {@link calcFragmentColor} to provide custom\r\n * uniforms and shading logic (e.g. sampling a texture).\r\n *\r\n * @public\r\n */\r\nexport class Sprite3DMaterial extends MeshMaterial implements Clonable<Sprite3DMaterial> {\r\n static UVINFO = this.defineInstanceUniform('uvinfo', 'vec4');\r\n static ANCHOR_ROTATION = this.defineInstanceUniform('anchorRotation', 'vec4');\r\n private _uvinfo: Vector4;\r\n private _anchorRotation: Vector4;\r\n /**\r\n * Creates a new {@link Sprite3DMaterial} instance.\r\n *\r\n * @remarks\r\n * - Default UV rectangle is the full texture [0, 0, 1, 1].\r\n * - Default anchor is the center [0.5, 0.5].\r\n * - Face culling is disabled (`cullMode = 'none'`) so the sprite\r\n * is visible from both sides.\r\n */\r\n constructor() {\r\n super();\r\n this._uvinfo = new Vector4(0, 0, 1, 1);\r\n this._anchorRotation = new Vector4(0.5, 0.5, 0, 0);\r\n this.cullMode = 'none';\r\n }\r\n /**\r\n * Gets the UV rectangle of the sprite in the texture.\r\n *\r\n * @returns A Vector4 storing \\([u0, v0, u1, v1]\\).\r\n */\r\n get uvinfo(): Immutable<Vector4> {\r\n return this._uvinfo;\r\n }\r\n set uvinfo(value: Immutable<Vector4>) {\r\n if (!value.equalsTo(this.uvinfo)) {\r\n this._uvinfo.set(value);\r\n this.uniformChanged();\r\n }\r\n }\r\n /**\r\n * Convenience method to set the UV rectangle via individual components.\r\n *\r\n * @param uvx0 - Left (U) coordinate.\r\n * @param uvy0 - Bottom (V) coordinate.\r\n * @param uvx1 - Right (U) coordinate.\r\n * @param uvy1 - Top (V) coordinate.\r\n */\r\n setUVInfo(uvx0: number, uvy0: number, uvx1: number, uvy1: number) {\r\n this.uvinfo = new Vector4(uvx0, uvy0, uvx1, uvy1);\r\n }\r\n /**\r\n * Gets the sprite anchor-rotation.\r\n *\r\n * @returns The current anchor-rotation.\r\n */\r\n get anchorRotation(): Immutable<Vector4> {\r\n return this._anchorRotation;\r\n }\r\n set anchorRotation(value: Immutable<Vector4>) {\r\n if (!value.equalsTo(this._anchorRotation)) {\r\n this._anchorRotation.set(value);\r\n this.uniformChanged();\r\n }\r\n }\r\n /**\r\n * Gets the sprite anchor point in normalized quad space.\r\n *\r\n * @returns The current anchor as a Vector2.\r\n */\r\n get anchor(): Immutable<Vector2> {\r\n return this._anchorRotation.xy();\r\n }\r\n set anchor(value: Immutable<Vector2>) {\r\n if (value.x !== this._anchorRotation.x || value.y !== this._anchorRotation.y) {\r\n this.anchorRotation = new Vector4(value.x, value.y, this._anchorRotation.z, this._anchorRotation.w);\r\n }\r\n }\r\n /**\r\n * Gets the sprite rotation around the Z axis.\r\n *\r\n * @returns The sprite rotation.\r\n */\r\n get rotation() {\r\n return this._anchorRotation.z;\r\n }\r\n set rotation(value) {\r\n if (value !== this._anchorRotation.z) {\r\n this.anchorRotation = new Vector4(\r\n this._anchorRotation.x,\r\n this._anchorRotation.y,\r\n value,\r\n this._anchorRotation.w\r\n );\r\n }\r\n }\r\n /**\r\n * Gets the X component of the sprite anchor.\r\n */\r\n get anchorX() {\r\n return this._anchorRotation.x;\r\n }\r\n set anchorX(value) {\r\n if (this._anchorRotation.x !== value) {\r\n this.anchorRotation = new Vector4(\r\n value,\r\n this._anchorRotation.y,\r\n this._anchorRotation.z,\r\n this._anchorRotation.w\r\n );\r\n }\r\n }\r\n /**\r\n * Gets the Y component of the sprite anchor.\r\n */\r\n get anchorY() {\r\n return this._anchorRotation.y;\r\n }\r\n set anchorY(value) {\r\n if (this._anchorRotation.y !== value) {\r\n this.anchorRotation = new Vector4(\r\n this._anchorRotation.x,\r\n value,\r\n this._anchorRotation.z,\r\n this._anchorRotation.w\r\n );\r\n }\r\n }\r\n /**\r\n * Convenience method to set both anchor components at once.\r\n *\r\n * @param anchorX - X coordinate of the anchor.\r\n * @param anchorY - Y coordinate of the anchor.\r\n */\r\n setAnchor(anchorX: number, anchorY: number) {\r\n if (this._anchorRotation.x !== anchorX || this._anchorRotation.y !== anchorY) {\r\n this.anchorRotation = new Vector4(anchorX, anchorY, this._anchorRotation.z, this._anchorRotation.w);\r\n }\r\n }\r\n /**\r\n * Creates a deep copy of this material.\r\n *\r\n * @returns A new {@link Sprite3DMaterial} instance with the same properties.\r\n */\r\n clone() {\r\n const other = new Sprite3DMaterial();\r\n other.copyFrom(this);\r\n return other;\r\n }\r\n /**\r\n * Copies all relevant state from another {@link Sprite3DMaterial}.\r\n *\r\n * @param other - The source material to copy from.\r\n */\r\n copyFrom(other: this) {\r\n super.copyFrom(other);\r\n this.uvinfo = other.uvinfo;\r\n this.anchorRotation = other.anchorRotation;\r\n }\r\n /**\r\n * Builds the vertex shader for this material.\r\n *\r\n * @remarks\r\n * This method:\r\n * - Calls the base implementation.\r\n * - Computes per-vertex positions for a camera-facing quad (billboard)\r\n * based on the sprite's world transform, size, and anchor.\r\n * - Selects the correct UV coordinates for each quad corner using\r\n * the `vertexId` attribute.\r\n * - Outputs world-space position (`zWorldPos`) and UVs (`zVertexUV`)\r\n * for use in the fragment shader.\r\n *\r\n * @param scope - The current programmable builder function scope.\r\n */\r\n vertexShader(scope: PBFunctionScope) {\r\n super.vertexShader(scope);\r\n const pb = scope.$builder;\r\n scope.$inputs.vertexId = pb.float().attrib('position');\r\n if (this.drawContext.materialFlags & MaterialVaryingFlags.INSTANCING) {\r\n scope.$l.uvinfo = this.getInstancedUniform(scope, Sprite3DMaterial.UVINFO);\r\n scope.$l.anchorRotation = this.getInstancedUniform(scope, Sprite3DMaterial.ANCHOR_ROTATION);\r\n } else {\r\n scope.uvinfo = pb.vec4().uniform(2);\r\n scope.anchorRotation = pb.vec4().uniform(2);\r\n }\r\n this.internalSetupUniforms(scope);\r\n scope.$l.worldPos = ShaderHelper.getWorldMatrix(scope)[3].xyz;\r\n scope.$l.width = pb.sqrt(\r\n pb.dot(ShaderHelper.getWorldMatrix(scope)[0].xyz, ShaderHelper.getWorldMatrix(scope)[0].xyz)\r\n );\r\n scope.$l.height = pb.sqrt(\r\n pb.dot(ShaderHelper.getWorldMatrix(scope)[1].xyz, ShaderHelper.getWorldMatrix(scope)[1].xyz)\r\n );\r\n const viewMatrix = ShaderHelper.getViewMatrix(scope);\r\n scope.$l.forward = pb.vec3(viewMatrix[0].z, viewMatrix[1].z, viewMatrix[2].z);\r\n scope.$l.axis = scope.$choice(\r\n pb.lessThan(pb.abs(scope.forward.y), 0.999),\r\n pb.vec3(0, 1, 0),\r\n pb.vec3(1, 0, 0)\r\n );\r\n scope.$l.right = pb.normalize(pb.cross(scope.axis, scope.forward));\r\n scope.$l.up = pb.normalize(pb.cross(scope.forward, scope.right));\r\n scope.$l.rotateAngle = scope.anchorRotation.z;\r\n scope.$l.c = pb.cos(scope.rotateAngle);\r\n scope.$l.s = pb.sin(scope.rotateAngle);\r\n scope.$l.rightRot = pb.add(pb.mul(scope.up, scope.s), pb.mul(scope.right, scope.c));\r\n scope.$l.upRot = pb.sub(pb.mul(scope.up, scope.c), pb.mul(scope.right, scope.s));\r\n scope.$l.v = pb.vec2();\r\n scope.$l.uv = pb.vec2();\r\n scope.$l.anchor = scope.anchorRotation.xy;\r\n scope\r\n .$if(pb.equal(scope.$inputs.vertexId, 0), function () {\r\n scope.v = pb.neg(scope.anchor);\r\n scope.uv = pb.vec2(scope.uvinfo.x, pb.sub(1, scope.uvinfo.y));\r\n })\r\n .$elseif(pb.equal(scope.$inputs.vertexId, 1), function () {\r\n scope.v = pb.sub(pb.vec2(1, 0), scope.anchor);\r\n scope.uv = pb.vec2(scope.uvinfo.z, pb.sub(1, scope.uvinfo.y));\r\n })\r\n .$elseif(pb.equal(scope.$inputs.vertexId, 2), function () {\r\n scope.v = pb.sub(pb.vec2(0, 1), scope.anchor);\r\n scope.uv = pb.vec2(scope.uvinfo.x, pb.sub(1, scope.uvinfo.w));\r\n })\r\n .$else(function () {\r\n scope.v = pb.sub(pb.vec2(1), scope.anchor);\r\n scope.uv = pb.vec2(scope.uvinfo.z, pb.sub(1, scope.uvinfo.w));\r\n });\r\n scope.v = pb.mul(scope.v, pb.vec2(scope.width, scope.height));\r\n scope.$outputs.zWorldPos = pb.add(\r\n scope.worldPos,\r\n pb.mul(scope.rightRot, scope.v.x),\r\n pb.mul(scope.upRot, scope.v.y)\r\n );\r\n scope.$outputs.zVertexUV = scope.uv;\r\n ShaderHelper.setClipSpacePosition(\r\n scope,\r\n pb.mul(ShaderHelper.getViewProjectionMatrix(scope), pb.vec4(scope.$outputs.zWorldPos, 1))\r\n );\r\n }\r\n /**\r\n * Builds the fragment shader for this material.\r\n *\r\n * @remarks\r\n * This method:\r\n * - Calls the base implementation.\r\n * - Invokes {@link Sprite3DMaterial.internalSetupUniforms} for\r\n * fragment-stage specific uniform declarations.\r\n * - Computes fragment color by calling {@link Sprite3DMaterial.calcFragmentColor}\r\n * if fragment color is needed.\r\n * - Outputs the final fragment color via {@link MeshMaterial.outputFragmentColor}.\r\n *\r\n * @param scope - The current programmable builder function scope.\r\n */\r\n fragmentShader(scope: PBFunctionScope) {\r\n super.fragmentShader(scope);\r\n this.internalSetupUniforms(scope);\r\n if (this.needFragmentColor()) {\r\n scope.$l.color = this.calcFragmentColor(scope);\r\n this.outputFragmentColor(scope, scope.$inputs.zWorldPos, scope.color);\r\n } else {\r\n this.outputFragmentColor(scope, scope.$inputs.zWorldPos, null);\r\n }\r\n }\r\n /**\r\n * Applies runtime uniform values to the given bind group before drawing.\r\n *\r\n * @remarks\r\n * This binds:\r\n * - UV information (`uvinfo`)\r\n * - Anchor (`anchor`)\r\n *\r\n * for non-instanced rendering. For instanced rendering, these values\r\n * are expected to be provided as per-instance uniforms instead.\r\n *\r\n * It also calls {@link Sprite3DMaterial.internalApplyUniforms} to allow\r\n * derived classes to bind additional resources (e.g. textures).\r\n *\r\n * @param bindGroup - The bind group to which uniforms and resources are bound.\r\n * @param ctx - The current draw context providing rendering state.\r\n * @param pass - Index of the active render pass.\r\n */\r\n applyUniformValues(bindGroup: BindGroup, ctx: DrawContext, pass: number) {\r\n super.applyUniformValues(bindGroup, ctx, pass);\r\n if (!(ctx.materialFlags & MaterialVaryingFlags.INSTANCING)) {\r\n bindGroup.setValue('uvinfo', this._uvinfo);\r\n bindGroup.setValue('anchorRotation', this._anchorRotation);\r\n }\r\n this.internalApplyUniforms(bindGroup, ctx, pass);\r\n }\r\n /**\r\n * Hook for derived classes to declare additional uniforms.\r\n *\r\n * @remarks\r\n * This is invoked in both the vertex and fragment shader construction\r\n * phases, allowing subclasses to register extra uniforms or resources\r\n * needed by their custom shading logic.\r\n *\r\n * The base implementation does nothing.\r\n *\r\n * @param _scope - The current shader function scope.\r\n */\r\n protected internalSetupUniforms(_scope: PBInsideFunctionScope) {}\r\n /**\r\n * Hook for derived classes to bind additional uniform values or resources.\r\n *\r\n * @remarks\r\n * This is called from {@link Sprite3DMaterial.applyUniformValues} and is\r\n * intended for subclasses to bind their own textures, samplers, or\r\n * other GPU resources.\r\n *\r\n * The base implementation does nothing.\r\n *\r\n * @param _bindGroup - The bind group used for binding uniforms and resources.\r\n * @param _ctx - The current draw context.\r\n * @param _pass - Index of the active render pass.\r\n */\r\n protected internalApplyUniforms(_bindGroup: BindGroup, _ctx: DrawContext, _pass: number) {}\r\n /**\r\n * Computes the fragment color expression for this material.\r\n *\r\n * @remarks\r\n * The default implementation simply outputs the interpolated UV\r\n * coordinates as color \\([u, v, 0, 1]\\), which is mainly useful\r\n * for debugging.\r\n *\r\n * Derived classes are expected to override this method to implement\r\n * actual shading, such as sampling a texture.\r\n *\r\n * @param scope - The current shader function scope.\r\n * @returns A shader expression representing the fragment color.\r\n\r\n */\r\n protected calcFragmentColor(scope: PBInsideFunctionScope) {\r\n return scope.$builder.vec4(scope.$inputs.zVertexUV, 0, 1);\r\n }\r\n}\r\n"],"names":["Sprite3DMaterial","MeshMaterial","UVINFO","defineInstanceUniform","ANCHOR_ROTATION","_uvinfo","_anchorRotation","Vector4","cullMode","uvinfo","value","equalsTo","set","uniformChanged","setUVInfo","uvx0","uvy0","uvx1","uvy1","anchorRotation","anchor","xy","x","y","z","w","rotation","anchorX","anchorY","setAnchor","clone","other","copyFrom","vertexShader","scope","pb","$builder","$inputs","vertexId","float","attrib","drawContext","materialFlags","MaterialVaryingFlags","INSTANCING","$l","getInstancedUniform","vec4","uniform","internalSetupUniforms","worldPos","ShaderHelper","getWorldMatrix","xyz","width","sqrt","dot","height","viewMatrix","getViewMatrix","forward","vec3","axis","$choice","lessThan","abs","right","normalize","cross","up","rotateAngle","c","cos","s","sin","rightRot","add","mul","upRot","sub","v","vec2","uv","$if","equal","neg","$elseif","$else","$outputs","zWorldPos","zVertexUV","setClipSpacePosition","getViewProjectionMatrix","fragmentShader","needFragmentColor","color","calcFragmentColor","outputFragmentColor","applyUniformValues","bindGroup","ctx","pass","setValue","internalApplyUniforms","_scope","_bindGroup","_ctx","_pass"],"mappings":";;;;;AAQA;;;;;;;;;;;;;;IAeO,MAAMA,gBAAyBC,SAAAA,YAAAA,CAAAA;AACpC,IAAA,OAAOC,SAAS,IAAI,CAACC,qBAAqB,CAAC,UAAU,MAAQ,CAAA;AAC7D,IAAA,OAAOC,kBAAkB,IAAI,CAACD,qBAAqB,CAAC,kBAAkB,MAAQ,CAAA;IACtEE,OAAiB;IACjBC,eAAyB;AACjC;;;;;;;;AAQC,MACD,WAAc,EAAA;QACZ,KAAK,EAAA;AACL,QAAA,IAAI,CAACD,OAAO,GAAG,IAAIE,OAAQ,CAAA,CAAA,EAAG,GAAG,CAAG,EAAA,CAAA,CAAA;AACpC,QAAA,IAAI,CAACD,eAAe,GAAG,IAAIC,OAAQ,CAAA,GAAA,EAAK,KAAK,CAAG,EAAA,CAAA,CAAA;QAChD,IAAI,CAACC,QAAQ,GAAG,MAAA;AAClB;AACA;;;;AAIC,MACD,IAAIC,MAA6B,GAAA;QAC/B,OAAO,IAAI,CAACJ,OAAO;AACrB;IACA,IAAII,MAAAA,CAAOC,KAAyB,EAAE;AACpC,QAAA,IAAI,CAACA,KAAMC,CAAAA,QAAQ,CAAC,IAAI,CAACF,MAAM,CAAG,EAAA;AAChC,YAAA,IAAI,CAACJ,OAAO,CAACO,GAAG,CAACF,KAAAA,CAAAA;AACjB,YAAA,IAAI,CAACG,cAAc,EAAA;AACrB;AACF;AACA;;;;;;;MAQAC,SAAAA,CAAUC,IAAY,EAA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iG,qBAAqB,CAACJ,SAAAA,EAAWC,GAAKC,EAAAA,IAAAA,CAAAA;AAC7C;AACA;;;;;;;;;;;AAWC,MACD,qBAAUpD,CAAsBuD,MAA6B,EAAE;AAC/D;;;;;;;;;;;;;MAcUD,sBAAsBE,UAAqB,EAAEC,IAAiB,EAAEC,KAAa,EAAE;AACzF;;;;;;;;;;;;;;MAeUX,iBAAkB9D,CAAAA,KAA4B,EAAE;QACxD,OAAOA,KAAAA,CAAME,QAAQ,CAACW,IAAI,CAACb,MAAMG,OAAO,CAACqD,SAAS,EAAE,CAAG,EAAA,CAAA,CAAA;AACzD;AACF;;;;"}
@@ -0,0 +1,116 @@
1
+ import { DRef } from '@zephyr3d/base';
2
+ import { Sprite3DMaterial } from './sprite3d.js';
3
+ import { fetchSampler } from '../utility/misc.js';
4
+
5
+ /**
6
+ * Standard Sprite3D material
7
+ * @public
8
+ */ class StandardSprite3DMaterial extends Sprite3DMaterial {
9
+ static FEATURE_SPRITE_TEXTURE = this.defineFeature();
10
+ _texture;
11
+ /**
12
+ * Creates a new instance of {@link StandardSprite3DMaterial}.
13
+ *
14
+ * @remarks
15
+ * By default, no sprite texture is assigned and the material renders
16
+ * as solid white until a texture is set.
17
+ */ constructor(){
18
+ super();
19
+ this._texture = new DRef();
20
+ }
21
+ /**
22
+ * Gets the 2D texture used by this sprite material.
23
+ *
24
+ * @returns The current sprite texture, or `null` if no texture is assigned.
25
+ */ get spriteTexture() {
26
+ return this._texture.get();
27
+ }
28
+ set spriteTexture(tex) {
29
+ tex = tex ?? null;
30
+ if (tex !== this._texture.get()) {
31
+ this._texture.set(tex);
32
+ this.useFeature(StandardSprite3DMaterial.FEATURE_SPRITE_TEXTURE, !!tex);
33
+ this.uniformChanged();
34
+ }
35
+ }
36
+ /**
37
+ * Creates a deep copy of this material instance.
38
+ *
39
+ * @remarks
40
+ * The new instance will copy all relevant state from this material,
41
+ * including the assigned sprite texture reference.
42
+ *
43
+ * @returns A new {@link StandardSprite3DMaterial} instance with the same settings.
44
+ */ clone() {
45
+ const other = new StandardSprite3DMaterial();
46
+ other.copyFrom(this);
47
+ return other;
48
+ }
49
+ /**
50
+ * Copies the state from another {@link StandardSprite3DMaterial} into this instance.
51
+ *
52
+ * @param other - The source material to copy from.
53
+ */ copyFrom(other) {
54
+ super.copyFrom(other);
55
+ this.spriteTexture = other.spriteTexture;
56
+ }
57
+ /**
58
+ * Applies runtime uniform values to the given bind group before drawing.
59
+ *
60
+ * @remarks
61
+ * This method is called by the rendering pipeline to bind GPU resources
62
+ * (such as textures and samplers) associated with this material.
63
+ *
64
+ * @param bindGroup - The bind group to which uniforms and resources are bound.
65
+ * @param ctx - The current draw context providing rendering-state information.
66
+ *
67
+ */ internalApplyUniforms(bindGroup, ctx) {
68
+ if (this.spriteTexture && this.needFragmentColor(ctx)) {
69
+ bindGroup.setTexture('zSpriteTexture', this.spriteTexture, fetchSampler('clamp_linear'));
70
+ }
71
+ }
72
+ /**
73
+ * Declares and configures shader uniforms for this material in the current scope.
74
+ *
75
+ * @remarks
76
+ * This is executed during shader construction. If the active shader stage
77
+ * is a fragment shader, and the material requires fragment color and has
78
+ * a sprite texture assigned, a 2D texture uniform named `zSpriteTexture`
79
+ * is added to the program.
80
+ *
81
+ * @param scope - The current shader function scope used to build the program.
82
+ */ internalSetupUniforms(scope) {
83
+ const pb = scope.$builder;
84
+ if (pb.shaderKind === 'fragment' && this.spriteTexture && this.needFragmentColor()) {
85
+ scope.zSpriteTexture = pb.tex2D().uniform(2);
86
+ }
87
+ }
88
+ /**
89
+ * Computes the fragment color expression for this material within the shader.
90
+ *
91
+ * @remarks
92
+ * - If a sprite texture is assigned, this samples the texture using
93
+ * the interpolated vertex UV coordinates (`zVertexUV`).
94
+ * - If no texture is assigned, this returns a solid white color.
95
+ *
96
+ * @param scope - The current shader function scope providing inputs and uniforms.
97
+ * @returns A shader expression representing the computed fragment color.
98
+ */ calcFragmentColor(scope) {
99
+ const pb = scope.$builder;
100
+ return this.spriteTexture ? pb.textureSample(scope.zSpriteTexture, scope.$inputs.zVertexUV) : pb.vec4(1);
101
+ }
102
+ /**
103
+ * Releases resources held by this material instance.
104
+ *
105
+ * @remarks
106
+ * This is called when the material is disposed. It forwards the dispose
107
+ * call to the internal texture reference so that the associated GPU
108
+ * resource can be released.
109
+ */ onDispose() {
110
+ super.onDispose();
111
+ this._texture.dispose();
112
+ }
113
+ }
114
+
115
+ export { StandardSprite3DMaterial };
116
+ //# sourceMappingURL=sprite3d_std.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sprite3d_std.js","sources":["../../src/material/sprite3d_std.ts"],"sourcesContent":["import type { BindGroup, PBInsideFunctionScope, Texture2D } from '@zephyr3d/device';\r\nimport type { Clonable } from '@zephyr3d/base';\r\nimport { DRef } from '@zephyr3d/base';\r\nimport type { DrawContext } from '../render/drawable';\r\nimport { Sprite3DMaterial } from './sprite3d';\r\nimport { fetchSampler } from '../utility/misc';\r\n\r\n/**\r\n * Standard Sprite3D material\r\n * @public\r\n */\r\nexport class StandardSprite3DMaterial extends Sprite3DMaterial implements Clonable<StandardSprite3DMaterial> {\r\n static FEATURE_SPRITE_TEXTURE = this.defineFeature();\r\n protected _texture: DRef<Texture2D>;\r\n /**\r\n * Creates a new instance of {@link StandardSprite3DMaterial}.\r\n *\r\n * @remarks\r\n * By default, no sprite texture is assigned and the material renders\r\n * as solid white until a texture is set.\r\n */\r\n constructor() {\r\n super();\r\n this._texture = new DRef();\r\n }\r\n /**\r\n * Gets the 2D texture used by this sprite material.\r\n *\r\n * @returns The current sprite texture, or `null` if no texture is assigned.\r\n */\r\n get spriteTexture() {\r\n return this._texture.get();\r\n }\r\n set spriteTexture(tex) {\r\n tex = tex ?? null;\r\n if (tex !== this._texture.get()) {\r\n this._texture.set(tex);\r\n this.useFeature(StandardSprite3DMaterial.FEATURE_SPRITE_TEXTURE, !!tex);\r\n this.uniformChanged();\r\n }\r\n }\r\n /**\r\n * Creates a deep copy of this material instance.\r\n *\r\n * @remarks\r\n * The new instance will copy all relevant state from this material,\r\n * including the assigned sprite texture reference.\r\n *\r\n * @returns A new {@link StandardSprite3DMaterial} instance with the same settings.\r\n */\r\n clone() {\r\n const other = new StandardSprite3DMaterial();\r\n other.copyFrom(this);\r\n return other;\r\n }\r\n /**\r\n * Copies the state from another {@link StandardSprite3DMaterial} into this instance.\r\n *\r\n * @param other - The source material to copy from.\r\n */\r\n copyFrom(other: this) {\r\n super.copyFrom(other);\r\n this.spriteTexture = other.spriteTexture;\r\n }\r\n /**\r\n * Applies runtime uniform values to the given bind group before drawing.\r\n *\r\n * @remarks\r\n * This method is called by the rendering pipeline to bind GPU resources\r\n * (such as textures and samplers) associated with this material.\r\n *\r\n * @param bindGroup - The bind group to which uniforms and resources are bound.\r\n * @param ctx - The current draw context providing rendering-state information.\r\n *\r\n */\r\n protected internalApplyUniforms(bindGroup: BindGroup, ctx: DrawContext) {\r\n if (this.spriteTexture && this.needFragmentColor(ctx)) {\r\n bindGroup.setTexture('zSpriteTexture', this.spriteTexture, fetchSampler('clamp_linear'));\r\n }\r\n }\r\n /**\r\n * Declares and configures shader uniforms for this material in the current scope.\r\n *\r\n * @remarks\r\n * This is executed during shader construction. If the active shader stage\r\n * is a fragment shader, and the material requires fragment color and has\r\n * a sprite texture assigned, a 2D texture uniform named `zSpriteTexture`\r\n * is added to the program.\r\n *\r\n * @param scope - The current shader function scope used to build the program.\r\n */\r\n protected internalSetupUniforms(scope: PBInsideFunctionScope) {\r\n const pb = scope.$builder;\r\n if (pb.shaderKind === 'fragment' && this.spriteTexture && this.needFragmentColor()) {\r\n scope.zSpriteTexture = pb.tex2D().uniform(2);\r\n }\r\n }\r\n /**\r\n * Computes the fragment color expression for this material within the shader.\r\n *\r\n * @remarks\r\n * - If a sprite texture is assigned, this samples the texture using\r\n * the interpolated vertex UV coordinates (`zVertexUV`).\r\n * - If no texture is assigned, this returns a solid white color.\r\n *\r\n * @param scope - The current shader function scope providing inputs and uniforms.\r\n * @returns A shader expression representing the computed fragment color.\r\n */\r\n protected calcFragmentColor(scope: PBInsideFunctionScope) {\r\n const pb = scope.$builder;\r\n return this.spriteTexture ? pb.textureSample(scope.zSpriteTexture, scope.$inputs.zVertexUV) : pb.vec4(1);\r\n }\r\n /**\r\n * Releases resources held by this material instance.\r\n *\r\n * @remarks\r\n * This is called when the material is disposed. It forwards the dispose\r\n * call to the internal texture reference so that the associated GPU\r\n * resource can be released.\r\n */\r\n protected onDispose() {\r\n super.onDispose();\r\n this._texture.dispose();\r\n }\r\n}\r\n"],"names":["StandardSprite3DMaterial","Sprite3DMaterial","FEATURE_SPRITE_TEXTURE","defineFeature","_texture","DRef","spriteTexture","get","tex","set","useFeature","uniformChanged","clone","other","copyFrom","internalApplyUniforms","bindGroup","ctx","needFragmentColor","setTexture","fetchSampler","internalSetupUniforms","scope","pb","$builder","shaderKind","zSpriteTexture","tex2D","uniform","calcFragmentColor","textureSample","$inputs","zVertexUV","vec4","onDispose","dispose"],"mappings":";;;;AAOA;;;IAIO,MAAMA,wBAAiCC,SAAAA,gBAAAA,CAAAA;AAC5C,IAAA,OAAOC,sBAAyB,GAAA,IAAI,CAACC,aAAa,EAAG;IAC3CC,QAA0B;AACpC;;;;;;AAMC,MACD,WAAc,EAAA;QACZ,KAAK,EAAA;QACL,IAAI,CAACA,QAAQ,GAAG,IAAIC,IAAAA,EAAAA;AACtB;AACA;;;;AAIC,MACD,IAAIC,aAAgB,GAAA;AAClB,QAAA,OAAO,IAAI,CAACF,QAAQ,CAACG,GAAG,EAAA;AAC1B;IACA,IAAID,aAAAA,CAAcE,GAAG,EAAE;AACrBA,QAAAA,GAAAA,GAAMA,GAAO,IAAA,IAAA;AACb,QAAA,IAAIA,QAAQ,IAAI,CAACJ,QAAQ,CAACG,GAAG,EAAI,EAAA;AAC/B,YAAA,IAAI,CAACH,QAAQ,CAACK,GAAG,CAACD,GAAAA,CAAAA;AAClB,YAAA,IAAI,CAACE,UAAU,CAACV,yBAAyBE,sBAAsB,EAAE,CAAC,C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CAAA,CAAA;AACxG;AACA;;;;;;;AAOC,MACD,SAAsB,GAAA;AACpB,QAAA,KAAK,CAACC,SAAAA,EAAAA;QACN,IAAI,CAAC9B,QAAQ,CAAC+B,OAAO,EAAA;AACvB;AACF;;;;"}
@@ -0,0 +1,235 @@
1
+ import { DRef, Vector4 } from '@zephyr3d/base';
2
+ import { Sprite3DBlockNode } from '../utility/blueprint/material/pbr.js';
3
+ import { MaterialBlueprintIR } from '../utility/blueprint/material/ir.js';
4
+ import { Sprite3DMaterial } from './sprite3d.js';
5
+
6
+ /**
7
+ * Sprite3D material driven by a blueprint graph.
8
+ *
9
+ * @remarks
10
+ * This material extends {@link Sprite3DMaterial} and uses a
11
+ * {@link MaterialBlueprintIR} fragment graph to compute the final
12
+ * sprite color. All fragment shading logic is defined in the
13
+ * blueprint instead of being hard-coded in the material.
14
+ *
15
+ * @public
16
+ */ class Sprite3DBlueprintMaterial extends Sprite3DMaterial {
17
+ /** @internal */ _irFrag;
18
+ /** @internal */ _uniformValues;
19
+ /** @internal */ _uniformTextures;
20
+ /**
21
+ * Creates a new {@link Sprite3DBlueprintMaterial} instance.
22
+ *
23
+ * @param irFrag - Optional fragment blueprint IR. If omitted, a default
24
+ * IR containing a single {@link Sprite3DBlockNode} is created.
25
+ * @param uniformValues - Optional initial list of uniform value descriptors.
26
+ * @param uniformTextures - Optional initial list of texture uniform descriptors.
27
+ */ constructor(irFrag, uniformValues, uniformTextures){
28
+ super();
29
+ this._irFrag = irFrag ?? new MaterialBlueprintIR({
30
+ nodeMap: {
31
+ '1': new Sprite3DBlockNode()
32
+ },
33
+ roots: [
34
+ 1
35
+ ],
36
+ order: [
37
+ 1
38
+ ],
39
+ graph: {
40
+ incoming: {},
41
+ outgoing: {}
42
+ }
43
+ }, '', {
44
+ nodes: [
45
+ {
46
+ id: 1,
47
+ title: '',
48
+ locked: true,
49
+ node: {
50
+ ClassName: 'Sprite3DBlockNode',
51
+ Object: ''
52
+ }
53
+ }
54
+ ],
55
+ links: []
56
+ });
57
+ this._uniformValues = uniformValues ?? [];
58
+ this._uniformTextures = uniformTextures ?? [];
59
+ }
60
+ /**
61
+ * Gets the fragment blueprint IR used to generate the fragment shader.
62
+ */ get fragmentIR() {
63
+ return this._irFrag;
64
+ }
65
+ set fragmentIR(ir) {
66
+ if (ir && ir !== this._irFrag) {
67
+ this._irFrag = ir;
68
+ this.clearCache();
69
+ this.optionChanged(true);
70
+ }
71
+ }
72
+ /**
73
+ * Gets the list of uniform value descriptors used by the blueprint.
74
+ */ get uniformValues() {
75
+ return this._uniformValues;
76
+ }
77
+ set uniformValues(val) {
78
+ this._uniformValues = (val ?? []).map((v)=>({
79
+ ...v
80
+ }));
81
+ this.uniformChanged();
82
+ }
83
+ /**
84
+ * Gets the list of texture uniform descriptors used by the blueprint.
85
+ */ get uniformTextures() {
86
+ return this._uniformTextures;
87
+ }
88
+ set uniformTextures(val) {
89
+ val = val ?? [];
90
+ if (val !== this._uniformTextures) {
91
+ const newUniforms = val.map((v)=>({
92
+ finalTexture: new DRef(v.finalTexture.get()),
93
+ finalSampler: v.finalSampler,
94
+ name: v.name,
95
+ params: v.params?.clone() ?? Vector4.zero(),
96
+ texture: v.texture,
97
+ type: v.type,
98
+ sRGB: v.sRGB,
99
+ wrapS: v.wrapS,
100
+ wrapT: v.wrapT,
101
+ inFragmentShader: v.inFragmentShader,
102
+ inVertexShader: v.inVertexShader,
103
+ minFilter: v.minFilter,
104
+ magFilter: v.magFilter,
105
+ mipFilter: v.mipFilter
106
+ }));
107
+ for (const u of this._uniformTextures){
108
+ u.finalTexture.dispose();
109
+ }
110
+ this._uniformTextures = newUniforms;
111
+ this.uniformChanged();
112
+ }
113
+ }
114
+ /**
115
+ * Creates a deep copy of this blueprint material.
116
+ *
117
+ * @remarks
118
+ * The clone shares the same fragment IR reference and copies the
119
+ * current uniform descriptors, then calls {@link Sprite3DMaterial.copyFrom}
120
+ * to copy base-class state.
121
+ *
122
+ * @returns A new {@link Sprite3DBlueprintMaterial} instance.
123
+ */ clone() {
124
+ const other = new Sprite3DBlueprintMaterial(this._irFrag, this._uniformValues, this._uniformTextures);
125
+ other.copyFrom(this);
126
+ return other;
127
+ }
128
+ /**
129
+ * Applies runtime uniform values and textures to the given bind group.
130
+ *
131
+ * @remarks
132
+ * - Calls the base implementation to bind sprite-related uniforms first.
133
+ * - If fragment color is needed for the current context, all blueprint
134
+ * uniform values and textures are then bound by name:
135
+ * - `uniformValues` via `bindGroup.setValue`.
136
+ * - `uniformTextures` via `bindGroup.setTexture`.
137
+ *
138
+ * @param bindGroup - The bind group to bind material resources to.
139
+ * @param ctx - The current draw context.
140
+ * @param pass - Index of the active render pass.
141
+ */ applyUniformValues(bindGroup, ctx, pass) {
142
+ super.applyUniformValues(bindGroup, ctx, pass);
143
+ if (this.needFragmentColor(ctx)) {
144
+ for (const u of this._uniformValues){
145
+ bindGroup.setValue(u.name, u.finalValue);
146
+ }
147
+ for (const u of this._uniformTextures){
148
+ bindGroup.setTexture(u.name, u.finalTexture.get(), u.finalSampler);
149
+ }
150
+ }
151
+ }
152
+ /**
153
+ * Computes the fragment color by invoking the blueprint-generated function.
154
+ *
155
+ * @remarks
156
+ * - A helper function `zCalcSpriteColor(zWorldPos, zVertexUV)` is declared
157
+ * on the shader builder using the current fragment IR.
158
+ * - The blueprint IR is asked to create its node network via
159
+ * {@link MaterialBlueprintIR.create}, and the output named `"Color"`
160
+ * is used as the return value.
161
+ * - The resulting function is invoked with the current world position and
162
+ * UV coordinates for each fragment.
163
+ *
164
+ * @param scope - The current fragment shader function scope.
165
+ * @returns A shader expression representing the final fragment color.
166
+ */ calcFragmentColor(scope) {
167
+ const pb = scope.$builder;
168
+ const that = this;
169
+ pb.func('zCalcSpriteColor', [
170
+ pb.vec3('zWorldPos'),
171
+ pb.vec2('zVertexUV')
172
+ ], function() {
173
+ const outputs = that._irFrag.create(pb);
174
+ this.$return(that.getOutput(outputs, 'Color'));
175
+ });
176
+ return scope.zCalcSpriteColor(scope.$inputs.zWorldPos, scope.$inputs.zVertexUV);
177
+ }
178
+ /**
179
+ * Creates a unique hash string used for program caching.
180
+ *
181
+ * @remarks
182
+ * The hash includes the base {@link Sprite3DMaterial} hash and the
183
+ * fragment IR hash, so that different blueprints will produce
184
+ * different shader programs.
185
+ *
186
+ * @returns A hash string that identifies this material configuration.
187
+ */ _createHash() {
188
+ return `${super._createHash()}:${this._irFrag.hash}`;
189
+ }
190
+ /**
191
+ * Creates the GPU program for this material.
192
+ *
193
+ * @remarks
194
+ * This simply delegates to the base implementation and returns its result.
195
+ * Commented-out logging lines are available for debugging the generated
196
+ * vertex and fragment shader sources.
197
+ *
198
+ * @param ctx - The current draw context.
199
+ * @param pass - Index of the active material pass.
200
+ * @returns The created GPU program.
201
+ */ createProgram(ctx, pass) {
202
+ const program = super.createProgram(ctx, pass);
203
+ //console.log(program.getShaderSource('vertex'));
204
+ //console.log(program.getShaderSource('fragment'));
205
+ return program;
206
+ }
207
+ /**
208
+ * Disposes resources associated with this material.
209
+ *
210
+ * @remarks
211
+ * - Calls the base `onDispose` to clean up inherited resources.
212
+ * - Disposes all `finalTexture` references from the blueprint texture
213
+ * uniform descriptors.
214
+ *
215
+ * This method is intended to be called by the engine's resource management
216
+ * system rather than directly from user code.
217
+ */ onDispose() {
218
+ super.onDispose();
219
+ for (const u of this._uniformTextures){
220
+ u.finalTexture.dispose();
221
+ }
222
+ }
223
+ /**
224
+ * Retrieves a named output expression from a blueprint output list.
225
+ *
226
+ * @param outputs - List of outputs generated by the blueprint graph.
227
+ * @param name - Name of the output to look for (e.g. `"Color"`).
228
+ * @returns The matching output expression, or `undefined` if not found.
229
+ */ getOutput(outputs, name) {
230
+ return outputs.find((output)=>output.name === name)?.exp;
231
+ }
232
+ }
233
+
234
+ export { Sprite3DBlueprintMaterial };
235
+ //# sourceMappingURL=sprite3dblueprint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sprite3dblueprint.js","sources":["../../src/material/sprite3dblueprint.ts"],"sourcesContent":["import { DRef, Vector4 } from '@zephyr3d/base';\r\nimport { type BluePrintUniformTexture, type BluePrintUniformValue } from '../utility/blueprint/material/ir';\r\nimport { Sprite3DBlockNode } from '../utility/blueprint/material/pbr';\r\nimport { MaterialBlueprintIR } from '../utility/blueprint/material/ir';\r\nimport { Sprite3DMaterial } from './sprite3d';\r\nimport type { BindGroup, PBInsideFunctionScope, PBShaderExp } from '@zephyr3d/device';\r\nimport type { DrawContext } from '../render';\r\n\r\n/**\r\n * Sprite3D material driven by a blueprint graph.\r\n *\r\n * @remarks\r\n * This material extends {@link Sprite3DMaterial} and uses a\r\n * {@link MaterialBlueprintIR} fragment graph to compute the final\r\n * sprite color. All fragment shading logic is defined in the\r\n * blueprint instead of being hard-coded in the material.\r\n *\r\n * @public\r\n */\r\nexport class Sprite3DBlueprintMaterial extends Sprite3DMaterial {\r\n /** @internal */\r\n private _irFrag: MaterialBlueprintIR;\r\n /** @internal */\r\n private _uniformValues: BluePrintUniformValue[];\r\n /** @internal */\r\n private _uniformTextures: BluePrintUniformTexture[];\r\n /**\r\n * Creates a new {@link Sprite3DBlueprintMaterial} instance.\r\n *\r\n * @param irFrag - Optional fragment blueprint IR. If omitted, a default\r\n * IR containing a single {@link Sprite3DBlockNode} is created.\r\n * @param uniformValues - Optional initial list of uniform value descriptors.\r\n * @param uniformTextures - Optional initial list of texture uniform descriptors.\r\n */\r\n constructor(\r\n irFrag?: MaterialBlueprintIR,\r\n uniformValues?: BluePrintUniformValue[],\r\n uniformTextures?: BluePrintUniformTexture[]\r\n ) {\r\n super();\r\n this._irFrag =\r\n irFrag ??\r\n new MaterialBlueprintIR(\r\n {\r\n nodeMap: { '1': new Sprite3DBlockNode() },\r\n roots: [1],\r\n order: [1],\r\n graph: { incoming: {}, outgoing: {} }\r\n },\r\n '',\r\n {\r\n nodes: [{ id: 1, title: '', locked: true, node: { ClassName: 'Sprite3DBlockNode', Object: '' } }],\r\n links: []\r\n }\r\n );\r\n this._uniformValues = uniformValues ?? [];\r\n this._uniformTextures = uniformTextures ?? [];\r\n }\r\n /**\r\n * Gets the fragment blueprint IR used to generate the fragment shader.\r\n */\r\n get fragmentIR() {\r\n return this._irFrag;\r\n }\r\n set fragmentIR(ir: MaterialBlueprintIR) {\r\n if (ir && ir !== this._irFrag) {\r\n this._irFrag = ir;\r\n this.clearCache();\r\n this.optionChanged(true);\r\n }\r\n }\r\n /**\r\n * Gets the list of uniform value descriptors used by the blueprint.\r\n */\r\n get uniformValues() {\r\n return this._uniformValues;\r\n }\r\n set uniformValues(val: BluePrintUniformValue[]) {\r\n this._uniformValues = (val ?? []).map((v) => ({ ...v }));\r\n this.uniformChanged();\r\n }\r\n /**\r\n * Gets the list of texture uniform descriptors used by the blueprint.\r\n */\r\n get uniformTextures() {\r\n return this._uniformTextures;\r\n }\r\n set uniformTextures(val: BluePrintUniformTexture[]) {\r\n val = val ?? [];\r\n if (val !== this._uniformTextures) {\r\n const newUniforms = val.map((v) => ({\r\n finalTexture: new DRef(v.finalTexture!.get()),\r\n finalSampler: v.finalSampler,\r\n name: v.name,\r\n params: v.params?.clone() ?? Vector4.zero(),\r\n texture: v.texture,\r\n type: v.type,\r\n sRGB: v.sRGB,\r\n wrapS: v.wrapS,\r\n wrapT: v.wrapT,\r\n inFragmentShader: v.inFragmentShader,\r\n inVertexShader: v.inVertexShader,\r\n minFilter: v.minFilter,\r\n magFilter: v.magFilter,\r\n mipFilter: v.mipFilter\r\n }));\r\n for (const u of this._uniformTextures) {\r\n u.finalTexture!.dispose();\r\n }\r\n this._uniformTextures = newUniforms;\r\n this.uniformChanged();\r\n }\r\n }\r\n /**\r\n * Creates a deep copy of this blueprint material.\r\n *\r\n * @remarks\r\n * The clone shares the same fragment IR reference and copies the\r\n * current uniform descriptors, then calls {@link Sprite3DMaterial.copyFrom}\r\n * to copy base-class state.\r\n *\r\n * @returns A new {@link Sprite3DBlueprintMaterial} instance.\r\n */\r\n clone() {\r\n const other = new Sprite3DBlueprintMaterial(this._irFrag, this._uniformValues, this._uniformTextures);\r\n other.copyFrom(this);\r\n return other;\r\n }\r\n /**\r\n * Applies runtime uniform values and textures to the given bind group.\r\n *\r\n * @remarks\r\n * - Calls the base implementation to bind sprite-related uniforms first.\r\n * - If fragment color is needed for the current context, all blueprint\r\n * uniform values and textures are then bound by name:\r\n * - `uniformValues` via `bindGroup.setValue`.\r\n * - `uniformTextures` via `bindGroup.setTexture`.\r\n *\r\n * @param bindGroup - The bind group to bind material resources to.\r\n * @param ctx - The current draw context.\r\n * @param pass - Index of the active render pass.\r\n */\r\n applyUniformValues(bindGroup: BindGroup, ctx: DrawContext, pass: number) {\r\n super.applyUniformValues(bindGroup, ctx, pass);\r\n if (this.needFragmentColor(ctx)) {\r\n for (const u of this._uniformValues) {\r\n bindGroup.setValue(u.name, u.finalValue!);\r\n }\r\n for (const u of this._uniformTextures) {\r\n bindGroup.setTexture(u.name, u.finalTexture!.get()!, u.finalSampler);\r\n }\r\n }\r\n }\r\n /**\r\n * Computes the fragment color by invoking the blueprint-generated function.\r\n *\r\n * @remarks\r\n * - A helper function `zCalcSpriteColor(zWorldPos, zVertexUV)` is declared\r\n * on the shader builder using the current fragment IR.\r\n * - The blueprint IR is asked to create its node network via\r\n * {@link MaterialBlueprintIR.create}, and the output named `\"Color\"`\r\n * is used as the return value.\r\n * - The resulting function is invoked with the current world position and\r\n * UV coordinates for each fragment.\r\n *\r\n * @param scope - The current fragment shader function scope.\r\n * @returns A shader expression representing the final fragment color.\r\n */\r\n protected calcFragmentColor(scope: PBInsideFunctionScope) {\r\n const pb = scope.$builder;\r\n const that = this;\r\n pb.func('zCalcSpriteColor', [pb.vec3('zWorldPos'), pb.vec2('zVertexUV')], function () {\r\n const outputs = that._irFrag.create(pb)!;\r\n this.$return(that.getOutput(outputs, 'Color') as PBShaderExp);\r\n });\r\n return scope.zCalcSpriteColor(scope.$inputs.zWorldPos, scope.$inputs.zVertexUV) as PBShaderExp;\r\n }\r\n /**\r\n * Creates a unique hash string used for program caching.\r\n *\r\n * @remarks\r\n * The hash includes the base {@link Sprite3DMaterial} hash and the\r\n * fragment IR hash, so that different blueprints will produce\r\n * different shader programs.\r\n *\r\n * @returns A hash string that identifies this material configuration.\r\n */\r\n protected _createHash() {\r\n return `${super._createHash()}:${this._irFrag.hash}`;\r\n }\r\n /**\r\n * Creates the GPU program for this material.\r\n *\r\n * @remarks\r\n * This simply delegates to the base implementation and returns its result.\r\n * Commented-out logging lines are available for debugging the generated\r\n * vertex and fragment shader sources.\r\n *\r\n * @param ctx - The current draw context.\r\n * @param pass - Index of the active material pass.\r\n * @returns The created GPU program.\r\n */\r\n protected createProgram(ctx: DrawContext, pass: number) {\r\n const program = super.createProgram(ctx, pass);\r\n //console.log(program.getShaderSource('vertex'));\r\n //console.log(program.getShaderSource('fragment'));\r\n return program;\r\n }\r\n /**\r\n * Disposes resources associated with this material.\r\n *\r\n * @remarks\r\n * - Calls the base `onDispose` to clean up inherited resources.\r\n * - Disposes all `finalTexture` references from the blueprint texture\r\n * uniform descriptors.\r\n *\r\n * This method is intended to be called by the engine's resource management\r\n * system rather than directly from user code.\r\n */\r\n protected onDispose() {\r\n super.onDispose();\r\n for (const u of this._uniformTextures) {\r\n u.finalTexture!.dispose();\r\n }\r\n }\r\n /**\r\n * Retrieves a named output expression from a blueprint output list.\r\n *\r\n * @param outputs - List of outputs generated by the blueprint graph.\r\n * @param name - Name of the output to look for (e.g. `\"Color\"`).\r\n * @returns The matching output expression, or `undefined` if not found.\r\n */\r\n private getOutput(\r\n outputs: {\r\n name: string;\r\n exp: number | boolean | PBShaderExp;\r\n }[],\r\n name: string\r\n ) {\r\n return outputs.find((output) => output.name === name)?.exp;\r\n }\r\n}\r\n"],"names":["Sprite3DBlueprintMaterial","Sprite3DMaterial","irFrag","uniformValues","uniformTextures","_irFrag","MaterialBlueprintIR","nodeMap","Sprite3DBlockNode","roots","order","graph","incoming","outgoing","nodes","id","title","locked","node","ClassName","Object","links","_uniformValues","_uniformTextures","fragmentIR","ir","clearCache","optionChanged","val","map","v","uniformChanged","newUniforms","finalTexture","DRef","get","finalSampler","name","params","clone","Vector4","zero","texture","type","sRGB","wrapS","wrapT","inFragmentShader","inVertexShader","minFilter","magFilter","mipFilter","u","dispose","other","copyFrom","applyUniformValues","bindGroup","ctx","pass","needFragmentColor","setValue","finalValue","setTexture","calcFragmentColor","scope","pb","$builder","that","func","vec3","vec2","outputs","create","$return","getOutput","zCalcSpriteColor","$inputs","zWorldPos","zVertexUV","_createHash","hash","createProgram","program","onDispose","find","output","exp"],"mappings":";;;;;AAQA;;;;;;;;;;IAWO,MAAMA,yBAAkCC,SAAAA,gBAAAA,CAAAA;qBAE7C,OAAqC;qBAErC,cAAgD;qBAEhD,gBAAoD;AACpD;;;;;;;AAOC,MACD,YACEC,MAA4B,EAC5BC,aAAuC,EACvCC,eAA2C,CAC3C;QACA,KAAK,EAAA;AACL,QAAA,IAAI,CAACC,OAAO,GACVH,MAAAA,IACA,IAAII,mBACF,CAAA;YACEC,OAAS,EAAA;AAAE,gBAAA,GAAA,EAAK,IAAIC,iBAAAA;AAAoB,aAAA;YACxCC,KAAO,EAAA;AAAC,gBAAA;AAAE,aAAA;YACVC,KAAO,EAAA;AAAC,gBAAA;AAAE,aAAA;YACVC,KAAO,EAAA;AAAEC,gBAAAA,QAAAA,EAAU,EAAC;AAAGC,gBAAAA,QAAAA,EAAU;AAAG;AACtC,SAAA,EACA,EACA,EAAA;YACEC,KAAO,EAAA;AAAC,gBAAA;oBAAEC,EAAI,EAAA,CAAA;oBAAGC,KAAO,EAAA,EAAA;oBAAIC,MAAQ,EAAA,IAAA;oBAAMC,IAAM,EAAA;wBAAEC,SAAW,EAAA,mBAAA;wBAAqBC,MAAQ,EAAA;AAAG;AAAE;AAAE,aAAA;AACjGC,YAAAA,KAAAA,EAAO;AACT,SAAA,CAAA;AAEJ,QAAA,IAAI,CAACC,cAAc,GAAGnB,aAAAA,IAAiB,EAAE;AACzC,QAAA,IAAI,CAACoB,gBAAgB,GAAGnB,eAAAA,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ACA;;;;;;;;;;AAUC,MACD,SAAsB,GAAA;AACpB,QAAA,KAAK,CAACC,SAAAA,EAAAA;AACN,QAAA,KAAK,MAAMhC,CAAAA,IAAK,IAAI,CAAC7B,gBAAgB,CAAE;YACrC6B,CAAEnB,CAAAA,YAAY,CAAEoB,OAAO,EAAA;AACzB;AACF;AACA;;;;;;AAMC,MACD,SAAQsB,CACNH,OAGG,EACHnC,IAAY,EACZ;QACA,OAAOmC,OAAAA,CAAQa,IAAI,CAAC,CAACC,SAAWA,MAAOjD,CAAAA,IAAI,KAAKA,IAAOkD,CAAAA,EAAAA,GAAAA;AACzD;AACF;;;;"}
@@ -0,0 +1,116 @@
1
+ import { DRef } from '@zephyr3d/base';
2
+ import { SpriteMaterial } from './sprite.js';
3
+ import { fetchSampler } from '../utility/misc.js';
4
+
5
+ /**
6
+ * Standard Sprite material
7
+ * @public
8
+ */ class StandardSpriteMaterial extends SpriteMaterial {
9
+ static FEATURE_SPRITE_TEXTURE = this.defineFeature();
10
+ _texture;
11
+ /**
12
+ * Creates a new instance of {@link StandardSpriteMaterial}.
13
+ *
14
+ * @remarks
15
+ * By default, no sprite texture is assigned and the material renders
16
+ * as solid white until a texture is set.
17
+ */ constructor(){
18
+ super();
19
+ this._texture = new DRef();
20
+ }
21
+ /**
22
+ * Gets the 2D texture used by this sprite material.
23
+ *
24
+ * @returns The current sprite texture, or `null` if no texture is assigned.
25
+ */ get spriteTexture() {
26
+ return this._texture.get();
27
+ }
28
+ set spriteTexture(tex) {
29
+ tex = tex ?? null;
30
+ if (tex !== this._texture.get()) {
31
+ this._texture.set(tex);
32
+ this.useFeature(StandardSpriteMaterial.FEATURE_SPRITE_TEXTURE, !!tex);
33
+ this.uniformChanged();
34
+ }
35
+ }
36
+ /**
37
+ * Creates a deep copy of this material instance.
38
+ *
39
+ * @remarks
40
+ * The new instance will copy all relevant state from this material,
41
+ * including the assigned sprite texture reference.
42
+ *
43
+ * @returns A new {@link StandardSpriteMaterial} instance with the same settings.
44
+ */ clone() {
45
+ const other = new StandardSpriteMaterial();
46
+ other.copyFrom(this);
47
+ return other;
48
+ }
49
+ /**
50
+ * Copies the state from another {@link StandardSpriteMaterial} into this instance.
51
+ *
52
+ * @param other - The source material to copy from.
53
+ */ copyFrom(other) {
54
+ super.copyFrom(other);
55
+ this.spriteTexture = other.spriteTexture;
56
+ }
57
+ /**
58
+ * Applies runtime uniform values to the given bind group before drawing.
59
+ *
60
+ * @remarks
61
+ * This method is called by the rendering pipeline to bind GPU resources
62
+ * (such as textures and samplers) associated with this material.
63
+ *
64
+ * @param bindGroup - The bind group to which uniforms and resources are bound.
65
+ * @param ctx - The current draw context providing rendering-state information.
66
+ *
67
+ */ internalApplyUniforms(bindGroup, ctx) {
68
+ if (this.spriteTexture && this.needFragmentColor(ctx)) {
69
+ bindGroup.setTexture('zSpriteTexture', this.spriteTexture, fetchSampler('clamp_linear'));
70
+ }
71
+ }
72
+ /**
73
+ * Declares and configures shader uniforms for this material in the current scope.
74
+ *
75
+ * @remarks
76
+ * This is executed during shader construction. If the active shader stage
77
+ * is a fragment shader, and the material requires fragment color and has
78
+ * a sprite texture assigned, a 2D texture uniform named `zSpriteTexture`
79
+ * is added to the program.
80
+ *
81
+ * @param scope - The current shader function scope used to build the program.
82
+ */ internalSetupUniforms(scope) {
83
+ const pb = scope.$builder;
84
+ if (pb.shaderKind === 'fragment' && this.spriteTexture && this.needFragmentColor()) {
85
+ scope.zSpriteTexture = pb.tex2D().uniform(2);
86
+ }
87
+ }
88
+ /**
89
+ * Computes the fragment color expression for this material within the shader.
90
+ *
91
+ * @remarks
92
+ * - If a sprite texture is assigned, this samples the texture using
93
+ * the interpolated vertex UV coordinates (`zVertexUV`).
94
+ * - If no texture is assigned, this returns a solid white color.
95
+ *
96
+ * @param scope - The current shader function scope providing inputs and uniforms.
97
+ * @returns A shader expression representing the computed fragment color.
98
+ */ calcFragmentColor(scope) {
99
+ const pb = scope.$builder;
100
+ return this.spriteTexture ? pb.textureSample(scope.zSpriteTexture, scope.$inputs.zVertexUV) : pb.vec4(1);
101
+ }
102
+ /**
103
+ * Releases resources held by this material instance.
104
+ *
105
+ * @remarks
106
+ * This is called when the material is disposed. It forwards the dispose
107
+ * call to the internal texture reference so that the associated GPU
108
+ * resource can be released.
109
+ */ onDispose() {
110
+ super.onDispose();
111
+ this._texture.dispose();
112
+ }
113
+ }
114
+
115
+ export { StandardSpriteMaterial };
116
+ //# sourceMappingURL=sprite_std.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sprite_std.js","sources":["../../src/material/sprite_std.ts"],"sourcesContent":["import type { BindGroup, PBInsideFunctionScope, Texture2D } from '@zephyr3d/device';\r\nimport type { Clonable } from '@zephyr3d/base';\r\nimport { DRef } from '@zephyr3d/base';\r\nimport type { DrawContext } from '../render/drawable';\r\nimport { SpriteMaterial } from './sprite';\r\nimport { fetchSampler } from '../utility/misc';\r\n\r\n/**\r\n * Standard Sprite material\r\n * @public\r\n */\r\nexport class StandardSpriteMaterial extends SpriteMaterial implements Clonable<StandardSpriteMaterial> {\r\n static FEATURE_SPRITE_TEXTURE = this.defineFeature();\r\n protected _texture: DRef<Texture2D>;\r\n /**\r\n * Creates a new instance of {@link StandardSpriteMaterial}.\r\n *\r\n * @remarks\r\n * By default, no sprite texture is assigned and the material renders\r\n * as solid white until a texture is set.\r\n */\r\n constructor() {\r\n super();\r\n this._texture = new DRef();\r\n }\r\n /**\r\n * Gets the 2D texture used by this sprite material.\r\n *\r\n * @returns The current sprite texture, or `null` if no texture is assigned.\r\n */\r\n get spriteTexture() {\r\n return this._texture.get();\r\n }\r\n set spriteTexture(tex) {\r\n tex = tex ?? null;\r\n if (tex !== this._texture.get()) {\r\n this._texture.set(tex);\r\n this.useFeature(StandardSpriteMaterial.FEATURE_SPRITE_TEXTURE, !!tex);\r\n this.uniformChanged();\r\n }\r\n }\r\n /**\r\n * Creates a deep copy of this material instance.\r\n *\r\n * @remarks\r\n * The new instance will copy all relevant state from this material,\r\n * including the assigned sprite texture reference.\r\n *\r\n * @returns A new {@link StandardSpriteMaterial} instance with the same settings.\r\n */\r\n clone() {\r\n const other = new StandardSpriteMaterial();\r\n other.copyFrom(this);\r\n return other;\r\n }\r\n /**\r\n * Copies the state from another {@link StandardSpriteMaterial} into this instance.\r\n *\r\n * @param other - The source material to copy from.\r\n */\r\n copyFrom(other: this) {\r\n super.copyFrom(other);\r\n this.spriteTexture = other.spriteTexture;\r\n }\r\n /**\r\n * Applies runtime uniform values to the given bind group before drawing.\r\n *\r\n * @remarks\r\n * This method is called by the rendering pipeline to bind GPU resources\r\n * (such as textures and samplers) associated with this material.\r\n *\r\n * @param bindGroup - The bind group to which uniforms and resources are bound.\r\n * @param ctx - The current draw context providing rendering-state information.\r\n *\r\n */\r\n protected internalApplyUniforms(bindGroup: BindGroup, ctx: DrawContext) {\r\n if (this.spriteTexture && this.needFragmentColor(ctx)) {\r\n bindGroup.setTexture('zSpriteTexture', this.spriteTexture, fetchSampler('clamp_linear'));\r\n }\r\n }\r\n /**\r\n * Declares and configures shader uniforms for this material in the current scope.\r\n *\r\n * @remarks\r\n * This is executed during shader construction. If the active shader stage\r\n * is a fragment shader, and the material requires fragment color and has\r\n * a sprite texture assigned, a 2D texture uniform named `zSpriteTexture`\r\n * is added to the program.\r\n *\r\n * @param scope - The current shader function scope used to build the program.\r\n */\r\n protected internalSetupUniforms(scope: PBInsideFunctionScope) {\r\n const pb = scope.$builder;\r\n if (pb.shaderKind === 'fragment' && this.spriteTexture && this.needFragmentColor()) {\r\n scope.zSpriteTexture = pb.tex2D().uniform(2);\r\n }\r\n }\r\n /**\r\n * Computes the fragment color expression for this material within the shader.\r\n *\r\n * @remarks\r\n * - If a sprite texture is assigned, this samples the texture using\r\n * the interpolated vertex UV coordinates (`zVertexUV`).\r\n * - If no texture is assigned, this returns a solid white color.\r\n *\r\n * @param scope - The current shader function scope providing inputs and uniforms.\r\n * @returns A shader expression representing the computed fragment color.\r\n */\r\n protected calcFragmentColor(scope: PBInsideFunctionScope) {\r\n const pb = scope.$builder;\r\n return this.spriteTexture ? pb.textureSample(scope.zSpriteTexture, scope.$inputs.zVertexUV) : pb.vec4(1);\r\n }\r\n /**\r\n * Releases resources held by this material instance.\r\n *\r\n * @remarks\r\n * This is called when the material is disposed. It forwards the dispose\r\n * call to the internal texture reference so that the associated GPU\r\n * resource can be released.\r\n */\r\n protected onDispose() {\r\n super.onDispose();\r\n this._texture.dispose();\r\n }\r\n}\r\n"],"names":["StandardSpriteMaterial","SpriteMaterial","FEATURE_SPRITE_TEXTURE","defineFeature","_texture","DRef","spriteTexture","get","tex","set","useFeature","uniformChanged","clone","other","copyFrom","internalApplyUniforms","bindGroup","ctx","needFragmentColor","setTexture","fetchSampler","internalSetupUniforms","scope","pb","$builder","shaderKind","zSpriteTexture","tex2D","uniform","calcFragmentColor","textureSample","$inputs","zVertexUV","vec4","onDispose","dispose"],"mappings":";;;;AAOA;;;IAIO,MAAMA,sBAA+BC,SAAAA,cAAAA,CAAAA;AAC1C,IAAA,OAAOC,sBAAyB,GAAA,IAAI,CAACC,aAAa,EAAG;IAC3CC,QAA0B;AACpC;;;;;;AAMC,MACD,WAAc,EAAA;QACZ,KAAK,EAAA;QACL,IAAI,CAACA,QAAQ,GAAG,IAAIC,IAAAA,EAAAA;AACtB;AACA;;;;AAIC,MACD,IAAIC,aAAgB,GAAA;AAClB,QAAA,OAAO,IAAI,CAACF,QAAQ,CAACG,GAAG,EAAA;AAC1B;IACA,IAAID,aAAAA,CAAcE,GAAG,EAAE;AACrBA,QAAAA,GAAAA,GAAMA,GAAO,IAAA,IAAA;AACb,QAAA,IAAIA,QAAQ,IAAI,CAACJ,QAAQ,CAACG,GAAG,EAAI,EAAA;AAC/B,YAAA,IAAI,CAACH,QAAQ,CAACK,GAAG,CAACD,GAAAA,CAAAA;AAClB,YAAA,IAAI,CAACE,UAAU,CAACV,uBAAuBE,sBAAsB,EAAE,CAAC,CAACM,GAAAA,CAAAA;AACjE,YAAA,IAAI,CAACG,cAA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