@babylonjs/core 8.10.1 → 8.12.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 (394) hide show
  1. package/Cameras/arcRotateCamera.js +8 -0
  2. package/Cameras/arcRotateCamera.js.map +1 -1
  3. package/Cameras/targetCamera.js +2 -0
  4. package/Cameras/targetCamera.js.map +1 -1
  5. package/Collisions/gpuPicker.d.ts +4 -0
  6. package/Collisions/gpuPicker.js +6 -0
  7. package/Collisions/gpuPicker.js.map +1 -1
  8. package/Engines/abstractEngine.js +2 -2
  9. package/Engines/abstractEngine.js.map +1 -1
  10. package/Engines/constants.d.ts +4 -0
  11. package/Engines/constants.js +4 -0
  12. package/Engines/constants.js.map +1 -1
  13. package/FrameGraph/Node/Blocks/Rendering/baseShadowGeneratorBlock.d.ts +1 -0
  14. package/FrameGraph/Node/Blocks/Rendering/baseShadowGeneratorBlock.js +2 -0
  15. package/FrameGraph/Node/Blocks/Rendering/baseShadowGeneratorBlock.js.map +1 -1
  16. package/FrameGraph/Node/Blocks/Rendering/csmShadowGeneratorBlock.d.ts +6 -1
  17. package/FrameGraph/Node/Blocks/Rendering/csmShadowGeneratorBlock.js +29 -0
  18. package/FrameGraph/Node/Blocks/Rendering/csmShadowGeneratorBlock.js.map +1 -1
  19. package/FrameGraph/Node/Blocks/Rendering/geometryRendererBlock.d.ts +6 -0
  20. package/FrameGraph/Node/Blocks/Rendering/geometryRendererBlock.js +36 -9
  21. package/FrameGraph/Node/Blocks/Rendering/geometryRendererBlock.js.map +1 -1
  22. package/FrameGraph/Node/Blocks/Rendering/shadowGeneratorBlock.js +1 -0
  23. package/FrameGraph/Node/Blocks/Rendering/shadowGeneratorBlock.js.map +1 -1
  24. package/FrameGraph/Node/Blocks/inputBlock.js +1 -0
  25. package/FrameGraph/Node/Blocks/inputBlock.js.map +1 -1
  26. package/FrameGraph/Node/Types/nodeRenderGraphTypes.d.ts +2 -0
  27. package/FrameGraph/Node/Types/nodeRenderGraphTypes.js +2 -0
  28. package/FrameGraph/Node/Types/nodeRenderGraphTypes.js.map +1 -1
  29. package/FrameGraph/Tasks/Rendering/csmShadowGeneratorTask.d.ts +23 -0
  30. package/FrameGraph/Tasks/Rendering/csmShadowGeneratorTask.js +126 -21
  31. package/FrameGraph/Tasks/Rendering/csmShadowGeneratorTask.js.map +1 -1
  32. package/FrameGraph/Tasks/Rendering/geometryRendererTask.d.ts +5 -0
  33. package/FrameGraph/Tasks/Rendering/geometryRendererTask.js +4 -0
  34. package/FrameGraph/Tasks/Rendering/geometryRendererTask.js.map +1 -1
  35. package/FrameGraph/Tasks/Rendering/shadowGeneratorTask.d.ts +2 -4
  36. package/FrameGraph/Tasks/Rendering/shadowGeneratorTask.js +4 -17
  37. package/FrameGraph/Tasks/Rendering/shadowGeneratorTask.js.map +1 -1
  38. package/FrameGraph/frameGraph.js +1 -1
  39. package/FrameGraph/frameGraph.js.map +1 -1
  40. package/FrameGraph/frameGraphContext.d.ts +30 -0
  41. package/FrameGraph/frameGraphContext.js +47 -0
  42. package/FrameGraph/frameGraphContext.js.map +1 -1
  43. package/FrameGraph/frameGraphRenderContext.d.ts +1 -4
  44. package/FrameGraph/frameGraphRenderContext.js +2 -5
  45. package/FrameGraph/frameGraphRenderContext.js.map +1 -1
  46. package/Lights/Shadows/cascadedShadowGenerator.d.ts +0 -1
  47. package/Lights/Shadows/cascadedShadowGenerator.js +0 -12
  48. package/Lights/Shadows/cascadedShadowGenerator.js.map +1 -1
  49. package/Materials/Node/Blocks/Dual/clipPlanesBlock.d.ts +1 -1
  50. package/Materials/Node/Blocks/Dual/clipPlanesBlock.js +4 -1
  51. package/Materials/Node/Blocks/Dual/clipPlanesBlock.js.map +1 -1
  52. package/Materials/Node/Blocks/Dual/currentScreenBlock.d.ts +2 -3
  53. package/Materials/Node/Blocks/Dual/currentScreenBlock.js +1 -1
  54. package/Materials/Node/Blocks/Dual/currentScreenBlock.js.map +1 -1
  55. package/Materials/Node/Blocks/Dual/fogBlock.d.ts +1 -1
  56. package/Materials/Node/Blocks/Dual/fogBlock.js +4 -1
  57. package/Materials/Node/Blocks/Dual/fogBlock.js.map +1 -1
  58. package/Materials/Node/Blocks/Dual/lightBlock.d.ts +1 -1
  59. package/Materials/Node/Blocks/Dual/lightBlock.js +2 -2
  60. package/Materials/Node/Blocks/Dual/lightBlock.js.map +1 -1
  61. package/Materials/Node/Blocks/Dual/reflectionTextureBaseBlock.d.ts +1 -2
  62. package/Materials/Node/Blocks/Dual/reflectionTextureBaseBlock.js +1 -1
  63. package/Materials/Node/Blocks/Dual/reflectionTextureBaseBlock.js.map +1 -1
  64. package/Materials/Node/Blocks/Dual/smartFilterTextureBlock.d.ts +13 -3
  65. package/Materials/Node/Blocks/Dual/smartFilterTextureBlock.js +64 -9
  66. package/Materials/Node/Blocks/Dual/smartFilterTextureBlock.js.map +1 -1
  67. package/Materials/Node/Blocks/Dual/textureBlock.d.ts +2 -3
  68. package/Materials/Node/Blocks/Dual/textureBlock.js +2 -2
  69. package/Materials/Node/Blocks/Dual/textureBlock.js.map +1 -1
  70. package/Materials/Node/Blocks/Fragment/TBNBlock.d.ts +1 -1
  71. package/Materials/Node/Blocks/Fragment/TBNBlock.js +4 -1
  72. package/Materials/Node/Blocks/Fragment/TBNBlock.js.map +1 -1
  73. package/Materials/Node/Blocks/Fragment/fragCoordBlock.js +2 -2
  74. package/Materials/Node/Blocks/Fragment/fragCoordBlock.js.map +1 -1
  75. package/Materials/Node/Blocks/Fragment/fragmentOutputBlock.d.ts +1 -2
  76. package/Materials/Node/Blocks/Fragment/fragmentOutputBlock.js +1 -1
  77. package/Materials/Node/Blocks/Fragment/fragmentOutputBlock.js.map +1 -1
  78. package/Materials/Node/Blocks/Fragment/frontFacingBlock.js +2 -2
  79. package/Materials/Node/Blocks/Fragment/frontFacingBlock.js.map +1 -1
  80. package/Materials/Node/Blocks/Fragment/heightToNormalBlock.js +1 -2
  81. package/Materials/Node/Blocks/Fragment/heightToNormalBlock.js.map +1 -1
  82. package/Materials/Node/Blocks/Fragment/imageProcessingBlock.d.ts +1 -1
  83. package/Materials/Node/Blocks/Fragment/imageProcessingBlock.js +1 -1
  84. package/Materials/Node/Blocks/Fragment/imageProcessingBlock.js.map +1 -1
  85. package/Materials/Node/Blocks/Fragment/perturbNormalBlock.d.ts +1 -2
  86. package/Materials/Node/Blocks/Fragment/perturbNormalBlock.js +1 -1
  87. package/Materials/Node/Blocks/Fragment/perturbNormalBlock.js.map +1 -1
  88. package/Materials/Node/Blocks/Fragment/screenSizeBlock.d.ts +4 -0
  89. package/Materials/Node/Blocks/Fragment/screenSizeBlock.js +8 -2
  90. package/Materials/Node/Blocks/Fragment/screenSizeBlock.js.map +1 -1
  91. package/Materials/Node/Blocks/GaussianSplatting/gaussianSplattingBlock.d.ts +3 -3
  92. package/Materials/Node/Blocks/GaussianSplatting/gaussianSplattingBlock.js +6 -3
  93. package/Materials/Node/Blocks/GaussianSplatting/gaussianSplattingBlock.js.map +1 -1
  94. package/Materials/Node/Blocks/PBR/anisotropyBlock.d.ts +1 -2
  95. package/Materials/Node/Blocks/PBR/anisotropyBlock.js +2 -4
  96. package/Materials/Node/Blocks/PBR/anisotropyBlock.js.map +1 -1
  97. package/Materials/Node/Blocks/PBR/clearCoatBlock.d.ts +1 -2
  98. package/Materials/Node/Blocks/PBR/clearCoatBlock.js +1 -2
  99. package/Materials/Node/Blocks/PBR/clearCoatBlock.js.map +1 -1
  100. package/Materials/Node/Blocks/PBR/iridescenceBlock.d.ts +2 -3
  101. package/Materials/Node/Blocks/PBR/iridescenceBlock.js +1 -2
  102. package/Materials/Node/Blocks/PBR/iridescenceBlock.js.map +1 -1
  103. package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.d.ts +1 -1
  104. package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.js +5 -2
  105. package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.js.map +1 -1
  106. package/Materials/Node/Blocks/PBR/reflectionBlock.d.ts +1 -2
  107. package/Materials/Node/Blocks/PBR/reflectionBlock.js +2 -2
  108. package/Materials/Node/Blocks/PBR/reflectionBlock.js.map +1 -1
  109. package/Materials/Node/Blocks/PBR/refractionBlock.d.ts +1 -2
  110. package/Materials/Node/Blocks/PBR/refractionBlock.js +1 -2
  111. package/Materials/Node/Blocks/PBR/refractionBlock.js.map +1 -1
  112. package/Materials/Node/Blocks/PBR/sheenBlock.d.ts +2 -3
  113. package/Materials/Node/Blocks/PBR/sheenBlock.js +1 -2
  114. package/Materials/Node/Blocks/PBR/sheenBlock.js.map +1 -1
  115. package/Materials/Node/Blocks/PBR/subSurfaceBlock.d.ts +2 -3
  116. package/Materials/Node/Blocks/PBR/subSurfaceBlock.js +1 -2
  117. package/Materials/Node/Blocks/PBR/subSurfaceBlock.js.map +1 -1
  118. package/Materials/Node/Blocks/Particle/particleTextureBlock.d.ts +1 -2
  119. package/Materials/Node/Blocks/Particle/particleTextureBlock.js +1 -1
  120. package/Materials/Node/Blocks/Particle/particleTextureBlock.js.map +1 -1
  121. package/Materials/Node/Blocks/Vertex/bonesBlock.d.ts +2 -2
  122. package/Materials/Node/Blocks/Vertex/bonesBlock.js +3 -3
  123. package/Materials/Node/Blocks/Vertex/bonesBlock.js.map +1 -1
  124. package/Materials/Node/Blocks/Vertex/instancesBlock.d.ts +1 -1
  125. package/Materials/Node/Blocks/Vertex/instancesBlock.js +1 -1
  126. package/Materials/Node/Blocks/Vertex/instancesBlock.js.map +1 -1
  127. package/Materials/Node/Blocks/Vertex/lightInformationBlock.d.ts +1 -2
  128. package/Materials/Node/Blocks/Vertex/lightInformationBlock.js +1 -1
  129. package/Materials/Node/Blocks/Vertex/lightInformationBlock.js.map +1 -1
  130. package/Materials/Node/Blocks/Vertex/morphTargetsBlock.d.ts +2 -2
  131. package/Materials/Node/Blocks/Vertex/morphTargetsBlock.js +8 -2
  132. package/Materials/Node/Blocks/Vertex/morphTargetsBlock.js.map +1 -1
  133. package/Materials/Node/Blocks/transformBlock.d.ts +3 -3
  134. package/Materials/Node/Blocks/transformBlock.js +4 -5
  135. package/Materials/Node/Blocks/transformBlock.js.map +1 -1
  136. package/Materials/Node/Blocks/triPlanarBlock.d.ts +1 -3
  137. package/Materials/Node/Blocks/triPlanarBlock.js +1 -1
  138. package/Materials/Node/Blocks/triPlanarBlock.js.map +1 -1
  139. package/Materials/Node/nodeMaterial.d.ts +1 -1
  140. package/Materials/Node/nodeMaterial.js +28 -42
  141. package/Materials/Node/nodeMaterial.js.map +1 -1
  142. package/Materials/Node/nodeMaterialBlock.d.ts +8 -12
  143. package/Materials/Node/nodeMaterialBlock.js +10 -12
  144. package/Materials/Node/nodeMaterialBlock.js.map +1 -1
  145. package/Materials/Node/nodeMaterialBuildState.js +7 -2
  146. package/Materials/Node/nodeMaterialBuildState.js.map +1 -1
  147. package/Materials/Node/nodeMaterialBuildStateSharedData.d.ts +14 -3
  148. package/Materials/Node/nodeMaterialBuildStateSharedData.js +24 -6
  149. package/Materials/Node/nodeMaterialBuildStateSharedData.js.map +1 -1
  150. package/Materials/PBR/pbrBaseMaterial.d.ts +2 -0
  151. package/Materials/PBR/pbrBaseMaterial.js +11 -0
  152. package/Materials/PBR/pbrBaseMaterial.js.map +1 -1
  153. package/Materials/Textures/Loaders/exrTextureLoader.d.ts +10 -0
  154. package/Materials/Textures/Loaders/exrTextureLoader.js +28 -1
  155. package/Materials/Textures/Loaders/exrTextureLoader.js.map +1 -1
  156. package/Materials/materialHelper.functions.js +1 -1
  157. package/Materials/materialHelper.functions.js.map +1 -1
  158. package/Materials/materialHelper.geometryrendering.js +7 -0
  159. package/Materials/materialHelper.geometryrendering.js.map +1 -1
  160. package/Materials/standardMaterial.d.ts +2 -0
  161. package/Materials/standardMaterial.js +11 -0
  162. package/Materials/standardMaterial.js.map +1 -1
  163. package/Materials/uniformBuffer.js +2 -1
  164. package/Materials/uniformBuffer.js.map +1 -1
  165. package/Meshes/Node/Blocks/Textures/geometryTextureBlock.d.ts +7 -0
  166. package/Meshes/Node/Blocks/Textures/geometryTextureBlock.js +11 -5
  167. package/Meshes/Node/Blocks/Textures/geometryTextureBlock.js.map +1 -1
  168. package/Meshes/Node/Blocks/Textures/geometryTextureFetchBlock.d.ts +6 -0
  169. package/Meshes/Node/Blocks/Textures/geometryTextureFetchBlock.js +42 -4
  170. package/Meshes/Node/Blocks/Textures/geometryTextureFetchBlock.js.map +1 -1
  171. package/Meshes/Node/Blocks/geometryOptimizeBlock.js +8 -0
  172. package/Meshes/Node/Blocks/geometryOptimizeBlock.js.map +1 -1
  173. package/Misc/environmentTextureTools.d.ts +4 -0
  174. package/Misc/environmentTextureTools.js +1 -0
  175. package/Misc/environmentTextureTools.js.map +1 -1
  176. package/Misc/minMaxReducer.d.ts +8 -6
  177. package/Misc/minMaxReducer.js +57 -90
  178. package/Misc/minMaxReducer.js.map +1 -1
  179. package/Misc/thinMinMaxReducer.d.ts +47 -0
  180. package/Misc/thinMinMaxReducer.js +148 -0
  181. package/Misc/thinMinMaxReducer.js.map +1 -0
  182. package/Particles/EmitterTypes/customParticleEmitter.d.ts +5 -0
  183. package/Particles/EmitterTypes/customParticleEmitter.js +9 -1
  184. package/Particles/EmitterTypes/customParticleEmitter.js.map +1 -1
  185. package/Particles/IParticleSystem.d.ts +4 -0
  186. package/Particles/IParticleSystem.js.map +1 -1
  187. package/Particles/Node/Blocks/Conditions/particleConditionBlock.d.ts +75 -0
  188. package/Particles/Node/Blocks/Conditions/particleConditionBlock.js +179 -0
  189. package/Particles/Node/Blocks/Conditions/particleConditionBlock.js.map +1 -0
  190. package/Particles/Node/Blocks/Emitters/boxShapeBlock.d.ts +47 -0
  191. package/Particles/Node/Blocks/Emitters/boxShapeBlock.js +107 -0
  192. package/Particles/Node/Blocks/Emitters/boxShapeBlock.js.map +1 -0
  193. package/Particles/Node/Blocks/Emitters/createParticleBlock.d.ts +46 -0
  194. package/Particles/Node/Blocks/Emitters/createParticleBlock.js +97 -0
  195. package/Particles/Node/Blocks/Emitters/createParticleBlock.js.map +1 -0
  196. package/Particles/Node/Blocks/Emitters/customShapeBlock.d.ts +39 -0
  197. package/Particles/Node/Blocks/Emitters/customShapeBlock.js +84 -0
  198. package/Particles/Node/Blocks/Emitters/customShapeBlock.js.map +1 -0
  199. package/Particles/Node/Blocks/Emitters/cylinderShapeBlock.d.ts +48 -0
  200. package/Particles/Node/Blocks/Emitters/cylinderShapeBlock.js +120 -0
  201. package/Particles/Node/Blocks/Emitters/cylinderShapeBlock.js.map +1 -0
  202. package/Particles/Node/Blocks/Emitters/index.d.ts +7 -0
  203. package/Particles/Node/Blocks/Emitters/index.js +8 -0
  204. package/Particles/Node/Blocks/Emitters/index.js.map +1 -0
  205. package/Particles/Node/Blocks/Emitters/pointShapeBlock.d.ts +39 -0
  206. package/Particles/Node/Blocks/Emitters/pointShapeBlock.js +86 -0
  207. package/Particles/Node/Blocks/Emitters/pointShapeBlock.js.map +1 -0
  208. package/Particles/Node/Blocks/Emitters/setupSpriteSheetBlock.d.ts +53 -0
  209. package/Particles/Node/Blocks/Emitters/setupSpriteSheetBlock.js +111 -0
  210. package/Particles/Node/Blocks/Emitters/setupSpriteSheetBlock.js.map +1 -0
  211. package/Particles/Node/Blocks/Emitters/sphereShapeBlock.d.ts +43 -0
  212. package/Particles/Node/Blocks/Emitters/sphereShapeBlock.js +108 -0
  213. package/Particles/Node/Blocks/Emitters/sphereShapeBlock.js.map +1 -0
  214. package/Particles/Node/Blocks/Teleport/particleTeleportInBlock.d.ts +48 -0
  215. package/Particles/Node/Blocks/Teleport/particleTeleportInBlock.js +100 -0
  216. package/Particles/Node/Blocks/Teleport/particleTeleportInBlock.js.map +1 -0
  217. package/Particles/Node/Blocks/Teleport/particleTeleportOutBlock.d.ts +47 -0
  218. package/Particles/Node/Blocks/Teleport/particleTeleportOutBlock.js +82 -0
  219. package/Particles/Node/Blocks/Teleport/particleTeleportOutBlock.js.map +1 -0
  220. package/Particles/Node/Blocks/Triggers/particleTriggerBlock.d.ts +48 -0
  221. package/Particles/Node/Blocks/Triggers/particleTriggerBlock.js +133 -0
  222. package/Particles/Node/Blocks/Triggers/particleTriggerBlock.js.map +1 -0
  223. package/Particles/Node/Blocks/Triggers/triggerTools.d.ts +9 -0
  224. package/Particles/Node/Blocks/Triggers/triggerTools.js +16 -0
  225. package/Particles/Node/Blocks/Triggers/triggerTools.js.map +1 -0
  226. package/Particles/Node/Blocks/Update/basicPositionUpdateBlock.d.ts +31 -0
  227. package/Particles/Node/Blocks/Update/basicPositionUpdateBlock.js +64 -0
  228. package/Particles/Node/Blocks/Update/basicPositionUpdateBlock.js.map +1 -0
  229. package/Particles/Node/Blocks/Update/basicSpriteUpdateBlock.d.ts +31 -0
  230. package/Particles/Node/Blocks/Update/basicSpriteUpdateBlock.js +63 -0
  231. package/Particles/Node/Blocks/Update/basicSpriteUpdateBlock.js.map +1 -0
  232. package/Particles/Node/Blocks/Update/updateAngleBlock.d.ts +35 -0
  233. package/Particles/Node/Blocks/Update/updateAngleBlock.js +73 -0
  234. package/Particles/Node/Blocks/Update/updateAngleBlock.js.map +1 -0
  235. package/Particles/Node/Blocks/Update/updateColorBlock.d.ts +35 -0
  236. package/Particles/Node/Blocks/Update/updateColorBlock.js +73 -0
  237. package/Particles/Node/Blocks/Update/updateColorBlock.js.map +1 -0
  238. package/Particles/Node/Blocks/Update/updateDirectionBlock.d.ts +35 -0
  239. package/Particles/Node/Blocks/Update/updateDirectionBlock.js +73 -0
  240. package/Particles/Node/Blocks/Update/updateDirectionBlock.js.map +1 -0
  241. package/Particles/Node/Blocks/Update/updateFlowMapBlock.d.ts +41 -0
  242. package/Particles/Node/Blocks/Update/updateFlowMapBlock.js +102 -0
  243. package/Particles/Node/Blocks/Update/updateFlowMapBlock.js.map +1 -0
  244. package/Particles/Node/Blocks/Update/updatePositionBlock.d.ts +35 -0
  245. package/Particles/Node/Blocks/Update/updatePositionBlock.js +73 -0
  246. package/Particles/Node/Blocks/Update/updatePositionBlock.js.map +1 -0
  247. package/Particles/Node/Blocks/Update/updateScaleBlock.d.ts +35 -0
  248. package/Particles/Node/Blocks/Update/updateScaleBlock.js +73 -0
  249. package/Particles/Node/Blocks/Update/updateScaleBlock.js.map +1 -0
  250. package/Particles/Node/Blocks/Update/updateSpriteCellIndexBlock.d.ts +35 -0
  251. package/Particles/Node/Blocks/Update/updateSpriteCellIndexBlock.js +74 -0
  252. package/Particles/Node/Blocks/Update/updateSpriteCellIndexBlock.js.map +1 -0
  253. package/Particles/Node/Blocks/index.d.ts +27 -0
  254. package/Particles/Node/Blocks/index.js +29 -0
  255. package/Particles/Node/Blocks/index.js.map +1 -0
  256. package/Particles/Node/Blocks/particleConverterBlock.d.ts +85 -0
  257. package/Particles/Node/Blocks/particleConverterBlock.js +267 -0
  258. package/Particles/Node/Blocks/particleConverterBlock.js.map +1 -0
  259. package/Particles/Node/Blocks/particleDebugBlock.d.ts +37 -0
  260. package/Particles/Node/Blocks/particleDebugBlock.js +109 -0
  261. package/Particles/Node/Blocks/particleDebugBlock.js.map +1 -0
  262. package/Particles/Node/Blocks/particleElbowBlock.d.ts +27 -0
  263. package/Particles/Node/Blocks/particleElbowBlock.js +47 -0
  264. package/Particles/Node/Blocks/particleElbowBlock.js.map +1 -0
  265. package/Particles/Node/Blocks/particleGradientBlock.d.ts +28 -0
  266. package/Particles/Node/Blocks/particleGradientBlock.js +118 -0
  267. package/Particles/Node/Blocks/particleGradientBlock.js.map +1 -0
  268. package/Particles/Node/Blocks/particleGradientValueBlock.d.ts +32 -0
  269. package/Particles/Node/Blocks/particleGradientValueBlock.js +79 -0
  270. package/Particles/Node/Blocks/particleGradientValueBlock.js.map +1 -0
  271. package/Particles/Node/Blocks/particleInputBlock.d.ts +87 -0
  272. package/Particles/Node/Blocks/particleInputBlock.js +279 -0
  273. package/Particles/Node/Blocks/particleInputBlock.js.map +1 -0
  274. package/Particles/Node/Blocks/particleLerpBlock.d.ts +34 -0
  275. package/Particles/Node/Blocks/particleLerpBlock.js +92 -0
  276. package/Particles/Node/Blocks/particleLerpBlock.js.map +1 -0
  277. package/Particles/Node/Blocks/particleMathBlock.d.ts +64 -0
  278. package/Particles/Node/Blocks/particleMathBlock.js +321 -0
  279. package/Particles/Node/Blocks/particleMathBlock.js.map +1 -0
  280. package/Particles/Node/Blocks/particleRandomBlock.d.ts +52 -0
  281. package/Particles/Node/Blocks/particleRandomBlock.js +161 -0
  282. package/Particles/Node/Blocks/particleRandomBlock.js.map +1 -0
  283. package/Particles/Node/Blocks/particleSourceTextureBlock.d.ts +65 -0
  284. package/Particles/Node/Blocks/particleSourceTextureBlock.js +173 -0
  285. package/Particles/Node/Blocks/particleSourceTextureBlock.js.map +1 -0
  286. package/Particles/Node/Blocks/particleTrigonometryBlock.d.ts +80 -0
  287. package/Particles/Node/Blocks/particleTrigonometryBlock.js +272 -0
  288. package/Particles/Node/Blocks/particleTrigonometryBlock.js.map +1 -0
  289. package/Particles/Node/Blocks/randomRangeBlock.d.ts +45 -0
  290. package/Particles/Node/Blocks/randomRangeBlock.js +151 -0
  291. package/Particles/Node/Blocks/randomRangeBlock.js.map +1 -0
  292. package/Particles/Node/Blocks/systemBlock.d.ts +71 -0
  293. package/Particles/Node/Blocks/systemBlock.js +193 -0
  294. package/Particles/Node/Blocks/systemBlock.js.map +1 -0
  295. package/Particles/Node/Enums/nodeParticleBlockConnectionPointTypes.d.ts +39 -0
  296. package/Particles/Node/Enums/nodeParticleBlockConnectionPointTypes.js +41 -0
  297. package/Particles/Node/Enums/nodeParticleBlockConnectionPointTypes.js.map +1 -0
  298. package/Particles/Node/Enums/nodeParticleContextualSources.d.ts +31 -0
  299. package/Particles/Node/Enums/nodeParticleContextualSources.js +34 -0
  300. package/Particles/Node/Enums/nodeParticleContextualSources.js.map +1 -0
  301. package/Particles/Node/Enums/nodeParticleSystemSources.d.ts +13 -0
  302. package/Particles/Node/Enums/nodeParticleSystemSources.js +15 -0
  303. package/Particles/Node/Enums/nodeParticleSystemSources.js.map +1 -0
  304. package/Particles/Node/index.d.ts +8 -0
  305. package/Particles/Node/index.js +10 -0
  306. package/Particles/Node/index.js.map +1 -0
  307. package/Particles/Node/nodeParticleBlock.d.ts +154 -0
  308. package/Particles/Node/nodeParticleBlock.js +355 -0
  309. package/Particles/Node/nodeParticleBlock.js.map +1 -0
  310. package/Particles/Node/nodeParticleBlockConnectionPoint.d.ts +188 -0
  311. package/Particles/Node/nodeParticleBlockConnectionPoint.js +337 -0
  312. package/Particles/Node/nodeParticleBlockConnectionPoint.js.map +1 -0
  313. package/Particles/Node/nodeParticleBuildState.d.ts +89 -0
  314. package/Particles/Node/nodeParticleBuildState.js +170 -0
  315. package/Particles/Node/nodeParticleBuildState.js.map +1 -0
  316. package/Particles/Node/nodeParticleSystemSet.d.ts +120 -0
  317. package/Particles/Node/nodeParticleSystemSet.js +382 -0
  318. package/Particles/Node/nodeParticleSystemSet.js.map +1 -0
  319. package/Particles/Queue/executionQueue.d.ts +2 -0
  320. package/Particles/Queue/executionQueue.js +10 -0
  321. package/Particles/Queue/executionQueue.js.map +1 -1
  322. package/Particles/baseParticleSystem.d.ts +2 -1
  323. package/Particles/baseParticleSystem.js +1 -0
  324. package/Particles/baseParticleSystem.js.map +1 -1
  325. package/Particles/flowMap.d.ts +7 -0
  326. package/Particles/flowMap.js +32 -0
  327. package/Particles/flowMap.js.map +1 -1
  328. package/Particles/gpuParticleSystem.d.ts +4 -0
  329. package/Particles/gpuParticleSystem.js +4 -0
  330. package/Particles/gpuParticleSystem.js.map +1 -1
  331. package/Particles/index.d.ts +1 -0
  332. package/Particles/index.js +1 -0
  333. package/Particles/index.js.map +1 -1
  334. package/Particles/particleSystem.d.ts +12 -0
  335. package/Particles/particleSystem.js +22 -1
  336. package/Particles/particleSystem.js.map +1 -1
  337. package/Particles/thinParticleSystem.d.ts +32 -11
  338. package/Particles/thinParticleSystem.js +62 -36
  339. package/Particles/thinParticleSystem.js.map +1 -1
  340. package/PostProcesses/postProcessManager.d.ts +2 -1
  341. package/PostProcesses/postProcessManager.js +3 -2
  342. package/PostProcesses/postProcessManager.js.map +1 -1
  343. package/Shaders/ShadersInclude/defaultUboDeclaration.js +1 -1
  344. package/Shaders/ShadersInclude/defaultUboDeclaration.js.map +1 -1
  345. package/Shaders/ShadersInclude/defaultVertexDeclaration.js +1 -0
  346. package/Shaders/ShadersInclude/defaultVertexDeclaration.js.map +1 -1
  347. package/Shaders/ShadersInclude/lightFragment.js +5 -2
  348. package/Shaders/ShadersInclude/lightFragment.js.map +1 -1
  349. package/Shaders/ShadersInclude/morphTargetsVertexDeclaration.js +3 -0
  350. package/Shaders/ShadersInclude/morphTargetsVertexDeclaration.js.map +1 -1
  351. package/Shaders/ShadersInclude/pbrBlockPrePass.js +3 -0
  352. package/Shaders/ShadersInclude/pbrBlockPrePass.js.map +1 -1
  353. package/Shaders/ShadersInclude/pbrDirectLightingFunctions.js +1 -1
  354. package/Shaders/ShadersInclude/pbrDirectLightingFunctions.js.map +1 -1
  355. package/Shaders/ShadersInclude/pbrUboDeclaration.js +1 -1
  356. package/Shaders/ShadersInclude/pbrUboDeclaration.js.map +1 -1
  357. package/Shaders/ShadersInclude/pbrVertexDeclaration.js +1 -0
  358. package/Shaders/ShadersInclude/pbrVertexDeclaration.js.map +1 -1
  359. package/Shaders/ShadersInclude/prePassDeclaration.js +3 -0
  360. package/Shaders/ShadersInclude/prePassDeclaration.js.map +1 -1
  361. package/Shaders/ShadersInclude/prePassVertex.js +3 -0
  362. package/Shaders/ShadersInclude/prePassVertex.js.map +1 -1
  363. package/Shaders/ShadersInclude/prePassVertexDeclaration.js +3 -0
  364. package/Shaders/ShadersInclude/prePassVertexDeclaration.js.map +1 -1
  365. package/Shaders/default.fragment.js +3 -0
  366. package/Shaders/default.fragment.js.map +1 -1
  367. package/Shaders/minmaxRedux.fragment.js +13 -5
  368. package/Shaders/minmaxRedux.fragment.js.map +1 -1
  369. package/ShadersWGSL/ShadersInclude/defaultUboDeclaration.js +1 -1
  370. package/ShadersWGSL/ShadersInclude/defaultUboDeclaration.js.map +1 -1
  371. package/ShadersWGSL/ShadersInclude/lightFragment.js +5 -2
  372. package/ShadersWGSL/ShadersInclude/lightFragment.js.map +1 -1
  373. package/ShadersWGSL/ShadersInclude/morphTargetsVertexDeclaration.js +3 -0
  374. package/ShadersWGSL/ShadersInclude/morphTargetsVertexDeclaration.js.map +1 -1
  375. package/ShadersWGSL/ShadersInclude/pbrBlockPrePass.js +3 -0
  376. package/ShadersWGSL/ShadersInclude/pbrBlockPrePass.js.map +1 -1
  377. package/ShadersWGSL/ShadersInclude/pbrDirectLightingFunctions.js +1 -1
  378. package/ShadersWGSL/ShadersInclude/pbrDirectLightingFunctions.js.map +1 -1
  379. package/ShadersWGSL/ShadersInclude/pbrUboDeclaration.js +1 -1
  380. package/ShadersWGSL/ShadersInclude/pbrUboDeclaration.js.map +1 -1
  381. package/ShadersWGSL/ShadersInclude/prePassDeclaration.js +3 -0
  382. package/ShadersWGSL/ShadersInclude/prePassDeclaration.js.map +1 -1
  383. package/ShadersWGSL/ShadersInclude/prePassVertex.js +3 -0
  384. package/ShadersWGSL/ShadersInclude/prePassVertex.js.map +1 -1
  385. package/ShadersWGSL/ShadersInclude/prePassVertexDeclaration.js +3 -0
  386. package/ShadersWGSL/ShadersInclude/prePassVertexDeclaration.js.map +1 -1
  387. package/ShadersWGSL/default.fragment.js +3 -0
  388. package/ShadersWGSL/default.fragment.js.map +1 -1
  389. package/ShadersWGSL/minmaxRedux.fragment.js +14 -6
  390. package/ShadersWGSL/minmaxRedux.fragment.js.map +1 -1
  391. package/package.json +1 -1
  392. package/scene.d.ts +5 -0
  393. package/scene.js +8 -0
  394. package/scene.js.map +1 -1
