@zephyr3d/scene 0.9.4 → 0.9.6

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 (517) hide show
  1. package/dist/animation/animationmask.js +224 -0
  2. package/dist/animation/animationmask.js.map +1 -0
  3. package/dist/animation/animationset.js +268 -67
  4. package/dist/animation/animationset.js.map +1 -1
  5. package/dist/animation/animationtrack.js.map +1 -1
  6. package/dist/animation/eulerrotationtrack.js +3 -0
  7. package/dist/animation/eulerrotationtrack.js.map +1 -1
  8. package/dist/animation/fixed_geometry_cache_track.js +7 -0
  9. package/dist/animation/fixed_geometry_cache_track.js.map +1 -1
  10. package/dist/animation/ik_modifier.js.map +1 -1
  11. package/dist/animation/joint_dynamics/collision.js +6 -4
  12. package/dist/animation/joint_dynamics/collision.js.map +1 -1
  13. package/dist/animation/joint_dynamics/controller.js +390 -43
  14. package/dist/animation/joint_dynamics/controller.js.map +1 -1
  15. package/dist/animation/joint_dynamics/joint_dynamics_system.js +62 -3
  16. package/dist/animation/joint_dynamics/joint_dynamics_system.js.map +1 -1
  17. package/dist/animation/joint_dynamics/solver.js +4 -3
  18. package/dist/animation/joint_dynamics/solver.js.map +1 -1
  19. package/dist/animation/joint_dynamics/types.js.map +1 -1
  20. package/dist/animation/joint_dynamics_modifier.js +2 -0
  21. package/dist/animation/joint_dynamics_modifier.js.map +1 -1
  22. package/dist/animation/morphtarget.js +3 -72
  23. package/dist/animation/morphtarget.js.map +1 -1
  24. package/dist/animation/morphtrack.js +3 -0
  25. package/dist/animation/morphtrack.js.map +1 -1
  26. package/dist/animation/pca_geometry_cache_track.js +3 -0
  27. package/dist/animation/pca_geometry_cache_track.js.map +1 -1
  28. package/dist/animation/proptrack.js +3 -0
  29. package/dist/animation/proptrack.js.map +1 -1
  30. package/dist/animation/rotationtrack.js +3 -0
  31. package/dist/animation/rotationtrack.js.map +1 -1
  32. package/dist/animation/scaletrack.js +3 -0
  33. package/dist/animation/scaletrack.js.map +1 -1
  34. package/dist/animation/skeleton.js +254 -79
  35. package/dist/animation/skeleton.js.map +1 -1
  36. package/dist/animation/skeleton_modifier.js.map +1 -1
  37. package/dist/animation/spring_modifier.js.map +1 -1
  38. package/dist/animation/translationtrack.js +3 -0
  39. package/dist/animation/translationtrack.js.map +1 -1
  40. package/dist/app/engine.js +171 -107
  41. package/dist/app/engine.js.map +1 -1
  42. package/dist/app/scriptregistry.js +251 -80
  43. package/dist/app/scriptregistry.js.map +1 -1
  44. package/dist/asset/assetmanager.js +344 -365
  45. package/dist/asset/assetmanager.js.map +1 -1
  46. package/dist/asset/loaders/loader.js +1 -6
  47. package/dist/asset/loaders/loader.js.map +1 -1
  48. package/dist/asset/loaders/zabc/zabc_loader.js.map +1 -1
  49. package/dist/asset/model.js +1000 -131
  50. package/dist/asset/model.js.map +1 -1
  51. package/dist/avatar/wardrobe.js +474 -0
  52. package/dist/avatar/wardrobe.js.map +1 -0
  53. package/dist/index.d.ts +1126 -199
  54. package/dist/index.js +3 -2
  55. package/dist/index.js.map +1 -1
  56. package/dist/material/mixins/lightmodel/pbrmetallicroughness.js +6 -3
  57. package/dist/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -1
  58. package/dist/material/mixins/pbr/common.js +72 -15
  59. package/dist/material/mixins/pbr/common.js.map +1 -1
  60. package/dist/material/msdf_text.js +3 -3
  61. package/dist/material/msdf_text.js.map +1 -1
  62. package/dist/material/msdf_text_sprite.js +4 -4
  63. package/dist/material/msdf_text_sprite.js.map +1 -1
  64. package/dist/material/pbrblueprint.js +102 -102
  65. package/dist/material/pbrblueprint.js.map +1 -1
  66. package/dist/render/envlight.js +54 -1
  67. package/dist/render/envlight.js.map +1 -1
  68. package/dist/render/sky.js +9 -0
  69. package/dist/render/sky.js.map +1 -1
  70. package/dist/scene/batchgroup.js +11 -13
  71. package/dist/scene/batchgroup.js.map +1 -1
  72. package/dist/scene/environment.js +15 -2
  73. package/dist/scene/environment.js.map +1 -1
  74. package/dist/scene/mesh.js +79 -16
  75. package/dist/scene/mesh.js.map +1 -1
  76. package/dist/scene/scene.js +1 -0
  77. package/dist/scene/scene.js.map +1 -1
  78. package/dist/scene/scene_node.js +203 -2
  79. package/dist/scene/scene_node.js.map +1 -1
  80. package/dist/text/font/cff_font.js +890 -0
  81. package/dist/text/font/cff_font.js.map +1 -0
  82. package/dist/text/font/font_asset.js +17 -3
  83. package/dist/text/font/font_asset.js.map +1 -1
  84. package/dist/text/msdf/generator.js.map +1 -1
  85. package/dist/text/msdf/shape.js +4 -1
  86. package/dist/text/msdf/shape.js.map +1 -1
  87. package/dist/text/runtime/msdf_text_atlas_manager.js +4 -1
  88. package/dist/text/runtime/msdf_text_atlas_manager.js.map +1 -1
  89. package/dist/utility/blueprint/material/inputs.js +1157 -1154
  90. package/dist/utility/blueprint/material/inputs.js.map +1 -1
  91. package/dist/utility/bounding_volume.js.map +1 -1
  92. package/dist/utility/pmrem.js +34 -8
  93. package/dist/utility/pmrem.js.map +1 -1
  94. package/dist/utility/serialization/manager.js +22 -9
  95. package/dist/utility/serialization/manager.js.map +1 -1
  96. package/dist/utility/serialization/scene/animation.js +700 -7
  97. package/dist/utility/serialization/scene/animation.js.map +1 -1
  98. package/dist/utility/serialization/scene/mesh.js +64 -4
  99. package/dist/utility/serialization/scene/mesh.js.map +1 -1
  100. package/dist/utility/serialization/scene/node.js +187 -8
  101. package/dist/utility/serialization/scene/node.js.map +1 -1
  102. package/dist/utility/serialization/types.js.map +1 -1
  103. package/dist/utility/textures/sheenlut.js +138 -0
  104. package/dist/utility/textures/sheenlut.js.map +1 -0
  105. package/package.json +2 -2
  106. package/dist/animation/ik/ik_chain_builder.js +0 -68
  107. package/dist/animation/ik/ik_chain_builder.js.map +0 -1
  108. package/dist/animation/ik/ik_pole_constraint.js +0 -123
  109. package/dist/animation/ik/ik_pole_constraint.js.map +0 -1
  110. package/dist/animation/ik/ik_track.js +0 -96
  111. package/dist/animation/ik/ik_track.js.map +0 -1
  112. package/dist/animation/ik_postprocessor.js +0 -71
  113. package/dist/animation/ik_postprocessor.js.map +0 -1
  114. package/dist/animation/joint_dynamics/math.js +0 -16
  115. package/dist/animation/joint_dynamics/math.js.map +0 -1
  116. package/dist/animation/manual_transform_processor.js +0 -156
  117. package/dist/animation/manual_transform_processor.js.map +0 -1
  118. package/dist/animation/skeleton_postprocessor.js +0 -50
  119. package/dist/animation/skeleton_postprocessor.js.map +0 -1
  120. package/dist/animation/spring2/collision.js +0 -469
  121. package/dist/animation/spring2/collision.js.map +0 -1
  122. package/dist/animation/spring2/constraints.js +0 -329
  123. package/dist/animation/spring2/constraints.js.map +0 -1
  124. package/dist/animation/spring2/controller.js +0 -434
  125. package/dist/animation/spring2/controller.js.map +0 -1
  126. package/dist/animation/spring2/math.js +0 -16
  127. package/dist/animation/spring2/math.js.map +0 -1
  128. package/dist/animation/spring2/solver.js +0 -624
  129. package/dist/animation/spring2/solver.js.map +0 -1
  130. package/dist/animation/spring2/spring_system.js +0 -118
  131. package/dist/animation/spring2/spring_system.js.map +0 -1
  132. package/dist/animation/spring2/types.js +0 -19
  133. package/dist/animation/spring2/types.js.map +0 -1
  134. package/dist/animation/spring_postprocessor.js +0 -54
  135. package/dist/animation/spring_postprocessor.js.map +0 -1
  136. package/dist/asset/loaders/gltf/gltf_loader.js +0 -1273
  137. package/dist/asset/loaders/gltf/gltf_loader.js.map +0 -1
  138. package/dist/asset/loaders/gltf/helpers.js +0 -331
  139. package/dist/asset/loaders/gltf/helpers.js.map +0 -1
  140. package/dist/material/sprite3d.js +0 -301
  141. package/dist/material/sprite3d.js.map +0 -1
  142. package/dist/material/sprite3d_std.js +0 -116
  143. package/dist/material/sprite3d_std.js.map +0 -1
  144. package/dist/material/sprite3dblueprint.js +0 -235
  145. package/dist/material/sprite3dblueprint.js.map +0 -1
  146. package/dist/material/sprite_sdf.js +0 -106
  147. package/dist/material/sprite_sdf.js.map +0 -1
  148. package/dist/material/terrainmaterial.js +0 -368
  149. package/dist/material/terrainmaterial.js.map +0 -1
  150. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimemgr.js +0 -38
  151. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimemgr.js.map +0 -1
  152. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimescript.js +0 -10
  153. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimescript.js.map +0 -1
  154. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptingsystem.js +0 -127
  155. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptingsystem.js.map +0 -1
  156. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptregistry.js +0 -263
  157. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptregistry.js.map +0 -1
  158. package/dist/render/deferredlightpass.js +0 -510
  159. package/dist/render/deferredlightpass.js.map +0 -1
  160. package/dist/render/deferredshadowlightpass.js +0 -428
  161. package/dist/render/deferredshadowlightpass.js.map +0 -1
  162. package/dist/render/gbufferpass.js +0 -50
  163. package/dist/render/gbufferpass.js.map +0 -1
  164. package/dist/scene/sdftextsprite.js +0 -322
  165. package/dist/scene/sdftextsprite.js.map +0 -1
  166. package/dist/scene/sprite3d.js +0 -18
  167. package/dist/scene/sprite3d.js.map +0 -1
  168. package/dist/scene/terrain/grass.js +0 -280
  169. package/dist/scene/terrain/grass.js.map +0 -1
  170. package/dist/scene/terrain/heightfield.js +0 -475
  171. package/dist/scene/terrain/heightfield.js.map +0 -1
  172. package/dist/scene/terrain/patch.js +0 -532
  173. package/dist/scene/terrain/patch.js.map +0 -1
  174. package/dist/scene/terrain/quadtree.js +0 -461
  175. package/dist/scene/terrain/quadtree.js.map +0 -1
  176. package/dist/scene/terrain/terrain.js +0 -231
  177. package/dist/scene/terrain/terrain.js.map +0 -1
  178. package/dist/src/animation/animation.js +0 -127
  179. package/dist/src/animation/animation.js.map +0 -1
  180. package/dist/src/animation/animationset.js +0 -255
  181. package/dist/src/animation/animationset.js.map +0 -1
  182. package/dist/src/animation/animationtrack.js +0 -34
  183. package/dist/src/animation/animationtrack.js.map +0 -1
  184. package/dist/src/animation/eulerrotationtrack.js +0 -52
  185. package/dist/src/animation/eulerrotationtrack.js.map +0 -1
  186. package/dist/src/animation/morphtarget.js +0 -93
  187. package/dist/src/animation/morphtarget.js.map +0 -1
  188. package/dist/src/animation/morphtrack.js +0 -70
  189. package/dist/src/animation/morphtrack.js.map +0 -1
  190. package/dist/src/animation/proptrack.js +0 -161
  191. package/dist/src/animation/proptrack.js.map +0 -1
  192. package/dist/src/animation/rotationtrack.js +0 -51
  193. package/dist/src/animation/rotationtrack.js.map +0 -1
  194. package/dist/src/animation/scaletrack.js +0 -50
  195. package/dist/src/animation/scaletrack.js.map +0 -1
  196. package/dist/src/animation/skeleton.js +0 -204
  197. package/dist/src/animation/skeleton.js.map +0 -1
  198. package/dist/src/animation/translationtrack.js +0 -50
  199. package/dist/src/animation/translationtrack.js.map +0 -1
  200. package/dist/src/app/app.js +0 -129
  201. package/dist/src/app/app.js.map +0 -1
  202. package/dist/src/app/inputmgr.js +0 -267
  203. package/dist/src/app/inputmgr.js.map +0 -1
  204. package/dist/src/asset/assetmanager.js +0 -404
  205. package/dist/src/asset/assetmanager.js.map +0 -1
  206. package/dist/src/asset/builtin.js +0 -337
  207. package/dist/src/asset/builtin.js.map +0 -1
  208. package/dist/src/asset/loaders/dds/dds.js +0 -470
  209. package/dist/src/asset/loaders/dds/dds.js.map +0 -1
  210. package/dist/src/asset/loaders/dds/dds_loader.js +0 -28
  211. package/dist/src/asset/loaders/dds/dds_loader.js.map +0 -1
  212. package/dist/src/asset/loaders/gltf/gltf_loader.js +0 -1265
  213. package/dist/src/asset/loaders/gltf/gltf_loader.js.map +0 -1
  214. package/dist/src/asset/loaders/gltf/helpers.js +0 -327
  215. package/dist/src/asset/loaders/gltf/helpers.js.map +0 -1
  216. package/dist/src/asset/loaders/hdr/hdr.js +0 -180
  217. package/dist/src/asset/loaders/hdr/hdr.js.map +0 -1
  218. package/dist/src/asset/loaders/image/tga_Loader.js +0 -116
  219. package/dist/src/asset/loaders/image/tga_Loader.js.map +0 -1
  220. package/dist/src/asset/loaders/image/webimage_loader.js +0 -63
  221. package/dist/src/asset/loaders/image/webimage_loader.js.map +0 -1
  222. package/dist/src/asset/loaders/loader.js +0 -45
  223. package/dist/src/asset/loaders/loader.js.map +0 -1
  224. package/dist/src/asset/model.js +0 -414
  225. package/dist/src/asset/model.js.map +0 -1
  226. package/dist/src/blitter/bilateralblur.js +0 -221
  227. package/dist/src/blitter/bilateralblur.js.map +0 -1
  228. package/dist/src/blitter/blitter.js +0 -390
  229. package/dist/src/blitter/blitter.js.map +0 -1
  230. package/dist/src/blitter/box.js +0 -118
  231. package/dist/src/blitter/box.js.map +0 -1
  232. package/dist/src/blitter/copy.js +0 -22
  233. package/dist/src/blitter/copy.js.map +0 -1
  234. package/dist/src/blitter/gaussianblur.js +0 -228
  235. package/dist/src/blitter/gaussianblur.js.map +0 -1
  236. package/dist/src/camera/base.js +0 -92
  237. package/dist/src/camera/base.js.map +0 -1
  238. package/dist/src/camera/camera.js +0 -1005
  239. package/dist/src/camera/camera.js.map +0 -1
  240. package/dist/src/camera/fps.js +0 -238
  241. package/dist/src/camera/fps.js.map +0 -1
  242. package/dist/src/camera/orbit.js +0 -245
  243. package/dist/src/camera/orbit.js.map +0 -1
  244. package/dist/src/camera/orthocamera.js +0 -167
  245. package/dist/src/camera/orthocamera.js.map +0 -1
  246. package/dist/src/camera/perspectivecamera.js +0 -141
  247. package/dist/src/camera/perspectivecamera.js.map +0 -1
  248. package/dist/src/index.js +0 -120
  249. package/dist/src/index.js.map +0 -1
  250. package/dist/src/material/blinn.js +0 -81
  251. package/dist/src/material/blinn.js.map +0 -1
  252. package/dist/src/material/grassmaterial.js +0 -113
  253. package/dist/src/material/grassmaterial.js.map +0 -1
  254. package/dist/src/material/lambert.js +0 -92
  255. package/dist/src/material/lambert.js.map +0 -1
  256. package/dist/src/material/material.js +0 -301
  257. package/dist/src/material/material.js.map +0 -1
  258. package/dist/src/material/meshmaterial.js +0 -704
  259. package/dist/src/material/meshmaterial.js.map +0 -1
  260. package/dist/src/material/mixins/albedocolor.js +0 -76
  261. package/dist/src/material/mixins/albedocolor.js.map +0 -1
  262. package/dist/src/material/mixins/foliage.js +0 -47
  263. package/dist/src/material/mixins/foliage.js.map +0 -1
  264. package/dist/src/material/mixins/lightmodel/blinnphong.js +0 -112
  265. package/dist/src/material/mixins/lightmodel/blinnphong.js.map +0 -1
  266. package/dist/src/material/mixins/lightmodel/lambert.js +0 -58
  267. package/dist/src/material/mixins/lightmodel/lambert.js.map +0 -1
  268. package/dist/src/material/mixins/lightmodel/pbrmetallicroughness.js +0 -178
  269. package/dist/src/material/mixins/lightmodel/pbrmetallicroughness.js.map +0 -1
  270. package/dist/src/material/mixins/lightmodel/pbrspecularglossness.js +0 -139
  271. package/dist/src/material/mixins/lightmodel/pbrspecularglossness.js.map +0 -1
  272. package/dist/src/material/mixins/lit.js +0 -476
  273. package/dist/src/material/mixins/lit.js.map +0 -1
  274. package/dist/src/material/mixins/pbr/common.js +0 -918
  275. package/dist/src/material/mixins/pbr/common.js.map +0 -1
  276. package/dist/src/material/mixins/texture.js +0 -172
  277. package/dist/src/material/mixins/texture.js.map +0 -1
  278. package/dist/src/material/mixins/vertexcolor.js +0 -56
  279. package/dist/src/material/mixins/vertexcolor.js.map +0 -1
  280. package/dist/src/material/particle.js +0 -178
  281. package/dist/src/material/particle.js.map +0 -1
  282. package/dist/src/material/pbrmr.js +0 -97
  283. package/dist/src/material/pbrmr.js.map +0 -1
  284. package/dist/src/material/pbrsg.js +0 -97
  285. package/dist/src/material/pbrsg.js.map +0 -1
  286. package/dist/src/material/shader/helper.js +0 -1209
  287. package/dist/src/material/shader/helper.js.map +0 -1
  288. package/dist/src/material/terrain-cm.js +0 -606
  289. package/dist/src/material/terrain-cm.js.map +0 -1
  290. package/dist/src/material/terrainmaterial.js +0 -375
  291. package/dist/src/material/terrainmaterial.js.map +0 -1
  292. package/dist/src/material/unlit.js +0 -41
  293. package/dist/src/material/unlit.js.map +0 -1
  294. package/dist/src/material/water.js +0 -417
  295. package/dist/src/material/water.js.map +0 -1
  296. package/dist/src/posteffect/bloom.js +0 -361
  297. package/dist/src/posteffect/bloom.js.map +0 -1
  298. package/dist/src/posteffect/compositor.js +0 -226
  299. package/dist/src/posteffect/compositor.js.map +0 -1
  300. package/dist/src/posteffect/fxaa.js +0 -273
  301. package/dist/src/posteffect/fxaa.js.map +0 -1
  302. package/dist/src/posteffect/grayscale.js +0 -69
  303. package/dist/src/posteffect/grayscale.js.map +0 -1
  304. package/dist/src/posteffect/motionblur.js +0 -96
  305. package/dist/src/posteffect/motionblur.js.map +0 -1
  306. package/dist/src/posteffect/posteffect.js +0 -126
  307. package/dist/src/posteffect/posteffect.js.map +0 -1
  308. package/dist/src/posteffect/sao.js +0 -324
  309. package/dist/src/posteffect/sao.js.map +0 -1
  310. package/dist/src/posteffect/ssr.js +0 -489
  311. package/dist/src/posteffect/ssr.js.map +0 -1
  312. package/dist/src/posteffect/taa.js +0 -172
  313. package/dist/src/posteffect/taa.js.map +0 -1
  314. package/dist/src/posteffect/tonemap.js +0 -94
  315. package/dist/src/posteffect/tonemap.js.map +0 -1
  316. package/dist/src/render/abuffer_oit.js +0 -361
  317. package/dist/src/render/abuffer_oit.js.map +0 -1
  318. package/dist/src/render/clipmap.js +0 -851
  319. package/dist/src/render/clipmap.js.map +0 -1
  320. package/dist/src/render/cluster_light.js +0 -333
  321. package/dist/src/render/cluster_light.js.map +0 -1
  322. package/dist/src/render/cull_visitor.js +0 -187
  323. package/dist/src/render/cull_visitor.js.map +0 -1
  324. package/dist/src/render/depthpass.js +0 -68
  325. package/dist/src/render/depthpass.js.map +0 -1
  326. package/dist/src/render/drawable_mixin.js +0 -227
  327. package/dist/src/render/drawable_mixin.js.map +0 -1
  328. package/dist/src/render/envlight.js +0 -463
  329. package/dist/src/render/envlight.js.map +0 -1
  330. package/dist/src/render/fbm_wavegenerator.js +0 -251
  331. package/dist/src/render/fbm_wavegenerator.js.map +0 -1
  332. package/dist/src/render/fft_wavegenerator.js +0 -1006
  333. package/dist/src/render/fft_wavegenerator.js.map +0 -1
  334. package/dist/src/render/fullscreenquad.js +0 -38
  335. package/dist/src/render/fullscreenquad.js.map +0 -1
  336. package/dist/src/render/gerstner_wavegenerator.js +0 -314
  337. package/dist/src/render/gerstner_wavegenerator.js.map +0 -1
  338. package/dist/src/render/globalbindgroup_allocator.js +0 -60
  339. package/dist/src/render/globalbindgroup_allocator.js.map +0 -1
  340. package/dist/src/render/hzb.js +0 -273
  341. package/dist/src/render/hzb.js.map +0 -1
  342. package/dist/src/render/lightpass.js +0 -172
  343. package/dist/src/render/lightpass.js.map +0 -1
  344. package/dist/src/render/objectcolorpass.js +0 -51
  345. package/dist/src/render/objectcolorpass.js.map +0 -1
  346. package/dist/src/render/primitive.js +0 -364
  347. package/dist/src/render/primitive.js.map +0 -1
  348. package/dist/src/render/render_queue.js +0 -467
  349. package/dist/src/render/render_queue.js.map +0 -1
  350. package/dist/src/render/renderbundle_wrapper.js +0 -152
  351. package/dist/src/render/renderbundle_wrapper.js.map +0 -1
  352. package/dist/src/render/renderer.js +0 -455
  353. package/dist/src/render/renderer.js.map +0 -1
  354. package/dist/src/render/renderpass.js +0 -200
  355. package/dist/src/render/renderpass.js.map +0 -1
  356. package/dist/src/render/shadowmap_pass.js +0 -56
  357. package/dist/src/render/shadowmap_pass.js.map +0 -1
  358. package/dist/src/render/sky.js +0 -1103
  359. package/dist/src/render/sky.js.map +0 -1
  360. package/dist/src/render/weightedblended_oit.js +0 -168
  361. package/dist/src/render/weightedblended_oit.js.map +0 -1
  362. package/dist/src/scene/batchgroup.js +0 -162
  363. package/dist/src/scene/batchgroup.js.map +0 -1
  364. package/dist/src/scene/environment.js +0 -209
  365. package/dist/src/scene/environment.js.map +0 -1
  366. package/dist/src/scene/graph_node.js +0 -72
  367. package/dist/src/scene/graph_node.js.map +0 -1
  368. package/dist/src/scene/light.js +0 -416
  369. package/dist/src/scene/light.js.map +0 -1
  370. package/dist/src/scene/mesh.js +0 -341
  371. package/dist/src/scene/mesh.js.map +0 -1
  372. package/dist/src/scene/octree.js +0 -649
  373. package/dist/src/scene/octree.js.map +0 -1
  374. package/dist/src/scene/particlesys.js +0 -738
  375. package/dist/src/scene/particlesys.js.map +0 -1
  376. package/dist/src/scene/raycast_visitor.js +0 -103
  377. package/dist/src/scene/raycast_visitor.js.map +0 -1
  378. package/dist/src/scene/scene.js +0 -284
  379. package/dist/src/scene/scene.js.map +0 -1
  380. package/dist/src/scene/scene_node.js +0 -732
  381. package/dist/src/scene/scene_node.js.map +0 -1
  382. package/dist/src/scene/terrain/grass.js +0 -278
  383. package/dist/src/scene/terrain/grass.js.map +0 -1
  384. package/dist/src/scene/terrain/heightfield.js +0 -475
  385. package/dist/src/scene/terrain/heightfield.js.map +0 -1
  386. package/dist/src/scene/terrain/patch.js +0 -530
  387. package/dist/src/scene/terrain/patch.js.map +0 -1
  388. package/dist/src/scene/terrain/quadtree.js +0 -461
  389. package/dist/src/scene/terrain/quadtree.js.map +0 -1
  390. package/dist/src/scene/terrain/terrain.js +0 -246
  391. package/dist/src/scene/terrain/terrain.js.map +0 -1
  392. package/dist/src/scene/terrain-cm/grass.js +0 -594
  393. package/dist/src/scene/terrain-cm/grass.js.map +0 -1
  394. package/dist/src/scene/terrain-cm/grassmaterial.js +0 -159
  395. package/dist/src/scene/terrain-cm/grassmaterial.js.map +0 -1
  396. package/dist/src/scene/terrain-cm/terrain-cm.js +0 -538
  397. package/dist/src/scene/terrain-cm/terrain-cm.js.map +0 -1
  398. package/dist/src/scene/water.js +0 -374
  399. package/dist/src/scene/water.js.map +0 -1
  400. package/dist/src/shaders/atmosphere.js +0 -957
  401. package/dist/src/shaders/atmosphere.js.map +0 -1
  402. package/dist/src/shaders/fog.js +0 -112
  403. package/dist/src/shaders/fog.js.map +0 -1
  404. package/dist/src/shaders/misc.js +0 -266
  405. package/dist/src/shaders/misc.js.map +0 -1
  406. package/dist/src/shaders/noise.js +0 -222
  407. package/dist/src/shaders/noise.js.map +0 -1
  408. package/dist/src/shaders/pbr.js +0 -51
  409. package/dist/src/shaders/pbr.js.map +0 -1
  410. package/dist/src/shaders/shadow.js +0 -636
  411. package/dist/src/shaders/shadow.js.map +0 -1
  412. package/dist/src/shaders/ssr.js +0 -490
  413. package/dist/src/shaders/ssr.js.map +0 -1
  414. package/dist/src/shaders/temporal.js +0 -215
  415. package/dist/src/shaders/temporal.js.map +0 -1
  416. package/dist/src/shaders/water.js +0 -756
  417. package/dist/src/shaders/water.js.map +0 -1
  418. package/dist/src/shadow/esm.js +0 -237
  419. package/dist/src/shadow/esm.js.map +0 -1
  420. package/dist/src/shadow/pcf_opt.js +0 -181
  421. package/dist/src/shadow/pcf_opt.js.map +0 -1
  422. package/dist/src/shadow/pcf_pd.js +0 -189
  423. package/dist/src/shadow/pcf_pd.js.map +0 -1
  424. package/dist/src/shadow/shader.js +0 -37
  425. package/dist/src/shadow/shader.js.map +0 -1
  426. package/dist/src/shadow/shadow_impl.js +0 -15
  427. package/dist/src/shadow/shadow_impl.js.map +0 -1
  428. package/dist/src/shadow/shadowmapper.js +0 -790
  429. package/dist/src/shadow/shadowmapper.js.map +0 -1
  430. package/dist/src/shadow/ssm.js +0 -159
  431. package/dist/src/shadow/ssm.js.map +0 -1
  432. package/dist/src/shadow/vsm.js +0 -297
  433. package/dist/src/shadow/vsm.js.map +0 -1
  434. package/dist/src/shapes/box.js +0 -386
  435. package/dist/src/shapes/box.js.map +0 -1
  436. package/dist/src/shapes/cylinder.js +0 -125
  437. package/dist/src/shapes/cylinder.js.map +0 -1
  438. package/dist/src/shapes/plane.js +0 -88
  439. package/dist/src/shapes/plane.js.map +0 -1
  440. package/dist/src/shapes/shape.js +0 -87
  441. package/dist/src/shapes/shape.js.map +0 -1
  442. package/dist/src/shapes/sphere.js +0 -114
  443. package/dist/src/shapes/sphere.js.map +0 -1
  444. package/dist/src/shapes/tetrahedron.js +0 -188
  445. package/dist/src/shapes/tetrahedron.js.map +0 -1
  446. package/dist/src/shapes/torus.js +0 -111
  447. package/dist/src/shapes/torus.js.map +0 -1
  448. package/dist/src/utility/aabbtree.js +0 -400
  449. package/dist/src/utility/aabbtree.js.map +0 -1
  450. package/dist/src/utility/bounding_volume.js +0 -29
  451. package/dist/src/utility/bounding_volume.js.map +0 -1
  452. package/dist/src/utility/debug.js +0 -28
  453. package/dist/src/utility/debug.js.map +0 -1
  454. package/dist/src/utility/draco/decoder.js +0 -116
  455. package/dist/src/utility/draco/decoder.js.map +0 -1
  456. package/dist/src/utility/misc.js +0 -105
  457. package/dist/src/utility/misc.js.map +0 -1
  458. package/dist/src/utility/panorama.js +0 -163
  459. package/dist/src/utility/panorama.js.map +0 -1
  460. package/dist/src/utility/pmrem.js +0 -354
  461. package/dist/src/utility/pmrem.js.map +0 -1
  462. package/dist/src/utility/rendermipmap.js +0 -115
  463. package/dist/src/utility/rendermipmap.js.map +0 -1
  464. package/dist/src/utility/serialization/json.js +0 -402
  465. package/dist/src/utility/serialization/json.js.map +0 -1
  466. package/dist/src/utility/serialization/manager.js +0 -623
  467. package/dist/src/utility/serialization/manager.js.map +0 -1
  468. package/dist/src/utility/serialization/scene/animation.js +0 -248
  469. package/dist/src/utility/serialization/scene/animation.js.map +0 -1
  470. package/dist/src/utility/serialization/scene/batch.js +0 -59
  471. package/dist/src/utility/serialization/scene/batch.js.map +0 -1
  472. package/dist/src/utility/serialization/scene/camera.js +0 -790
  473. package/dist/src/utility/serialization/scene/camera.js.map +0 -1
  474. package/dist/src/utility/serialization/scene/common.js +0 -222
  475. package/dist/src/utility/serialization/scene/common.js.map +0 -1
  476. package/dist/src/utility/serialization/scene/light.js +0 -575
  477. package/dist/src/utility/serialization/scene/light.js.map +0 -1
  478. package/dist/src/utility/serialization/scene/material.js +0 -1111
  479. package/dist/src/utility/serialization/scene/material.js.map +0 -1
  480. package/dist/src/utility/serialization/scene/mesh.js +0 -148
  481. package/dist/src/utility/serialization/scene/mesh.js.map +0 -1
  482. package/dist/src/utility/serialization/scene/misc.js +0 -39
  483. package/dist/src/utility/serialization/scene/misc.js.map +0 -1
  484. package/dist/src/utility/serialization/scene/node.js +0 -451
  485. package/dist/src/utility/serialization/scene/node.js.map +0 -1
  486. package/dist/src/utility/serialization/scene/particle.js +0 -425
  487. package/dist/src/utility/serialization/scene/particle.js.map +0 -1
  488. package/dist/src/utility/serialization/scene/primitive.js +0 -692
  489. package/dist/src/utility/serialization/scene/primitive.js.map +0 -1
  490. package/dist/src/utility/serialization/scene/scene.js +0 -704
  491. package/dist/src/utility/serialization/scene/scene.js.map +0 -1
  492. package/dist/src/utility/serialization/scene/terrain.js +0 -488
  493. package/dist/src/utility/serialization/scene/terrain.js.map +0 -1
  494. package/dist/src/utility/serialization/scene/water.js +0 -465
  495. package/dist/src/utility/serialization/scene/water.js.map +0 -1
  496. package/dist/src/utility/shprojector.js +0 -297
  497. package/dist/src/utility/shprojector.js.map +0 -1
  498. package/dist/src/utility/textures/ggxlut.js +0 -213
  499. package/dist/src/utility/textures/ggxlut.js.map +0 -1
  500. package/dist/src/utility/textures/gradientnoise.js +0 -62
  501. package/dist/src/utility/textures/gradientnoise.js.map +0 -1
  502. package/dist/src/utility/textures/randomnoise.js +0 -41
  503. package/dist/src/utility/textures/randomnoise.js.map +0 -1
  504. package/dist/src/values.js +0 -162
  505. package/dist/src/values.js.map +0 -1
  506. package/dist/utility/blueprint/material/common.js +0 -7
  507. package/dist/utility/blueprint/material/common.js.map +0 -1
  508. package/dist/utility/serialization/blueprint/constants.js +0 -255
  509. package/dist/utility/serialization/blueprint/constants.js.map +0 -1
  510. package/dist/utility/serialization/blueprint/material/constants.js +0 -203
  511. package/dist/utility/serialization/blueprint/material/constants.js.map +0 -1
  512. package/dist/utility/serialization/blueprint/material/texture.js +0 -165
  513. package/dist/utility/serialization/blueprint/material/texture.js.map +0 -1
  514. package/dist/utility/serialization/scene/cloth_script.js +0 -834
  515. package/dist/utility/serialization/scene/cloth_script.js.map +0 -1
  516. package/dist/utility/serialization/scene/spring_script.js +0 -596
  517. package/dist/utility/serialization/scene/spring_script.js.map +0 -1
@@ -1,1209 +0,0 @@
1
- import { Vector3, Vector4, Vector2 } from '@zephyr3d/base';
2
- import { RENDER_PASS_TYPE_DEPTH, RENDER_PASS_TYPE_SHADOWMAP, RENDER_PASS_TYPE_OBJECT_COLOR, RENDER_PASS_TYPE_LIGHT, MaterialVaryingFlags, MAX_CLUSTERED_LIGHTS, MORPH_WEIGHTS_VECTOR_COUNT, MORPH_TARGET_POSITION, MORPH_TARGET_NORMAL, MORPH_TARGET_TANGENT, MORPH_ATTRIBUTE_VECTOR_COUNT } from '../../values.js';
3
- import { ProgramBuilder } from '@zephyr3d/device';
4
- import { decodeNormalizedFloatFromRGBA, linearToGamma } from '../../shaders/misc.js';
5
- import { Application } from '../../app/app.js';
6
- import { fetchSampler } from '../../utility/misc.js';
7
- import { getDefaultAtmosphereParams, getAtmosphereParamsStruct } from '../../shaders/atmosphere.js';
8
- import { getDefaultHeightFogParams, getHeightFogParamsStruct, calculateFog } from '../../shaders/fog.js';
9
-
10
- const UNIFORM_NAME_LIGHT_BUFFER = 'Z_UniformLightBuffer';
11
- const UNIFORM_NAME_LIGHT_INDEX_TEXTURE = 'Z_UniformLightIndexTex';
12
- const UNIFORM_NAME_BAKED_SKY_MAP = 'Z_UniformBakedSky';
13
- const UNIFORM_NAME_AERIALPERSPECTIVE_LUT = 'Z_UniformAerialPerspectiveLUT';
14
- const UNIFORM_NAME_SKYDISTANTLIGHT_LUT = 'Z_UniformSkyDistantLightLUT';
15
- const UNIFORM_NAME_SHADOW_MAP = 'Z_UniformShadowMap';
16
- const UNIFORM_NAME_LINEAR_DEPTH_MAP = 'Z_UniformLinearDepth';
17
- const UNIFORM_NAME_LINEAR_DEPTH_MAP_SIZE = 'Z_UniformLinearDepthSize';
18
- const UNIFORM_NAME_SCENE_COLOR_MAP = 'Z_UniformSceneColor';
19
- const UNIFORM_NAME_SCENE_COLOR_MAP_SIZE = 'Z_UniformSceneColorSize';
20
- const UNIFORM_NAME_HIZ_DEPTH_MAP = 'Z_UniformHiZDepth';
21
- const UNIFORM_NAME_HIZ_DEPTH_MAP_INFO = 'Z_UniformHiZDepthInfo';
22
- const UNIFORM_NAME_WORLD_MATRIX = 'Z_UniformWorldMatrix';
23
- const UNIFORM_NAME_PREV_WORLD_MATRIX = 'Z_UniformPrevWorldMatrix';
24
- const UNIFORM_NAME_PREV_WORLD_MATRXI_FRAME = 'Z_UniformPrevWorldMatrixFrame';
25
- const UNIFORM_NAME_INSTANCE_DATA_STRIDE = 'Z_UniformInstanceDataStride';
26
- const UNIFORM_NAME_INSTANCE_DATA = 'Z_UniformInstanceData';
27
- const UNIFORM_NAME_INSTANCE_DATA_OFFSET = 'Z_UniformInstanceDataOffset';
28
- const UNIFORM_NAME_BONE_MATRICES = 'Z_UniformBoneMatrices';
29
- const UNIFORM_NAME_BONE_TEXTURE_SIZE = 'Z_UniformBoneTexSize';
30
- const UNIFORM_NAME_BONE_INV_BIND_MATRIX = 'Z_UniformBoneInvBindMatrix';
31
- const UNIFORM_NAME_MORPH_DATA = 'Z_UniformMorphData';
32
- const UNIFORM_NAME_MORPH_INFO = 'Z_UniformMorphInfo';
33
- /**
34
- * Helper shader functions for the builtin material system
35
- * @public
36
- */ class ShaderHelper {
37
- static BILLBOARD_SPHERICAL = 1;
38
- static BILLBOARD_SYLINDRAL = 2;
39
- static MATERIAL_INSTANCE_DATA_OFFSET = 9;
40
- /** @internal */ static defaultSunDir = Vector3.one().inplaceNormalize();
41
- /** @internal */ static SKIN_MATRIX_NAME = 'Z_SkinMatrix';
42
- static SKIN_PREV_MATRIX_NAME = 'Z_PrevSkinMatrix';
43
- static SKIN_BONE_OFFSET = 'Z_boneOffset';
44
- /** @internal */ static _drawableBindGroupLayouts = {};
45
- /** @internal */ static _lightUniformShadow = {
46
- sunDir: new Vector3(),
47
- envLightStrength: 1,
48
- shadowCascades: 1,
49
- positionAndRange: new Vector4(),
50
- directionAndCutoff: new Vector4(),
51
- diffuseAndIntensity: new Vector4(),
52
- cascadeDistances: new Vector4(),
53
- depthBiasValues: new Vector4(),
54
- shadowCameraParams: new Vector4(),
55
- depthBiasScales: new Vector4(),
56
- shadowMatrices: new Float32Array(16 * 4)
57
- };
58
- /** @internal */ static _fogUniforms = {
59
- withAerialPerspective: 0,
60
- fogType: 0,
61
- additive: 0,
62
- atmosphereParams: getDefaultAtmosphereParams(),
63
- heightFogParams: getDefaultHeightFogParams()
64
- };
65
- static getWorldMatrixUniformName() {
66
- return UNIFORM_NAME_WORLD_MATRIX;
67
- }
68
- static getPrevWorldMatrixUniformName() {
69
- return UNIFORM_NAME_PREV_WORLD_MATRIX;
70
- }
71
- static getPrevWorldMatrixFrameUniformName() {
72
- return UNIFORM_NAME_PREV_WORLD_MATRXI_FRAME;
73
- }
74
- static getInstanceDataUniformName() {
75
- return UNIFORM_NAME_INSTANCE_DATA;
76
- }
77
- static getInstanceDataOffsetUniformName() {
78
- return UNIFORM_NAME_INSTANCE_DATA_OFFSET;
79
- }
80
- static getInstanceDataStrideUniformName() {
81
- return UNIFORM_NAME_INSTANCE_DATA_STRIDE;
82
- }
83
- static getBoneMatricesUniformName() {
84
- return UNIFORM_NAME_BONE_MATRICES;
85
- }
86
- static getBoneTextureSizeUniformName() {
87
- return UNIFORM_NAME_BONE_TEXTURE_SIZE;
88
- }
89
- static getBoneInvBindMatrixUniformName() {
90
- return UNIFORM_NAME_BONE_INV_BIND_MATRIX;
91
- }
92
- static getMorphDataUniformName() {
93
- return UNIFORM_NAME_MORPH_DATA;
94
- }
95
- static getMorphInfoUniformName() {
96
- return UNIFORM_NAME_MORPH_INFO;
97
- }
98
- static getLightBufferUniformName() {
99
- return UNIFORM_NAME_LIGHT_BUFFER;
100
- }
101
- static getDrawableBindGroupLayout(skinning, morphing, instancing) {
102
- const hash = `${skinning ? 1 : 0}${morphing ? 1 : 0}${instancing ? 1 : 0}`;
103
- let bindGroupLayout = this._drawableBindGroupLayouts[hash];
104
- if (!bindGroupLayout) {
105
- const device = Application.instance.device;
106
- const buildInfo = new ProgramBuilder(device).buildRender({
107
- vertex (pb) {
108
- ShaderHelper.vertexShaderDrawableStuff(this, skinning, morphing, instancing);
109
- pb.main(function() {});
110
- },
111
- fragment (pb) {
112
- pb.main(function() {});
113
- }
114
- });
115
- bindGroupLayout = buildInfo[2][1];
116
- this._drawableBindGroupLayouts[hash] = bindGroupLayout;
117
- }
118
- return bindGroupLayout;
119
- }
120
- /**
121
- * Prepares the fragment shader which is going to be used in our material system
122
- *
123
- * @remarks
124
- * This function will setup all nessesary uniforms acoording to the drawing context
125
- *
126
- * @param pb - The program builder
127
- * @param ctx - The drawing context
128
- */ static prepareFragmentShader(pb, ctx) {
129
- this.setupGlobalUniforms(pb, ctx);
130
- }
131
- /**
132
- * Prepares the vertex shader which is going to be used in our material system
133
- *
134
- * @remarks
135
- * This function will setup all nessesary uniforms according to the drawing context
136
- *
137
- * @param pb - The program builder
138
- * @param ctx - The drawing context
139
- */ static prepareVertexShader(pb, ctx) {
140
- this.setupGlobalUniforms(pb, ctx);
141
- this.prepareVertexShaderCommon(pb, ctx);
142
- }
143
- /** @internal */ static setupGlobalUniforms(pb, ctx) {
144
- const scope = pb.getGlobalScope();
145
- const cameraStruct = pb.defineStruct([
146
- pb.vec4('position'),
147
- pb.vec4('clipPlane'),
148
- pb.mat4('viewProjectionMatrix'),
149
- pb.mat4('invViewProjectionMatrix'),
150
- pb.mat4('unjitteredVPMatrix'),
151
- pb.mat4('jitteredInvVPMatrix'),
152
- pb.mat4('viewMatrix'),
153
- pb.mat4('projectionMatrix'),
154
- pb.mat4('invProjectionMatrix'),
155
- pb.vec4('params'),
156
- ...ctx.motionVectors && ctx.renderPass.type === RENDER_PASS_TYPE_DEPTH ? [
157
- pb.mat4('prevUnjitteredVPMatrix')
158
- ] : [],
159
- pb.vec2('renderSize'),
160
- pb.vec2('jitterValue'),
161
- pb.float('roughnessFactor'),
162
- pb.float('frameDeltaTime'),
163
- pb.float('elapsedTime'),
164
- pb.int('framestamp')
165
- ]);
166
- if (ctx.renderPass.type === RENDER_PASS_TYPE_SHADOWMAP) {
167
- const lightStruct = pb.defineStruct([
168
- pb.vec4('positionAndRange'),
169
- pb.vec4('directionCutoff'),
170
- pb.mat4('viewMatrix'),
171
- pb.vec4('depthBias'),
172
- pb.int('lightType')
173
- ]);
174
- scope.camera = cameraStruct().uniform(0);
175
- scope.light = lightStruct().uniform(0);
176
- } else if (ctx.renderPass.type === RENDER_PASS_TYPE_DEPTH || ctx.renderPass.type === RENDER_PASS_TYPE_OBJECT_COLOR) {
177
- scope.camera = cameraStruct().uniform(0);
178
- } else if (ctx.renderPass.type === RENDER_PASS_TYPE_LIGHT) {
179
- const useClusteredLighting = !ctx.currentShadowLight;
180
- if (ctx.materialFlags & MaterialVaryingFlags.APPLY_FOG) {
181
- const fogStructMembers = [
182
- pb.int('withAerialPerspective'),
183
- pb.int('fogType'),
184
- pb.int('additive'),
185
- getAtmosphereParamsStruct(pb)('atmosphereParams'),
186
- getHeightFogParamsStruct(pb)('heightFogParams')
187
- ];
188
- const fogStruct = pb.defineStruct(fogStructMembers);
189
- scope.fog = fogStruct().uniform(0);
190
- scope[UNIFORM_NAME_AERIALPERSPECTIVE_LUT] = pb.tex2D().uniform(0);
191
- scope[UNIFORM_NAME_SKYDISTANTLIGHT_LUT] = pb.tex2D().uniform(0);
192
- }
193
- const lightStruct = ctx.currentShadowLight ? pb.defineStruct([
194
- pb.vec3('sunDir'),
195
- pb.int('shadowCascades'),
196
- pb.vec4('positionAndRange'),
197
- pb.vec4('directionAndCutoff'),
198
- pb.vec4('diffuseAndIntensity'),
199
- pb.vec4('cascadeDistances'),
200
- pb.vec4('depthBiasValues'),
201
- pb.vec4('shadowCameraParams'),
202
- pb.vec4('depthBiasScales'),
203
- pb.vec4[16]('shadowMatrices'),
204
- pb.float('envLightStrength')
205
- ]) : pb.defineStruct([
206
- pb.vec3('sunDir'),
207
- pb.float('envLightStrength'),
208
- pb.vec4('clusterParams'),
209
- pb.ivec4('countParams'),
210
- pb.ivec2('lightIndexTexSize')
211
- ]);
212
- scope.camera = cameraStruct().uniform(0);
213
- scope.light = lightStruct().uniform(0);
214
- if (useClusteredLighting) {
215
- scope[UNIFORM_NAME_LIGHT_BUFFER] = pb.vec4[(MAX_CLUSTERED_LIGHTS + 1) * 3]().uniformBuffer(0);
216
- scope[UNIFORM_NAME_LIGHT_INDEX_TEXTURE] = (pb.getDevice().type === 'webgl' ? pb.tex2D() : pb.utex2D()).uniform(0);
217
- }
218
- scope[UNIFORM_NAME_BAKED_SKY_MAP] = pb.texCube().uniform(0);
219
- if (ctx.currentShadowLight) {
220
- const scope = pb.getGlobalScope();
221
- const shadowMapParams = ctx.shadowMapInfo.get(ctx.currentShadowLight);
222
- const tex = shadowMapParams.shadowMap.isTextureCube() ? shadowMapParams.shadowMap.isDepth() ? scope.$builder.texCubeShadow() : scope.$builder.texCube() : shadowMapParams.shadowMap.isTexture2D() ? shadowMapParams.shadowMap.isDepth() ? scope.$builder.tex2DShadow() : scope.$builder.tex2D() : shadowMapParams.shadowMap.isDepth() ? scope.$builder.tex2DArrayShadow() : scope.$builder.tex2DArray();
223
- if (!shadowMapParams.shadowMap.isDepth() && !ctx.device.getDeviceCaps().textureCaps.getTextureFormatInfo(shadowMapParams.shadowMap.format).filterable) {
224
- tex.sampleType('unfilterable-float');
225
- }
226
- scope[UNIFORM_NAME_SHADOW_MAP] = tex.uniform(0);
227
- }
228
- if (ctx.drawEnvLight) {
229
- ctx.env.light.envLight.initShaderBindings(pb);
230
- }
231
- if (ctx.linearDepthTexture) {
232
- scope[UNIFORM_NAME_LINEAR_DEPTH_MAP] = pb.tex2D().uniform(0);
233
- scope[UNIFORM_NAME_LINEAR_DEPTH_MAP_SIZE] = pb.vec2().uniform(0);
234
- }
235
- if (ctx.sceneColorTexture) {
236
- scope[UNIFORM_NAME_SCENE_COLOR_MAP] = pb.tex2D().uniform(0);
237
- scope[UNIFORM_NAME_SCENE_COLOR_MAP_SIZE] = pb.vec2().uniform(0);
238
- }
239
- if (ctx.HiZTexture) {
240
- scope[UNIFORM_NAME_HIZ_DEPTH_MAP] = pb.tex2D().uniform(0);
241
- scope[UNIFORM_NAME_HIZ_DEPTH_MAP_INFO] = pb.vec4().uniform(0);
242
- }
243
- }
244
- }
245
- /**
246
- * This function checks if the shader needs to process skeletal animation.
247
- *
248
- * @param scope - Current shader scope
249
- *
250
- * @returns true if the shader needs to process skeletal animation, otherwise false.
251
- */ static hasSkinning(scope) {
252
- return !!scope[UNIFORM_NAME_BONE_MATRICES];
253
- }
254
- /**
255
- * This function checks if the shader needs to process morph target animation.
256
- *
257
- * @param scope - Current shader scope
258
- *
259
- * @returns true if the shader needs to process morph target animation, otherwise false.
260
- */ static hasMorphing(scope) {
261
- return !!scope[UNIFORM_NAME_MORPH_DATA];
262
- }
263
- /**
264
- * Calculate skinning matrix for current vertex
265
- *
266
- * @param scope - Current shader scope
267
- *
268
- * @returns Skinning matrix for current vertex, or null if there is not skeletal animation
269
- */ static calculateSkinMatrix(scope) {
270
- if (!this.hasSkinning(scope)) {
271
- return null;
272
- }
273
- const pb = scope.$builder;
274
- const funcNameGetBoneMatrixFromTexture = 'Z_getBoneMatrixFromTexture';
275
- pb.func(funcNameGetBoneMatrixFromTexture, [
276
- pb.int('boneIndex')
277
- ], function() {
278
- const boneTexture = this[UNIFORM_NAME_BONE_MATRICES];
279
- this.$l.uvOffsets = pb.textureSampleLevel(boneTexture, pb.div(pb.vec2(0.5), this[UNIFORM_NAME_BONE_TEXTURE_SIZE]), 0);
280
- this.$l.currentOffset = pb.int(this.uvOffsets.x);
281
- this.$l.w = this[UNIFORM_NAME_BONE_TEXTURE_SIZE].x;
282
- this.$l.pixelIndex = pb.float(pb.mul(pb.add(this.boneIndex, this.currentOffset), 4));
283
- this.$l.xIndex = pb.mod(this.pixelIndex, this.w);
284
- this.$l.yIndex = pb.floor(pb.div(this.pixelIndex, this.w));
285
- this.$l.u1 = pb.div(pb.add(this.xIndex, 0.5), this.w);
286
- this.$l.u2 = pb.div(pb.add(this.xIndex, 1.5), this.w);
287
- this.$l.u3 = pb.div(pb.add(this.xIndex, 2.5), this.w);
288
- this.$l.u4 = pb.div(pb.add(this.xIndex, 3.5), this.w);
289
- this.$l.v = pb.div(pb.add(this.yIndex, 0.5), this.w);
290
- this.$l.row1 = pb.textureSampleLevel(boneTexture, pb.vec2(this.u1, this.v), 0);
291
- this.$l.row2 = pb.textureSampleLevel(boneTexture, pb.vec2(this.u2, this.v), 0);
292
- this.$l.row3 = pb.textureSampleLevel(boneTexture, pb.vec2(this.u3, this.v), 0);
293
- this.$l.row4 = pb.textureSampleLevel(boneTexture, pb.vec2(this.u4, this.v), 0);
294
- this.$return(pb.mat4(this.row1, this.row2, this.row3, this.row4));
295
- });
296
- const funcNameGetSkinningMatrix = 'Z_getSkinningMatrix';
297
- pb.func(funcNameGetSkinningMatrix, [], function() {
298
- const invBindMatrix = this[UNIFORM_NAME_BONE_INV_BIND_MATRIX];
299
- const blendIndices = scope.$getVertexAttrib('blendIndices');
300
- const blendWeights = scope.$getVertexAttrib('blendWeights');
301
- this.$l.m0 = scope.$g[funcNameGetBoneMatrixFromTexture](pb.int(blendIndices[0]));
302
- this.$l.m1 = scope.$g[funcNameGetBoneMatrixFromTexture](pb.int(blendIndices[1]));
303
- this.$l.m2 = scope.$g[funcNameGetBoneMatrixFromTexture](pb.int(blendIndices[2]));
304
- this.$l.m3 = scope.$g[funcNameGetBoneMatrixFromTexture](pb.int(blendIndices[3]));
305
- this.$l.m = pb.add(pb.mul(this.m0, blendWeights.x), pb.mul(this.m1, blendWeights.y), pb.mul(this.m2, blendWeights.z), pb.mul(this.m3, blendWeights.w));
306
- this.$return(pb.mul(invBindMatrix, this.m));
307
- });
308
- return scope.$g[funcNameGetSkinningMatrix]();
309
- }
310
- static calculateMorphDelta(scope, attrib) {
311
- const pb = scope.$builder;
312
- const isWebGL1 = pb.getDevice().type === 'webgl';
313
- if (pb.shaderKind !== 'vertex') {
314
- throw new Error(`ShaderHelper.calculateMorphDelta(): must be called at vertex stage`);
315
- }
316
- const funcName = 'Z_calculateMorph';
317
- const that = this;
318
- pb.func(funcName, [
319
- pb.int('offset')
320
- ], function() {
321
- this.$if(pb.lessThan(this.offset, 0), function() {
322
- this.$return(pb.vec4(0));
323
- });
324
- this.$l.vertexIndex = isWebGL1 ? pb.int(scope.$inputs.zFakeVertexID) : pb.int(scope.$builtins.vertexIndex);
325
- const morphInfo = scope[that.getMorphInfoUniformName()];
326
- this.$l.metaData = pb.ivec4(morphInfo[0]);
327
- this.$l.texWidth = pb.float(this.metaData.x);
328
- this.$l.texHeight = pb.float(this.metaData.y);
329
- this.$l.numVertices = this.metaData.z;
330
- this.$l.numTargets = this.metaData.w;
331
- this.$l.value = pb.vec4(0);
332
- if (isWebGL1) {
333
- this.$for(pb.int('i'), 0, MORPH_WEIGHTS_VECTOR_COUNT, function() {
334
- this.$for(pb.int('j'), 0, 4, function() {
335
- this.$l.index = pb.add(pb.mul(this.i, 4), this.j);
336
- this.$if(pb.greaterThanEqual(this.index, this.numTargets), function() {
337
- this.$return(this.value);
338
- });
339
- this.$l.weight = morphInfo.at(pb.add(1, this.i)).at(this.j);
340
- this.$l.pixelIndex = pb.float(pb.add(this.offset, pb.mul(this.index, this.numVertices), this.vertexIndex));
341
- this.$l.xIndex = pb.mod(this.pixelIndex, this.texWidth);
342
- this.$l.yIndex = pb.floor(pb.div(this.pixelIndex, this.texWidth));
343
- this.$l.u = pb.div(pb.add(this.xIndex, 0.5), this.texWidth);
344
- this.$l.v = pb.div(pb.add(this.yIndex, 0.5), this.texHeight);
345
- this.$l.morphValue = pb.textureSampleLevel(this[that.getMorphDataUniformName()], pb.vec2(this.u, this.v), 0);
346
- this.value = pb.add(this.value, pb.mul(this.morphValue, this.weight));
347
- });
348
- });
349
- } else {
350
- this.$for(pb.int('t'), 0, this.numTargets, function() {
351
- this.$l.i = pb.sar(this.t, 2);
352
- this.$l.j = pb.compAnd(this.t, 3);
353
- this.$l.weight = morphInfo.at(pb.add(1, this.i)).at(this.j);
354
- this.$l.pixelIndex = pb.float(pb.add(this.offset, pb.mul(this.t, this.numVertices), this.vertexIndex));
355
- this.$l.xIndex = pb.mod(this.pixelIndex, this.texWidth);
356
- this.$l.yIndex = pb.floor(pb.div(this.pixelIndex, this.texWidth));
357
- this.$l.u = pb.div(pb.add(this.xIndex, 0.5), this.texWidth);
358
- this.$l.v = pb.div(pb.add(this.yIndex, 0.5), this.texHeight);
359
- this.$l.morphValue = pb.textureSampleLevel(this[that.getMorphDataUniformName()], pb.vec2(this.u, this.v), 0);
360
- this.value = pb.add(this.value, pb.mul(this.morphValue, this.weight));
361
- });
362
- }
363
- this.$return(this.value);
364
- });
365
- const pos = 1 + MORPH_WEIGHTS_VECTOR_COUNT + (attrib >> 2);
366
- const comp = attrib & 3;
367
- const offset = scope[this.getMorphInfoUniformName()][pos][comp];
368
- return scope[funcName](pb.int(offset));
369
- }
370
- /** @internal */ static prepareSkinAnimation(scope) {
371
- if (!this.hasSkinning(scope)) {
372
- return;
373
- }
374
- const that = this;
375
- const pb = scope.$builder;
376
- const funcNameGetBoneMatrixFromTexture = 'Z_getBoneMatrixFromTexture';
377
- pb.func(funcNameGetBoneMatrixFromTexture, [
378
- pb.float('boneIndex'),
379
- pb.float('boneOffset')
380
- ], function() {
381
- const boneTexture = this[UNIFORM_NAME_BONE_MATRICES];
382
- this.$l.w = this[UNIFORM_NAME_BONE_TEXTURE_SIZE].x;
383
- this.$l.pixelIndex = pb.mul(pb.add(this.boneIndex, this.boneOffset), 4);
384
- this.$l.xIndex = pb.mod(this.pixelIndex, this.w);
385
- this.$l.yIndex = pb.floor(pb.div(this.pixelIndex, this.w));
386
- this.$l.u1 = pb.div(pb.add(this.xIndex, 0.5), this.w);
387
- this.$l.u2 = pb.div(pb.add(this.xIndex, 1.5), this.w);
388
- this.$l.u3 = pb.div(pb.add(this.xIndex, 2.5), this.w);
389
- this.$l.u4 = pb.div(pb.add(this.xIndex, 3.5), this.w);
390
- this.$l.v = pb.div(pb.add(this.yIndex, 0.5), this.w);
391
- this.$l.row1 = pb.textureSampleLevel(boneTexture, pb.vec2(this.u1, this.v), 0);
392
- this.$l.row2 = pb.textureSampleLevel(boneTexture, pb.vec2(this.u2, this.v), 0);
393
- this.$l.row3 = pb.textureSampleLevel(boneTexture, pb.vec2(this.u3, this.v), 0);
394
- this.$l.row4 = pb.textureSampleLevel(boneTexture, pb.vec2(this.u4, this.v), 0);
395
- this.$return(pb.mat4(this.row1, this.row2, this.row3, this.row4));
396
- });
397
- const funcNameGetSkinningMatrix = 'Z_getSkinningMatrix';
398
- pb.func(funcNameGetSkinningMatrix, [
399
- pb.float('boneOffset')
400
- ], function() {
401
- const invBindMatrix = this[UNIFORM_NAME_BONE_INV_BIND_MATRIX];
402
- const blendIndices = scope.$getVertexAttrib('blendIndices');
403
- const blendWeights = scope.$getVertexAttrib('blendWeights');
404
- this.$l.m0 = scope.$g[funcNameGetBoneMatrixFromTexture](blendIndices[0], this.boneOffset);
405
- this.$l.m1 = scope.$g[funcNameGetBoneMatrixFromTexture](blendIndices[1], this.boneOffset);
406
- this.$l.m2 = scope.$g[funcNameGetBoneMatrixFromTexture](blendIndices[2], this.boneOffset);
407
- this.$l.m3 = scope.$g[funcNameGetBoneMatrixFromTexture](blendIndices[3], this.boneOffset);
408
- this.$l.m = pb.add(pb.mul(this.m0, blendWeights.x), pb.mul(this.m1, blendWeights.y), pb.mul(this.m2, blendWeights.z), pb.mul(this.m3, blendWeights.w));
409
- this.$return(pb.mul(invBindMatrix, this.m));
410
- });
411
- const motionVector = !!this.getUnjitteredViewProjectionMatrix(scope);
412
- const boneTexture = scope[UNIFORM_NAME_BONE_MATRICES];
413
- scope.$l[that.SKIN_BONE_OFFSET] = pb.textureSampleLevel(boneTexture, pb.div(pb.vec2(0.5), scope[UNIFORM_NAME_BONE_TEXTURE_SIZE]), 0).xy;
414
- scope.$l[that.SKIN_MATRIX_NAME] = scope[funcNameGetSkinningMatrix](scope[that.SKIN_BONE_OFFSET].x);
415
- if (motionVector) {
416
- scope.$l[that.SKIN_PREV_MATRIX_NAME] = scope[funcNameGetSkinningMatrix](scope[that.SKIN_BONE_OFFSET].y);
417
- }
418
- }
419
- /**
420
- * Calculates the vertex position of type vec3 in object space
421
- *
422
- * @param scope - Current shader scope
423
- * @param skinMatrix - The skinning matrix if there is skeletal animation, otherwise null
424
- * @returns The calculated vertex position in object space, or null if pos is null
425
- */ static resolveVertexPosition(scope) {
426
- const pb = scope.$builder;
427
- if (pb.shaderKind !== 'vertex') {
428
- throw new Error(`ShaderHelper.resolveVertexPosition(): must be called at vertex stage`);
429
- }
430
- if (!pb.getGlobalScope().$getVertexAttrib('position')) {
431
- pb.getGlobalScope().$inputs.Z_pos = pb.vec3().attrib('position');
432
- }
433
- const that = this;
434
- const params = scope[that.SKIN_MATRIX_NAME] && scope[that.SKIN_PREV_MATRIX_NAME] ? [
435
- pb.mat4('skinMatrix'),
436
- pb.mat4('prevSkinMatrix')
437
- ] : scope[that.SKIN_MATRIX_NAME] ? [
438
- pb.mat4('skinMatrix')
439
- ] : [];
440
- pb.func('Z_resolveVertexPosition', params, function() {
441
- this.$l.opos = this.$getVertexAttrib('position').xyz;
442
- if (that.hasMorphing(scope)) {
443
- this.opos = pb.add(this.opos, that.calculateMorphDelta(this, MORPH_TARGET_POSITION).xyz);
444
- }
445
- if (this.skinMatrix) {
446
- this.$l.pos = pb.mul(this.skinMatrix, pb.vec4(this.opos, 1)).xyz;
447
- } else {
448
- this.$l.pos = this.opos;
449
- }
450
- const prevUnjitteredVPMatrix = that.getPrevUnjitteredViewProjectionMatrix(this);
451
- if (prevUnjitteredVPMatrix) {
452
- this.$l.unjitteredVPMatrix = that.getUnjitteredViewProjectionMatrix(this);
453
- this.$l.worldPos = pb.mul(that.getWorldMatrix(this), pb.vec4(this.pos, 1));
454
- if (this.prevSkinMatrix) {
455
- this.$l.prevWorldPos = pb.mul(that.getPrevWorldMatrix(this), pb.mul(this.prevSkinMatrix, pb.vec4(this.opos, 1)));
456
- } else {
457
- this.$l.prevWorldPos = pb.mul(that.getPrevWorldMatrix(this), pb.vec4(this.pos, 1));
458
- }
459
- this.$outputs.zMotionVectorPosCurrent = pb.mul(this.unjitteredVPMatrix, this.worldPos);
460
- this.$outputs.zMotionVectorPosPrev = pb.mul(prevUnjitteredVPMatrix, this.prevWorldPos);
461
- }
462
- this.$return(this.pos);
463
- });
464
- return scope[that.SKIN_MATRIX_NAME] && scope[that.SKIN_PREV_MATRIX_NAME] ? scope.Z_resolveVertexPosition(scope[that.SKIN_MATRIX_NAME], scope[that.SKIN_PREV_MATRIX_NAME]) : scope[that.SKIN_MATRIX_NAME] ? scope.Z_resolveVertexPosition(scope[that.SKIN_MATRIX_NAME]) : scope.Z_resolveVertexPosition();
465
- }
466
- /**
467
- * Resolve motion vector
468
- *
469
- * @param scope - Current shader scope
470
- * @param worldPos - Current object position in world space
471
- * @param prevWorldPos - Previous object position in world space
472
- */ static resolveMotionVector(scope, worldPos, prevWorldPos) {
473
- const that = this;
474
- const pb = scope.$builder;
475
- const prevUnjitteredVPMatrix = that.getPrevUnjitteredViewProjectionMatrix(scope);
476
- if (prevUnjitteredVPMatrix) {
477
- const unjitteredVPMatrix = that.getUnjitteredViewProjectionMatrix(scope);
478
- scope.$outputs.zMotionVectorPosCurrent = pb.mul(unjitteredVPMatrix, pb.vec4(worldPos.xyz, 1));
479
- scope.$outputs.zMotionVectorPosPrev = pb.mul(prevUnjitteredVPMatrix, pb.vec4(prevWorldPos.xyz, 1));
480
- }
481
- }
482
- /**
483
- * Calculates the normal vector of type vec3 in object space
484
- *
485
- * @param scope - Current shader scope
486
- * @param normal - Vertex normal input, must be type of vec3, null if no vertex normal input
487
- * @param skinMatrix - The skinning matrix if there is skeletal animation, otherwise null
488
- * @returns The calculated normal vector in object space, or null if normal is null
489
- */ static resolveVertexNormal(scope, normal) {
490
- const pb = scope.$builder;
491
- if (pb.shaderKind !== 'vertex') {
492
- throw new Error(`ShaderHelper.resolveVertexNormal(): must be called in vertex stage`);
493
- }
494
- const funcScope = pb.getCurrentFunctionScope();
495
- if (!funcScope || !funcScope.$isMain()) {
496
- throw new Error(`ShaderHelper.resolveVertexNormal(): must be called at entry function`);
497
- }
498
- if (!normal) {
499
- if (!scope.$getVertexAttrib('normal')) {
500
- scope.$inputs.Z_normal = pb.vec3().attrib('normal');
501
- }
502
- normal = scope.$getVertexAttrib('normal');
503
- }
504
- if (this.hasMorphing(scope)) {
505
- normal = pb.normalize(pb.add(normal, this.calculateMorphDelta(scope, MORPH_TARGET_NORMAL).xyz));
506
- }
507
- if (scope[this.SKIN_MATRIX_NAME]) {
508
- return pb.mul(scope[this.SKIN_MATRIX_NAME], pb.vec4(normal, 0)).xyz;
509
- } else {
510
- return normal;
511
- }
512
- }
513
- /**
514
- * Calculates the tangent vector of type vec3 in object space
515
- *
516
- * @param scope - Current shader scope
517
- * @param tangent - Vertex tangent input, must be type of vec4, null if no vertex tangent input
518
- * @param skinMatrix - The skinning matrix if there is skeletal animation, otherwise null
519
- * @returns The calculated tangent vector of type vec4 in object space, or null if tangent is null
520
- */ static resolveVertexTangent(scope, tangent) {
521
- const pb = scope.$builder;
522
- if (pb.shaderKind !== 'vertex') {
523
- throw new Error(`ShaderHelper.resolveVertexTangent(): must be called in vertex stage`);
524
- }
525
- const funcScope = pb.getCurrentFunctionScope();
526
- if (!funcScope || !funcScope.$isMain()) {
527
- throw new Error(`ShaderHelper.resolveVertexTangent(): must be called at entry function`);
528
- }
529
- if (!tangent) {
530
- if (!scope.$getVertexAttrib('tangent')) {
531
- scope.$inputs.Z_tangent = pb.vec4().attrib('tangent');
532
- }
533
- tangent = scope.$getVertexAttrib('tangent');
534
- }
535
- if (this.hasMorphing(scope)) {
536
- tangent = pb.normalize(pb.add(tangent, pb.vec4(this.calculateMorphDelta(scope, MORPH_TARGET_TANGENT).xyz, 0)));
537
- }
538
- if (scope[this.SKIN_MATRIX_NAME]) {
539
- return pb.vec4(pb.mul(scope[this.SKIN_MATRIX_NAME], pb.vec4(tangent.xyz, 0)).xyz, tangent.w);
540
- } else {
541
- return tangent;
542
- }
543
- }
544
- /**
545
- * Gets the uniform variable of type mat4 which holds the world matrix of current object to be drawn
546
- * @param scope - Current shader scope
547
- * @returns The world matrix of current object to be drawn
548
- */ static getWorldMatrix(scope) {
549
- const pb = scope.$builder;
550
- return scope[UNIFORM_NAME_WORLD_MATRIX] ?? pb.mat4(this.getInstancedUniform(scope, 0), this.getInstancedUniform(scope, 1), this.getInstancedUniform(scope, 2), this.getInstancedUniform(scope, 3));
551
- }
552
- /**
553
- * Gets the uniform variable of type mat4 which holds the world matrix at previous frame of current object to be drawn
554
- * @param scope - Current shader scope
555
- * @returns The world matrix at previous frame of current object to be drawn
556
- */ static getPrevWorldMatrix(scope) {
557
- const pb = scope.$builder;
558
- const that = this;
559
- const framestamp = this.getFramestamp(scope);
560
- if (scope[UNIFORM_NAME_WORLD_MATRIX]) {
561
- if (pb.getDevice().type === 'webgpu') {
562
- pb.func('Z_getPrevWorldMatrix', [
563
- pb.int('framestamp')
564
- ], function() {
565
- this.$if(pb.equal(this.framestamp, this[UNIFORM_NAME_PREV_WORLD_MATRXI_FRAME]), function() {
566
- this.$return(this[UNIFORM_NAME_PREV_WORLD_MATRIX]);
567
- }).$else(function() {
568
- this.$return(this[UNIFORM_NAME_WORLD_MATRIX]);
569
- });
570
- });
571
- return scope.Z_getPrevWorldMatrix(framestamp);
572
- } else {
573
- return scope.$choice(pb.equal(framestamp, scope[UNIFORM_NAME_PREV_WORLD_MATRXI_FRAME]), scope[UNIFORM_NAME_PREV_WORLD_MATRIX], scope[UNIFORM_NAME_WORLD_MATRIX]);
574
- }
575
- } else {
576
- pb.func('Z_getPrevWorldMatrix', [
577
- pb.int('framestamp')
578
- ], function() {
579
- this.$l.prevFrame = pb.floatBitsToInt(that.getInstancedUniform(this, 4).x);
580
- this.$l.index = this.$choice(pb.equal(this.framestamp, this.prevFrame), pb.int(5), pb.int(0));
581
- this.$return(pb.mat4(that.getInstancedUniform(scope, this.index), that.getInstancedUniform(scope, pb.add(this.index, 1)), that.getInstancedUniform(scope, pb.add(this.index, 2)), that.getInstancedUniform(scope, pb.add(this.index, 3))));
582
- });
583
- return scope.Z_getPrevWorldMatrix(framestamp);
584
- }
585
- }
586
- /**
587
- * Gets the instance uniform value of type vec4 by uniform index
588
- * @param scope - Current shader scope
589
- * @returns instance uniform value
590
- */ static getInstancedUniform(scope, uniformIndex) {
591
- const pb = scope.$builder;
592
- return scope[UNIFORM_NAME_INSTANCE_DATA].at(pb.add(pb.mul(scope[UNIFORM_NAME_INSTANCE_DATA_STRIDE], pb.uint(scope.$builtins.instanceIndex)), scope[UNIFORM_NAME_INSTANCE_DATA_OFFSET], pb.uint(uniformIndex)));
593
- }
594
- /**
595
- * Gets the uniform variable of type mat4 which holds the normal matrix of current object to be drawn
596
- *
597
- * @param scope - Current shader scope
598
- * @returns The normal matrix of current object to be drawn
599
- */ static getNormalMatrix(scope) {
600
- return this.getWorldMatrix(scope);
601
- }
602
- /**
603
- * Vertex shader drawable stuff
604
- *
605
- * @param scope - Current shader scope
606
- * @param skinning - true if skinning is used, otherwise false.
607
- * @param instanced - true if instancing is used, otherwise false.
608
- */ static vertexShaderDrawableStuff(scope, skinning, morphing, instanced) {
609
- const pb = scope.$builder;
610
- if (instanced) {
611
- scope[UNIFORM_NAME_INSTANCE_DATA_STRIDE] = pb.uint().uniform(1);
612
- scope[UNIFORM_NAME_INSTANCE_DATA_OFFSET] = pb.uint().uniform(1);
613
- scope[UNIFORM_NAME_INSTANCE_DATA] = pb.vec4[65536 >> 4]().uniformBuffer(3);
614
- } else {
615
- scope[UNIFORM_NAME_WORLD_MATRIX] = pb.mat4().uniform(1);
616
- scope[UNIFORM_NAME_PREV_WORLD_MATRIX] = pb.mat4().uniform(1);
617
- scope[UNIFORM_NAME_PREV_WORLD_MATRXI_FRAME] = pb.int().uniform(1);
618
- }
619
- if (skinning) {
620
- scope[UNIFORM_NAME_BONE_MATRICES] = pb.tex2D().uniform(1).sampleType('unfilterable-float');
621
- scope[UNIFORM_NAME_BONE_INV_BIND_MATRIX] = pb.mat4().uniform(1);
622
- scope[UNIFORM_NAME_BONE_TEXTURE_SIZE] = pb.vec2().uniform(1);
623
- }
624
- if (morphing) {
625
- scope[UNIFORM_NAME_MORPH_DATA] = pb.tex2D().uniform(1).sampleType('unfilterable-float');
626
- scope[UNIFORM_NAME_MORPH_INFO] = pb.vec4[1 + MORPH_WEIGHTS_VECTOR_COUNT + MORPH_ATTRIBUTE_VECTOR_COUNT]().uniformBuffer(1);
627
- }
628
- }
629
- /** @internal */ static prepareVertexShaderCommon(pb, ctx) {
630
- this.vertexShaderDrawableStuff(pb.getGlobalScope(), !!(ctx.materialFlags & MaterialVaryingFlags.SKIN_ANIMATION), !!(ctx.materialFlags & MaterialVaryingFlags.MORPH_ANIMATION), !!(ctx.materialFlags & MaterialVaryingFlags.INSTANCING));
631
- }
632
- /** @internal */ static setCameraUniforms(bindGroup, ctx, linear) {
633
- const pos = ctx.camera.getWorldPosition();
634
- const useJitter = ctx.motionVectors && ctx.renderPass.type !== RENDER_PASS_TYPE_SHADOWMAP && ctx.renderPass.type !== RENDER_PASS_TYPE_OBJECT_COLOR;
635
- const cameraStruct = {
636
- position: new Vector4(pos.x, pos.y, pos.z, ctx.camera.clipPlane ? 1 : 0),
637
- clipPlane: ctx.camera.clipPlane ?? Vector4.zero(),
638
- renderSize: new Vector2(ctx.renderWidth, ctx.renderHeight),
639
- viewProjectionMatrix: useJitter ? ctx.camera.jitteredVPMatrix : ctx.camera.viewProjectionMatrix,
640
- unjitteredVPMatrix: ctx.camera.viewProjectionMatrix,
641
- jitteredInvVPMatrix: useJitter ? ctx.camera.jitteredInvVPMatrix : ctx.camera.invViewProjectionMatrix,
642
- jitterValue: ctx.camera.jitterValue,
643
- invViewProjectionMatrix: ctx.camera.invViewProjectionMatrix,
644
- projectionMatrix: ctx.camera.getProjectionMatrix(),
645
- invProjectionMatrix: ctx.camera.getInvProjectionMatrix(),
646
- viewMatrix: ctx.camera.viewMatrix,
647
- params: new Vector4(ctx.camera.getNearPlane(), ctx.camera.getFarPlane(), ctx.flip ? -1 : 1, linear ? 0 : 1),
648
- roughnessFactor: ctx.camera.SSR ? ctx.camera.ssrRoughnessFactor : 1,
649
- frameDeltaTime: Application.instance.device.frameInfo.elapsedFrame * 0.001,
650
- elapsedTime: Application.instance.device.frameInfo.elapsedOverall * 0.001,
651
- framestamp: Application.instance.device.frameInfo.frameCounter
652
- };
653
- if (ctx.motionVectors && ctx.renderPass.type === RENDER_PASS_TYPE_DEPTH) {
654
- cameraStruct.prevUnjitteredVPMatrix = ctx.camera.prevVPMatrix;
655
- }
656
- if (ctx.renderPass.type === RENDER_PASS_TYPE_LIGHT) {
657
- if (ctx.linearDepthTexture) {
658
- bindGroup.setTexture(UNIFORM_NAME_LINEAR_DEPTH_MAP, ctx.linearDepthTexture);
659
- bindGroup.setValue(UNIFORM_NAME_LINEAR_DEPTH_MAP_SIZE, new Vector2(ctx.linearDepthTexture.width, ctx.linearDepthTexture.height));
660
- }
661
- if (ctx.sceneColorTexture) {
662
- bindGroup.setTexture(UNIFORM_NAME_SCENE_COLOR_MAP, ctx.sceneColorTexture);
663
- bindGroup.setValue(UNIFORM_NAME_SCENE_COLOR_MAP_SIZE, new Vector2(ctx.sceneColorTexture.width, ctx.sceneColorTexture.height));
664
- }
665
- if (ctx.HiZTexture) {
666
- bindGroup.setTexture(UNIFORM_NAME_HIZ_DEPTH_MAP, ctx.HiZTexture, fetchSampler('clamp_nearest'));
667
- bindGroup.setValue(UNIFORM_NAME_HIZ_DEPTH_MAP_INFO, new Vector4(ctx.HiZTexture.width, ctx.HiZTexture.height, ctx.HiZTexture.mipLevelCount, 0));
668
- }
669
- }
670
- bindGroup.setValue('camera', cameraStruct);
671
- }
672
- /** @internal */ static setLightUniformsShadowMap(bindGroup, ctx, light) {
673
- if (light) {
674
- const shadowMapParams = ctx.shadowMapInfo.get(light);
675
- bindGroup.setValue('light', {
676
- positionAndRange: light.positionAndRange,
677
- directionCutoff: light.directionAndCutoff,
678
- viewMatrix: light.viewMatrix,
679
- depthBias: shadowMapParams.depthBiasValues[0],
680
- lightType: light.lightType
681
- });
682
- }
683
- }
684
- /** @internal */ static setFogUniforms(bindGroup, withAerialPerspective, fogType, additive, atmosphereParams, heightFogParams, aerialPerspectiveLUT, skyDistantLightLUT) {
685
- this._fogUniforms.withAerialPerspective = withAerialPerspective;
686
- this._fogUniforms.fogType = fogType;
687
- this._fogUniforms.additive = additive;
688
- this._fogUniforms.atmosphereParams = atmosphereParams;
689
- this._fogUniforms.heightFogParams = heightFogParams;
690
- bindGroup.setValue('fog', this._fogUniforms);
691
- bindGroup.setTexture(UNIFORM_NAME_AERIALPERSPECTIVE_LUT, aerialPerspectiveLUT);
692
- bindGroup.setTexture(UNIFORM_NAME_SKYDISTANTLIGHT_LUT, skyDistantLightLUT);
693
- }
694
- /** @internal */ static setLightUniforms(bindGroup, ctx, clusterParams, countParams, lightBuffer, lightIndexTexture) {
695
- bindGroup.setValue('light', {
696
- sunDir: ctx.sunLight ? ctx.sunLight.directionAndCutoff.xyz().scaleBy(-1) : this.defaultSunDir,
697
- clusterParams: clusterParams,
698
- countParams: countParams,
699
- envLightStrength: ctx.env.light.strength ?? 0,
700
- lightIndexTexSize: new Int32Array([
701
- lightIndexTexture.width,
702
- lightIndexTexture.height
703
- ])
704
- });
705
- bindGroup.setBuffer(UNIFORM_NAME_LIGHT_BUFFER, lightBuffer);
706
- bindGroup.setTexture(UNIFORM_NAME_LIGHT_INDEX_TEXTURE, lightIndexTexture);
707
- bindGroup.setTexture(UNIFORM_NAME_BAKED_SKY_MAP, ctx.scene.env.sky.getBakedSkyTexture(ctx));
708
- if (ctx.drawEnvLight) {
709
- ctx.env.light.envLight.updateBindGroup(bindGroup);
710
- }
711
- }
712
- /** @internal */ static setLightUniformsShadow(bindGroup, ctx, light) {
713
- const shadowMapParams = ctx.shadowMapInfo.get(light);
714
- this._lightUniformShadow.sunDir = ctx.sunLight ? ctx.sunLight.directionAndCutoff.xyz().scaleBy(-1) : this.defaultSunDir;
715
- this._lightUniformShadow.envLightStrength = ctx.env?.light.strength ?? 0;
716
- this._lightUniformShadow.shadowCascades = shadowMapParams.numShadowCascades;
717
- this._lightUniformShadow.positionAndRange.set(light.positionAndRange);
718
- this._lightUniformShadow.directionAndCutoff.set(light.directionAndCutoff);
719
- this._lightUniformShadow.diffuseAndIntensity.set(light.diffuseAndIntensity);
720
- this._lightUniformShadow.cascadeDistances.set(shadowMapParams.cascadeDistances);
721
- this._lightUniformShadow.depthBiasValues.set(shadowMapParams.depthBiasValues[0]);
722
- this._lightUniformShadow.shadowCameraParams.set(shadowMapParams.cameraParams);
723
- this._lightUniformShadow.depthBiasScales.set(shadowMapParams.depthBiasScales);
724
- this._lightUniformShadow.shadowMatrices.set(shadowMapParams.shadowMatrices);
725
- bindGroup.setValue('light', this._lightUniformShadow);
726
- bindGroup.setTexture(UNIFORM_NAME_SHADOW_MAP, shadowMapParams.shadowMap, shadowMapParams.shadowMapSampler);
727
- bindGroup.setTexture(UNIFORM_NAME_BAKED_SKY_MAP, ctx.scene.env.sky.getBakedSkyTexture(ctx));
728
- if (ctx.drawEnvLight) {
729
- ctx.env.light.envLight.updateBindGroup(bindGroup);
730
- }
731
- }
732
- /**
733
- * Gets the uniform variable of type float which holds the strength of the environment light
734
- *
735
- * @remarks
736
- * This function can only be used in the fragment shader
737
- *
738
- * @param scope - Current shader scope
739
- * @returns The uniform variable of which presents the strength of the environment light
740
- */ static getEnvLightStrength(scope) {
741
- return scope.light.envLightStrength;
742
- }
743
- /**
744
- * Gets current scene color texture
745
- * @param scope - Current shader scope
746
- * @returns current scene color texture
747
- */ static getSceneColorTexture(scope) {
748
- return scope[UNIFORM_NAME_SCENE_COLOR_MAP];
749
- }
750
- /**
751
- * Gets the size of current scene color texture
752
- * @param scope - Current shader scope
753
- * @returns The size of current scene color texture
754
- */ static getSceneColorTextureSize(scope) {
755
- return scope[UNIFORM_NAME_SCENE_COLOR_MAP_SIZE];
756
- }
757
- /**
758
- * Gets current linear depth texture
759
- * @param scope - Current shader scope
760
- * @returns current linear depth texture
761
- */ static getLinearDepthTexture(scope) {
762
- return scope[UNIFORM_NAME_LINEAR_DEPTH_MAP];
763
- }
764
- /**
765
- * Gets the size of current linear depth texture
766
- * @param scope - Current shader scope
767
- * @returns The size of current linear depth texture
768
- */ static getLinearDepthTextureSize(scope) {
769
- return scope[UNIFORM_NAME_LINEAR_DEPTH_MAP_SIZE];
770
- }
771
- /**
772
- * Gets current HiZ depth texture
773
- * @param scope - Current shader scope
774
- * @returns current HiZ depth texture
775
- */ static getHiZDepthTexture(scope) {
776
- return scope[UNIFORM_NAME_HIZ_DEPTH_MAP];
777
- }
778
- /**
779
- * Gets the size of current HiZ depth texture
780
- * @param scope - Current shader scope
781
- * @returns The size of current HiZ depth texture
782
- */ static getHiZDepthTextureSize(scope) {
783
- return scope[UNIFORM_NAME_HIZ_DEPTH_MAP_INFO].xy;
784
- }
785
- /**
786
- * Gets the mipmap levels count of current HiZ depth texture
787
- * @param scope - Current shader scope
788
- * @returns The mipmap levels count of current HiZ depth texture
789
- */ static getHiZDepthTextureMipLevelCount(scope) {
790
- return scope[UNIFORM_NAME_HIZ_DEPTH_MAP_INFO].z;
791
- }
792
- /**
793
- * Gets current baked skybox texture
794
- * @param scope - Current shader scope
795
- * @returns current baked skybox texture
796
- */ static getBakedSkyTexture(scope) {
797
- return scope[UNIFORM_NAME_BAKED_SKY_MAP];
798
- }
799
- /**
800
- * Gets the elapsed time in seconds
801
- * @param scope - Current shader scope
802
- * @returns The elapsed time in seconds
803
- */ static getElapsedTime(scope) {
804
- return scope.camera.elapsedTime;
805
- }
806
- /**
807
- * Gets the elapsed time since last frame in seconds
808
- * @param scope - Current shader scope
809
- * @returns The elapsed time since last frame in seconds
810
- */ static getElapsedTimeFrame(scope) {
811
- return scope.camera.frameDeltaTime;
812
- }
813
- /**
814
- * Gets the uniform variable of type vec3 which holds the camera position
815
- * @param scope - Current shader scope
816
- * @returns The camera position
817
- */ static getCameraPosition(scope) {
818
- return scope.camera.position.xyz;
819
- }
820
- /**
821
- * Gets the uniform variable of type float which holds the roughness factor
822
- * @param scope - Current shader scope
823
- * @returns The roughness factor
824
- */ static getCameraRoughnessFactor(scope) {
825
- return scope.camera.roughnessFactor;
826
- }
827
- /**
828
- * Gets framebuffer size for rendering
829
- * @param scope - Current shader scope
830
- * @returns The roughness factor
831
- */ static getRenderSize(scope) {
832
- return scope.camera.renderSize;
833
- }
834
- /**
835
- * Gets the uniform variable of type uint which holds the framestamp
836
- * @param scope - Current shader scope
837
- * @returns The framestamp
838
- */ static getFramestamp(scope) {
839
- return scope.camera.framestamp;
840
- }
841
- /**
842
- * Discard the fragment if it was clipped by the clip plane
843
- * @param scope - Current shader scope
844
- */ static discardIfClipped(scope, worldPos) {
845
- const funcName = 'Z_discardIfClippped';
846
- const pb = scope.$builder;
847
- const that = this;
848
- pb.func(funcName, [
849
- pb.vec3('worldPos')
850
- ], function() {
851
- this.$if(pb.notEqual(that.getCameraClipPlaneFlag(this), 0), function() {
852
- this.$l.clipPlane = that.getCameraClipPlane(this);
853
- this.$if(pb.greaterThan(pb.add(pb.dot(this.worldPos.xyz, this.clipPlane.xyz), this.clipPlane.w), 0), function() {
854
- pb.discard();
855
- });
856
- });
857
- });
858
- pb.getGlobalScope()[funcName](worldPos);
859
- }
860
- /**
861
- * Gets the clip plane flag
862
- * @param scope - Current shader scope
863
- * @returns A float value of 1 indices the clip plane presents, otherwise 0
864
- */ static getCameraClipPlaneFlag(scope) {
865
- return scope.camera.position.w;
866
- }
867
- /**
868
- * Gets the clip plane
869
- * @param scope - Current shader scope
870
- * @returns A vec4 presents the clip plane
871
- */ static getCameraClipPlane(scope) {
872
- return scope.camera.clipPlane;
873
- }
874
- /**
875
- * Gets the uniform variable of type vec4 which holds the camera parameters
876
- * @param scope - Current shader scope
877
- * @returns The camera parameters
878
- */ static getCameraParams(scope) {
879
- return scope.camera.params;
880
- }
881
- /** @internal */ static getClusterParams(scope) {
882
- return scope.light.clusterParams;
883
- }
884
- /** @internal */ static getCountParams(scope) {
885
- return scope.light.countParams;
886
- }
887
- /** @internal */ static getClusteredLightIndexTexture(scope) {
888
- return scope[UNIFORM_NAME_LIGHT_INDEX_TEXTURE];
889
- }
890
- /**
891
- * Gets the uniform variable that contains atmosphere parameters
892
- * @param scope - Current shader scope
893
- * @returns The atmosphere parameters
894
- */ static getAtmosphereParams(scope) {
895
- return scope.fog.atmosphereParams;
896
- }
897
- /**
898
- * Gets the aerial perspective LUT
899
- * @param scope - Current shader scope
900
- * @returns The aerial perspective LUT texture
901
- */ static getAerialPerspectiveLUT(scope) {
902
- return scope[UNIFORM_NAME_AERIALPERSPECTIVE_LUT];
903
- }
904
- /**
905
- * Gets the uniform variable of type mat4 which holds the view projection matrix of current camera
906
- * @param scope - Current shader scope
907
- * @returns The view projection matrix of current camera
908
- */ static getViewProjectionMatrix(scope) {
909
- return scope.camera.viewProjectionMatrix;
910
- }
911
- /**
912
- * Gets the uniform variable of type mat4 which holds the inversed view projection matrix of current camera
913
- * @param scope - Current shader scope
914
- * @returns The inversed view projection matrix of current camera
915
- */ static getInvViewProjectionMatrix(scope) {
916
- return scope.camera.invViewProjectionMatrix;
917
- }
918
- /**
919
- * Gets the uniform variable of type mat4 which holds the projection matrix of current camera
920
- * @param scope - Current shader scope
921
- * @returns The projection matrix of current camera
922
- */ static getProjectionMatrix(scope) {
923
- return scope.camera.projectionMatrix;
924
- }
925
- /**
926
- * Gets the uniform variable of type mat4 which holds the inversed projection matrix of current camera
927
- * @param scope - Current shader scope
928
- * @returns The inversed projection matrix of current camera
929
- */ static getInvProjectionMatrix(scope) {
930
- return scope.camera.invProjectionMatrix;
931
- }
932
- /**
933
- * Gets the uniform variable of type mat4 which holds the unjittered view projection matrix of current camera
934
- * @param scope - Current shader scope
935
- * @returns The unjittered view projection matrix of current camera
936
- */ static getUnjitteredViewProjectionMatrix(scope) {
937
- return scope.camera.unjitteredVPMatrix;
938
- }
939
- /**
940
- * Gets the uniform variable of type vec2 which holds the jitter value of the projection matrix of current camera
941
- * @param scope - Current shader scope
942
- * @returns The jitter value of projection matrix of current camera
943
- */ static getProjectionMatrixJitterValue(scope) {
944
- return scope.camera.jitterValue;
945
- }
946
- /**
947
- * Gets the uniform variable of type mat4 which holds the jittered inversed view-projection matrix
948
- * @param scope - Current shader scope
949
- * @returns The jittered inversed view-projection matrix
950
- */ static getJitteredInvVPMatrix(scope) {
951
- return scope.camera.jitteredInvVPMatrix;
952
- }
953
- /**
954
- * Gets the uniform variable of type mat4 which holds the unjittered view projection at previous frame matrix of current camera
955
- * @param scope - Current shader scope
956
- * @returns The unjittered view projection matrix at previous frame of current camera
957
- */ static getPrevUnjitteredViewProjectionMatrix(scope) {
958
- return scope.camera.prevUnjitteredVPMatrix;
959
- }
960
- /**
961
- * Gets the uniform variable of type mat4 which holds the view matrix of current camera
962
- * @param scope - Current shader scope
963
- * @returns The view matrix of current camera
964
- */ static getViewMatrix(scope) {
965
- return scope.camera.viewMatrix;
966
- }
967
- /** @internal */ static getCascadeDistances(scope) {
968
- return scope.light.cascadeDistances;
969
- }
970
- /** @internal */ static getDepthBiasValues(scope) {
971
- return scope.light.depthBiasValues;
972
- }
973
- /** @internal */ static getShadowCameraParams(scope) {
974
- return scope.light.shadowCameraParams;
975
- }
976
- /** @internal */ static getDepthBiasScales(scope) {
977
- return scope.light.depthBiasScales;
978
- }
979
- /** @internal */ static getNumLights(scope) {
980
- return scope.light.numLights;
981
- }
982
- /** @internal */ static getSunLightDir(scope) {
983
- return scope.light.sunDir;
984
- }
985
- /** @internal */ static getLightTypeForShadow(scope) {
986
- return scope.light.lightType;
987
- }
988
- /** @internal */ static getLightPositionAndRangeForShadow(scope) {
989
- return scope.light.positionAndRange;
990
- }
991
- /** @internal */ static getLightViewMatrixForShadow(scope) {
992
- return scope.light.viewMatrix;
993
- }
994
- /** @internal */ static calculateShadowSpaceVertex(scope, worldPos, cascade = 0) {
995
- const pb = scope.$builder;
996
- if (typeof cascade === 'number') {
997
- return pb.vec4(pb.dot(scope.light.shadowMatrices.at(cascade * 4 + 0), worldPos), pb.dot(scope.light.shadowMatrices.at(cascade * 4 + 1), worldPos), pb.dot(scope.light.shadowMatrices.at(cascade * 4 + 2), worldPos), pb.dot(scope.light.shadowMatrices.at(cascade * 4 + 3), worldPos));
998
- } else {
999
- return pb.vec4(pb.dot(scope.light.shadowMatrices.at(pb.add(pb.mul(cascade, 4), 0)), worldPos), pb.dot(scope.light.shadowMatrices.at(pb.add(pb.mul(cascade, 4), 1)), worldPos), pb.dot(scope.light.shadowMatrices.at(pb.add(pb.mul(cascade, 4), 2)), worldPos), pb.dot(scope.light.shadowMatrices.at(pb.add(pb.mul(cascade, 4), 3)), worldPos));
1000
- }
1001
- }
1002
- /** @internal */ static getLightPositionAndRange(scope, lightIndex) {
1003
- return scope[UNIFORM_NAME_LIGHT_BUFFER].at(scope.$builder.mul(lightIndex, 3));
1004
- }
1005
- /** @internal */ static getLightDirectionAndCutoff(scope, lightIndex) {
1006
- return scope[UNIFORM_NAME_LIGHT_BUFFER].at(scope.$builder.add(scope.$builder.mul(lightIndex, 3), 1));
1007
- }
1008
- /** @internal */ static getLightColorAndIntensity(scope, lightIndex) {
1009
- return scope[UNIFORM_NAME_LIGHT_BUFFER].at(scope.$builder.add(scope.$builder.mul(lightIndex, 3), 2));
1010
- }
1011
- /**
1012
- * Sets the clip space position in vertex shader
1013
- *
1014
- * @remarks
1015
- * Use this function instead of using
1016
- * <pre>
1017
- * // Do not use this
1018
- * this.$builtins.position = some_value;
1019
- * // Use this
1020
- * ShaderFramework.setClipSpacePosition(some_value);
1021
- * </pre>,
1022
- *
1023
- * @param scope - Current shader scope
1024
- * @param pos - The clip space position to be set
1025
- */ static setClipSpacePosition(scope, pos) {
1026
- const pb = scope.$builder;
1027
- const cameraParams = this.getCameraParams(scope);
1028
- if (cameraParams) {
1029
- scope.$builtins.position = pb.mul(pos, pb.vec4(1, cameraParams.z, 1, 1));
1030
- } else {
1031
- scope.$builtins.position = pos;
1032
- }
1033
- }
1034
- /**
1035
- * Get shadow map uniform value
1036
- *
1037
- * @param scope - Shader scope
1038
- * @returns The shadow map texture uniform
1039
- */ static getShadowMap(scope) {
1040
- return scope[UNIFORM_NAME_SHADOW_MAP];
1041
- }
1042
- /**
1043
- * Calculates shadow of current fragment
1044
- *
1045
- * @param scope - Shader scope
1046
- * @param NoL - NdotL vector
1047
- * @returns Shadow of current fragment, 1 means no shadow and 0 means full shadowed.
1048
- */ static calculateShadow(scope, worldPos, NoL, ctx) {
1049
- const pb = scope.$builder;
1050
- const that = this;
1051
- const shadowMapParams = ctx.shadowMapInfo.get(ctx.currentShadowLight);
1052
- const funcName = 'Z_calculateShadow';
1053
- pb.func(funcName, [
1054
- pb.vec3('worldPos'),
1055
- pb.float('NoL')
1056
- ], function() {
1057
- if (shadowMapParams.numShadowCascades > 1) {
1058
- this.$l.shadowCascades = this.light.shadowCascades;
1059
- this.$l.shadowBound = pb.vec4(0, 0, 1, 1);
1060
- this.$l.linearDepth = that.nonLinearDepthToLinear(this, this.$builtins.fragCoord.z);
1061
- this.$l.splitDistances = that.getCascadeDistances(this);
1062
- this.$l.comparison = pb.vec4(pb.greaterThan(pb.vec4(this.linearDepth), this.splitDistances));
1063
- this.$l.cascadeFlags = pb.vec4(pb.float(pb.greaterThan(this.shadowCascades, 0)), pb.float(pb.greaterThan(this.shadowCascades, 1)), pb.float(pb.greaterThan(this.shadowCascades, 2)), pb.float(pb.greaterThan(this.shadowCascades, 3)));
1064
- this.$l.split = pb.int(pb.dot(this.comparison, this.cascadeFlags));
1065
- if (ctx.device.type === 'webgl') {
1066
- this.$l.shadowVertex = pb.vec4();
1067
- this.$for(pb.int('cascade'), 0, 4, function() {
1068
- this.$if(pb.equal(this.cascade, this.split), function() {
1069
- this.shadowVertex = that.calculateShadowSpaceVertex(this, pb.vec4(this.worldPos, 1), this.cascade);
1070
- this.$break();
1071
- });
1072
- });
1073
- } else {
1074
- this.$l.shadowVertex = that.calculateShadowSpaceVertex(this, pb.vec4(this.worldPos, 1), this.split);
1075
- }
1076
- const shadowMapParams = ctx.shadowMapInfo.get(ctx.currentShadowLight);
1077
- this.$l.shadow = shadowMapParams.impl.computeShadowCSM(shadowMapParams, this, this.shadowVertex, this.NoL, this.split);
1078
- this.$l.shadowDistance = that.getShadowCameraParams(scope).w;
1079
- this.shadow = pb.mix(this.shadow, 1, pb.smoothStep(pb.mul(this.shadowDistance, 0.8), this.shadowDistance, pb.distance(that.getCameraPosition(this), this.worldPos)));
1080
- this.$return(this.shadow);
1081
- } else {
1082
- this.$l.shadowVertex = that.calculateShadowSpaceVertex(this, pb.vec4(this.worldPos, 1));
1083
- const shadowMapParams = ctx.shadowMapInfo.get(ctx.currentShadowLight);
1084
- this.$l.shadow = shadowMapParams.impl.computeShadow(shadowMapParams, this, this.shadowVertex, this.NoL);
1085
- this.$l.shadowDistance = that.getShadowCameraParams(scope).w;
1086
- this.shadow = pb.mix(this.shadow, 1, pb.smoothStep(pb.mul(this.shadowDistance, 0.8), this.shadowDistance, pb.distance(that.getCameraPosition(this), this.worldPos)));
1087
- this.$return(this.shadow);
1088
- }
1089
- });
1090
- return pb.getGlobalScope()[funcName](worldPos, NoL);
1091
- }
1092
- static applyFog(scope, worldPos, color, ctx) {
1093
- const pb = scope.$builder;
1094
- const that = this;
1095
- if (ctx.materialFlags & MaterialVaryingFlags.APPLY_FOG) {
1096
- const funcName = 'Z_applyFog';
1097
- pb.func(funcName, [
1098
- pb.vec3('worldPos'),
1099
- pb.vec4('color').inout()
1100
- ], function() {
1101
- this.$l.uv = pb.div(pb.vec2(this.$builtins.fragCoord.xy), that.getRenderSize(this));
1102
- this.$l.fogging = calculateFog(this, this.fog.withAerialPerspective, this.fog.fogType, this.fog.atmosphereParams, this.fog.heightFogParams, this.uv, false, that.getCameraPosition(this).xyz, this.worldPos, this.fog.additive, this[UNIFORM_NAME_AERIALPERSPECTIVE_LUT], this[UNIFORM_NAME_SKYDISTANTLIGHT_LUT]);
1103
- this.color = pb.vec4(pb.add(pb.mul(this.color.rgb, this.fogging.a), this.fogging.rgb), this.color.a);
1104
- //this.color = pb.vec4(pb.vec3(pb.mix(this.u0, this.u1, this.factor)), this.color.a);
1105
- });
1106
- scope[funcName](worldPos, color);
1107
- }
1108
- }
1109
- /**
1110
- * Calculates the non-linear depth from linear depth
1111
- *
1112
- * @param scope - Current shader scope
1113
- * @param depth - The linear depth
1114
- * @param nearFar - A vector that contains the near clip plane in x component and the far clip plane in y component
1115
- * @returns The calculated non-linear depth
1116
- */ static linearDepthToNonLinear(scope, depth, nearFar) {
1117
- const pb = scope.$builder;
1118
- nearFar = nearFar ?? this.getCameraParams(scope);
1119
- return pb.div(pb.sub(nearFar.y, pb.div(pb.mul(nearFar.x, nearFar.y), depth)), pb.sub(nearFar.y, nearFar.x));
1120
- }
1121
- /**
1122
- * Calculates the linear depth from non-linear depth
1123
- *
1124
- * @param scope - Current shader scope
1125
- * @param depth - The non-linear depth
1126
- * @param nearFar - A vector that contains the near clip plane in x component and the far clip plane in y component
1127
- * @returns The calculated linear depth
1128
- */ static nonLinearDepthToLinear(scope, depth, nearFar) {
1129
- const pb = scope.$builder;
1130
- nearFar = nearFar ?? this.getCameraParams(scope);
1131
- return pb.div(pb.mul(nearFar.x, nearFar.y), pb.mix(nearFar.y, nearFar.x, depth));
1132
- }
1133
- /**
1134
- * Calculates the normalized linear depth from non-linear depth
1135
- *
1136
- * @param scope - Current shader scope
1137
- * @param depth - The non-linear depth
1138
- * @param nearFar - A vector that contains the near clip plane in x component and the far clip plane in y component
1139
- * @returns The calculated normalized linear depth
1140
- */ static nonLinearDepthToLinearNormalized(scope, depth, nearFar) {
1141
- const pb = scope.$builder;
1142
- nearFar = nearFar ?? this.getCameraParams(scope);
1143
- return pb.div(nearFar.x, pb.mix(nearFar.y, nearFar.x, depth));
1144
- }
1145
- /**
1146
- * Sample linear depth from linear depth texture
1147
- * @param scope - Current shader scope
1148
- * @param tex - The linear depth texture
1149
- * @param uv - The uv coordinates
1150
- * @param level - The mipmap level to sample
1151
- * @returns Linear depth value
1152
- */ static sampleLinearDepth(scope, tex, uv, level) {
1153
- const pb = scope.$builder;
1154
- const depth = pb.textureSampleLevel(tex, uv, level);
1155
- return pb.getDevice().type === 'webgl' ? decodeNormalizedFloatFromRGBA(scope, depth) : depth.r;
1156
- }
1157
- static samplePositionFromDepth(scope, depthTex, uv, mat, cameraNearFar) {
1158
- const pb = scope.$builder;
1159
- const that = this;
1160
- pb.func('zSamplePositionFromDepth', [
1161
- pb.vec2('uv'),
1162
- pb.vec2('cameraNearFar'),
1163
- pb.mat4('mat')
1164
- ], function() {
1165
- this.$l.linearDepth = that.sampleLinearDepth(this, depthTex, this.uv, 0);
1166
- this.$l.nonLinearDepth = pb.div(pb.sub(pb.div(this.cameraNearFar.x, this.linearDepth), this.cameraNearFar.y), pb.sub(this.cameraNearFar.x, this.cameraNearFar.y));
1167
- this.$l.clipSpacePos = pb.vec4(pb.sub(pb.mul(this.uv, 2), pb.vec2(1)), pb.sub(pb.mul(pb.clamp(this.nonLinearDepth, 0, 1), 2), 1), 1);
1168
- this.$l.wPos = pb.mul(this.mat, this.clipSpacePos);
1169
- this.$return(pb.vec4(pb.div(this.wPos.xyz, this.wPos.w), this.linearDepth));
1170
- });
1171
- return scope.zSamplePositionFromDepth(uv, cameraNearFar, mat);
1172
- }
1173
- /**
1174
- * Sample linear depth from linear depth texture with backface
1175
- * @param scope - Current shader scope
1176
- * @param tex - The linear depth texture
1177
- * @param uv - The uv coordinates
1178
- * @param level - The mipmap level to sample
1179
- * @returns Linear depth value
1180
- */ static sampleLinearDepthWithBackface(scope, tex, uv, level) {
1181
- const pb = scope.$builder;
1182
- return pb.textureSampleLevel(tex, uv, level).rg;
1183
- }
1184
- /**
1185
- * Transform color to sRGB color space if nessesary
1186
- *
1187
- * @param scope - Current shader scope
1188
- * @param outputColor - The color to be transformed
1189
- * @returns The transformed color
1190
- */ static encodeColorOutput(scope, outputColor) {
1191
- const pb = scope.$builder;
1192
- const that = this;
1193
- const funcName = 'Z_encodeColorOutput';
1194
- pb.func(funcName, [
1195
- pb.vec4('outputColor')
1196
- ], function() {
1197
- const params = that.getCameraParams(this);
1198
- this.$if(pb.notEqual(params.w, 0), function() {
1199
- this.$return(pb.vec4(linearToGamma(this, this.outputColor.rgb), this.outputColor.w));
1200
- }).$else(function() {
1201
- this.$return(this.outputColor);
1202
- });
1203
- });
1204
- return pb.getGlobalScope()[funcName](outputColor);
1205
- }
1206
- }
1207
-
1208
- export { ShaderHelper };
1209
- //# sourceMappingURL=helper.js.map