@@ -1,7 +1,7 @@
1
1
 
2
- import { Observable } from "./observable.js";
3
2
  import { PostProcess } from "../PostProcesses/postProcess.js";
4
3
  import { PostProcessManager } from "../PostProcesses/postProcessManager.js";
4
+ import { ThinMinMaxReducer, ThinMinMaxReducerPostProcess } from "./thinMinMaxReducer.js";
5
5
  import "../Shaders/minmaxRedux.fragment.js";
6
6
  import "../ShadersWGSL/minmaxRedux.fragment.js";
7
7
  /**
@@ -11,19 +11,24 @@ import "../ShadersWGSL/minmaxRedux.fragment.js";
11
11
  * The source values are read from the red channel of the texture.
12
12
  */
13
13
  export class MinMaxReducer {
14
+ /**
15
+ * Observable triggered when the computation has been performed
16
+ */
17
+ get onAfterReductionPerformed() {
18
+ return this._thinMinMaxReducer.onAfterReductionPerformed;
19
+ }
14
20
  /**
15
21
  * Creates a min/max reducer
16
22
  * @param camera The camera to use for the post processes
17
23
  */
18
24
  constructor(camera) {
19
- /**
20
- * Observable triggered when the computation has been performed
21
- */
22
- this.onAfterReductionPerformed = new Observable();
25
+ this._onAfterUnbindObserver = null;
23
26
  this._forceFullscreenViewport = true;
24
27
  this._activated = false;
25
28
  this._camera = camera;
26
29
  this._postProcessManager = new PostProcessManager(camera.getScene());
30
+ this._thinMinMaxReducer = new ThinMinMaxReducer(camera.getScene());
31
+ this._reductionSteps = [];
27
32
  this._onContextRestoredObserver = camera.getEngine().onContextRestoredObservable.add(() => {
28
33
  this._postProcessManager._rebuild();
29
34
  });
@@ -49,75 +54,37 @@ export class MinMaxReducer {
49
54
  if (sourceTexture === this._sourceTexture) {
50
55
  return;
51
56
  }
52
- this.dispose(false);
57
+ this._thinMinMaxReducer.depthRedux = depthRedux;
58
+ this.deactivate();
53
59
  this._sourceTexture = sourceTexture;
54
- this._reductionSteps = [];
55
60
  this._forceFullscreenViewport = forceFullscreenViewport;
56
- const scene = this._camera.getScene();
57
- // create the first step
58
- const reductionInitial = new PostProcess("Initial reduction phase", "minmaxRedux", // shader
59
- ["texSize"], ["sourceTexture"], // textures
60
- 1.0, // options
61
- null, // camera
62
- 1, // sampling
63
- scene.getEngine(), // engine
64
- false, // reusable
65
- "#define INITIAL" + (depthRedux ? "\n#define DEPTH_REDUX" : ""), // defines
66
- type, undefined, undefined, undefined, 7, scene.getEngine().isWebGPU ? 1 /* ShaderLanguage.WGSL */ : 0 /* ShaderLanguage.GLSL */);
67
- reductionInitial.autoClear = false;
68
- reductionInitial.forceFullscreenViewport = forceFullscreenViewport;
69
- let w = this._sourceTexture.getRenderWidth(), h = this._sourceTexture.getRenderHeight();
70
- reductionInitial.onApply = ((w, h) => {
71
- return (effect) => {
72
- effect.setTexture("sourceTexture", this._sourceTexture);
73
- effect.setFloat2("texSize", w, h);
74
- };
75
- })(w, h);
76
- this._reductionSteps.push(reductionInitial);
77
- let index = 1;
78
- // create the additional steps
79
- while (w > 1 || h > 1) {
80
- w = Math.max(Math.round(w / 2), 1);
81
- h = Math.max(Math.round(h / 2), 1);
82
- const reduction = new PostProcess("Reduction phase " + index, "minmaxRedux", // shader
83
- ["texSize"], null, { width: w, height: h }, // options
84
- null, // camera
85
- 1, // sampling
86
- scene.getEngine(), // engine
87
- false, // reusable
88
- "#define " + (w == 1 && h == 1 ? "LAST" : w == 1 || h == 1 ? "ONEBEFORELAST" : "MAIN"), // defines
89
- type, undefined, undefined, undefined, 7, scene.getEngine().isWebGPU ? 1 /* ShaderLanguage.WGSL */ : 0 /* ShaderLanguage.GLSL */);
90
- reduction.autoClear = false;
91
- reduction.forceFullscreenViewport = forceFullscreenViewport;
92
- reduction.onApply = ((w, h) => {
93
- return (effect) => {
94
- if (w == 1 || h == 1) {
95
- effect.setInt2("texSize", w, h);
96
- }
97
- else {
98
- effect.setFloat2("texSize", w, h);
99
- }
100
- };
101
- })(w, h);
102
- this._reductionSteps.push(reduction);
103
- index++;
104
- if (w == 1 && h == 1) {
105
- const func = (w, h, reduction) => {
106
- const buffer = new Float32Array(4 * w * h), minmax = { min: 0, max: 0 };
107
- return () => {
108
- // Note that we should normally await the call to _readTexturePixels!
109
- // But because WebGL does the read synchronously, we know the values will be updated without waiting for the promise to be resolved, which will let us get the updated values
110
- // in the current frame, whereas in WebGPU, the read is asynchronous and we should normally wait for the promise to be resolved to get the updated values.
111
- // However, it's safe to avoid waiting for the promise to be resolved in WebGPU as well, because we will simply use the current values until "buffer" is updated later on.
112
- // Note that it means we can suffer some rendering artifacts in WebGPU because we may use previous min/max values for the current frame.
113
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
114
- scene.getEngine()._readTexturePixels(reduction.inputTexture.texture, w, h, -1, 0, buffer, false);
115
- minmax.min = buffer[0];
116
- minmax.max = buffer[1];
117
- this.onAfterReductionPerformed.notifyObservers(minmax);
118
- };
119
- };
120
- reduction.onAfterRenderObservable.add(func(w, h, reduction));
61
+ if (this._thinMinMaxReducer.setTextureDimensions(sourceTexture.getRenderWidth(), sourceTexture.getRenderHeight())) {
62
+ this._disposePostProcesses();
63
+ const reductionSteps = this._thinMinMaxReducer.reductionSteps;
64
+ for (let i = 0; i < reductionSteps.length; ++i) {
65
+ const reductionStep = reductionSteps[i];
66
+ const postProcess = new PostProcess(reductionStep.name, ThinMinMaxReducerPostProcess.FragmentUrl, {
67
+ effectWrapper: reductionStep,
68
+ samplingMode: 1,
69
+ engine: this._camera.getScene().getEngine(),
70
+ textureType: type,
71
+ textureFormat: 7,
72
+ size: { width: reductionStep.textureWidth, height: reductionStep.textureHeight },
73
+ });
74
+ this._reductionSteps.push(postProcess);
75
+ postProcess.autoClear = false;
76
+ postProcess.forceFullscreenViewport = forceFullscreenViewport;
77
+ if (i === 0) {
78
+ postProcess.externalTextureSamplerBinding = true;
79
+ postProcess.onApplyObservable.add((effect) => {
80
+ effect.setTexture("textureSampler", this._sourceTexture);
81
+ });
82
+ }
83
+ if (i === reductionSteps.length - 1) {
84
+ this._reductionSteps[i - 1].onAfterRenderObservable.add(() => {
85
+ this._thinMinMaxReducer.readMinMax(postProcess.inputTexture.texture);
86
+ });
87
+ }
121
88
  }
122
89
  }
123
90
  }
@@ -152,8 +119,8 @@ export class MinMaxReducer {
152
119
  const engine = this._camera.getScene().getEngine();
153
120
  engine._debugPushGroup?.(`min max reduction`, 1);
154
121
  this._reductionSteps[0].activate(this._camera);
155
- this._postProcessManager.directRender(this._reductionSteps, this._reductionSteps[0].inputTexture, this._forceFullscreenViewport);
156
- engine.unBindFramebuffer(this._reductionSteps[0].inputTexture, false);
122
+ this._postProcessManager.directRender(this._reductionSteps, this._reductionSteps[0].inputTexture, this._forceFullscreenViewport, 0, 0, true, this._reductionSteps.length - 1);
123
+ engine.unBindFramebuffer(this._reductionSteps[this._reductionSteps.length - 1].inputTexture, false);
157
124
  engine._debugPopGroup?.(1);
158
125
  });
159
126
  this._activated = true;
@@ -174,24 +141,24 @@ export class MinMaxReducer {
174
141
  * @param disposeAll true to dispose all the resources. You should always call this function with true as the parameter (or without any parameter as it is the default one). This flag is meant to be used internally.
175
142
  */
176
143
  dispose(disposeAll = true) {
177
- if (disposeAll) {
178
- this.onAfterReductionPerformed.clear();
179
- if (this._onContextRestoredObserver) {
180
- this._camera.getEngine().onContextRestoredObservable.remove(this._onContextRestoredObserver);
181
- this._onContextRestoredObserver = null;
182
- }
183
- }
184
- this.deactivate();
185
- if (this._reductionSteps) {
186
- for (let i = 0; i < this._reductionSteps.length; ++i) {
187
- this._reductionSteps[i].dispose();
188
- }
189
- this._reductionSteps = null;
190
- }
191
- if (this._postProcessManager && disposeAll) {
192
- this._postProcessManager.dispose();
144
+ if (!disposeAll) {
145
+ return;
193
146
  }
147
+ this.onAfterReductionPerformed.clear();
148
+ this._camera.getEngine().onContextRestoredObservable.remove(this._onContextRestoredObserver);
149
+ this._onContextRestoredObserver = undefined;
150
+ this._disposePostProcesses();
151
+ this._postProcessManager.dispose();
152
+ this._postProcessManager = undefined;
153
+ this._thinMinMaxReducer.dispose();
154
+ this._thinMinMaxReducer = undefined;
194
155
  this._sourceTexture = null;
195
156
  }
157
+ _disposePostProcesses() {
158
+ for (let i = 0; i < this._reductionSteps.length; ++i) {
159
+ this._reductionSteps[i].dispose();
160
+ }
161
+ this._reductionSteps.length = 0;
162
+ }
196
163
  }
197
164
  //# sourceMappingURL=minMaxReducer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"minMaxReducer.js","sourceRoot":"","sources":["../../../../dev/core/src/Misc/minMaxReducer.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,UAAU,EAAE,CAAC;YACzC,IAAI,CAAC,mBAAmB,CAAC,OAAO,EAAE,CAAC;QACvC,CAAC;QAED,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;IAC/B,CAAC;CACJ","sourcesContent":["import type { Nullable } from \"../types\";\r\nimport type { RenderTargetTexture } from \"../Materials/Textures/renderTargetTexture\";\r\nimport type { Camera } from \"../Cameras/camera\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport type { Observer } from \"./observable\";\r\nimport { Observable } from \"./observable\";\r\nimport type { Effect } from \"../Materials/effect\";\r\nimport { PostProcess } from \"../PostProcesses/postProcess\";\r\nimport { PostProcessManager } from \"../PostProcesses/postProcessManager\";\r\nimport { ShaderLanguage } from \"core/Materials/shaderLanguage\";\r\n\r\nimport type { AbstractEngine } from \"../Engines/abstractEngine\";\r\n\r\nimport \"../Shaders/minmaxRedux.fragment\";\r\nimport \"../ShadersWGSL/minmaxRedux.fragment\";\r\n\r\n/**\r\n * This class computes a min/max reduction from a texture: it means it computes the minimum\r\n * and maximum values from all values of the texture.\r\n * It is performed on the GPU for better performances, thanks to a succession of post processes.\r\n * The source values are read from the red channel of the texture.\r\n */\r\nexport class MinMaxReducer {\r\n /**\r\n * Observable triggered when the computation has been performed\r\n */\r\n public onAfterReductionPerformed = new Observable<{ min: number; max: number }>();\r\n\r\n protected _camera: Camera;\r\n protected _sourceTexture: Nullable<RenderTargetTexture>;\r\n protected _reductionSteps: Nullable<Array<PostProcess>>;\r\n protected _postProcessManager: PostProcessManager;\r\n protected _onAfterUnbindObserver: Nullable<Observer<RenderTargetTexture>>;\r\n protected _forceFullscreenViewport = true;\r\n protected _onContextRestoredObserver: Nullable<Observer<AbstractEngine>>;\r\n\r\n /**\r\n * Creates a min/max reducer\r\n * @param camera The camera to use for the post processes\r\n */\r\n constructor(camera: Camera) {\r\n this._camera = camera;\r\n this._postProcessManager = new PostProcessManager(camera.getScene());\r\n\r\n this._onContextRestoredObserver = camera.getEngine().onContextRestoredObservable.add(() => {\r\n this._postProcessManager._rebuild();\r\n });\r\n }\r\n\r\n /**\r\n * Gets the texture used to read the values from.\r\n */\r\n public get sourceTexture(): Nullable<RenderTargetTexture> {\r\n return this._sourceTexture;\r\n }\r\n\r\n /**\r\n * Sets the source texture to read the values from.\r\n * One must indicate if the texture is a depth texture or not through the depthRedux parameter\r\n * because in such textures '1' value must not be taken into account to compute the maximum\r\n * as this value is used to clear the texture.\r\n * Note that the computation is not activated by calling this function, you must call activate() for that!\r\n * @param sourceTexture The texture to read the values from. The values should be in the red channel.\r\n * @param depthRedux Indicates if the texture is a depth texture or not\r\n * @param type The type of the textures created for the reduction (defaults to TEXTURETYPE_HALF_FLOAT)\r\n * @param forceFullscreenViewport Forces the post processes used for the reduction to be applied without taking into account viewport (defaults to true)\r\n */\r\n public setSourceTexture(sourceTexture: RenderTargetTexture, depthRedux: boolean, type: number = Constants.TEXTURETYPE_HALF_FLOAT, forceFullscreenViewport = true): void {\r\n if (sourceTexture === this._sourceTexture) {\r\n return;\r\n }\r\n\r\n this.dispose(false);\r\n\r\n this._sourceTexture = sourceTexture;\r\n this._reductionSteps = [];\r\n this._forceFullscreenViewport = forceFullscreenViewport;\r\n\r\n const scene = this._camera.getScene();\r\n\r\n // create the first step\r\n const reductionInitial = new PostProcess(\r\n \"Initial reduction phase\",\r\n \"minmaxRedux\", // shader\r\n [\"texSize\"],\r\n [\"sourceTexture\"], // textures\r\n 1.0, // options\r\n null, // camera\r\n Constants.TEXTURE_NEAREST_NEAREST, // sampling\r\n scene.getEngine(), // engine\r\n false, // reusable\r\n \"#define INITIAL\" + (depthRedux ? \"\\n#define DEPTH_REDUX\" : \"\"), // defines\r\n type,\r\n undefined,\r\n undefined,\r\n undefined,\r\n Constants.TEXTUREFORMAT_RG,\r\n scene.getEngine().isWebGPU ? ShaderLanguage.WGSL : ShaderLanguage.GLSL\r\n );\r\n\r\n reductionInitial.autoClear = false;\r\n reductionInitial.forceFullscreenViewport = forceFullscreenViewport;\r\n\r\n let w = this._sourceTexture.getRenderWidth(),\r\n h = this._sourceTexture.getRenderHeight();\r\n\r\n reductionInitial.onApply = ((w: number, h: number) => {\r\n return (effect: Effect) => {\r\n effect.setTexture(\"sourceTexture\", this._sourceTexture);\r\n effect.setFloat2(\"texSize\", w, h);\r\n };\r\n })(w, h);\r\n\r\n this._reductionSteps.push(reductionInitial);\r\n\r\n let index = 1;\r\n\r\n // create the additional steps\r\n while (w > 1 || h > 1) {\r\n w = Math.max(Math.round(w / 2), 1);\r\n h = Math.max(Math.round(h / 2), 1);\r\n\r\n const reduction = new PostProcess(\r\n \"Reduction phase \" + index,\r\n \"minmaxRedux\", // shader\r\n [\"texSize\"],\r\n null,\r\n { width: w, height: h }, // options\r\n null, // camera\r\n Constants.TEXTURE_NEAREST_NEAREST, // sampling\r\n scene.getEngine(), // engine\r\n false, // reusable\r\n \"#define \" + (w == 1 && h == 1 ? \"LAST\" : w == 1 || h == 1 ? \"ONEBEFORELAST\" : \"MAIN\"), // defines\r\n type,\r\n undefined,\r\n undefined,\r\n undefined,\r\n Constants.TEXTUREFORMAT_RG,\r\n scene.getEngine().isWebGPU ? ShaderLanguage.WGSL : ShaderLanguage.GLSL\r\n );\r\n\r\n reduction.autoClear = false;\r\n reduction.forceFullscreenViewport = forceFullscreenViewport;\r\n\r\n reduction.onApply = ((w: number, h: number) => {\r\n return (effect: Effect) => {\r\n if (w == 1 || h == 1) {\r\n effect.setInt2(\"texSize\", w, h);\r\n } else {\r\n effect.setFloat2(\"texSize\", w, h);\r\n }\r\n };\r\n })(w, h);\r\n\r\n this._reductionSteps.push(reduction);\r\n\r\n index++;\r\n\r\n if (w == 1 && h == 1) {\r\n const func = (w: number, h: number, reduction: PostProcess) => {\r\n const buffer = new Float32Array(4 * w * h),\r\n minmax = { min: 0, max: 0 };\r\n return () => {\r\n // Note that we should normally await the call to _readTexturePixels!\r\n // But because WebGL does the read synchronously, we know the values will be updated without waiting for the promise to be resolved, which will let us get the updated values\r\n // in the current frame, whereas in WebGPU, the read is asynchronous and we should normally wait for the promise to be resolved to get the updated values.\r\n // However, it's safe to avoid waiting for the promise to be resolved in WebGPU as well, because we will simply use the current values until \"buffer\" is updated later on.\r\n // Note that it means we can suffer some rendering artifacts in WebGPU because we may use previous min/max values for the current frame.\r\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\r\n scene.getEngine()._readTexturePixels(reduction.inputTexture.texture!, w, h, -1, 0, buffer, false);\r\n minmax.min = buffer[0];\r\n minmax.max = buffer[1];\r\n this.onAfterReductionPerformed.notifyObservers(minmax);\r\n };\r\n };\r\n reduction.onAfterRenderObservable.add(func(w, h, reduction));\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Defines the refresh rate of the computation.\r\n * Use 0 to compute just once, 1 to compute on every frame, 2 to compute every two frames and so on...\r\n */\r\n public get refreshRate(): number {\r\n return this._sourceTexture ? this._sourceTexture.refreshRate : -1;\r\n }\r\n\r\n public set refreshRate(value: number) {\r\n if (this._sourceTexture) {\r\n this._sourceTexture.refreshRate = value;\r\n }\r\n }\r\n\r\n protected _activated = false;\r\n\r\n /**\r\n * Gets the activation status of the reducer\r\n */\r\n public get activated(): boolean {\r\n return this._activated;\r\n }\r\n\r\n /**\r\n * Activates the reduction computation.\r\n * When activated, the observers registered in onAfterReductionPerformed are\r\n * called after the computation is performed\r\n */\r\n public activate(): void {\r\n if (this._onAfterUnbindObserver || !this._sourceTexture) {\r\n return;\r\n }\r\n\r\n this._onAfterUnbindObserver = this._sourceTexture.onAfterUnbindObservable.add(() => {\r\n const engine = this._camera.getScene().getEngine();\r\n engine._debugPushGroup?.(`min max reduction`, 1);\r\n this._reductionSteps![0].activate(this._camera);\r\n this._postProcessManager.directRender(this._reductionSteps!, this._reductionSteps![0].inputTexture, this._forceFullscreenViewport);\r\n engine.unBindFramebuffer(this._reductionSteps![0].inputTexture, false);\r\n engine._debugPopGroup?.(1);\r\n });\r\n\r\n this._activated = true;\r\n }\r\n\r\n /**\r\n * Deactivates the reduction computation.\r\n */\r\n public deactivate(): void {\r\n if (!this._onAfterUnbindObserver || !this._sourceTexture) {\r\n return;\r\n }\r\n\r\n this._sourceTexture.onAfterUnbindObservable.remove(this._onAfterUnbindObserver);\r\n this._onAfterUnbindObserver = null;\r\n this._activated = false;\r\n }\r\n\r\n /**\r\n * Disposes the min/max reducer\r\n * @param disposeAll true to dispose all the resources. You should always call this function with true as the parameter (or without any parameter as it is the default one). This flag is meant to be used internally.\r\n */\r\n public dispose(disposeAll = true): void {\r\n if (disposeAll) {\r\n this.onAfterReductionPerformed.clear();\r\n\r\n if (this._onContextRestoredObserver) {\r\n this._camera.getEngine().onContextRestoredObservable.remove(this._onContextRestoredObserver);\r\n this._onContextRestoredObserver = null;\r\n }\r\n }\r\n\r\n this.deactivate();\r\n\r\n if (this._reductionSteps) {\r\n for (let i = 0; i < this._reductionSteps.length; ++i) {\r\n this._reductionSteps[i].dispose();\r\n }\r\n this._reductionSteps = null;\r\n }\r\n\r\n if (this._postProcessManager && disposeAll) {\r\n this._postProcessManager.dispose();\r\n }\r\n\r\n this._sourceTexture = null;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"minMaxReducer.js","sourceRoot":"","sources":["../../../../dev/core/src/Misc/minMaxReducer.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGjD,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AAGzE,OAAO,EAAE,iBAAiB,EAAE,4BAA4B,EAAE,MAAM,qBAAqB,CAAC;AAEtF,OAAO,iCAAiC,CAAC;AACzC,OAAO,qCAAqC,CAAC;AAE7C;;;;;GAKG;AACH,MAAM,OAAO,aAAa;IACtB;;OAEG;IACH,IAAW,yBAAyB;QAChC,OAAO,IAAI,CAAC,kBAAkB,CAAC,yBAAyB,CAAC;IAC7D,CAAC;IAWD;;;OAGG;IACH,YAAY,MAAc;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C,eAAe,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC;YACnD,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;QACtC,CAAC;QACD,IAAI,CAAC,eAAe,CAAC,MAAM,GAAG,CAAC,CAAC;IACpC,CAAC;CACJ","sourcesContent":["import type { Nullable } from \"../types\";\r\nimport type { RenderTargetTexture } from \"../Materials/Textures/renderTargetTexture\";\r\nimport type { Camera } from \"../Cameras/camera\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport type { Observer } from \"./observable\";\r\nimport type { Effect } from \"../Materials/effect\";\r\nimport { PostProcess } from \"../PostProcesses/postProcess\";\r\nimport { PostProcessManager } from \"../PostProcesses/postProcessManager\";\r\n\r\nimport type { AbstractEngine } from \"../Engines/abstractEngine\";\r\nimport { ThinMinMaxReducer, ThinMinMaxReducerPostProcess } from \"./thinMinMaxReducer\";\r\n\r\nimport \"../Shaders/minmaxRedux.fragment\";\r\nimport \"../ShadersWGSL/minmaxRedux.fragment\";\r\n\r\n/**\r\n * This class computes a min/max reduction from a texture: it means it computes the minimum\r\n * and maximum values from all values of the texture.\r\n * It is performed on the GPU for better performances, thanks to a succession of post processes.\r\n * The source values are read from the red channel of the texture.\r\n */\r\nexport class MinMaxReducer {\r\n /**\r\n * Observable triggered when the computation has been performed\r\n */\r\n public get onAfterReductionPerformed() {\r\n return this._thinMinMaxReducer.onAfterReductionPerformed;\r\n }\r\n\r\n protected readonly _camera: Camera;\r\n protected readonly _thinMinMaxReducer: ThinMinMaxReducer;\r\n protected _sourceTexture: Nullable<RenderTargetTexture>;\r\n protected readonly _reductionSteps: Array<PostProcess>;\r\n protected readonly _postProcessManager: PostProcessManager;\r\n protected _onAfterUnbindObserver: Nullable<Observer<RenderTargetTexture>> = null;\r\n protected _forceFullscreenViewport = true;\r\n protected readonly _onContextRestoredObserver: Observer<AbstractEngine>;\r\n\r\n /**\r\n * Creates a min/max reducer\r\n * @param camera The camera to use for the post processes\r\n */\r\n constructor(camera: Camera) {\r\n this._camera = camera;\r\n this._postProcessManager = new PostProcessManager(camera.getScene());\r\n this._thinMinMaxReducer = new ThinMinMaxReducer(camera.getScene());\r\n this._reductionSteps = [];\r\n\r\n this._onContextRestoredObserver = camera.getEngine().onContextRestoredObservable.add(() => {\r\n this._postProcessManager._rebuild();\r\n });\r\n }\r\n\r\n /**\r\n * Gets the texture used to read the values from.\r\n */\r\n public get sourceTexture(): Nullable<RenderTargetTexture> {\r\n return this._sourceTexture;\r\n }\r\n\r\n /**\r\n * Sets the source texture to read the values from.\r\n * One must indicate if the texture is a depth texture or not through the depthRedux parameter\r\n * because in such textures '1' value must not be taken into account to compute the maximum\r\n * as this value is used to clear the texture.\r\n * Note that the computation is not activated by calling this function, you must call activate() for that!\r\n * @param sourceTexture The texture to read the values from. The values should be in the red channel.\r\n * @param depthRedux Indicates if the texture is a depth texture or not\r\n * @param type The type of the textures created for the reduction (defaults to TEXTURETYPE_HALF_FLOAT)\r\n * @param forceFullscreenViewport Forces the post processes used for the reduction to be applied without taking into account viewport (defaults to true)\r\n */\r\n public setSourceTexture(sourceTexture: RenderTargetTexture, depthRedux: boolean, type: number = Constants.TEXTURETYPE_HALF_FLOAT, forceFullscreenViewport = true): void {\r\n if (sourceTexture === this._sourceTexture) {\r\n return;\r\n }\r\n\r\n this._thinMinMaxReducer.depthRedux = depthRedux;\r\n\r\n this.deactivate();\r\n\r\n this._sourceTexture = sourceTexture;\r\n this._forceFullscreenViewport = forceFullscreenViewport;\r\n\r\n if (this._thinMinMaxReducer.setTextureDimensions(sourceTexture.getRenderWidth(), sourceTexture.getRenderHeight())) {\r\n this._disposePostProcesses();\r\n\r\n const reductionSteps = this._thinMinMaxReducer.reductionSteps;\r\n\r\n for (let i = 0; i < reductionSteps.length; ++i) {\r\n const reductionStep = reductionSteps[i];\r\n\r\n const postProcess = new PostProcess(reductionStep.name, ThinMinMaxReducerPostProcess.FragmentUrl, {\r\n effectWrapper: reductionStep,\r\n samplingMode: Constants.TEXTURE_NEAREST_NEAREST,\r\n engine: this._camera.getScene().getEngine(),\r\n textureType: type,\r\n textureFormat: Constants.TEXTUREFORMAT_RG,\r\n size: { width: reductionStep.textureWidth, height: reductionStep.textureHeight },\r\n });\r\n\r\n this._reductionSteps.push(postProcess);\r\n\r\n postProcess.autoClear = false;\r\n postProcess.forceFullscreenViewport = forceFullscreenViewport;\r\n\r\n if (i === 0) {\r\n postProcess.externalTextureSamplerBinding = true;\r\n postProcess.onApplyObservable.add((effect: Effect) => {\r\n effect.setTexture(\"textureSampler\", this._sourceTexture);\r\n });\r\n }\r\n\r\n if (i === reductionSteps.length - 1) {\r\n this._reductionSteps[i - 1].onAfterRenderObservable.add(() => {\r\n this._thinMinMaxReducer.readMinMax(postProcess.inputTexture.texture!);\r\n });\r\n }\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Defines the refresh rate of the computation.\r\n * Use 0 to compute just once, 1 to compute on every frame, 2 to compute every two frames and so on...\r\n */\r\n public get refreshRate(): number {\r\n return this._sourceTexture ? this._sourceTexture.refreshRate : -1;\r\n }\r\n\r\n public set refreshRate(value: number) {\r\n if (this._sourceTexture) {\r\n this._sourceTexture.refreshRate = value;\r\n }\r\n }\r\n\r\n protected _activated = false;\r\n\r\n /**\r\n * Gets the activation status of the reducer\r\n */\r\n public get activated(): boolean {\r\n return this._activated;\r\n }\r\n\r\n /**\r\n * Activates the reduction computation.\r\n * When activated, the observers registered in onAfterReductionPerformed are\r\n * called after the computation is performed\r\n */\r\n public activate(): void {\r\n if (this._onAfterUnbindObserver || !this._sourceTexture) {\r\n return;\r\n }\r\n\r\n this._onAfterUnbindObserver = this._sourceTexture.onAfterUnbindObservable.add(() => {\r\n const engine = this._camera.getScene().getEngine();\r\n engine._debugPushGroup?.(`min max reduction`, 1);\r\n this._reductionSteps![0].activate(this._camera);\r\n this._postProcessManager.directRender(\r\n this._reductionSteps!,\r\n this._reductionSteps![0].inputTexture,\r\n this._forceFullscreenViewport,\r\n 0,\r\n 0,\r\n true,\r\n this._reductionSteps.length - 1\r\n );\r\n engine.unBindFramebuffer(this._reductionSteps![this._reductionSteps.length - 1].inputTexture, false);\r\n engine._debugPopGroup?.(1);\r\n });\r\n\r\n this._activated = true;\r\n }\r\n\r\n /**\r\n * Deactivates the reduction computation.\r\n */\r\n public deactivate(): void {\r\n if (!this._onAfterUnbindObserver || !this._sourceTexture) {\r\n return;\r\n }\r\n\r\n this._sourceTexture.onAfterUnbindObservable.remove(this._onAfterUnbindObserver);\r\n this._onAfterUnbindObserver = null;\r\n this._activated = false;\r\n }\r\n\r\n /**\r\n * Disposes the min/max reducer\r\n * @param disposeAll true to dispose all the resources. You should always call this function with true as the parameter (or without any parameter as it is the default one). This flag is meant to be used internally.\r\n */\r\n public dispose(disposeAll = true): void {\r\n if (!disposeAll) {\r\n return;\r\n }\r\n\r\n this.onAfterReductionPerformed.clear();\r\n\r\n this._camera.getEngine().onContextRestoredObservable.remove(this._onContextRestoredObserver);\r\n (this._onContextRestoredObserver as any) = undefined;\r\n\r\n this._disposePostProcesses();\r\n\r\n this._postProcessManager.dispose();\r\n (this._postProcessManager as any) = undefined as any;\r\n this._thinMinMaxReducer.dispose();\r\n (this._thinMinMaxReducer as any) = undefined;\r\n this._sourceTexture = null;\r\n }\r\n\r\n private _disposePostProcesses() {\r\n for (let i = 0; i < this._reductionSteps.length; ++i) {\r\n this._reductionSteps[i].dispose();\r\n }\r\n this._reductionSteps.length = 0;\r\n }\r\n}\r\n"]}
@@ -0,0 +1,47 @@
1
+ import type { Nullable, EffectWrapperCreationOptions, AbstractEngine, InternalTexture, Scene } from "../index.js";
2
+ import { Observable } from "./observable.js";
3
+ import { EffectWrapper } from "../Materials/effectRenderer.js";
4
+ /**
5
+ * @internal
6
+ */
7
+ export declare enum DepthTextureType {
8
+ NormalizedViewDepth = 0,
9
+ ViewDepth = 1,
10
+ ScreenDepth = 2
11
+ }
12
+ /**
13
+ * @internal
14
+ */
15
+ export declare class ThinMinMaxReducerPostProcess extends EffectWrapper {
16
+ static readonly FragmentUrl = "minmaxRedux";
17
+ static readonly Uniforms: string[];
18
+ protected _gatherImports(useWebGPU: boolean, list: Promise<any>[]): void;
19
+ textureWidth: number;
20
+ textureHeight: number;
21
+ constructor(name: string, engine?: Nullable<AbstractEngine>, defines?: string, options?: EffectWrapperCreationOptions);
22
+ bind(noDefaultBindings?: boolean): void;
23
+ }
24
+ /**
25
+ * @internal
26
+ */
27
+ export declare class ThinMinMaxReducer {
28
+ readonly onAfterReductionPerformed: Observable<{
29
+ min: number;
30
+ max: number;
31
+ }>;
32
+ readonly reductionSteps: Array<ThinMinMaxReducerPostProcess>;
33
+ private _depthRedux;
34
+ private _depthTextureType;
35
+ get depthRedux(): boolean;
36
+ set depthRedux(value: boolean);
37
+ protected readonly _scene: Scene;
38
+ private _textureWidth;
39
+ private _textureHeight;
40
+ get textureWidth(): number;
41
+ get textureHeight(): number;
42
+ constructor(scene: Scene, depthRedux?: boolean);
43
+ setTextureDimensions(width: number, height: number, depthTextureType?: DepthTextureType): boolean;
44
+ readMinMax(texture: InternalTexture): void;
45
+ dispose(disposeAll?: boolean): void;
46
+ private _recreatePostProcesses;
47
+ }
@@ -0,0 +1,148 @@
1
+ import { Observable } from "./observable.js";
2
+ import { EffectWrapper } from "../Materials/effectRenderer.js";
3
+ import { Engine } from "../Engines/engine.js";
4
+ /**
5
+ * @internal
6
+ */
7
+ export var DepthTextureType;
8
+ (function (DepthTextureType) {
9
+ DepthTextureType[DepthTextureType["NormalizedViewDepth"] = 0] = "NormalizedViewDepth";
10
+ DepthTextureType[DepthTextureType["ViewDepth"] = 1] = "ViewDepth";
11
+ DepthTextureType[DepthTextureType["ScreenDepth"] = 2] = "ScreenDepth";
12
+ })(DepthTextureType || (DepthTextureType = {}));
13
+ /**
14
+ * @internal
15
+ */
16
+ export class ThinMinMaxReducerPostProcess extends EffectWrapper {
17
+ _gatherImports(useWebGPU, list) {
18
+ if (useWebGPU) {
19
+ this._webGPUReady = true;
20
+ list.push(import("../ShadersWGSL/minmaxRedux.fragment.js"));
21
+ }
22
+ else {
23
+ list.push(import("../Shaders/minmaxRedux.fragment.js"));
24
+ }
25
+ }
26
+ constructor(name, engine = null, defines = "", options) {
27
+ super({
28
+ ...options,
29
+ name,
30
+ engine: engine || Engine.LastCreatedEngine,
31
+ useShaderStore: true,
32
+ useAsPostProcess: true,
33
+ fragmentShader: ThinMinMaxReducerPostProcess.FragmentUrl,
34
+ uniforms: ThinMinMaxReducerPostProcess.Uniforms,
35
+ defines,
36
+ });
37
+ this.textureWidth = 0;
38
+ this.textureHeight = 0;
39
+ }
40
+ bind(noDefaultBindings = false) {
41
+ super.bind(noDefaultBindings);
42
+ const effect = this.drawWrapper.effect;
43
+ if (this.textureWidth === 1 || this.textureHeight === 1) {
44
+ effect.setInt2("texSize", this.textureWidth, this.textureHeight);
45
+ }
46
+ else {
47
+ effect.setFloat2("texSize", this.textureWidth, this.textureHeight);
48
+ }
49
+ }
50
+ }
51
+ ThinMinMaxReducerPostProcess.FragmentUrl = "minmaxRedux";
52
+ ThinMinMaxReducerPostProcess.Uniforms = ["texSize"];
53
+ const BufferFloat = new Float32Array(4 * 1 * 1);
54
+ const BufferUint8 = new Uint8Array(4 * 1 * 1);
55
+ const MinMax = { min: 0, max: 0 };
56
+ /**
57
+ * @internal
58
+ */
59
+ export class ThinMinMaxReducer {
60
+ get depthRedux() {
61
+ return this._depthRedux;
62
+ }
63
+ set depthRedux(value) {
64
+ if (this._depthRedux === value) {
65
+ return;
66
+ }
67
+ this._depthRedux = value;
68
+ this._recreatePostProcesses();
69
+ }
70
+ get textureWidth() {
71
+ return this._textureWidth;
72
+ }
73
+ get textureHeight() {
74
+ return this._textureHeight;
75
+ }
76
+ constructor(scene, depthRedux = true) {
77
+ this.onAfterReductionPerformed = new Observable();
78
+ this._textureWidth = 0;
79
+ this._textureHeight = 0;
80
+ this._scene = scene;
81
+ this._depthRedux = depthRedux;
82
+ this.reductionSteps = [];
83
+ }
84
+ setTextureDimensions(width, height, depthTextureType = 0 /* DepthTextureType.NormalizedViewDepth */) {
85
+ if (width === this._textureWidth && height === this._textureHeight && depthTextureType === this._depthTextureType) {
86
+ return false;
87
+ }
88
+ this._textureWidth = width;
89
+ this._textureHeight = height;
90
+ this._depthTextureType = depthTextureType;
91
+ this._recreatePostProcesses();
92
+ return true;
93
+ }
94
+ readMinMax(texture) {
95
+ // Note that we should normally await the call to _readTexturePixels!
96
+ // But because WebGL does the read synchronously, we know the values will be updated without waiting for the promise to be resolved, which will let us get the updated values
97
+ // in the current frame, whereas in WebGPU, the read is asynchronous and we should normally wait for the promise to be resolved to get the updated values.
98
+ // However, it's safe to avoid waiting for the promise to be resolved in WebGPU as well, because we will simply use the current values until "buffer" is updated later on.
99
+ // Note that it means we can suffer some rendering artifacts in WebGPU because we may use previous min/max values for the current frame.
100
+ const isFloat = texture.type === Engine.TEXTURETYPE_FLOAT || texture.type === Engine.TEXTURETYPE_HALF_FLOAT;
101
+ const buffer = isFloat ? BufferFloat : BufferUint8;
102
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
103
+ this._scene.getEngine()._readTexturePixels(texture, 1, 1, -1, 0, buffer, false);
104
+ MinMax.min = buffer[0];
105
+ MinMax.max = buffer[1];
106
+ if (!isFloat) {
107
+ MinMax.min = MinMax.min / 255.0;
108
+ MinMax.max = MinMax.max / 255.0;
109
+ }
110
+ if (MinMax.min >= MinMax.max) {
111
+ MinMax.min = 0;
112
+ MinMax.max = 1;
113
+ }
114
+ this.onAfterReductionPerformed.notifyObservers(MinMax);
115
+ }
116
+ dispose(disposeAll = true) {
117
+ if (disposeAll) {
118
+ this.onAfterReductionPerformed.clear();
119
+ this._textureWidth = 0;
120
+ this._textureHeight = 0;
121
+ }
122
+ for (let i = 0; i < this.reductionSteps.length; ++i) {
123
+ this.reductionSteps[i].dispose();
124
+ }
125
+ this.reductionSteps.length = 0;
126
+ }
127
+ _recreatePostProcesses() {
128
+ this.dispose(false);
129
+ const scene = this._scene;
130
+ let w = this.textureWidth, h = this.textureHeight;
131
+ const reductionInitial = new ThinMinMaxReducerPostProcess("Initial reduction phase", scene.getEngine(), "#define INITIAL" + (this._depthRedux ? "\n#define DEPTH_REDUX" : "") + (this._depthTextureType === 1 /* DepthTextureType.ViewDepth */ ? "\n#define VIEW_DEPTH" : ""));
132
+ reductionInitial.textureWidth = w;
133
+ reductionInitial.textureHeight = h;
134
+ this.reductionSteps.push(reductionInitial);
135
+ let index = 1;
136
+ // create the additional steps
137
+ while (w > 1 || h > 1) {
138
+ w = Math.max(Math.round(w / 2), 1);
139
+ h = Math.max(Math.round(h / 2), 1);
140
+ const reduction = new ThinMinMaxReducerPostProcess("Reduction phase " + index, scene.getEngine(), "#define " + (w == 1 && h == 1 ? "LAST" : w == 1 || h == 1 ? "ONEBEFORELAST" : "MAIN"));
141
+ reduction.textureWidth = w;
142
+ reduction.textureHeight = h;
143
+ this.reductionSteps.push(reduction);
144
+ index++;
145
+ }
146
+ }
147
+ }
148
+ //# sourceMappingURL=thinMinMaxReducer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"thinMinMaxReducer.js","sourceRoot":"","sources":["../../../../dev/core/src/Misc/thinMinMaxReducer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,MAAM,EAAE,6BAA4B;AAE7C;;GAEG;AACH,MAAM,CAAN,IAAkB,gBAIjB;AAJD,WAAkB,gBAAgB;IAC9B,qFAAuB,CAAA;IACvB,iEAAa,CAAA;IACb,qEAAe,CAAA;AACnB,CAAC,EAJiB,gBAAgB,KAAhB,gBAAgB,QAIjC;AAED;;GAEG;AACH,MAAM,OAAO,4BAA6B,SAAQ,aAAa;IAKxC,cAAc,CAAC,SAAkB,EAAE,IAAoB;QACtE,IAAI,SAAS,EAAE,CAAC;YACZ,IAAI,CAAC,YAAY,G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K,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;YACnC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;YAEnC,MAAM,SAAS,GAAG,IAAI,4BAA4B,CAC9C,kBAAkB,GAAG,KAAK,EAC1B,KAAK,CAAC,SAAS,EAAE,EACjB,UAAU,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,MAAM,CAAC,CACzF,CAAC;YAEF,SAAS,CAAC,YAAY,GAAG,CAAC,CAAC;YAC3B,SAAS,CAAC,aAAa,GAAG,CAAC,CAAC;YAE5B,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YAEpC,KAAK,EAAE,CAAC;QACZ,CAAC;IACL,CAAC;CACJ","sourcesContent":["/* eslint-disable import/no-internal-modules */\r\nimport type { Nullable, EffectWrapperCreationOptions, AbstractEngine, InternalTexture, Scene } from \"core/index\";\r\nimport { Observable } from \"./observable\";\r\nimport { EffectWrapper } from \"../Materials/effectRenderer\";\r\nimport { Engine } from \"core/Engines/engine\";\r\n\r\n/**\r\n * @internal\r\n */\r\nexport const enum DepthTextureType {\r\n NormalizedViewDepth = 0,\r\n ViewDepth = 1,\r\n ScreenDepth = 2,\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport class ThinMinMaxReducerPostProcess extends EffectWrapper {\r\n public static readonly FragmentUrl = \"minmaxRedux\";\r\n\r\n public static readonly Uniforms = [\"texSize\"];\r\n\r\n protected override _gatherImports(useWebGPU: boolean, list: Promise<any>[]) {\r\n if (useWebGPU) {\r\n this._webGPUReady = true;\r\n list.push(import(\"../ShadersWGSL/minmaxRedux.fragment\"));\r\n } else {\r\n list.push(import(\"../Shaders/minmaxRedux.fragment\"));\r\n }\r\n }\r\n\r\n public textureWidth = 0;\r\n\r\n public textureHeight = 0;\r\n\r\n constructor(name: string, engine: Nullable<AbstractEngine> = null, defines = \"\", options?: EffectWrapperCreationOptions) {\r\n super({\r\n ...options,\r\n name,\r\n engine: engine || Engine.LastCreatedEngine!,\r\n useShaderStore: true,\r\n useAsPostProcess: true,\r\n fragmentShader: ThinMinMaxReducerPostProcess.FragmentUrl,\r\n uniforms: ThinMinMaxReducerPostProcess.Uniforms,\r\n defines,\r\n });\r\n }\r\n\r\n public override bind(noDefaultBindings = false) {\r\n super.bind(noDefaultBindings);\r\n\r\n const effect = this.drawWrapper.effect!;\r\n\r\n if (this.textureWidth === 1 || this.textureHeight === 1) {\r\n effect.setInt2(\"texSize\", this.textureWidth, this.textureHeight);\r\n } else {\r\n effect.setFloat2(\"texSize\", this.textureWidth, this.textureHeight);\r\n }\r\n }\r\n}\r\n\r\nconst BufferFloat = new Float32Array(4 * 1 * 1);\r\nconst BufferUint8 = new Uint8Array(4 * 1 * 1);\r\nconst MinMax = { min: 0, max: 0 };\r\n\r\n/**\r\n * @internal\r\n */\r\nexport class ThinMinMaxReducer {\r\n public readonly onAfterReductionPerformed = new Observable<{ min: number; max: number }>();\r\n\r\n public readonly reductionSteps: Array<ThinMinMaxReducerPostProcess>;\r\n\r\n private _depthRedux: boolean;\r\n private _depthTextureType: DepthTextureType;\r\n\r\n public get depthRedux() {\r\n return this._depthRedux;\r\n }\r\n\r\n public set depthRedux(value: boolean) {\r\n if (this._depthRedux === value) {\r\n return;\r\n }\r\n\r\n this._depthRedux = value;\r\n\r\n this._recreatePostProcesses();\r\n }\r\n\r\n protected readonly _scene: Scene;\r\n\r\n private _textureWidth = 0;\r\n private _textureHeight = 0;\r\n\r\n public get textureWidth() {\r\n return this._textureWidth;\r\n }\r\n\r\n public get textureHeight() {\r\n return this._textureHeight;\r\n }\r\n\r\n constructor(scene: Scene, depthRedux = true) {\r\n this._scene = scene;\r\n this._depthRedux = depthRedux;\r\n this.reductionSteps = [];\r\n }\r\n\r\n public setTextureDimensions(width: number, height: number, depthTextureType: DepthTextureType = DepthTextureType.NormalizedViewDepth) {\r\n if (width === this._textureWidth && height === this._textureHeight && depthTextureType === this._depthTextureType) {\r\n return false;\r\n }\r\n\r\n this._textureWidth = width;\r\n this._textureHeight = height;\r\n this._depthTextureType = depthTextureType;\r\n\r\n this._recreatePostProcesses();\r\n\r\n return true;\r\n }\r\n\r\n public readMinMax(texture: InternalTexture) {\r\n // Note that we should normally await the call to _readTexturePixels!\r\n // But because WebGL does the read synchronously, we know the values will be updated without waiting for the promise to be resolved, which will let us get the updated values\r\n // in the current frame, whereas in WebGPU, the read is asynchronous and we should normally wait for the promise to be resolved to get the updated values.\r\n // However, it's safe to avoid waiting for the promise to be resolved in WebGPU as well, because we will simply use the current values until \"buffer\" is updated later on.\r\n // Note that it means we can suffer some rendering artifacts in WebGPU because we may use previous min/max values for the current frame.\r\n const isFloat = texture.type === Engine.TEXTURETYPE_FLOAT || texture.type === Engine.TEXTURETYPE_HALF_FLOAT;\r\n const buffer = isFloat ? BufferFloat : BufferUint8;\r\n\r\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\r\n this._scene.getEngine()._readTexturePixels(texture, 1, 1, -1, 0, buffer, false);\r\n\r\n MinMax.min = buffer[0];\r\n MinMax.max = buffer[1];\r\n\r\n if (!isFloat) {\r\n MinMax.min = MinMax.min / 255.0;\r\n MinMax.max = MinMax.max / 255.0;\r\n }\r\n\r\n if (MinMax.min >= MinMax.max) {\r\n MinMax.min = 0;\r\n MinMax.max = 1;\r\n }\r\n\r\n this.onAfterReductionPerformed.notifyObservers(MinMax);\r\n }\r\n\r\n public dispose(disposeAll = true): void {\r\n if (disposeAll) {\r\n this.onAfterReductionPerformed.clear();\r\n this._textureWidth = 0;\r\n this._textureHeight = 0;\r\n }\r\n\r\n for (let i = 0; i < this.reductionSteps.length; ++i) {\r\n this.reductionSteps[i].dispose();\r\n }\r\n this.reductionSteps.length = 0;\r\n }\r\n\r\n private _recreatePostProcesses() {\r\n this.dispose(false);\r\n\r\n const scene = this._scene;\r\n\r\n let w = this.textureWidth,\r\n h = this.textureHeight;\r\n\r\n const reductionInitial = new ThinMinMaxReducerPostProcess(\r\n \"Initial reduction phase\",\r\n scene.getEngine(),\r\n \"#define INITIAL\" + (this._depthRedux ? \"\\n#define DEPTH_REDUX\" : \"\") + (this._depthTextureType === DepthTextureType.ViewDepth ? \"\\n#define VIEW_DEPTH\" : \"\")\r\n );\r\n\r\n reductionInitial.textureWidth = w;\r\n reductionInitial.textureHeight = h;\r\n\r\n this.reductionSteps.push(reductionInitial);\r\n\r\n let index = 1;\r\n\r\n // create the additional steps\r\n while (w > 1 || h > 1) {\r\n w = Math.max(Math.round(w / 2), 1);\r\n h = Math.max(Math.round(h / 2), 1);\r\n\r\n const reduction = new ThinMinMaxReducerPostProcess(\r\n \"Reduction phase \" + index,\r\n scene.getEngine(),\r\n \"#define \" + (w == 1 && h == 1 ? \"LAST\" : w == 1 || h == 1 ? \"ONEBEFORELAST\" : \"MAIN\")\r\n );\r\n\r\n reduction.textureWidth = w;\r\n reduction.textureHeight = h;\r\n\r\n this.reductionSteps.push(reduction);\r\n\r\n index++;\r\n }\r\n }\r\n}\r\n"]}
@@ -19,6 +19,11 @@ export declare class CustomParticleEmitter implements IParticleEmitterType {
19
19
  * * Index will be provided when used with GPU particle. Particle will be provided when used with CPU particles
20
20
  */
21
21
  particleDestinationGenerator: (index: number, particle: Nullable<Particle>, outDestination: Vector3) => void;
22
+ /**
23
+ * Gets or sets the direction generator that will create the initial direction of each particle.
24
+ * * Index will be provided when used with GPU particle. Particle will be provided when used with CPU particles
25
+ */
26
+ particleDirectionGenerator: (index: number, particle: Nullable<Particle>, outDestination: Vector3) => void;
22
27
  /**
23
28
  * Creates a new instance CustomParticleEmitter
24
29
  */
@@ -18,6 +18,11 @@ export class CustomParticleEmitter {
18
18
  * * Index will be provided when used with GPU particle. Particle will be provided when used with CPU particles
19
19
  */
20
20
  this.particleDestinationGenerator = () => { };
21
+ /**
22
+ * Gets or sets the direction generator that will create the initial direction of each particle.
23
+ * * Index will be provided when used with GPU particle. Particle will be provided when used with CPU particles
24
+ */
25
+ this.particleDirectionGenerator = () => { };
21
26
  }
22
27
  /**
23
28
  * Called by the particle System when the direction is computed for the created particle.
@@ -28,7 +33,10 @@ export class CustomParticleEmitter {
28
33
  */
29
34
  startDirectionFunction(worldMatrix, directionToUpdate, particle, isLocal) {
30
35
  const tmpVector = TmpVectors.Vector3[0];
31
- if (this.particleDestinationGenerator) {
36
+ if (this.particleDirectionGenerator) {
37
+ this.particleDirectionGenerator(-1, particle, tmpVector);
38
+ }
39
+ else if (this.particleDestinationGenerator) {
32
40
  this.particleDestinationGenerator(-1, particle, tmpVector);
33
41
  // Get direction
34
42
  const diffVector = TmpVectors.Vector3[1];
@@ -1 +1 @@
1
- {"version":3,"file":"customParticleEmitter.js","sourceRoot":"","sources":["../../../../../dev/core/src/Particles/EmitterTypes/customParticleEmitter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAM9D;;GAEG;AACH,MAAM,OAAO,qBAAqB;IAa9B;;OAEG;IACH;QAfA;;;WAGG;QACI,8BAAyB,GAAgF,GAAG,EAAE,GAAE,CAAC,CAAC;QAEzH;;;WAGG;QACI,iCAA4B,GAAmF,GAAG,EAAE,GAAE,CAAC,CAAC;IAKhH,CAAC;IAEhB;;;;;;OAMG;IACI,sBAAsB,CAAC,WAAmB,EAAE,iBAA0B,EAAE,QAAkB,EAAE,OAAgB;QAC/G,MAAM,SAAS,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QAExC,IAAI,IAAI,CAAC,4BAA4B,EAAE,CAAC;YACpC,IAAI,CAA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GAAG,IAAI,qBAAqB,EAAE,CAAC;QAE3C,UAAU,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAElC,OAAO,MAAM,CAAC;IAClB,CAAC;IAED;;;OAGG;IACH,6DAA6D;IACtD,aAAa,CAAC,WAA8C,IAAS,CAAC;IAE7E;;;OAGG;IACH,6DAA6D;IACtD,kBAAkB,CAAC,GAAkB,IAAS,CAAC;IAEtD;;;OAGG;IACI,gBAAgB;QACnB,OAAO,uBAAuB,CAAC;IACnC,CAAC;IAED;;;OAGG;IACI,YAAY;QACf,OAAO,uBAAuB,CAAC;IACnC,CAAC;IAED;;;OAGG;IACI,SAAS;QACZ,MAAM,mBAAmB,GAAQ,EAAE,CAAC;QAEpC,mBAAmB,CAAC,IAAI,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QAC/C,mBAAmB,CAAC,yBAAyB,GAAG,IAAI,CAAC,yBAAyB,CAAC;QAC/E,mBAAmB,CAAC,4BAA4B,GAAG,IAAI,CAAC,4BAA4B,CAAC;QAErF,OAAO,mBAAmB,CAAC;IAC/B,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,mBAAwB;QACjC,IAAI,mBAAmB,CAAC,yBAAyB,EAAE,CAAC;YAChD,IAAI,CAAC,yBAAyB,GAAG,mBAAmB,CAAC,yBAAyB,CAAC;QACnF,CAAC;QAED,IAAI,mBAAmB,CAAC,4BAA4B,EAAE,CAAC;YACnD,IAAI,CAAC,4BAA4B,GAAG,mBAAmB,CAAC,4BAA4B,CAAC;QACzF,CAAC;IACL,CAAC;CACJ","sourcesContent":["import { DeepCopier } from \"../../Misc/deepCopier\";\r\nimport type { Matrix } from \"../../Maths/math.vector\";\r\nimport { Vector3, TmpVectors } from \"../../Maths/math.vector\";\r\nimport type { Particle } from \"../particle\";\r\nimport type { IParticleEmitterType } from \"./IParticleEmitterType\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { UniformBufferEffectCommonAccessor } from \"../../Materials/uniformBufferEffectCommonAccessor\";\r\nimport type { UniformBuffer } from \"../../Materials/uniformBuffer\";\r\n/**\r\n * Particle emitter emitting particles from a custom list of positions.\r\n */\r\nexport class CustomParticleEmitter implements IParticleEmitterType {\r\n /**\r\n * Gets or sets the position generator that will create the initial position of each particle.\r\n * Index will be provided when used with GPU particle. Particle will be provided when used with CPU particles\r\n */\r\n public particlePositionGenerator: (index: number, particle: Nullable<Particle>, outPosition: Vector3) => void = () => {};\r\n\r\n /**\r\n * Gets or sets the destination generator that will create the final destination of each particle.\r\n * * Index will be provided when used with GPU particle. Particle will be provided when used with CPU particles\r\n */\r\n public particleDestinationGenerator: (index: number, particle: Nullable<Particle>, outDestination: Vector3) => void = () => {};\r\n\r\n /**\r\n * Creates a new instance CustomParticleEmitter\r\n */\r\n constructor() {}\r\n\r\n /**\r\n * Called by the particle System when the direction is computed for the created particle.\r\n * @param worldMatrix is the world matrix of the particle system\r\n * @param directionToUpdate is the direction vector to update with the result\r\n * @param particle is the particle we are computed the direction for\r\n * @param isLocal defines if the direction should be set in local space\r\n */\r\n public startDirectionFunction(worldMatrix: Matrix, directionToUpdate: Vector3, particle: Particle, isLocal: boolean): void {\r\n const tmpVector = TmpVectors.Vector3[0];\r\n\r\n if (this.particleDestinationGenerator) {\r\n this.particleDestinationGenerator(-1, particle, tmpVector);\r\n\r\n // Get direction\r\n const diffVector = TmpVectors.Vector3[1];\r\n tmpVector.subtractToRef(particle.position, diffVector);\r\n\r\n diffVector.scaleToRef(1 / particle.lifeTime, tmpVector);\r\n } else {\r\n tmpVector.set(0, 0, 0);\r\n }\r\n\r\n if (isLocal) {\r\n directionToUpdate.copyFrom(tmpVector);\r\n return;\r\n }\r\n\r\n Vector3.TransformNormalToRef(tmpVector, worldMatrix, directionToUpdate);\r\n }\r\n\r\n /**\r\n * Called by the particle System when the position is computed for the created particle.\r\n * @param worldMatrix is the world matrix of the particle system\r\n * @param positionToUpdate is the position vector to update with the result\r\n * @param particle is the particle we are computed the position for\r\n * @param isLocal defines if the position should be set in local space\r\n */\r\n public startPositionFunction(worldMatrix: Matrix, positionToUpdate: Vector3, particle: Particle, isLocal: boolean): void {\r\n const tmpVector = TmpVectors.Vector3[0];\r\n\r\n if (this.particlePositionGenerator) {\r\n this.particlePositionGenerator(-1, particle, tmpVector);\r\n } else {\r\n tmpVector.set(0, 0, 0);\r\n }\r\n\r\n if (isLocal) {\r\n positionToUpdate.copyFrom(tmpVector);\r\n return;\r\n }\r\n\r\n Vector3.TransformCoordinatesToRef(tmpVector, worldMatrix, positionToUpdate);\r\n }\r\n\r\n /**\r\n * Clones the current emitter and returns a copy of it\r\n * @returns the new emitter\r\n */\r\n public clone(): CustomParticleEmitter {\r\n const newOne = new CustomParticleEmitter();\r\n\r\n DeepCopier.DeepCopy(this, newOne);\r\n\r\n return newOne;\r\n }\r\n\r\n /**\r\n * Called by the GPUParticleSystem to setup the update shader\r\n * @param uboOrEffect defines the update shader\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public applyToShader(uboOrEffect: UniformBufferEffectCommonAccessor): void {}\r\n\r\n /**\r\n * Creates the structure of the ubo for this particle emitter\r\n * @param ubo ubo to create the structure for\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public buildUniformLayout(ubo: UniformBuffer): void {}\r\n\r\n /**\r\n * Returns a string to use to update the GPU particles update shader\r\n * @returns a string containing the defines string\r\n */\r\n public getEffectDefines(): string {\r\n return \"#define CUSTOMEMITTER\";\r\n }\r\n\r\n /**\r\n * Returns the string \"PointParticleEmitter\"\r\n * @returns a string containing the class name\r\n */\r\n public getClassName(): string {\r\n return \"CustomParticleEmitter\";\r\n }\r\n\r\n /**\r\n * Serializes the particle system to a JSON object.\r\n * @returns the JSON object\r\n */\r\n public serialize(): any {\r\n const serializationObject: any = {};\r\n\r\n serializationObject.type = this.getClassName();\r\n serializationObject.particlePositionGenerator = this.particlePositionGenerator;\r\n serializationObject.particleDestinationGenerator = this.particleDestinationGenerator;\r\n\r\n return serializationObject;\r\n }\r\n\r\n /**\r\n * Parse properties from a JSON object\r\n * @param serializationObject defines the JSON object\r\n */\r\n public parse(serializationObject: any): void {\r\n if (serializationObject.particlePositionGenerator) {\r\n this.particlePositionGenerator = serializationObject.particlePositionGenerator;\r\n }\r\n\r\n if (serializationObject.particleDestinationGenerator) {\r\n this.particleDestinationGenerator = serializationObject.particleDestinationGenerator;\r\n }\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"customParticleEmitter.js","sourceRoot":"","sources":["../../../../../dev/core/src/Particles/EmitterTypes/customParticleEmitter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAM9D;;GAEG;AACH,MAAM,OAAO,qBAAqB;IAmB9B;;OAEG;IACH;QArBA;;;WAGG;QACI,8BAAyB,GAAgF,GAAG,EAAE,GAAE,CAAC,CAAC;QAEzH;;;WAGG;QACI,iCAA4B,GAAmF,GAAG,EAAE,GAAE,CAAC,CAAC;QAE/H;;;WAGG;QACI,+BAA0B,GAAmF,GAAG,EAAE,GAAE,CAAC,CAAC;IAK9G,CAAC;IAEhB;;;;;;OAMG;IACI,sBAAsB,CAAC,WAAmB,EAAE,iBAA0B,EAAE,QAAkB,EAAE,OAAgB;QAC/G,MAAM,SAAS,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QAExC,IAAI,IAAI,CAAC,0BAA0B,EAAE,CAAC;YAClC,IAAI,CAAC,0BAA0B,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;QAC7D,CAAC;aAAM,IAAI,IAAI,CAAC,4BAA4B,EAAE,CAAC;YAC3C,IAAI,CAAC,4BAA4B,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;YAE3D,gBAAgB;YAChB,MAAM,UAAU,GAAG,UAAU,CAA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AC;IAClB,CAAC;IAED;;;OAGG;IACH,6DAA6D;IACtD,aAAa,CAAC,WAA8C,IAAS,CAAC;IAE7E;;;OAGG;IACH,6DAA6D;IACtD,kBAAkB,CAAC,GAAkB,IAAS,CAAC;IAEtD;;;OAGG;IACI,gBAAgB;QACnB,OAAO,uBAAuB,CAAC;IACnC,CAAC;IAED;;;OAGG;IACI,YAAY;QACf,OAAO,uBAAuB,CAAC;IACnC,CAAC;IAED;;;OAGG;IACI,SAAS;QACZ,MAAM,mBAAmB,GAAQ,EAAE,CAAC;QAEpC,mBAAmB,CAAC,IAAI,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QAC/C,mBAAmB,CAAC,yBAAyB,GAAG,IAAI,CAAC,yBAAyB,CAAC;QAC/E,mBAAmB,CAAC,4BAA4B,GAAG,IAAI,CAAC,4BAA4B,CAAC;QAErF,OAAO,mBAAmB,CAAC;IAC/B,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,mBAAwB;QACjC,IAAI,mBAAmB,CAAC,yBAAyB,EAAE,CAAC;YAChD,IAAI,CAAC,yBAAyB,GAAG,mBAAmB,CAAC,yBAAyB,CAAC;QACnF,CAAC;QAED,IAAI,mBAAmB,CAAC,4BAA4B,EAAE,CAAC;YACnD,IAAI,CAAC,4BAA4B,GAAG,mBAAmB,CAAC,4BAA4B,CAAC;QACzF,CAAC;IACL,CAAC;CACJ","sourcesContent":["import { DeepCopier } from \"../../Misc/deepCopier\";\r\nimport type { Matrix } from \"../../Maths/math.vector\";\r\nimport { Vector3, TmpVectors } from \"../../Maths/math.vector\";\r\nimport type { Particle } from \"../particle\";\r\nimport type { IParticleEmitterType } from \"./IParticleEmitterType\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { UniformBufferEffectCommonAccessor } from \"../../Materials/uniformBufferEffectCommonAccessor\";\r\nimport type { UniformBuffer } from \"../../Materials/uniformBuffer\";\r\n/**\r\n * Particle emitter emitting particles from a custom list of positions.\r\n */\r\nexport class CustomParticleEmitter implements IParticleEmitterType {\r\n /**\r\n * Gets or sets the position generator that will create the initial position of each particle.\r\n * Index will be provided when used with GPU particle. Particle will be provided when used with CPU particles\r\n */\r\n public particlePositionGenerator: (index: number, particle: Nullable<Particle>, outPosition: Vector3) => void = () => {};\r\n\r\n /**\r\n * Gets or sets the destination generator that will create the final destination of each particle.\r\n * * Index will be provided when used with GPU particle. Particle will be provided when used with CPU particles\r\n */\r\n public particleDestinationGenerator: (index: number, particle: Nullable<Particle>, outDestination: Vector3) => void = () => {};\r\n\r\n /**\r\n * Gets or sets the direction generator that will create the initial direction of each particle.\r\n * * Index will be provided when used with GPU particle. Particle will be provided when used with CPU particles\r\n */\r\n public particleDirectionGenerator: (index: number, particle: Nullable<Particle>, outDestination: Vector3) => void = () => {};\r\n\r\n /**\r\n * Creates a new instance CustomParticleEmitter\r\n */\r\n constructor() {}\r\n\r\n /**\r\n * Called by the particle System when the direction is computed for the created particle.\r\n * @param worldMatrix is the world matrix of the particle system\r\n * @param directionToUpdate is the direction vector to update with the result\r\n * @param particle is the particle we are computed the direction for\r\n * @param isLocal defines if the direction should be set in local space\r\n */\r\n public startDirectionFunction(worldMatrix: Matrix, directionToUpdate: Vector3, particle: Particle, isLocal: boolean): void {\r\n const tmpVector = TmpVectors.Vector3[0];\r\n\r\n if (this.particleDirectionGenerator) {\r\n this.particleDirectionGenerator(-1, particle, tmpVector);\r\n } else if (this.particleDestinationGenerator) {\r\n this.particleDestinationGenerator(-1, particle, tmpVector);\r\n\r\n // Get direction\r\n const diffVector = TmpVectors.Vector3[1];\r\n tmpVector.subtractToRef(particle.position, diffVector);\r\n\r\n diffVector.scaleToRef(1 / particle.lifeTime, tmpVector);\r\n } else {\r\n tmpVector.set(0, 0, 0);\r\n }\r\n\r\n if (isLocal) {\r\n directionToUpdate.copyFrom(tmpVector);\r\n return;\r\n }\r\n\r\n Vector3.TransformNormalToRef(tmpVector, worldMatrix, directionToUpdate);\r\n }\r\n\r\n /**\r\n * Called by the particle System when the position is computed for the created particle.\r\n * @param worldMatrix is the world matrix of the particle system\r\n * @param positionToUpdate is the position vector to update with the result\r\n * @param particle is the particle we are computed the position for\r\n * @param isLocal defines if the position should be set in local space\r\n */\r\n public startPositionFunction(worldMatrix: Matrix, positionToUpdate: Vector3, particle: Particle, isLocal: boolean): void {\r\n const tmpVector = TmpVectors.Vector3[0];\r\n\r\n if (this.particlePositionGenerator) {\r\n this.particlePositionGenerator(-1, particle, tmpVector);\r\n } else {\r\n tmpVector.set(0, 0, 0);\r\n }\r\n\r\n if (isLocal) {\r\n positionToUpdate.copyFrom(tmpVector);\r\n return;\r\n }\r\n\r\n Vector3.TransformCoordinatesToRef(tmpVector, worldMatrix, positionToUpdate);\r\n }\r\n\r\n /**\r\n * Clones the current emitter and returns a copy of it\r\n * @returns the new emitter\r\n */\r\n public clone(): CustomParticleEmitter {\r\n const newOne = new CustomParticleEmitter();\r\n\r\n DeepCopier.DeepCopy(this, newOne);\r\n\r\n return newOne;\r\n }\r\n\r\n /**\r\n * Called by the GPUParticleSystem to setup the update shader\r\n * @param uboOrEffect defines the update shader\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public applyToShader(uboOrEffect: UniformBufferEffectCommonAccessor): void {}\r\n\r\n /**\r\n * Creates the structure of the ubo for this particle emitter\r\n * @param ubo ubo to create the structure for\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public buildUniformLayout(ubo: UniformBuffer): void {}\r\n\r\n /**\r\n * Returns a string to use to update the GPU particles update shader\r\n * @returns a string containing the defines string\r\n */\r\n public getEffectDefines(): string {\r\n return \"#define CUSTOMEMITTER\";\r\n }\r\n\r\n /**\r\n * Returns the string \"PointParticleEmitter\"\r\n * @returns a string containing the class name\r\n */\r\n public getClassName(): string {\r\n return \"CustomParticleEmitter\";\r\n }\r\n\r\n /**\r\n * Serializes the particle system to a JSON object.\r\n * @returns the JSON object\r\n */\r\n public serialize(): any {\r\n const serializationObject: any = {};\r\n\r\n serializationObject.type = this.getClassName();\r\n serializationObject.particlePositionGenerator = this.particlePositionGenerator;\r\n serializationObject.particleDestinationGenerator = this.particleDestinationGenerator;\r\n\r\n return serializationObject;\r\n }\r\n\r\n /**\r\n * Parse properties from a JSON object\r\n * @param serializationObject defines the JSON object\r\n */\r\n public parse(serializationObject: any): void {\r\n if (serializationObject.particlePositionGenerator) {\r\n this.particlePositionGenerator = serializationObject.particlePositionGenerator;\r\n }\r\n\r\n if (serializationObject.particleDestinationGenerator) {\r\n this.particleDestinationGenerator = serializationObject.particleDestinationGenerator;\r\n }\r\n }\r\n}\r\n"]}
@@ -280,6 +280,10 @@ export interface IParticleSystem {
280
280
  * An event triggered when the system is stopped
281
281
  */
282
282
  onStoppedObservable: Observable<IParticleSystem>;
283
+ /**
284
+ * An event triggered when the system is started
285
+ */
286
+ onStartedObservable: Observable<IParticleSystem>;
283
287
  /**
284
288
  * Clones the particle system.
285
289
  * @param name The name of the cloned object