@needle-tools/three 0.169.20 → 0.183.2-canary.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 (1051) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +5 -6
  3. package/build/three.cjs +54178 -56709
  4. package/build/three.core.js +59506 -0
  5. package/build/three.core.min.js +6 -0
  6. package/build/three.module.js +11645 -73012
  7. package/build/three.module.min.js +2 -2
  8. package/build/three.tsl.js +648 -0
  9. package/build/three.tsl.min.js +6 -0
  10. package/build/three.webgpu.js +53905 -51657
  11. package/build/three.webgpu.min.js +2 -2
  12. package/build/three.webgpu.nodes.js +53884 -51814
  13. package/build/three.webgpu.nodes.min.js +2 -2
  14. package/examples/fonts/MPLUSRounded1c/MPLUSRounded1c-Regular.typeface.json.zip +0 -0
  15. package/examples/fonts/MPLUSRounded1c/OFL.txt +91 -0
  16. package/examples/jsm/Addons.js +5 -15
  17. package/examples/jsm/animation/AnimationClipCreator.js +58 -6
  18. package/examples/jsm/animation/CCDIKSolver.js +152 -45
  19. package/examples/jsm/capabilities/WebGL.js +28 -29
  20. package/examples/jsm/capabilities/WebGPU.js +19 -17
  21. package/examples/jsm/controls/ArcballControls.js +474 -178
  22. package/examples/jsm/controls/DragControls.js +100 -58
  23. package/examples/jsm/controls/FirstPersonControls.js +116 -6
  24. package/examples/jsm/controls/FlyControls.js +50 -2
  25. package/examples/jsm/controls/MapControls.js +96 -8
  26. package/examples/jsm/controls/OrbitControls.js +496 -57
  27. package/examples/jsm/controls/PointerLockControls.js +115 -22
  28. package/examples/jsm/controls/TrackballControls.js +166 -14
  29. package/examples/jsm/controls/TransformControls.js +336 -26
  30. package/examples/jsm/csm/CSM.js +232 -18
  31. package/examples/jsm/csm/CSMFrustum.js +61 -4
  32. package/examples/jsm/csm/CSMHelper.js +50 -0
  33. package/examples/jsm/csm/CSMShader.js +13 -1
  34. package/examples/jsm/csm/CSMShadowNode.js +599 -0
  35. package/examples/jsm/curves/CurveExtras.js +303 -31
  36. package/examples/jsm/curves/NURBSCurve.js +91 -16
  37. package/examples/jsm/curves/NURBSSurface.js +52 -6
  38. package/examples/jsm/curves/NURBSUtils.js +102 -112
  39. package/examples/jsm/curves/NURBSVolume.js +24 -4
  40. package/examples/jsm/effects/AnaglyphEffect.js +134 -7
  41. package/examples/jsm/effects/AsciiEffect.js +69 -22
  42. package/examples/jsm/effects/OutlineEffect.js +61 -111
  43. package/examples/jsm/effects/ParallaxBarrierEffect.js +30 -0
  44. package/examples/jsm/effects/StereoEffect.js +31 -0
  45. package/examples/jsm/environments/ColorEnvironment.js +59 -0
  46. package/examples/jsm/environments/DebugEnvironment.js +50 -0
  47. package/examples/jsm/environments/RoomEnvironment.js +83 -42
  48. package/examples/jsm/exporters/DRACOExporter.js +56 -14
  49. package/examples/jsm/exporters/EXRExporter.js +40 -9
  50. package/examples/jsm/exporters/GLTFExporter.js +502 -169
  51. package/examples/jsm/exporters/OBJExporter.js +21 -1
  52. package/examples/jsm/exporters/PLYExporter.js +44 -12
  53. package/examples/jsm/exporters/STLExporter.js +27 -5
  54. package/examples/jsm/exporters/USDZExporter.js +781 -291
  55. package/examples/jsm/geometries/BoxLineGeometry.js +23 -0
  56. package/examples/jsm/geometries/ConvexGeometry.js +19 -0
  57. package/examples/jsm/geometries/DecalGeometry.js +91 -30
  58. package/examples/jsm/geometries/ParametricFunctions.js +100 -0
  59. package/examples/jsm/geometries/ParametricGeometry.js +38 -5
  60. package/examples/jsm/geometries/RoundedBoxGeometry.js +68 -7
  61. package/examples/jsm/geometries/TeapotGeometry.js +23 -38
  62. package/examples/jsm/geometries/TextGeometry.js +48 -29
  63. package/examples/jsm/gpgpu/BitonicSort.js +715 -0
  64. package/examples/jsm/helpers/AnimationPathHelper.js +302 -0
  65. package/examples/jsm/helpers/LightProbeHelper.js +36 -0
  66. package/examples/jsm/helpers/LightProbeHelperGPU.js +38 -1
  67. package/examples/jsm/helpers/OctreeHelper.js +36 -0
  68. package/examples/jsm/helpers/PositionalAudioHelper.js +60 -0
  69. package/examples/jsm/helpers/RapierHelper.js +59 -0
  70. package/examples/jsm/helpers/RectAreaLightHelper.js +36 -3
  71. package/examples/jsm/helpers/TextureHelper.js +28 -0
  72. package/examples/jsm/helpers/TextureHelperGPU.js +214 -0
  73. package/examples/jsm/helpers/VertexNormalsHelper.js +61 -2
  74. package/examples/jsm/helpers/VertexTangentsHelper.js +47 -2
  75. package/examples/jsm/helpers/ViewHelper.js +181 -9
  76. package/examples/jsm/inspector/Inspector.js +487 -0
  77. package/examples/jsm/inspector/RendererInspector.js +425 -0
  78. package/examples/jsm/inspector/tabs/Console.js +238 -0
  79. package/examples/jsm/inspector/tabs/Parameters.js +348 -0
  80. package/examples/jsm/inspector/tabs/Performance.js +268 -0
  81. package/examples/jsm/inspector/tabs/Viewer.js +166 -0
  82. package/examples/jsm/inspector/ui/Graph.js +95 -0
  83. package/examples/jsm/inspector/ui/Item.js +170 -0
  84. package/examples/jsm/inspector/ui/List.js +75 -0
  85. package/examples/jsm/inspector/ui/Profiler.js +1975 -0
  86. package/examples/jsm/inspector/ui/Style.js +1613 -0
  87. package/examples/jsm/inspector/ui/Tab.js +233 -0
  88. package/examples/jsm/inspector/ui/Values.js +439 -0
  89. package/examples/jsm/inspector/ui/utils.js +56 -0
  90. package/examples/jsm/interactive/HTMLMesh.js +43 -12
  91. package/examples/jsm/interactive/InteractiveGroup.js +170 -52
  92. package/examples/jsm/interactive/SelectionBox.js +106 -9
  93. package/examples/jsm/interactive/SelectionHelper.js +76 -30
  94. package/examples/jsm/libs/demuxer_mp4.js +109 -0
  95. package/examples/jsm/libs/meshopt_decoder.module.js +76 -58
  96. package/examples/jsm/libs/motion-controllers.module.js +1 -1
  97. package/examples/jsm/lighting/TiledLighting.js +42 -0
  98. package/examples/jsm/lights/LightProbeGenerator.js +44 -7
  99. package/examples/jsm/lights/RectAreaLightTexturesLib.js +50 -14
  100. package/examples/jsm/lights/RectAreaLightUniformsLib.js +16 -0
  101. package/examples/jsm/lines/Line2.js +41 -4
  102. package/examples/jsm/lines/LineGeometry.js +80 -2
  103. package/examples/jsm/lines/LineMaterial.js +105 -5
  104. package/examples/jsm/lines/LineSegments2.js +54 -4
  105. package/examples/jsm/lines/LineSegmentsGeometry.js +65 -8
  106. package/examples/jsm/lines/Wireframe.js +41 -4
  107. package/examples/jsm/lines/WireframeGeometry2.js +27 -2
  108. package/examples/jsm/lines/webgpu/Line2.js +28 -2
  109. package/examples/jsm/lines/webgpu/LineSegments2.js +59 -24
  110. package/examples/jsm/lines/webgpu/Wireframe.js +86 -0
  111. package/examples/jsm/loaders/3DMLoader.js +78 -6
  112. package/examples/jsm/loaders/3MFLoader.js +148 -7
  113. package/examples/jsm/loaders/AMFLoader.js +34 -14
  114. package/examples/jsm/loaders/BVHLoader.js +59 -12
  115. package/examples/jsm/loaders/ColladaLoader.js +61 -4027
  116. package/examples/jsm/loaders/DDSLoader.js +68 -1
  117. package/examples/jsm/loaders/DRACOLoader.js +146 -22
  118. package/examples/jsm/loaders/EXRLoader.js +255 -34
  119. package/examples/jsm/loaders/FBXLoader.js +80 -42
  120. package/examples/jsm/loaders/FontLoader.js +83 -6
  121. package/examples/jsm/loaders/GCodeLoader.js +71 -14
  122. package/examples/jsm/loaders/GLTFLoader.js +381 -263
  123. package/examples/jsm/loaders/HDRCubeTextureLoader.js +52 -3
  124. package/examples/jsm/loaders/HDRLoader.js +485 -0
  125. package/examples/jsm/loaders/IESLoader.js +42 -0
  126. package/examples/jsm/loaders/KMZLoader.js +39 -6
  127. package/examples/jsm/loaders/KTX2Loader.js +124 -48
  128. package/examples/jsm/loaders/KTXLoader.js +31 -10
  129. package/examples/jsm/loaders/LDrawLoader.js +192 -145
  130. package/examples/jsm/loaders/LUT3dlLoader.js +47 -10
  131. package/examples/jsm/loaders/LUTCubeLoader.js +46 -9
  132. package/examples/jsm/loaders/LUTImageLoader.js +79 -38
  133. package/examples/jsm/loaders/LWOLoader.js +54 -59
  134. package/examples/jsm/loaders/LottieLoader.js +54 -1
  135. package/examples/jsm/loaders/MD2Loader.js +37 -1
  136. package/examples/jsm/loaders/MDDLoader.js +57 -12
  137. package/examples/jsm/loaders/MTLLoader.js +60 -35
  138. package/examples/jsm/loaders/MaterialXLoader.js +268 -34
  139. package/examples/jsm/loaders/NRRDLoader.js +40 -8
  140. package/examples/jsm/loaders/OBJLoader.js +51 -2
  141. package/examples/jsm/loaders/PCDLoader.js +173 -21
  142. package/examples/jsm/loaders/PDBLoader.js +41 -2
  143. package/examples/jsm/loaders/PLYLoader.js +70 -39
  144. package/examples/jsm/loaders/PVRLoader.js +25 -6
  145. package/examples/jsm/loaders/RGBELoader.js +6 -438
  146. package/examples/jsm/loaders/STLLoader.js +48 -38
  147. package/examples/jsm/loaders/SVGLoader.js +119 -25
  148. package/examples/jsm/loaders/TDSLoader.js +92 -74
  149. package/examples/jsm/loaders/TGALoader.js +23 -2
  150. package/examples/jsm/loaders/TIFFLoader.js +23 -0
  151. package/examples/jsm/loaders/TTFLoader.js +50 -3
  152. package/examples/jsm/loaders/USDLoader.js +279 -0
  153. package/examples/jsm/loaders/USDZLoader.js +4 -858
  154. package/examples/jsm/loaders/UltraHDRLoader.js +338 -166
  155. package/examples/jsm/loaders/VOXLoader.js +688 -87
  156. package/examples/jsm/loaders/VRMLLoader.js +121 -12
  157. package/examples/jsm/loaders/VTKLoader.js +77 -25
  158. package/examples/jsm/loaders/XYZLoader.js +36 -0
  159. package/examples/jsm/loaders/collada/ColladaComposer.js +2950 -0
  160. package/examples/jsm/loaders/collada/ColladaParser.js +1962 -0
  161. package/examples/jsm/loaders/lwo/IFFParser.js +77 -77
  162. package/examples/jsm/loaders/usd/USDAParser.js +822 -0
  163. package/examples/jsm/loaders/usd/USDCParser.js +1852 -0
  164. package/examples/jsm/loaders/usd/USDComposer.js +4041 -0
  165. package/examples/jsm/materials/LDrawConditionalLineMaterial.js +183 -0
  166. package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +154 -0
  167. package/examples/jsm/materials/WoodNodeMaterial.js +533 -0
  168. package/examples/jsm/math/Capsule.js +91 -14
  169. package/examples/jsm/math/ColorConverter.js +22 -0
  170. package/examples/jsm/math/ColorSpaces.js +74 -2
  171. package/examples/jsm/math/ConvexHull.js +517 -93
  172. package/examples/jsm/math/ImprovedNoise.js +32 -15
  173. package/examples/jsm/math/Lut.js +113 -0
  174. package/examples/jsm/math/MeshSurfaceSampler.js +78 -13
  175. package/examples/jsm/math/OBB.js +141 -29
  176. package/examples/jsm/math/Octree.js +283 -7
  177. package/examples/jsm/math/SimplexNoise.js +68 -42
  178. package/examples/jsm/misc/ConvexObjectBreaker.js +45 -25
  179. package/examples/jsm/misc/GPUComputationRenderer.js +96 -20
  180. package/examples/jsm/misc/Gyroscope.js +12 -0
  181. package/examples/jsm/misc/MD2Character.js +117 -2
  182. package/examples/jsm/misc/MD2CharacterComplex.js +175 -11
  183. package/examples/jsm/misc/MorphAnimMesh.js +44 -0
  184. package/examples/jsm/misc/MorphBlendMesh.js +103 -0
  185. package/examples/jsm/misc/ProgressiveLightMap.js +100 -54
  186. package/examples/jsm/misc/ProgressiveLightMapGPU.js +322 -0
  187. package/examples/jsm/misc/RollerCoaster.js +57 -0
  188. package/examples/jsm/misc/TubePainter.js +437 -40
  189. package/examples/jsm/misc/Volume.js +123 -76
  190. package/examples/jsm/misc/VolumeSlice.js +95 -49
  191. package/examples/jsm/modifiers/CurveModifier.js +66 -38
  192. package/examples/jsm/modifiers/CurveModifierGPU.js +42 -19
  193. package/examples/jsm/modifiers/EdgeSplitModifier.js +20 -0
  194. package/examples/jsm/modifiers/SimplifyModifier.js +24 -10
  195. package/examples/jsm/modifiers/TessellateModifier.js +35 -2
  196. package/examples/jsm/objects/GroundedSkybox.js +25 -6
  197. package/examples/jsm/objects/Lensflare.js +94 -2
  198. package/examples/jsm/objects/LensflareMesh.js +64 -10
  199. package/examples/jsm/objects/MarchingCubes.js +90 -5
  200. package/examples/jsm/objects/Reflector.js +76 -2
  201. package/examples/jsm/objects/ReflectorForSSRPass.js +41 -0
  202. package/examples/jsm/objects/Refractor.js +62 -0
  203. package/examples/jsm/objects/ShadowMesh.js +54 -4
  204. package/examples/jsm/objects/Sky.js +106 -16
  205. package/examples/jsm/objects/SkyMesh.js +211 -38
  206. package/examples/jsm/objects/Water.js +49 -8
  207. package/examples/jsm/objects/Water2.js +49 -7
  208. package/examples/jsm/objects/Water2Mesh.js +50 -9
  209. package/examples/jsm/objects/WaterMesh.js +136 -43
  210. package/examples/jsm/physics/AmmoPhysics.js +60 -7
  211. package/examples/jsm/physics/JoltPhysics.js +65 -12
  212. package/examples/jsm/physics/RapierPhysics.js +217 -21
  213. package/examples/jsm/postprocessing/AfterimagePass.js +110 -29
  214. package/examples/jsm/postprocessing/BloomPass.js +128 -26
  215. package/examples/jsm/postprocessing/BokehPass.js +99 -22
  216. package/examples/jsm/postprocessing/ClearPass.js +54 -3
  217. package/examples/jsm/postprocessing/CubeTexturePass.js +82 -21
  218. package/examples/jsm/postprocessing/DotScreenPass.js +59 -10
  219. package/examples/jsm/postprocessing/EffectComposer.js +140 -6
  220. package/examples/jsm/postprocessing/FXAAPass.js +40 -0
  221. package/examples/jsm/postprocessing/FilmPass.js +54 -5
  222. package/examples/jsm/postprocessing/GTAOPass.js +202 -57
  223. package/examples/jsm/postprocessing/GlitchPass.js +86 -34
  224. package/examples/jsm/postprocessing/HalftonePass.js +65 -10
  225. package/examples/jsm/postprocessing/LUTPass.js +38 -8
  226. package/examples/jsm/postprocessing/MaskPass.js +91 -0
  227. package/examples/jsm/postprocessing/OutlinePass.js +272 -135
  228. package/examples/jsm/postprocessing/OutputPass.js +65 -14
  229. package/examples/jsm/postprocessing/Pass.js +100 -4
  230. package/examples/jsm/postprocessing/RenderPass.js +94 -0
  231. package/examples/jsm/postprocessing/RenderPixelatedPass.js +124 -45
  232. package/examples/jsm/postprocessing/RenderTransitionPass.js +120 -21
  233. package/examples/jsm/postprocessing/SAOPass.js +128 -55
  234. package/examples/jsm/postprocessing/SMAAPass.js +106 -75
  235. package/examples/jsm/postprocessing/SSAARenderPass.js +118 -35
  236. package/examples/jsm/postprocessing/SSAOPass.js +173 -60
  237. package/examples/jsm/postprocessing/SSRPass.js +268 -53
  238. package/examples/jsm/postprocessing/SavePass.js +69 -16
  239. package/examples/jsm/postprocessing/ShaderPass.js +65 -7
  240. package/examples/jsm/postprocessing/TAARenderPass.js +79 -24
  241. package/examples/jsm/postprocessing/TexturePass.js +72 -8
  242. package/examples/jsm/postprocessing/UnrealBloomPass.js +168 -59
  243. package/examples/jsm/renderers/CSS2DRenderer.js +98 -5
  244. package/examples/jsm/renderers/CSS3DRenderer.js +111 -7
  245. package/examples/jsm/renderers/Projector.js +288 -32
  246. package/examples/jsm/renderers/SVGRenderer.js +323 -61
  247. package/examples/jsm/renderers/webgl-legacy/nodes/GLSL1NodeBuilder.js +3 -1
  248. package/examples/jsm/renderers/webgl-legacy/nodes/SlotNode.js +1 -1
  249. package/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodeBuilder.js +5 -1
  250. package/examples/jsm/shaders/ACESFilmicToneMappingShader.js +12 -5
  251. package/examples/jsm/shaders/AfterimageShader.js +8 -3
  252. package/examples/jsm/shaders/BasicShader.js +8 -1
  253. package/examples/jsm/shaders/BleachBypassShader.js +10 -3
  254. package/examples/jsm/shaders/BlendShader.js +8 -1
  255. package/examples/jsm/shaders/BokehShader.js +9 -3
  256. package/examples/jsm/shaders/BokehShader2.js +11 -4
  257. package/examples/jsm/shaders/BrightnessContrastShader.js +10 -4
  258. package/examples/jsm/shaders/ColorCorrectionShader.js +8 -1
  259. package/examples/jsm/shaders/ColorifyShader.js +8 -1
  260. package/examples/jsm/shaders/ConvolutionShader.js +9 -38
  261. package/examples/jsm/shaders/CopyShader.js +8 -1
  262. package/examples/jsm/shaders/DOFMipMapShader.js +10 -3
  263. package/examples/jsm/shaders/DepthLimitedBlurShader.js +10 -1
  264. package/examples/jsm/shaders/DigitalGlitch.js +10 -7
  265. package/examples/jsm/shaders/DotScreenShader.js +8 -3
  266. package/examples/jsm/shaders/ExposureShader.js +8 -1
  267. package/examples/jsm/shaders/FXAAShader.js +233 -221
  268. package/examples/jsm/shaders/FilmShader.js +13 -0
  269. package/examples/jsm/shaders/FocusShader.js +8 -3
  270. package/examples/jsm/shaders/FreiChenShader.js +10 -3
  271. package/examples/jsm/shaders/GTAOShader.js +55 -45
  272. package/examples/jsm/shaders/GammaCorrectionShader.js +11 -2
  273. package/examples/jsm/shaders/HalftoneShader.js +24 -4
  274. package/examples/jsm/shaders/HorizontalBlurShader.js +12 -3
  275. package/examples/jsm/shaders/HorizontalTiltShiftShader.js +9 -2
  276. package/examples/jsm/shaders/HueSaturationShader.js +10 -3
  277. package/examples/jsm/shaders/KaleidoShader.js +11 -4
  278. package/examples/jsm/shaders/LuminosityHighPassShader.js +8 -4
  279. package/examples/jsm/shaders/LuminosityShader.js +8 -2
  280. package/examples/jsm/shaders/MirrorShader.js +10 -4
  281. package/examples/jsm/shaders/NormalMapShader.js +7 -2
  282. package/examples/jsm/shaders/OutputShader.js +19 -1
  283. package/examples/jsm/shaders/PoissonDenoiseShader.js +30 -17
  284. package/examples/jsm/shaders/RGBShiftShader.js +8 -1
  285. package/examples/jsm/shaders/SAOShader.js +27 -5
  286. package/examples/jsm/shaders/SMAAShader.js +24 -1
  287. package/examples/jsm/shaders/SSAOShader.js +37 -6
  288. package/examples/jsm/shaders/SSRShader.js +32 -6
  289. package/examples/jsm/shaders/SepiaShader.js +8 -3
  290. package/examples/jsm/shaders/SobelOperatorShader.js +9 -3
  291. package/examples/jsm/shaders/SubsurfaceScatteringShader.js +13 -8
  292. package/examples/jsm/shaders/TechnicolorShader.js +10 -4
  293. package/examples/jsm/shaders/ToonShader.js +29 -6
  294. package/examples/jsm/shaders/TriangleBlurShader.js +9 -4
  295. package/examples/jsm/shaders/UnpackDepthRGBAShader.js +19 -6
  296. package/examples/jsm/shaders/VelocityShader.js +8 -1
  297. package/examples/jsm/shaders/VerticalBlurShader.js +9 -2
  298. package/examples/jsm/shaders/VerticalTiltShiftShader.js +8 -1
  299. package/examples/jsm/shaders/VignetteShader.js +8 -3
  300. package/examples/jsm/shaders/VolumeShader.js +11 -2
  301. package/examples/jsm/shaders/WaterRefractionShader.js +11 -0
  302. package/examples/jsm/textures/FlakesTexture.js +14 -0
  303. package/examples/jsm/transpiler/AST.js +436 -31
  304. package/examples/jsm/transpiler/GLSLDecoder.js +380 -135
  305. package/examples/jsm/transpiler/Linker.js +327 -0
  306. package/examples/jsm/transpiler/ShaderToyDecoder.js +3 -1
  307. package/examples/jsm/transpiler/TSLEncoder.js +363 -97
  308. package/examples/jsm/transpiler/Transpiler.js +50 -1
  309. package/examples/jsm/transpiler/TranspilerUtils.js +29 -0
  310. package/examples/jsm/transpiler/WGSLEncoder.js +839 -0
  311. package/examples/jsm/tsl/display/AfterImageNode.js +244 -0
  312. package/examples/jsm/tsl/display/AnaglyphPassNode.js +549 -0
  313. package/examples/jsm/tsl/display/AnamorphicNode.js +282 -0
  314. package/examples/jsm/tsl/display/BilateralBlurNode.js +364 -0
  315. package/{src/nodes → examples/jsm/tsl}/display/BleachBypass.js +11 -4
  316. package/examples/jsm/tsl/display/BloomNode.js +534 -0
  317. package/examples/jsm/tsl/display/CRT.js +150 -0
  318. package/examples/jsm/tsl/display/ChromaticAberrationNode.js +207 -0
  319. package/examples/jsm/tsl/display/DenoiseNode.js +334 -0
  320. package/examples/jsm/tsl/display/DepthOfFieldNode.js +554 -0
  321. package/examples/jsm/tsl/display/DotScreenNode.js +104 -0
  322. package/examples/jsm/tsl/display/FXAANode.js +365 -0
  323. package/examples/jsm/tsl/display/FilmNode.js +101 -0
  324. package/examples/jsm/tsl/display/GTAONode.js +571 -0
  325. package/examples/jsm/tsl/display/GaussianBlurNode.js +389 -0
  326. package/examples/jsm/tsl/display/GodraysNode.js +624 -0
  327. package/examples/jsm/tsl/display/LensflareNode.js +279 -0
  328. package/examples/jsm/tsl/display/Lut3DNode.js +109 -0
  329. package/examples/jsm/tsl/display/MotionBlur.js +33 -0
  330. package/examples/jsm/tsl/display/OutlineNode.js +762 -0
  331. package/examples/jsm/tsl/display/ParallaxBarrierPassNode.js +89 -0
  332. package/examples/jsm/tsl/display/PixelationPassNode.js +335 -0
  333. package/examples/jsm/tsl/display/RGBShiftNode.js +96 -0
  334. package/examples/jsm/tsl/display/RetroPassNode.js +263 -0
  335. package/examples/jsm/tsl/display/SMAANode.js +768 -0
  336. package/{src/nodes → examples/jsm/tsl}/display/SSAAPassNode.js +120 -49
  337. package/examples/jsm/tsl/display/SSGINode.js +642 -0
  338. package/examples/jsm/tsl/display/SSRNode.js +656 -0
  339. package/examples/jsm/tsl/display/SSSNode.js +490 -0
  340. package/{src/nodes → examples/jsm/tsl}/display/Sepia.js +9 -2
  341. package/examples/jsm/tsl/display/Shape.js +29 -0
  342. package/{src/nodes → examples/jsm/tsl}/display/SobelOperatorNode.js +61 -19
  343. package/examples/jsm/tsl/display/StereoCompositePassNode.js +192 -0
  344. package/{src/nodes → examples/jsm/tsl}/display/StereoPassNode.js +48 -12
  345. package/examples/jsm/tsl/display/TRAANode.js +726 -0
  346. package/examples/jsm/tsl/display/TransitionNode.js +141 -0
  347. package/examples/jsm/tsl/display/boxBlur.js +65 -0
  348. package/examples/jsm/tsl/display/depthAwareBlend.js +80 -0
  349. package/examples/jsm/tsl/display/hashBlur.js +54 -0
  350. package/examples/jsm/tsl/display/radialBlur.js +68 -0
  351. package/examples/jsm/tsl/lighting/TiledLightsNode.js +442 -0
  352. package/examples/jsm/tsl/math/Bayer.js +73 -0
  353. package/examples/jsm/tsl/shadows/TileShadowNode.js +456 -0
  354. package/examples/jsm/tsl/shadows/TileShadowNodeHelper.js +212 -0
  355. package/examples/jsm/tsl/utils/Raymarching.js +70 -0
  356. package/examples/jsm/utils/BufferGeometryUtils.js +91 -29
  357. package/examples/jsm/utils/CameraUtils.js +15 -6
  358. package/examples/jsm/utils/GeometryCompressionUtils.js +23 -30
  359. package/examples/jsm/utils/GeometryUtils.js +32 -27
  360. package/examples/jsm/utils/LDrawUtils.js +14 -5
  361. package/examples/jsm/utils/SceneOptimizer.js +458 -0
  362. package/examples/jsm/utils/SceneUtils.js +53 -3
  363. package/examples/jsm/utils/ShadowMapViewer.js +72 -33
  364. package/examples/jsm/utils/ShadowMapViewerGPU.js +61 -29
  365. package/examples/jsm/utils/SkeletonUtils.js +48 -0
  366. package/examples/jsm/utils/SortUtils.js +17 -5
  367. package/examples/jsm/utils/UVsDebug.js +12 -4
  368. package/examples/jsm/utils/{TextureUtils.js → WebGLTextureUtils.js} +16 -0
  369. package/examples/jsm/utils/{TextureUtilsGPU.js → WebGPUTextureUtils.js} +20 -2
  370. package/examples/jsm/utils/WorkerPool.js +67 -2
  371. package/examples/jsm/webxr/ARButton.js +19 -0
  372. package/examples/jsm/webxr/OculusHandModel.js +84 -0
  373. package/examples/jsm/webxr/OculusHandPointerModel.js +148 -22
  374. package/examples/jsm/webxr/Text2D.js +20 -6
  375. package/examples/jsm/webxr/VRButton.js +31 -0
  376. package/examples/jsm/webxr/XRButton.js +23 -0
  377. package/examples/jsm/webxr/XRControllerModelFactory.js +94 -3
  378. package/examples/jsm/webxr/XREstimatedLight.js +35 -4
  379. package/examples/jsm/webxr/XRHandMeshModel.js +37 -0
  380. package/examples/jsm/webxr/XRHandModelFactory.js +96 -6
  381. package/examples/jsm/webxr/XRHandPrimitiveModel.js +44 -0
  382. package/examples/jsm/webxr/XRPlanes.js +18 -0
  383. package/package.json +29 -34
  384. package/src/Three.Core.js +198 -0
  385. package/src/Three.Legacy.js +0 -21
  386. package/src/Three.TSL.js +641 -0
  387. package/src/Three.WebGPU.Nodes.js +14 -186
  388. package/src/Three.WebGPU.js +16 -186
  389. package/src/Three.js +2 -197
  390. package/src/animation/AnimationAction.js +263 -31
  391. package/src/animation/AnimationClip.js +162 -7
  392. package/src/animation/AnimationMixer.js +99 -15
  393. package/src/animation/AnimationObjectGroup.js +45 -21
  394. package/src/animation/AnimationUtils.js +163 -24
  395. package/src/animation/KeyframeTrack.js +191 -17
  396. package/src/animation/PropertyBinding.js +91 -16
  397. package/src/animation/PropertyMixer.js +72 -5
  398. package/src/animation/tracks/BooleanKeyframeTrack.js +33 -6
  399. package/src/animation/tracks/ColorKeyframeTrack.js +26 -5
  400. package/src/animation/tracks/NumberKeyframeTrack.js +26 -2
  401. package/src/animation/tracks/QuaternionKeyframeTrack.js +30 -1
  402. package/src/animation/tracks/StringKeyframeTrack.js +33 -2
  403. package/src/animation/tracks/VectorKeyframeTrack.js +26 -2
  404. package/src/audio/Audio.js +386 -8
  405. package/src/audio/AudioAnalyser.js +58 -1
  406. package/src/audio/AudioContext.js +15 -0
  407. package/src/audio/AudioListener.js +94 -13
  408. package/src/audio/PositionalAudio.js +107 -0
  409. package/src/cameras/ArrayCamera.js +37 -0
  410. package/src/cameras/Camera.js +61 -0
  411. package/src/cameras/CubeCamera.js +86 -0
  412. package/src/cameras/OrthographicCamera.js +110 -1
  413. package/src/cameras/PerspectiveCamera.js +174 -35
  414. package/src/cameras/StereoCamera.js +48 -2
  415. package/src/constants.js +1546 -11
  416. package/src/core/BufferAttribute.js +417 -3
  417. package/src/core/BufferGeometry.js +407 -22
  418. package/src/core/Clock.js +69 -8
  419. package/src/core/EventDispatcher.js +52 -8
  420. package/src/core/GLBufferAttribute.js +113 -2
  421. package/src/core/InstancedBufferAttribute.js +29 -0
  422. package/src/core/InstancedBufferGeometry.js +20 -0
  423. package/src/core/InstancedInterleavedBuffer.js +26 -0
  424. package/src/core/InterleavedBuffer.js +141 -7
  425. package/src/core/InterleavedBufferAttribute.js +200 -2
  426. package/src/core/Layers.js +71 -10
  427. package/src/core/Object3D.js +673 -26
  428. package/src/core/Raycaster.js +136 -2
  429. package/src/core/RenderTarget.js +256 -27
  430. package/src/core/RenderTarget3D.js +48 -0
  431. package/src/core/Timer.js +184 -0
  432. package/src/core/Uniform.js +29 -0
  433. package/src/core/UniformsGroup.js +84 -2
  434. package/src/extras/Controls.js +89 -1
  435. package/src/extras/DataUtils.js +50 -9
  436. package/src/extras/Earcut.js +18 -779
  437. package/src/extras/ImageUtils.js +22 -14
  438. package/src/extras/PMREMGenerator.js +316 -67
  439. package/src/extras/ShapeUtils.js +24 -2
  440. package/src/extras/TextureUtils.js +101 -15
  441. package/src/extras/core/Curve.js +156 -55
  442. package/src/extras/core/CurvePath.js +63 -22
  443. package/src/extras/core/Interpolations.js +34 -2
  444. package/src/extras/core/Path.js +134 -1
  445. package/src/extras/core/Shape.js +66 -3
  446. package/src/extras/core/ShapePath.js +80 -4
  447. package/src/extras/curves/ArcCurve.js +22 -0
  448. package/src/extras/curves/CatmullRomCurve3.js +89 -18
  449. package/src/extras/curves/CubicBezierCurve.js +67 -0
  450. package/src/extras/curves/CubicBezierCurve3.js +50 -0
  451. package/src/extras/curves/EllipseCurve.js +102 -0
  452. package/src/extras/curves/LineCurve.js +36 -0
  453. package/src/extras/curves/LineCurve3.js +36 -0
  454. package/src/extras/curves/QuadraticBezierCurve.js +59 -0
  455. package/src/extras/curves/QuadraticBezierCurve3.js +43 -0
  456. package/src/extras/curves/SplineCurve.js +48 -0
  457. package/src/extras/lib/earcut.js +685 -0
  458. package/src/geometries/BoxGeometry.js +39 -0
  459. package/src/geometries/CapsuleGeometry.js +196 -11
  460. package/src/geometries/CircleGeometry.js +41 -0
  461. package/src/geometries/ConeGeometry.js +39 -0
  462. package/src/geometries/CylinderGeometry.js +42 -2
  463. package/src/geometries/DodecahedronGeometry.js +33 -0
  464. package/src/geometries/EdgesGeometry.js +30 -2
  465. package/src/geometries/ExtrudeGeometry.js +148 -52
  466. package/src/geometries/IcosahedronGeometry.js +33 -0
  467. package/src/geometries/LatheGeometry.js +44 -3
  468. package/src/geometries/OctahedronGeometry.js +33 -0
  469. package/src/geometries/PlaneGeometry.js +35 -0
  470. package/src/geometries/PolyhedronGeometry.js +30 -1
  471. package/src/geometries/RingGeometry.js +37 -0
  472. package/src/geometries/ShapeGeometry.js +38 -0
  473. package/src/geometries/SphereGeometry.js +38 -0
  474. package/src/geometries/TetrahedronGeometry.js +33 -0
  475. package/src/geometries/TorusGeometry.js +44 -3
  476. package/src/geometries/TorusKnotGeometry.js +39 -0
  477. package/src/geometries/TubeGeometry.js +50 -0
  478. package/src/geometries/WireframeGeometry.js +32 -0
  479. package/src/helpers/ArrowHelper.js +62 -5
  480. package/src/helpers/AxesHelper.js +28 -0
  481. package/src/helpers/Box3Helper.js +28 -0
  482. package/src/helpers/BoxHelper.js +43 -7
  483. package/src/helpers/CameraHelper.js +103 -27
  484. package/src/helpers/DirectionalLightHelper.js +55 -0
  485. package/src/helpers/GridHelper.js +26 -0
  486. package/src/helpers/HemisphereLightHelper.js +42 -0
  487. package/src/helpers/PlaneHelper.js +33 -0
  488. package/src/helpers/PointLightHelper.js +43 -24
  489. package/src/helpers/PolarGridHelper.js +30 -0
  490. package/src/helpers/SkeletonHelper.js +73 -7
  491. package/src/helpers/SpotLightHelper.js +43 -0
  492. package/src/lights/AmbientLight.js +25 -0
  493. package/src/lights/DirectionalLight.js +70 -0
  494. package/src/lights/DirectionalLightShadow.js +15 -0
  495. package/src/lights/HemisphereLight.js +42 -0
  496. package/src/lights/Light.js +37 -11
  497. package/src/lights/LightProbe.js +37 -9
  498. package/src/lights/LightShadow.js +202 -7
  499. package/src/lights/PointLight.js +74 -0
  500. package/src/lights/PointLightShadow.js +15 -80
  501. package/src/lights/RectAreaLight.js +59 -0
  502. package/src/lights/SpotLight.js +124 -1
  503. package/src/lights/SpotLightShadow.js +33 -3
  504. package/src/lights/webgpu/IESSpotLight.js +22 -0
  505. package/src/lights/webgpu/ProjectorLight.js +46 -0
  506. package/src/loaders/AnimationLoader.js +34 -2
  507. package/src/loaders/AudioLoader.js +34 -2
  508. package/src/loaders/BufferGeometryLoader.js +38 -13
  509. package/src/loaders/Cache.js +75 -2
  510. package/src/loaders/CompressedTextureLoader.js +36 -3
  511. package/src/loaders/CubeTextureLoader.js +45 -0
  512. package/src/loaders/DataTextureLoader.js +45 -4
  513. package/src/loaders/FileLoader.js +85 -5
  514. package/src/loaders/ImageBitmapLoader.js +113 -11
  515. package/src/loaders/ImageLoader.js +85 -8
  516. package/src/loaders/Loader.js +144 -0
  517. package/src/loaders/LoaderUtils.js +18 -36
  518. package/src/loaders/LoadingManager.js +187 -0
  519. package/src/loaders/MaterialLoader.js +62 -3
  520. package/src/loaders/ObjectLoader.js +131 -31
  521. package/src/loaders/TextureLoader.js +33 -0
  522. package/src/loaders/nodes/NodeLoader.js +68 -4
  523. package/src/loaders/nodes/NodeMaterialLoader.js +45 -0
  524. package/src/loaders/nodes/NodeObjectLoader.js +61 -0
  525. package/src/materials/LineBasicMaterial.js +74 -1
  526. package/src/materials/LineDashedMaterial.js +52 -1
  527. package/src/materials/Material.js +502 -8
  528. package/src/materials/MeshBasicMaterial.js +168 -2
  529. package/src/materials/MeshDepthMaterial.js +94 -0
  530. package/src/materials/MeshDistanceMaterial.js +76 -0
  531. package/src/materials/MeshLambertMaterial.js +283 -0
  532. package/src/materials/MeshMatcapMaterial.js +164 -0
  533. package/src/materials/MeshNormalMaterial.js +114 -0
  534. package/src/materials/MeshPhongMaterial.js +298 -0
  535. package/src/materials/MeshPhysicalMaterial.js +296 -4
  536. package/src/materials/MeshStandardMaterial.js +300 -2
  537. package/src/materials/MeshToonMaterial.js +219 -0
  538. package/src/materials/PointsMaterial.js +89 -0
  539. package/src/materials/RawShaderMaterial.js +25 -0
  540. package/src/materials/ShaderMaterial.js +234 -6
  541. package/src/materials/ShadowMaterial.js +54 -0
  542. package/src/materials/SpriteMaterial.js +82 -0
  543. package/src/materials/nodes/Line2NodeMaterial.js +158 -53
  544. package/src/materials/nodes/LineBasicNodeMaterial.js +17 -2
  545. package/src/materials/nodes/LineDashedNodeMaterial.js +81 -6
  546. package/src/materials/nodes/MeshBasicNodeMaterial.js +59 -2
  547. package/src/materials/nodes/MeshLambertNodeMaterial.js +35 -0
  548. package/src/materials/nodes/MeshMatcapNodeMaterial.js +23 -3
  549. package/src/materials/nodes/MeshNormalNodeMaterial.js +27 -4
  550. package/src/materials/nodes/MeshPhongNodeMaterial.js +64 -1
  551. package/src/materials/nodes/MeshPhysicalNodeMaterial.js +276 -3
  552. package/src/materials/nodes/MeshSSSNodeMaterial.js +98 -10
  553. package/src/materials/nodes/MeshStandardNodeMaterial.js +83 -4
  554. package/src/materials/nodes/MeshToonNodeMaterial.js +28 -0
  555. package/src/materials/nodes/NodeMaterial.js +789 -74
  556. package/src/materials/nodes/NodeMaterials.js +0 -1
  557. package/src/materials/nodes/PointsNodeMaterial.js +180 -11
  558. package/src/materials/nodes/ShadowNodeMaterial.js +38 -0
  559. package/src/materials/nodes/SpriteNodeMaterial.js +86 -23
  560. package/src/materials/nodes/VolumeNodeMaterial.js +57 -84
  561. package/src/materials/nodes/manager/NodeMaterialObserver.js +329 -12
  562. package/src/math/Box2.js +177 -0
  563. package/src/math/Box3.js +271 -0
  564. package/src/math/Color.js +355 -11
  565. package/src/math/ColorManagement.js +158 -92
  566. package/src/math/Cylindrical.js +65 -6
  567. package/src/math/Euler.js +139 -5
  568. package/src/math/Frustum.js +108 -9
  569. package/src/math/FrustumArray.js +258 -0
  570. package/src/math/Interpolant.js +87 -8
  571. package/src/math/Line3.js +221 -2
  572. package/src/math/MathUtils.js +408 -20
  573. package/src/math/Matrix2.js +70 -0
  574. package/src/math/Matrix3.js +229 -4
  575. package/src/math/Matrix4.js +489 -94
  576. package/src/math/Plane.js +164 -2
  577. package/src/math/Quaternion.js +322 -90
  578. package/src/math/Ray.js +162 -0
  579. package/src/math/Sphere.js +175 -0
  580. package/src/math/Spherical.js +73 -11
  581. package/src/math/SphericalHarmonics3.js +112 -14
  582. package/src/math/Triangle.js +206 -2
  583. package/src/math/Vector2.js +396 -10
  584. package/src/math/Vector3.js +550 -15
  585. package/src/math/Vector4.js +415 -9
  586. package/src/math/interpolants/BezierInterpolant.js +108 -0
  587. package/src/math/interpolants/CubicInterpolant.js +10 -1
  588. package/src/math/interpolants/DiscreteInterpolant.js +10 -2
  589. package/src/math/interpolants/LinearInterpolant.js +13 -0
  590. package/src/math/interpolants/QuaternionLinearInterpolant.js +10 -1
  591. package/src/nodes/Nodes.js +91 -88
  592. package/src/nodes/TSL.js +32 -38
  593. package/src/nodes/accessors/AccessorsUtils.js +37 -9
  594. package/src/nodes/accessors/Arrays.js +68 -0
  595. package/src/nodes/accessors/BatchNode.js +49 -14
  596. package/src/nodes/accessors/Bitangent.js +82 -13
  597. package/src/nodes/accessors/BufferAttributeNode.js +269 -8
  598. package/src/nodes/accessors/BufferNode.js +91 -2
  599. package/src/nodes/accessors/BuiltinNode.js +63 -0
  600. package/src/nodes/accessors/Camera.js +400 -10
  601. package/src/nodes/accessors/ClippingNode.js +149 -45
  602. package/src/nodes/accessors/CubeTextureNode.js +137 -7
  603. package/src/nodes/accessors/InstanceNode.js +245 -40
  604. package/src/nodes/accessors/InstancedMeshNode.js +50 -0
  605. package/src/nodes/accessors/Lights.js +88 -0
  606. package/src/nodes/accessors/MaterialNode.js +355 -13
  607. package/src/nodes/accessors/MaterialProperties.js +57 -1
  608. package/src/nodes/accessors/MaterialReferenceNode.js +52 -14
  609. package/src/nodes/accessors/ModelNode.js +117 -5
  610. package/src/nodes/accessors/ModelViewProjectionNode.js +10 -39
  611. package/src/nodes/accessors/MorphNode.js +73 -26
  612. package/src/nodes/accessors/Normal.js +174 -19
  613. package/src/nodes/accessors/Object3DNode.js +146 -12
  614. package/src/nodes/accessors/PointUVNode.js +25 -0
  615. package/src/nodes/accessors/Position.js +119 -7
  616. package/src/nodes/accessors/ReferenceBaseNode.js +190 -4
  617. package/src/nodes/accessors/ReferenceNode.js +223 -8
  618. package/src/nodes/accessors/ReflectVector.js +29 -3
  619. package/src/nodes/accessors/RendererReferenceNode.js +45 -2
  620. package/src/nodes/accessors/SceneProperties.js +53 -0
  621. package/src/nodes/accessors/SkinningNode.js +180 -43
  622. package/src/nodes/accessors/StorageBufferNode.js +278 -26
  623. package/src/nodes/accessors/StorageTextureNode.js +205 -12
  624. package/src/nodes/accessors/Tangent.js +48 -10
  625. package/src/nodes/accessors/TangentUtils.js +46 -0
  626. package/src/nodes/accessors/Texture3DNode.js +104 -11
  627. package/src/nodes/accessors/TextureBicubic.js +31 -4
  628. package/src/nodes/accessors/TextureNode.js +564 -52
  629. package/src/nodes/accessors/TextureSizeNode.js +42 -1
  630. package/src/nodes/accessors/UV.js +9 -1
  631. package/src/nodes/accessors/UniformArrayNode.js +226 -34
  632. package/src/nodes/accessors/UserDataNode.js +46 -2
  633. package/src/nodes/accessors/VelocityNode.js +93 -3
  634. package/src/nodes/accessors/VertexColorNode.js +39 -4
  635. package/src/nodes/code/CodeNode.js +101 -8
  636. package/src/nodes/code/ExpressionNode.js +29 -2
  637. package/src/nodes/code/FunctionCallNode.js +98 -10
  638. package/src/nodes/code/FunctionNode.js +69 -2
  639. package/src/nodes/core/ArrayNode.js +174 -0
  640. package/src/nodes/core/AssignNode.js +80 -9
  641. package/src/nodes/core/AttributeNode.js +47 -4
  642. package/src/nodes/core/BypassNode.js +47 -3
  643. package/src/nodes/core/ConstNode.js +32 -0
  644. package/src/nodes/core/ContextNode.js +220 -14
  645. package/src/nodes/core/IndexNode.js +72 -7
  646. package/src/nodes/core/InputNode.js +50 -1
  647. package/src/nodes/core/InspectorNode.js +128 -0
  648. package/src/nodes/core/IsolateNode.js +133 -0
  649. package/src/nodes/core/LightingModel.js +65 -5
  650. package/src/nodes/core/MRTNode.js +113 -2
  651. package/src/nodes/core/Node.js +595 -36
  652. package/src/nodes/core/NodeAttribute.js +38 -0
  653. package/src/nodes/core/NodeBuilder.js +1840 -121
  654. package/src/nodes/core/NodeCache.js +41 -2
  655. package/src/nodes/core/NodeCode.js +31 -0
  656. package/src/nodes/core/NodeError.js +28 -0
  657. package/src/nodes/core/NodeFrame.js +153 -24
  658. package/src/nodes/core/NodeFunction.js +48 -1
  659. package/src/nodes/core/NodeFunctionInput.js +44 -0
  660. package/src/nodes/core/NodeParser.js +13 -1
  661. package/src/nodes/core/NodeUniform.js +53 -1
  662. package/src/nodes/core/NodeUtils.js +201 -51
  663. package/src/nodes/core/NodeVar.js +47 -1
  664. package/src/nodes/core/NodeVarying.js +47 -1
  665. package/src/nodes/core/OutputStructNode.js +54 -12
  666. package/src/nodes/core/ParameterNode.js +60 -2
  667. package/src/nodes/core/PropertyNode.js +286 -7
  668. package/src/nodes/core/StackNode.js +337 -20
  669. package/src/nodes/core/StackTrace.js +139 -0
  670. package/src/nodes/core/StructNode.js +134 -0
  671. package/src/nodes/core/StructType.js +13 -0
  672. package/src/nodes/core/StructTypeNode.js +126 -6
  673. package/src/nodes/core/SubBuildNode.js +89 -0
  674. package/src/nodes/core/TempNode.js +31 -5
  675. package/src/nodes/core/UniformGroupNode.js +85 -7
  676. package/src/nodes/core/UniformNode.js +163 -16
  677. package/src/nodes/core/VarNode.js +317 -10
  678. package/src/nodes/core/VaryingNode.js +115 -13
  679. package/src/nodes/core/constants.js +40 -0
  680. package/src/nodes/display/BlendModes.js +171 -0
  681. package/src/nodes/display/BumpMapNode.js +38 -2
  682. package/src/nodes/display/ColorAdjustment.js +118 -6
  683. package/src/nodes/display/ColorSpaceFunctions.js +22 -6
  684. package/src/nodes/display/ColorSpaceNode.js +97 -47
  685. package/src/nodes/display/FrontFacingNode.js +64 -7
  686. package/src/nodes/display/NormalMapNode.js +101 -54
  687. package/src/nodes/display/PassNode.js +690 -33
  688. package/src/nodes/display/RenderOutputNode.js +94 -4
  689. package/src/nodes/display/ScreenNode.js +138 -27
  690. package/src/nodes/display/ToneMappingFunctions.js +62 -10
  691. package/src/nodes/display/ToneMappingNode.js +88 -8
  692. package/src/nodes/display/ToonOutlinePassNode.js +84 -4
  693. package/src/nodes/display/ViewportDepthNode.js +227 -10
  694. package/src/nodes/display/ViewportDepthTextureNode.js +39 -5
  695. package/src/nodes/display/ViewportSharedTextureNode.js +35 -1
  696. package/src/nodes/display/ViewportTextureNode.js +171 -7
  697. package/src/nodes/fog/Fog.js +97 -0
  698. package/src/nodes/functions/BSDF/BRDF_GGX.js +2 -6
  699. package/src/nodes/functions/BSDF/BRDF_GGX_Multiscatter.js +52 -0
  700. package/src/nodes/functions/BSDF/BRDF_Sheen.js +4 -4
  701. package/src/nodes/functions/BSDF/DFGLUT.js +56 -0
  702. package/src/nodes/functions/BSDF/EnvironmentBRDF.js +2 -2
  703. package/src/nodes/functions/BSDF/LTC.js +45 -1
  704. package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated_Anisotropic.js +1 -1
  705. package/src/nodes/functions/BasicLightingModel.js +28 -6
  706. package/src/nodes/functions/PhongLightingModel.js +36 -6
  707. package/src/nodes/functions/PhysicalLightingModel.js +336 -91
  708. package/src/nodes/functions/ShadowMaskModel.js +30 -3
  709. package/src/nodes/functions/ToonLightingModel.js +21 -2
  710. package/src/nodes/functions/VolumetricLightingModel.js +183 -0
  711. package/src/nodes/functions/material/getAlphaHashThreshold.js +68 -0
  712. package/src/nodes/functions/material/getGeometryRoughness.js +10 -4
  713. package/src/nodes/functions/material/getParallaxCorrectNormal.js +37 -0
  714. package/src/nodes/geometry/RangeNode.js +97 -8
  715. package/src/nodes/gpgpu/AtomicFunctionNode.js +198 -23
  716. package/src/nodes/gpgpu/BarrierNode.js +52 -3
  717. package/src/nodes/gpgpu/ComputeBuiltinNode.js +135 -6
  718. package/src/nodes/gpgpu/ComputeNode.js +212 -16
  719. package/src/nodes/gpgpu/SubgroupFunctionNode.js +455 -0
  720. package/src/nodes/gpgpu/WorkgroupInfoNode.js +143 -9
  721. package/src/nodes/lighting/AONode.js +18 -0
  722. package/src/nodes/lighting/AmbientLightNode.js +10 -0
  723. package/src/nodes/lighting/AnalyticLightNode.js +186 -399
  724. package/src/nodes/lighting/BasicEnvironmentNode.js +19 -0
  725. package/src/nodes/lighting/BasicLightMapNode.js +17 -0
  726. package/src/nodes/lighting/DirectionalLightNode.js +12 -11
  727. package/src/nodes/lighting/EnvironmentNode.js +59 -19
  728. package/src/nodes/lighting/HemisphereLightNode.js +33 -2
  729. package/src/nodes/lighting/IESSpotLightNode.js +13 -1
  730. package/src/nodes/lighting/IrradianceNode.js +17 -0
  731. package/src/nodes/lighting/LightProbeNode.js +20 -0
  732. package/src/nodes/lighting/LightUtils.js +11 -3
  733. package/src/nodes/lighting/LightingContextNode.js +52 -4
  734. package/src/nodes/lighting/LightingNode.js +15 -6
  735. package/src/nodes/lighting/LightsNode.js +238 -35
  736. package/src/nodes/lighting/PointLightNode.js +60 -25
  737. package/src/nodes/lighting/PointShadowNode.js +325 -0
  738. package/src/nodes/lighting/ProjectorLightNode.js +91 -0
  739. package/src/nodes/lighting/RectAreaLightNode.js +50 -14
  740. package/src/nodes/lighting/ShadowBaseNode.js +81 -0
  741. package/src/nodes/lighting/ShadowFilterNode.js +264 -0
  742. package/src/nodes/lighting/ShadowNode.js +867 -0
  743. package/src/nodes/lighting/SpotLightNode.js +99 -18
  744. package/src/nodes/materialx/MaterialXNodes.js +131 -2
  745. package/src/nodes/materialx/lib/mx_noise.js +166 -2
  746. package/src/nodes/math/BitcastNode.js +156 -0
  747. package/src/nodes/math/BitcountNode.js +433 -0
  748. package/src/nodes/math/ConditionalNode.js +110 -21
  749. package/src/nodes/math/Hash.js +8 -0
  750. package/src/nodes/math/MathNode.js +820 -97
  751. package/src/nodes/math/MathUtils.js +47 -1
  752. package/src/nodes/math/OperatorNode.js +517 -84
  753. package/src/nodes/math/PackFloatNode.js +98 -0
  754. package/src/nodes/math/TriNoise3D.js +17 -7
  755. package/src/nodes/math/UnpackFloatNode.js +96 -0
  756. package/src/nodes/parsers/GLSLNodeFunction.js +16 -0
  757. package/src/nodes/parsers/GLSLNodeParser.js +11 -0
  758. package/src/nodes/pmrem/PMREMNode.js +180 -23
  759. package/src/nodes/pmrem/PMREMUtils.js +114 -5
  760. package/src/nodes/procedural/Checker.js +8 -0
  761. package/src/nodes/shapes/Shapes.js +33 -0
  762. package/src/nodes/tsl/TSLBase.js +10 -4
  763. package/src/nodes/tsl/TSLCore.js +732 -160
  764. package/src/nodes/utils/ArrayElementNode.js +55 -4
  765. package/src/nodes/utils/ConvertNode.js +31 -0
  766. package/src/nodes/utils/CubeMapNode.js +79 -2
  767. package/src/nodes/utils/DebugNode.js +83 -0
  768. package/src/nodes/utils/Discard.js +18 -2
  769. package/src/nodes/utils/EquirectUV.js +27 -0
  770. package/src/nodes/utils/EventNode.js +118 -0
  771. package/src/nodes/utils/FlipNode.js +38 -0
  772. package/src/nodes/utils/FunctionOverloadingNode.js +91 -22
  773. package/src/nodes/utils/JoinNode.js +57 -4
  774. package/src/nodes/utils/LoopNode.js +193 -55
  775. package/src/nodes/utils/MatcapUV.js +22 -0
  776. package/src/nodes/utils/MaxMipLevelNode.js +49 -1
  777. package/src/nodes/utils/MemberNode.js +120 -0
  778. package/src/nodes/utils/Oscillators.js +41 -0
  779. package/src/nodes/utils/Packing.js +30 -1
  780. package/src/nodes/utils/PostProcessingUtils.js +154 -0
  781. package/src/nodes/utils/RTTNode.js +165 -9
  782. package/src/nodes/utils/ReflectorNode.js +407 -21
  783. package/src/nodes/utils/RemapNode.js +81 -2
  784. package/src/nodes/utils/RotateNode.js +41 -1
  785. package/src/nodes/utils/SampleNode.js +91 -0
  786. package/src/nodes/utils/SetNode.js +44 -1
  787. package/src/nodes/utils/SplitNode.js +66 -3
  788. package/src/nodes/utils/SpriteSheetUV.js +35 -0
  789. package/src/nodes/utils/SpriteUtils.js +16 -0
  790. package/src/nodes/utils/StorageArrayElementNode.js +56 -3
  791. package/src/nodes/utils/Timer.js +26 -0
  792. package/src/nodes/utils/TriplanarTextures.js +65 -0
  793. package/src/nodes/utils/UVUtils.js +48 -0
  794. package/src/nodes/utils/ViewportUtils.js +12 -0
  795. package/src/objects/BatchedMesh.js +798 -309
  796. package/src/objects/Bone.js +24 -0
  797. package/src/objects/ClippingGroup.js +68 -0
  798. package/src/objects/Group.js +24 -0
  799. package/src/objects/InstancedMesh.js +131 -2
  800. package/src/objects/LOD.js +99 -5
  801. package/src/objects/Line.js +90 -7
  802. package/src/objects/LineLoop.js +20 -0
  803. package/src/objects/LineSegments.js +20 -1
  804. package/src/objects/Mesh.js +84 -0
  805. package/src/objects/Points.js +60 -0
  806. package/src/objects/Skeleton.js +120 -5
  807. package/src/objects/SkinnedMesh.js +102 -6
  808. package/src/objects/Sprite.js +65 -1
  809. package/src/renderers/WebGL3DRenderTarget.js +26 -0
  810. package/src/renderers/WebGLArrayRenderTarget.js +26 -0
  811. package/src/renderers/WebGLCubeRenderTarget.js +41 -5
  812. package/src/renderers/WebGLRenderTarget.js +19 -0
  813. package/src/renderers/WebGLRenderer.js +1016 -278
  814. package/src/renderers/common/Animation.js +123 -14
  815. package/src/renderers/common/Attributes.js +41 -1
  816. package/src/renderers/common/Backend.js +623 -44
  817. package/src/renderers/common/Background.js +99 -16
  818. package/src/renderers/common/BindGroup.js +37 -2
  819. package/src/renderers/common/Binding.js +46 -0
  820. package/src/renderers/common/Bindings.js +211 -20
  821. package/src/renderers/common/BlendMode.js +143 -0
  822. package/src/renderers/common/Buffer.js +89 -0
  823. package/src/renderers/common/BufferUtils.js +25 -0
  824. package/src/renderers/common/BundleGroup.js +57 -0
  825. package/src/renderers/common/CanvasTarget.js +341 -0
  826. package/src/renderers/common/ChainMap.js +73 -10
  827. package/src/renderers/common/ClippingContext.js +172 -87
  828. package/src/renderers/common/Color4.js +40 -0
  829. package/src/renderers/common/ComputePipeline.js +24 -0
  830. package/src/renderers/common/Constants.js +2 -1
  831. package/src/renderers/common/CubeRenderTarget.js +77 -7
  832. package/src/renderers/common/DataMap.js +37 -1
  833. package/src/renderers/common/Geometries.js +163 -14
  834. package/src/renderers/common/IndirectStorageBufferAttribute.js +38 -0
  835. package/src/renderers/common/Info.js +81 -36
  836. package/src/renderers/common/InspectorBase.js +146 -0
  837. package/src/renderers/common/Lighting.js +57 -0
  838. package/src/renderers/common/Pipeline.js +22 -0
  839. package/src/renderers/common/Pipelines.js +150 -7
  840. package/src/renderers/common/PostProcessing.js +22 -84
  841. package/src/renderers/common/ProgrammableStage.js +60 -2
  842. package/src/renderers/common/QuadMesh.js +63 -6
  843. package/src/renderers/common/RenderBundle.js +14 -8
  844. package/src/renderers/common/RenderBundles.js +40 -10
  845. package/src/renderers/common/RenderContext.js +219 -4
  846. package/src/renderers/common/RenderContexts.js +54 -17
  847. package/src/renderers/common/RenderList.js +233 -24
  848. package/src/renderers/common/RenderLists.js +46 -6
  849. package/src/renderers/common/RenderObject.js +548 -46
  850. package/src/renderers/common/RenderObjectPipeline.js +40 -0
  851. package/src/renderers/common/RenderObjects.js +133 -15
  852. package/src/renderers/common/RenderPipeline.js +216 -6
  853. package/src/renderers/common/Renderer.js +2155 -332
  854. package/src/renderers/common/RendererUtils.js +200 -0
  855. package/src/renderers/common/SampledTexture.js +99 -39
  856. package/src/renderers/common/Sampler.js +148 -1
  857. package/src/renderers/common/Storage3DTexture.js +100 -0
  858. package/src/renderers/common/StorageArrayTexture.js +84 -0
  859. package/src/renderers/common/StorageBuffer.js +38 -2
  860. package/src/renderers/common/StorageBufferAttribute.js +31 -2
  861. package/src/renderers/common/StorageInstancedBufferAttribute.js +31 -2
  862. package/src/renderers/common/StorageTexture.js +65 -0
  863. package/src/renderers/common/Textures.js +273 -57
  864. package/src/renderers/common/TimestampQueryPool.js +163 -0
  865. package/src/renderers/common/Uniform.js +233 -3
  866. package/src/renderers/common/UniformBuffer.js +19 -0
  867. package/src/renderers/common/UniformsGroup.js +235 -26
  868. package/src/renderers/common/XRManager.js +1677 -0
  869. package/src/renderers/common/XRRenderTarget.js +91 -0
  870. package/src/renderers/common/extras/PMREMGenerator.js +371 -108
  871. package/src/renderers/common/nodes/NodeBuilderState.js +100 -6
  872. package/src/renderers/common/nodes/NodeLibrary.js +95 -17
  873. package/src/renderers/common/nodes/NodeManager.js +852 -0
  874. package/src/renderers/common/nodes/NodeSampledTexture.js +84 -8
  875. package/src/renderers/common/nodes/NodeSampler.js +41 -1
  876. package/src/renderers/common/nodes/NodeStorageBuffer.js +48 -3
  877. package/src/renderers/common/nodes/NodeUniform.js +285 -2
  878. package/src/renderers/common/nodes/NodeUniformBuffer.js +81 -0
  879. package/src/renderers/common/nodes/NodeUniformsGroup.js +31 -18
  880. package/src/renderers/shaders/DFGLUTData.js +49 -0
  881. package/src/renderers/shaders/ShaderChunk/batching_pars_vertex.glsl.js +2 -2
  882. package/src/renderers/shaders/ShaderChunk/color_fragment.glsl.js +1 -5
  883. package/src/renderers/shaders/ShaderChunk/color_pars_fragment.glsl.js +1 -5
  884. package/src/renderers/shaders/ShaderChunk/color_pars_vertex.glsl.js +1 -5
  885. package/src/renderers/shaders/ShaderChunk/color_vertex.glsl.js +8 -10
  886. package/src/renderers/shaders/ShaderChunk/colorspace_pars_fragment.glsl.js +4 -24
  887. package/src/renderers/shaders/ShaderChunk/common.glsl.js +0 -12
  888. package/src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl.js +8 -0
  889. package/src/renderers/shaders/ShaderChunk/envmap_common_pars_fragment.glsl.js +1 -1
  890. package/src/renderers/shaders/ShaderChunk/envmap_fragment.glsl.js +7 -11
  891. package/src/renderers/shaders/ShaderChunk/envmap_physical_pars_fragment.glsl.js +1 -1
  892. package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +5 -2
  893. package/src/renderers/shaders/ShaderChunk/lights_fragment_end.glsl.js +6 -0
  894. package/src/renderers/shaders/ShaderChunk/lights_fragment_maps.glsl.js +6 -2
  895. package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +8 -4
  896. package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +154 -59
  897. package/src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl.js +1 -1
  898. package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl.js +1 -1
  899. package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_vertex.glsl.js +1 -1
  900. package/src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl.js +1 -1
  901. package/src/renderers/shaders/ShaderChunk/map_fragment.glsl.js +2 -2
  902. package/src/renderers/shaders/ShaderChunk/packing.glsl.js +20 -4
  903. package/src/renderers/shaders/ShaderChunk/premultiplied_alpha_fragment.glsl.js +1 -1
  904. package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +230 -181
  905. package/src/renderers/shaders/ShaderChunk/shadowmask_pars_fragment.glsl.js +1 -1
  906. package/src/renderers/shaders/ShaderChunk/transmission_fragment.glsl.js +1 -1
  907. package/src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js +7 -7
  908. package/src/renderers/shaders/ShaderChunk.js +3 -3
  909. package/src/renderers/shaders/ShaderLib/background.glsl.js +1 -1
  910. package/src/renderers/shaders/ShaderLib/depth.glsl.js +14 -2
  911. package/src/renderers/shaders/ShaderLib/{distanceRGBA.glsl.js → distance.glsl.js} +1 -2
  912. package/src/renderers/shaders/ShaderLib/meshlambert.glsl.js +2 -1
  913. package/src/renderers/shaders/ShaderLib/meshnormal.glsl.js +1 -2
  914. package/src/renderers/shaders/ShaderLib/meshphong.glsl.js +2 -1
  915. package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +4 -9
  916. package/src/renderers/shaders/ShaderLib/meshtoon.glsl.js +0 -1
  917. package/src/renderers/shaders/ShaderLib/shadow.glsl.js +1 -1
  918. package/src/renderers/shaders/ShaderLib/vsm.glsl.js +4 -6
  919. package/src/renderers/shaders/ShaderLib.js +7 -5
  920. package/src/renderers/shaders/UniformsLib.js +2 -7
  921. package/src/renderers/shaders/UniformsUtils.js +21 -2
  922. package/src/renderers/webgl/WebGLAttributes.js +4 -0
  923. package/src/renderers/webgl/WebGLBackground.js +30 -5
  924. package/src/renderers/webgl/WebGLBindingStates.js +99 -27
  925. package/src/renderers/webgl/WebGLBufferRenderer.js +2 -6
  926. package/src/renderers/webgl/WebGLCapabilities.js +7 -14
  927. package/src/renderers/webgl/WebGLEnvironments.js +228 -0
  928. package/src/renderers/webgl/WebGLExtensions.js +2 -25
  929. package/src/renderers/webgl/WebGLGeometries.js +10 -35
  930. package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +2 -6
  931. package/src/renderers/webgl/WebGLInfo.js +3 -1
  932. package/src/renderers/webgl/WebGLLights.js +18 -1
  933. package/src/renderers/webgl/WebGLMaterials.js +12 -0
  934. package/src/renderers/webgl/WebGLObjects.js +3 -1
  935. package/src/renderers/webgl/WebGLOutput.js +267 -0
  936. package/src/renderers/webgl/WebGLProgram.js +87 -148
  937. package/src/renderers/webgl/WebGLPrograms.js +53 -51
  938. package/src/renderers/webgl/WebGLRenderLists.js +15 -0
  939. package/src/renderers/webgl/WebGLShadowMap.js +204 -28
  940. package/src/renderers/webgl/WebGLState.js +88 -56
  941. package/src/renderers/webgl/WebGLTextures.js +293 -59
  942. package/src/renderers/webgl/WebGLUniforms.js +40 -3
  943. package/src/renderers/webgl/WebGLUniformsGroups.js +5 -3
  944. package/src/renderers/webgl/WebGLUtils.js +7 -5
  945. package/src/renderers/webgl-fallback/WebGLBackend.js +1416 -293
  946. package/src/renderers/webgl-fallback/WebGLBufferRenderer.js +5 -10
  947. package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +785 -92
  948. package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +62 -1
  949. package/src/renderers/webgl-fallback/utils/WebGLCapabilities.js +28 -0
  950. package/src/renderers/webgl-fallback/utils/WebGLConstants.js +3 -3
  951. package/src/renderers/webgl-fallback/utils/WebGLExtensions.js +45 -0
  952. package/src/renderers/webgl-fallback/utils/WebGLState.js +584 -20
  953. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +468 -80
  954. package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +396 -0
  955. package/src/renderers/webgl-fallback/utils/WebGLUtils.js +72 -24
  956. package/src/renderers/webgpu/WebGPUBackend.js +1517 -428
  957. package/src/renderers/webgpu/WebGPURenderer.Nodes.js +31 -4
  958. package/src/renderers/webgpu/WebGPURenderer.js +55 -4
  959. package/src/renderers/webgpu/nodes/BasicNodeLibrary.js +23 -16
  960. package/src/renderers/webgpu/nodes/StandardNodeLibrary.js +37 -42
  961. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +1335 -241
  962. package/src/renderers/webgpu/nodes/WGSLNodeFunction.js +32 -4
  963. package/src/renderers/webgpu/nodes/WGSLNodeParser.js +11 -0
  964. package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +144 -20
  965. package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +460 -116
  966. package/src/renderers/webgpu/utils/WebGPUConstants.js +17 -4
  967. package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +283 -69
  968. package/src/renderers/webgpu/utils/WebGPUTexturePassUtils.js +225 -178
  969. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +583 -191
  970. package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +310 -0
  971. package/src/renderers/webgpu/utils/WebGPUUtils.js +150 -28
  972. package/src/renderers/webxr/WebXRController.js +87 -2
  973. package/src/renderers/webxr/WebXRDepthSensing.js +52 -7
  974. package/src/renderers/webxr/WebXRManager.js +275 -15
  975. package/src/scenes/Fog.js +60 -0
  976. package/src/scenes/FogExp2.js +51 -0
  977. package/src/scenes/Scene.js +88 -0
  978. package/src/textures/CanvasTexture.js +28 -0
  979. package/src/textures/CompressedArrayTexture.js +57 -0
  980. package/src/textures/CompressedCubeTexture.js +29 -0
  981. package/src/textures/CompressedTexture.js +64 -6
  982. package/src/textures/CubeDepthTexture.js +76 -0
  983. package/src/textures/CubeTexture.js +52 -4
  984. package/src/textures/Data3DTexture.js +79 -2
  985. package/src/textures/DataArrayTexture.js +93 -0
  986. package/src/textures/DataTexture.js +65 -0
  987. package/src/textures/DepthTexture.js +59 -11
  988. package/src/textures/ExternalTexture.js +56 -0
  989. package/src/textures/FramebufferTexture.js +62 -0
  990. package/src/textures/Source.js +106 -4
  991. package/src/textures/Texture.js +488 -6
  992. package/src/textures/VideoFrameTexture.js +72 -0
  993. package/src/textures/VideoTexture.js +78 -6
  994. package/src/utils.js +322 -3
  995. package/examples/jsm/animation/MMDAnimationHelper.js +0 -1207
  996. package/examples/jsm/animation/MMDPhysics.js +0 -1406
  997. package/examples/jsm/cameras/CinematicCamera.js +0 -208
  998. package/examples/jsm/effects/PeppersGhostEffect.js +0 -153
  999. package/examples/jsm/exporters/MMDExporter.js +0 -217
  1000. package/examples/jsm/geometries/InstancedPointsGeometry.js +0 -174
  1001. package/examples/jsm/geometries/ParametricGeometries.js +0 -254
  1002. package/examples/jsm/libs/mmdparser.module.js +0 -11530
  1003. package/examples/jsm/loaders/GLTFLoaderAnimationPointer.js +0 -729
  1004. package/examples/jsm/loaders/MMDLoader.js +0 -2295
  1005. package/examples/jsm/loaders/RGBMLoader.js +0 -1081
  1006. package/examples/jsm/materials/MeshGouraudMaterial.js +0 -432
  1007. package/examples/jsm/materials/MeshPostProcessingMaterial.js +0 -144
  1008. package/examples/jsm/misc/Timer.js +0 -128
  1009. package/examples/jsm/objects/InstancedPoints.js +0 -21
  1010. package/examples/jsm/shaders/GodRaysShader.js +0 -321
  1011. package/examples/jsm/shaders/MMDToonShader.js +0 -134
  1012. package/src/materials/nodes/InstancedPointsNodeMaterial.js +0 -156
  1013. package/src/nodes/accessors/InstancedPointsMaterialNode.js +0 -24
  1014. package/src/nodes/accessors/SceneNode.js +0 -55
  1015. package/src/nodes/code/ScriptableNode.js +0 -505
  1016. package/src/nodes/code/ScriptableValueNode.js +0 -170
  1017. package/src/nodes/core/CacheNode.js +0 -50
  1018. package/src/nodes/core/UniformGroup.js +0 -13
  1019. package/src/nodes/display/AfterImageNode.js +0 -158
  1020. package/src/nodes/display/AnaglyphPassNode.js +0 -67
  1021. package/src/nodes/display/AnamorphicNode.js +0 -151
  1022. package/src/nodes/display/BlendMode.js +0 -54
  1023. package/src/nodes/display/BloomNode.js +0 -341
  1024. package/src/nodes/display/DenoiseNode.js +0 -204
  1025. package/src/nodes/display/DepthOfFieldNode.js +0 -124
  1026. package/src/nodes/display/DotScreenNode.js +0 -66
  1027. package/src/nodes/display/FXAANode.js +0 -332
  1028. package/src/nodes/display/FilmNode.js +0 -56
  1029. package/src/nodes/display/GTAONode.js +0 -331
  1030. package/src/nodes/display/GaussianBlurNode.js +0 -213
  1031. package/src/nodes/display/Lut3DNode.js +0 -57
  1032. package/src/nodes/display/MotionBlur.js +0 -25
  1033. package/src/nodes/display/ParallaxBarrierPassNode.js +0 -58
  1034. package/src/nodes/display/PixelationPassNode.js +0 -213
  1035. package/src/nodes/display/PosterizeNode.js +0 -33
  1036. package/src/nodes/display/RGBShiftNode.js +0 -53
  1037. package/src/nodes/display/StereoCompositePassNode.js +0 -110
  1038. package/src/nodes/display/TransitionNode.js +0 -80
  1039. package/src/nodes/fog/FogExp2Node.js +0 -35
  1040. package/src/nodes/fog/FogNode.js +0 -50
  1041. package/src/nodes/fog/FogRangeNode.js +0 -36
  1042. package/src/nodes/functions/BSDF/DFGApprox.js +0 -30
  1043. package/src/nodes/utils/EquirectUVNode.js +0 -36
  1044. package/src/nodes/utils/MatcapUVNode.js +0 -33
  1045. package/src/nodes/utils/OscNode.js +0 -85
  1046. package/src/nodes/utils/SpriteSheetUVNode.js +0 -45
  1047. package/src/nodes/utils/TimerNode.js +0 -97
  1048. package/src/nodes/utils/TriplanarTexturesNode.js +0 -64
  1049. package/src/renderers/common/nodes/Nodes.js +0 -534
  1050. package/src/renderers/webgl/WebGLCubeMaps.js +0 -99
  1051. package/src/renderers/webgl/WebGLCubeUVMaps.js +0 -136
@@ -2,7 +2,7 @@
2
2
  import 'https://greggman.github.io/webgpu-avoid-redundant-state-setting/webgpu-check-redundant-state-setting.js';
3
3
  //*/
4
4
 
5
- import { GPUFeatureName, GPULoadOp, GPUStoreOp, GPUIndexFormat, GPUTextureViewDimension } from './utils/WebGPUConstants.js';
5
+ import { GPUFeatureName, GPULoadOp, GPUStoreOp, GPUIndexFormat, GPUTextureViewDimension, GPUFeatureMap } from './utils/WebGPUConstants.js';
6
6
 
7
7
  import WGSLNodeBuilder from './nodes/WGSLNodeBuilder.js';
8
8
  import Backend from '../common/Backend.js';
@@ -13,16 +13,53 @@ import WebGPUBindingUtils from './utils/WebGPUBindingUtils.js';
13
13
  import WebGPUPipelineUtils from './utils/WebGPUPipelineUtils.js';
14
14
  import WebGPUTextureUtils from './utils/WebGPUTextureUtils.js';
15
15
 
16
- import { WebGPUCoordinateSystem } from '../../constants.js';
17
-
18
- //
16
+ import { WebGPUCoordinateSystem, TimestampQuery, REVISION, HalfFloatType, Compatibility } from '../../constants.js';
17
+ import WebGPUTimestampQueryPool from './utils/WebGPUTimestampQueryPool.js';
18
+ import { warnOnce, error } from '../../utils.js';
19
19
 
20
+ /**
21
+ * A backend implementation targeting WebGPU.
22
+ *
23
+ * @private
24
+ * @augments Backend
25
+ */
20
26
  class WebGPUBackend extends Backend {
21
27
 
28
+ /**
29
+ * WebGPUBackend options.
30
+ *
31
+ * @typedef {Object} WebGPUBackend~Options
32
+ * @property {boolean} [logarithmicDepthBuffer=false] - Whether logarithmic depth buffer is enabled or not.
33
+ * @property {boolean} [reversedDepthBuffer=false] - Whether reversed depth buffer is enabled or not.
34
+ * @property {boolean} [alpha=true] - Whether the default framebuffer (which represents the final contents of the canvas) should be transparent or opaque.
35
+ * @property {boolean} [depth=true] - Whether the default framebuffer should have a depth buffer or not.
36
+ * @property {boolean} [stencil=false] - Whether the default framebuffer should have a stencil buffer or not.
37
+ * @property {boolean} [antialias=false] - Whether MSAA as the default anti-aliasing should be enabled or not.
38
+ * @property {number} [samples=0] - When `antialias` is `true`, `4` samples are used by default. Set this parameter to any other integer value than 0 to overwrite the default.
39
+ * @property {boolean} [forceWebGL=false] - If set to `true`, the renderer uses a WebGL 2 backend no matter if WebGPU is supported or not.
40
+ * @property {boolean} [trackTimestamp=false] - Whether to track timestamps with a Timestamp Query API or not.
41
+ * @property {string} [powerPreference=undefined] - The power preference.
42
+ * @property {Object} [requiredLimits=undefined] - Specifies the limits that are required by the device request. The request will fail if the adapter cannot provide these limits.
43
+ * @property {GPUDevice} [device=undefined] - If there is an existing GPU device on app level, it can be passed to the renderer as a parameter.
44
+ * @property {number} [outputType=undefined] - Texture type for output to canvas. By default, device's preferred format is used; other formats may incur overhead.
45
+ */
46
+
47
+ /**
48
+ * Constructs a new WebGPU backend.
49
+ *
50
+ * @param {WebGPUBackend~Options} [parameters] - The configuration parameter.
51
+ */
22
52
  constructor( parameters = {} ) {
23
53
 
24
54
  super( parameters );
25
55
 
56
+ /**
57
+ * This flag can be used for type testing.
58
+ *
59
+ * @type {boolean}
60
+ * @readonly
61
+ * @default true
62
+ */
26
63
  this.isWebGPUBackend = true;
27
64
 
28
65
  // some parameters require default values other than "undefined"
@@ -30,22 +67,100 @@ class WebGPUBackend extends Backend {
30
67
 
31
68
  this.parameters.requiredLimits = ( parameters.requiredLimits === undefined ) ? {} : parameters.requiredLimits;
32
69
 
33
- this.trackTimestamp = ( parameters.trackTimestamp === true );
34
-
70
+ /**
71
+ * Indicates whether the backend is in WebGPU compatibility mode or not.
72
+ * The backend must be initialized before the property can be evaluated.
73
+ *
74
+ * @type {?boolean}
75
+ * @readonly
76
+ * @default null
77
+ */
78
+ this.compatibilityMode = null;
79
+
80
+ /**
81
+ * A reference to the device.
82
+ *
83
+ * @type {?GPUDevice}
84
+ * @default null
85
+ */
35
86
  this.device = null;
36
- this.context = null;
37
- this.colorBuffer = null;
87
+
88
+ /**
89
+ * A reference to the default render pass descriptor.
90
+ *
91
+ * @type {?Object}
92
+ * @default null
93
+ */
38
94
  this.defaultRenderPassdescriptor = null;
39
95
 
96
+ /**
97
+ * A reference to a backend module holding common utility functions.
98
+ *
99
+ * @type {WebGPUUtils}
100
+ */
40
101
  this.utils = new WebGPUUtils( this );
102
+
103
+ /**
104
+ * A reference to a backend module holding shader attribute-related
105
+ * utility functions.
106
+ *
107
+ * @type {WebGPUAttributeUtils}
108
+ */
41
109
  this.attributeUtils = new WebGPUAttributeUtils( this );
110
+
111
+ /**
112
+ * A reference to a backend module holding shader binding-related
113
+ * utility functions.
114
+ *
115
+ * @type {WebGPUBindingUtils}
116
+ */
42
117
  this.bindingUtils = new WebGPUBindingUtils( this );
118
+
119
+ /**
120
+ * A reference to a backend module holding shader pipeline-related
121
+ * utility functions.
122
+ *
123
+ * @type {WebGPUPipelineUtils}
124
+ */
43
125
  this.pipelineUtils = new WebGPUPipelineUtils( this );
126
+
127
+ /**
128
+ * A reference to a backend module holding shader texture-related
129
+ * utility functions.
130
+ *
131
+ * @type {WebGPUTextureUtils}
132
+ */
44
133
  this.textureUtils = new WebGPUTextureUtils( this );
134
+
135
+ /**
136
+ * A map that manages the resolve buffers for occlusion queries.
137
+ *
138
+ * @type {Map<number,GPUBuffer>}
139
+ */
45
140
  this.occludedResolveCache = new Map();
46
141
 
142
+ // compatibility checks
143
+
144
+ const compatibilityTextureCompare = typeof navigator === 'undefined' ? true : /Android/.test( navigator.userAgent ) === false;
145
+
146
+ /**
147
+ * A map of compatibility checks.
148
+ *
149
+ * @type {Object}
150
+ */
151
+ this._compatibility = {
152
+ [ Compatibility.TEXTURE_COMPARE ]: compatibilityTextureCompare
153
+ };
154
+
47
155
  }
48
156
 
157
+ /**
158
+ * Initializes the backend so it is ready for usage.
159
+ *
160
+ * @async
161
+ * @param {Renderer} renderer - The renderer.
162
+ * @return {Promise} A Promise that resolves when the backend has been initialized.
163
+ */
49
164
  async init( renderer ) {
50
165
 
51
166
  await super.init( renderer );
@@ -61,10 +176,11 @@ class WebGPUBackend extends Backend {
61
176
  if ( parameters.device === undefined ) {
62
177
 
63
178
  const adapterOptions = {
64
- powerPreference: parameters.powerPreference
179
+ powerPreference: parameters.powerPreference,
180
+ featureLevel: 'compatibility'
65
181
  };
66
182
 
67
- const adapter = await navigator.gpu.requestAdapter( adapterOptions );
183
+ const adapter = ( typeof navigator !== 'undefined' ) ? await navigator.gpu.requestAdapter( adapterOptions ) : null;
68
184
 
69
185
  if ( adapter === null ) {
70
186
 
@@ -101,66 +217,166 @@ class WebGPUBackend extends Backend {
101
217
 
102
218
  }
103
219
 
104
- const context = ( parameters.context !== undefined ) ? parameters.context : renderer.domElement.getContext( 'webgpu' );
220
+ this.compatibilityMode = ! device.features.has( 'core-features-and-limits' );
105
221
 
106
- this.device = device;
107
- this.context = context;
222
+ if ( this.compatibilityMode ) {
108
223
 
109
- const alphaMode = parameters.alpha ? 'premultiplied' : 'opaque';
224
+ renderer._samples = 0;
110
225
 
111
- this.trackTimestamp = this.trackTimestamp && this.hasFeature( GPUFeatureName.TimestampQuery );
226
+ }
227
+
228
+ device.lost.then( ( info ) => {
229
+
230
+ if ( info.reason === 'destroyed' ) return;
231
+
232
+ const deviceLossInfo = {
233
+ api: 'WebGPU',
234
+ message: info.message || 'Unknown reason',
235
+ reason: info.reason || null,
236
+ originalEvent: info
237
+ };
238
+
239
+ renderer.onDeviceLost( deviceLossInfo );
112
240
 
113
- this.context.configure( {
114
- device: this.device,
115
- format: this.utils.getPreferredCanvasFormat(),
116
- usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_SRC,
117
- alphaMode: alphaMode
118
241
  } );
119
242
 
243
+ this.device = device;
244
+
245
+ this.trackTimestamp = this.trackTimestamp && this.hasFeature( GPUFeatureName.TimestampQuery );
246
+
120
247
  this.updateSize();
121
248
 
122
249
  }
123
250
 
251
+ /**
252
+ * A reference to the context.
253
+ *
254
+ * @type {?GPUCanvasContext}
255
+ * @default null
256
+ */
257
+ get context() {
258
+
259
+ const canvasTarget = this.renderer.getCanvasTarget();
260
+ const canvasData = this.get( canvasTarget );
261
+
262
+ let context = canvasData.context;
263
+
264
+ if ( context === undefined ) {
265
+
266
+ const parameters = this.parameters;
267
+
268
+ if ( canvasTarget.isDefaultCanvasTarget === true && parameters.context !== undefined ) {
269
+
270
+ context = parameters.context;
271
+
272
+ } else {
273
+
274
+ context = canvasTarget.domElement.getContext( 'webgpu' );
275
+
276
+ }
277
+
278
+ // OffscreenCanvas does not have setAttribute, see #22811
279
+ if ( 'setAttribute' in canvasTarget.domElement ) canvasTarget.domElement.setAttribute( 'data-engine', `three.js r${ REVISION } webgpu` );
280
+
281
+ const alphaMode = parameters.alpha ? 'premultiplied' : 'opaque';
282
+
283
+ const toneMappingMode = parameters.outputType === HalfFloatType ? 'extended' : 'standard';
284
+
285
+ context.configure( {
286
+ device: this.device,
287
+ format: this.utils.getPreferredCanvasFormat(),
288
+ usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_SRC,
289
+ alphaMode: alphaMode,
290
+ toneMapping: {
291
+ mode: toneMappingMode
292
+ }
293
+ } );
294
+
295
+ canvasData.context = context;
296
+
297
+ }
298
+
299
+ return context;
300
+
301
+ }
302
+
303
+ /**
304
+ * The coordinate system of the backend.
305
+ *
306
+ * @type {number}
307
+ * @readonly
308
+ */
124
309
  get coordinateSystem() {
125
310
 
126
311
  return WebGPUCoordinateSystem;
127
312
 
128
313
  }
129
314
 
315
+ /**
316
+ * This method performs a readback operation by moving buffer data from
317
+ * a storage buffer attribute from the GPU to the CPU.
318
+ *
319
+ * @async
320
+ * @param {StorageBufferAttribute} attribute - The storage buffer attribute.
321
+ * @return {Promise<ArrayBuffer>} A promise that resolves with the buffer data when the data are ready.
322
+ */
130
323
  async getArrayBufferAsync( attribute ) {
131
324
 
132
325
  return await this.attributeUtils.getArrayBufferAsync( attribute );
133
326
 
134
327
  }
135
328
 
329
+ /**
330
+ * Returns the backend's rendering context.
331
+ *
332
+ * @return {GPUCanvasContext} The rendering context.
333
+ */
136
334
  getContext() {
137
335
 
138
336
  return this.context;
139
337
 
140
338
  }
141
339
 
340
+ /**
341
+ * Returns the default render pass descriptor.
342
+ *
343
+ * In WebGPU, the default framebuffer must be configured
344
+ * like custom framebuffers so the backend needs a render
345
+ * pass descriptor even when rendering directly to screen.
346
+ *
347
+ * @private
348
+ * @return {Object} The render pass descriptor.
349
+ */
142
350
  _getDefaultRenderPassDescriptor() {
143
351
 
144
- let descriptor = this.defaultRenderPassdescriptor;
352
+ const renderer = this.renderer;
353
+ const canvasTarget = renderer.getCanvasTarget();
354
+ const canvasData = this.get( canvasTarget );
355
+ const samples = renderer.currentSamples;
145
356
 
146
- if ( descriptor === null ) {
357
+ let descriptor = canvasData.descriptor;
147
358
 
148
- const renderer = this.renderer;
359
+ if ( descriptor === undefined || canvasData.samples !== samples ) {
149
360
 
150
361
  descriptor = {
151
362
  colorAttachments: [ {
152
363
  view: null
153
- } ],
154
- depthStencilAttachment: {
155
- view: this.textureUtils.getDepthBuffer( renderer.depth, renderer.stencil ).createView()
156
- }
364
+ } ]
157
365
  };
158
366
 
367
+ if ( renderer.depth === true || renderer.stencil === true ) {
368
+
369
+ descriptor.depthStencilAttachment = {
370
+ view: this.textureUtils.getDepthBuffer( renderer.depth, renderer.stencil ).createView()
371
+ };
372
+
373
+ }
374
+
159
375
  const colorAttachment = descriptor.colorAttachments[ 0 ];
160
376
 
161
- if ( this.renderer.samples > 0 ) {
377
+ if ( samples > 0 ) {
162
378
 
163
- colorAttachment.view = this.colorBuffer.createView();
379
+ colorAttachment.view = this.textureUtils.getColorBuffer().createView();
164
380
 
165
381
  } else {
166
382
 
@@ -168,13 +384,14 @@ class WebGPUBackend extends Backend {
168
384
 
169
385
  }
170
386
 
171
- this.defaultRenderPassdescriptor = descriptor;
387
+ canvasData.descriptor = descriptor;
388
+ canvasData.samples = samples;
172
389
 
173
390
  }
174
391
 
175
392
  const colorAttachment = descriptor.colorAttachments[ 0 ];
176
393
 
177
- if ( this.renderer.samples > 0 ) {
394
+ if ( samples > 0 ) {
178
395
 
179
396
  colorAttachment.resolveTarget = this.context.getCurrentTexture().createView();
180
397
 
@@ -188,7 +405,29 @@ class WebGPUBackend extends Backend {
188
405
 
189
406
  }
190
407
 
191
- _getRenderPassDescriptor( renderContext ) {
408
+ /**
409
+ * Internal to determine if the current render target is a render target array with depth 2D array texture.
410
+ *
411
+ * @param {RenderContext} renderContext - The render context.
412
+ * @return {boolean} Whether the render target is a render target array with depth 2D array texture.
413
+ *
414
+ * @private
415
+ */
416
+ _isRenderCameraDepthArray( renderContext ) {
417
+
418
+ return renderContext.depthTexture && renderContext.depthTexture.image.depth > 1 && renderContext.camera.isArrayCamera;
419
+
420
+ }
421
+
422
+ /**
423
+ * Returns the render pass descriptor for the given render context.
424
+ *
425
+ * @private
426
+ * @param {RenderContext} renderContext - The render context.
427
+ * @param {Object} colorAttachmentsConfig - Configuration object for the color attachments.
428
+ * @return {Object} The render pass descriptor.
429
+ */
430
+ _getRenderPassDescriptor( renderContext, colorAttachmentsConfig = {} ) {
192
431
 
193
432
  const renderTarget = renderContext.renderTarget;
194
433
  const renderTargetData = this.get( renderTarget );
@@ -198,7 +437,6 @@ class WebGPUBackend extends Backend {
198
437
  if ( descriptors === undefined ||
199
438
  renderTargetData.width !== renderTarget.width ||
200
439
  renderTargetData.height !== renderTarget.height ||
201
- renderTargetData.activeMipmapLevel !== renderTarget.activeMipmapLevel ||
202
440
  renderTargetData.samples !== renderTarget.samples
203
441
  ) {
204
442
 
@@ -206,80 +444,160 @@ class WebGPUBackend extends Backend {
206
444
 
207
445
  renderTargetData.descriptors = descriptors;
208
446
 
209
- // dispose
210
-
211
- const onDispose = () => {
212
-
213
- renderTarget.removeEventListener( 'dispose', onDispose );
214
-
215
- this.delete( renderTarget );
216
-
217
- };
218
-
219
- renderTarget.addEventListener( 'dispose', onDispose );
220
-
221
447
  }
222
448
 
223
449
  const cacheKey = renderContext.getCacheKey();
450
+ let descriptorBase = descriptors[ cacheKey ];
224
451
 
225
- let descriptor = descriptors[ cacheKey ];
226
-
227
- if ( descriptor === undefined ) {
452
+ if ( descriptorBase === undefined ) {
228
453
 
229
454
  const textures = renderContext.textures;
230
- const colorAttachments = [];
455
+ const textureViews = [];
456
+
457
+ let sliceIndex;
458
+
459
+ const isRenderCameraDepthArray = this._isRenderCameraDepthArray( renderContext );
231
460
 
232
461
  for ( let i = 0; i < textures.length; i ++ ) {
233
462
 
234
463
  const textureData = this.get( textures[ i ] );
235
464
 
236
- const textureView = textureData.texture.createView( {
465
+ const viewDescriptor = {
466
+ label: `colorAttachment_${ i }`,
237
467
  baseMipLevel: renderContext.activeMipmapLevel,
238
468
  mipLevelCount: 1,
239
469
  baseArrayLayer: renderContext.activeCubeFace,
470
+ arrayLayerCount: 1,
240
471
  dimension: GPUTextureViewDimension.TwoD
241
- } );
472
+ };
242
473
 
243
- let view, resolveTarget;
474
+ if ( renderTarget.isRenderTarget3D ) {
244
475
 
245
- if ( textureData.msaaTexture !== undefined ) {
476
+ sliceIndex = renderContext.activeCubeFace;
246
477
 
247
- view = textureData.msaaTexture.createView();
248
- resolveTarget = textureView;
478
+ viewDescriptor.baseArrayLayer = 0;
479
+ viewDescriptor.dimension = GPUTextureViewDimension.ThreeD;
480
+ viewDescriptor.depthOrArrayLayers = textures[ i ].image.depth;
249
481
 
250
- } else {
482
+ } else if ( renderTarget.isRenderTarget && textures[ i ].image.depth > 1 ) {
483
+
484
+ if ( isRenderCameraDepthArray === true ) {
485
+
486
+ const cameras = renderContext.camera.cameras;
487
+ for ( let layer = 0; layer < cameras.length; layer ++ ) {
488
+
489
+ const layerViewDescriptor = {
490
+ ...viewDescriptor,
491
+ baseArrayLayer: layer,
492
+ arrayLayerCount: 1,
493
+ dimension: GPUTextureViewDimension.TwoD
494
+ };
495
+ const textureView = textureData.texture.createView( layerViewDescriptor );
496
+ textureViews.push( {
497
+ view: textureView,
498
+ resolveTarget: undefined,
499
+ depthSlice: undefined
500
+ } );
251
501
 
252
- view = textureView;
253
- resolveTarget = undefined;
502
+ }
503
+
504
+ } else {
505
+
506
+ viewDescriptor.dimension = GPUTextureViewDimension.TwoDArray;
507
+ viewDescriptor.depthOrArrayLayers = textures[ i ].image.depth;
508
+
509
+ }
254
510
 
255
511
  }
256
512
 
257
- colorAttachments.push( {
258
- view,
259
- resolveTarget,
260
- loadOp: GPULoadOp.Load,
261
- storeOp: GPUStoreOp.Store
262
- } );
513
+ if ( isRenderCameraDepthArray !== true ) {
514
+
515
+ const textureView = textureData.texture.createView( viewDescriptor );
516
+
517
+ let view, resolveTarget;
518
+
519
+ if ( textureData.msaaTexture !== undefined ) {
520
+
521
+ view = textureData.msaaTexture.createView();
522
+ resolveTarget = textureView;
523
+
524
+ } else {
525
+
526
+ view = textureView;
527
+ resolveTarget = undefined;
528
+
529
+ }
530
+
531
+ textureViews.push( {
532
+ view,
533
+ resolveTarget,
534
+ depthSlice: sliceIndex
535
+ } );
536
+
537
+ }
263
538
 
264
539
  }
265
540
 
266
- const depthTextureData = this.get( renderContext.depthTexture );
541
+ descriptorBase = { textureViews };
267
542
 
268
- const depthStencilAttachment = {
269
- view: depthTextureData.texture.createView()
270
- };
543
+ if ( renderContext.depth ) {
271
544
 
272
- descriptor = {
273
- colorAttachments,
274
- depthStencilAttachment
275
- };
545
+ const depthTextureData = this.get( renderContext.depthTexture );
546
+ const options = {};
547
+ if ( renderContext.depthTexture.isArrayTexture || renderContext.depthTexture.isCubeTexture ) {
548
+
549
+ options.dimension = GPUTextureViewDimension.TwoD;
550
+ options.arrayLayerCount = 1;
551
+ options.baseArrayLayer = renderContext.activeCubeFace;
552
+
553
+ }
554
+
555
+ descriptorBase.depthStencilView = depthTextureData.texture.createView( options );
276
556
 
277
- descriptors[ cacheKey ] = descriptor;
557
+ }
558
+
559
+ descriptors[ cacheKey ] = descriptorBase;
278
560
 
279
561
  renderTargetData.width = renderTarget.width;
280
562
  renderTargetData.height = renderTarget.height;
281
563
  renderTargetData.samples = renderTarget.samples;
282
- renderTargetData.activeMipmapLevel = renderTarget.activeMipmapLevel;
564
+ renderTargetData.activeMipmapLevel = renderContext.activeMipmapLevel;
565
+ renderTargetData.activeCubeFace = renderContext.activeCubeFace;
566
+
567
+ }
568
+
569
+ const descriptor = {
570
+ colorAttachments: []
571
+ };
572
+
573
+ // Apply dynamic properties to cached views
574
+ for ( let i = 0; i < descriptorBase.textureViews.length; i ++ ) {
575
+
576
+ const viewInfo = descriptorBase.textureViews[ i ];
577
+
578
+ let clearValue = { r: 0, g: 0, b: 0, a: 1 };
579
+ if ( i === 0 && colorAttachmentsConfig.clearValue ) {
580
+
581
+ clearValue = colorAttachmentsConfig.clearValue;
582
+
583
+ }
584
+
585
+ descriptor.colorAttachments.push( {
586
+ view: viewInfo.view,
587
+ depthSlice: viewInfo.depthSlice,
588
+ resolveTarget: viewInfo.resolveTarget,
589
+ loadOp: colorAttachmentsConfig.loadOp || GPULoadOp.Load,
590
+ storeOp: colorAttachmentsConfig.storeOp || GPUStoreOp.Store,
591
+ clearValue: clearValue
592
+ } );
593
+
594
+ }
595
+
596
+ if ( descriptorBase.depthStencilView ) {
597
+
598
+ descriptor.depthStencilAttachment = {
599
+ view: descriptorBase.depthStencilView
600
+ };
283
601
 
284
602
  }
285
603
 
@@ -287,10 +605,18 @@ class WebGPUBackend extends Backend {
287
605
 
288
606
  }
289
607
 
608
+ /**
609
+ * This method is executed at the beginning of a render call and prepares
610
+ * the WebGPU state for upcoming render calls
611
+ *
612
+ * @param {RenderContext} renderContext - The render context.
613
+ */
290
614
  beginRender( renderContext ) {
291
615
 
292
616
  const renderContextData = this.get( renderContext );
293
617
 
618
+ //
619
+
294
620
  const device = this.device;
295
621
  const occlusionQueryCount = renderContext.occlusionQueryCount;
296
622
 
@@ -309,7 +635,7 @@ class WebGPUBackend extends Backend {
309
635
 
310
636
  //
311
637
 
312
- occlusionQuerySet = device.createQuerySet( { type: 'occlusion', count: occlusionQueryCount } );
638
+ occlusionQuerySet = device.createQuerySet( { type: 'occlusion', count: occlusionQueryCount, label: `occlusionQuerySet_${ renderContext.id }` } );
313
639
 
314
640
  renderContextData.occlusionQuerySet = occlusionQuerySet;
315
641
  renderContextData.occlusionQueryIndex = 0;
@@ -327,11 +653,11 @@ class WebGPUBackend extends Backend {
327
653
 
328
654
  } else {
329
655
 
330
- descriptor = this._getRenderPassDescriptor( renderContext );
656
+ descriptor = this._getRenderPassDescriptor( renderContext, { loadOp: GPULoadOp.Load } );
331
657
 
332
658
  }
333
659
 
334
- this.initTimestampQuery( renderContext, descriptor );
660
+ this.initTimestampQuery( TimestampQuery.RENDER, this.getTimestampUID( renderContext ), descriptor );
335
661
 
336
662
  descriptor.occlusionQuerySet = occlusionQuerySet;
337
663
 
@@ -349,15 +675,15 @@ class WebGPUBackend extends Backend {
349
675
 
350
676
  colorAttachment.clearValue = i === 0 ? renderContext.clearColorValue : { r: 0, g: 0, b: 0, a: 1 };
351
677
  colorAttachment.loadOp = GPULoadOp.Clear;
352
- colorAttachment.storeOp = GPUStoreOp.Store;
353
678
 
354
679
  } else {
355
680
 
356
681
  colorAttachment.loadOp = GPULoadOp.Load;
357
- colorAttachment.storeOp = GPUStoreOp.Store;
358
682
 
359
683
  }
360
684
 
685
+ colorAttachment.storeOp = GPUStoreOp.Store;
686
+
361
687
  }
362
688
 
363
689
  } else {
@@ -368,15 +694,15 @@ class WebGPUBackend extends Backend {
368
694
 
369
695
  colorAttachment.clearValue = renderContext.clearColorValue;
370
696
  colorAttachment.loadOp = GPULoadOp.Clear;
371
- colorAttachment.storeOp = GPUStoreOp.Store;
372
697
 
373
698
  } else {
374
699
 
375
700
  colorAttachment.loadOp = GPULoadOp.Load;
376
- colorAttachment.storeOp = GPUStoreOp.Store;
377
701
 
378
702
  }
379
703
 
704
+ colorAttachment.storeOp = GPUStoreOp.Store;
705
+
380
706
  }
381
707
 
382
708
  //
@@ -387,65 +713,245 @@ class WebGPUBackend extends Backend {
387
713
 
388
714
  depthStencilAttachment.depthClearValue = renderContext.clearDepthValue;
389
715
  depthStencilAttachment.depthLoadOp = GPULoadOp.Clear;
390
- depthStencilAttachment.depthStoreOp = GPUStoreOp.Store;
391
716
 
392
717
  } else {
393
718
 
394
719
  depthStencilAttachment.depthLoadOp = GPULoadOp.Load;
395
- depthStencilAttachment.depthStoreOp = GPUStoreOp.Store;
396
720
 
397
721
  }
398
722
 
723
+ depthStencilAttachment.depthStoreOp = GPUStoreOp.Store;
724
+
399
725
  }
400
726
 
401
727
  if ( renderContext.stencil ) {
402
728
 
403
- if ( renderContext.clearStencil ) {
729
+ if ( renderContext.clearStencil ) {
404
730
 
405
731
  depthStencilAttachment.stencilClearValue = renderContext.clearStencilValue;
406
732
  depthStencilAttachment.stencilLoadOp = GPULoadOp.Clear;
407
- depthStencilAttachment.stencilStoreOp = GPUStoreOp.Store;
408
733
 
409
734
  } else {
410
735
 
411
736
  depthStencilAttachment.stencilLoadOp = GPULoadOp.Load;
412
- depthStencilAttachment.stencilStoreOp = GPUStoreOp.Store;
413
737
 
414
738
  }
415
739
 
740
+ depthStencilAttachment.stencilStoreOp = GPUStoreOp.Store;
741
+
416
742
  }
417
743
 
418
744
  //
419
745
 
420
746
  const encoder = device.createCommandEncoder( { label: 'renderContext_' + renderContext.id } );
421
- const currentPass = encoder.beginRenderPass( descriptor );
747
+
748
+ // shadow arrays - prepare bundle encoders for each camera in an array camera
749
+
750
+ if ( this._isRenderCameraDepthArray( renderContext ) === true ) {
751
+
752
+ const cameras = renderContext.camera.cameras;
753
+
754
+ if ( ! renderContextData.layerDescriptors || renderContextData.layerDescriptors.length !== cameras.length ) {
755
+
756
+ this._createDepthLayerDescriptors( renderContext, renderContextData, descriptor, cameras );
757
+
758
+ } else {
759
+
760
+ this._updateDepthLayerDescriptors( renderContext, renderContextData, cameras );
761
+
762
+ }
763
+
764
+ // Create bundle encoders for each layer
765
+ renderContextData.bundleEncoders = [];
766
+ renderContextData.bundleSets = [];
767
+
768
+ // Create separate bundle encoders for each camera in the array
769
+ for ( let i = 0; i < cameras.length; i ++ ) {
770
+
771
+ const bundleEncoder = this.pipelineUtils.createBundleEncoder(
772
+ renderContext,
773
+ 'renderBundleArrayCamera_' + i
774
+ );
775
+
776
+ // Initialize state tracking for this bundle
777
+ const bundleSets = {
778
+ attributes: {},
779
+ bindingGroups: [],
780
+ pipeline: null,
781
+ index: null
782
+ };
783
+
784
+ renderContextData.bundleEncoders.push( bundleEncoder );
785
+ renderContextData.bundleSets.push( bundleSets );
786
+
787
+ }
788
+
789
+ // We'll complete the bundles in finishRender
790
+ renderContextData.currentPass = null;
791
+
792
+ } else {
793
+
794
+ const currentPass = encoder.beginRenderPass( descriptor );
795
+ renderContextData.currentPass = currentPass;
796
+
797
+ if ( renderContext.viewport ) {
798
+
799
+ this.updateViewport( renderContext );
800
+
801
+ }
802
+
803
+ if ( renderContext.scissor ) {
804
+
805
+ this.updateScissor( renderContext );
806
+
807
+ }
808
+
809
+ }
422
810
 
423
811
  //
424
812
 
425
813
  renderContextData.descriptor = descriptor;
426
814
  renderContextData.encoder = encoder;
427
- renderContextData.currentPass = currentPass;
428
815
  renderContextData.currentSets = { attributes: {}, bindingGroups: [], pipeline: null, index: null };
429
816
  renderContextData.renderBundles = [];
430
817
 
431
- //
818
+ }
819
+
820
+ /**
821
+ * This method creates layer descriptors for each camera in an array camera
822
+ * to prepare for rendering to a depth array texture.
823
+ *
824
+ * @param {RenderContext} renderContext - The render context.
825
+ * @param {Object} renderContextData - The render context data.
826
+ * @param {Object} descriptor - The render pass descriptor.
827
+ * @param {ArrayCamera} cameras - The array camera.
828
+ *
829
+ * @private
830
+ */
831
+ _createDepthLayerDescriptors( renderContext, renderContextData, descriptor, cameras ) {
832
+
833
+ const depthStencilAttachment = descriptor.depthStencilAttachment;
834
+ renderContextData.layerDescriptors = [];
835
+
836
+ const depthTextureData = this.get( renderContext.depthTexture );
837
+ if ( ! depthTextureData.viewCache ) {
838
+
839
+ depthTextureData.viewCache = [];
840
+
841
+ }
842
+
843
+ for ( let i = 0; i < cameras.length; i ++ ) {
844
+
845
+ const layerDescriptor = {
846
+ ...descriptor,
847
+ colorAttachments: [ {
848
+ ...descriptor.colorAttachments[ 0 ],
849
+ view: descriptor.colorAttachments[ i ].view
850
+ } ]
851
+ };
852
+
853
+ if ( descriptor.depthStencilAttachment ) {
854
+
855
+ const layerIndex = i;
856
+
857
+ if ( ! depthTextureData.viewCache[ layerIndex ] ) {
858
+
859
+ depthTextureData.viewCache[ layerIndex ] = depthTextureData.texture.createView( {
860
+ dimension: GPUTextureViewDimension.TwoD,
861
+ baseArrayLayer: i,
862
+ arrayLayerCount: 1
863
+ } );
432
864
 
433
- if ( renderContext.viewport ) {
865
+ }
866
+
867
+ layerDescriptor.depthStencilAttachment = {
868
+ view: depthTextureData.viewCache[ layerIndex ],
869
+ depthLoadOp: depthStencilAttachment.depthLoadOp || GPULoadOp.Clear,
870
+ depthStoreOp: depthStencilAttachment.depthStoreOp || GPUStoreOp.Store,
871
+ depthClearValue: depthStencilAttachment.depthClearValue || 1.0
872
+ };
873
+
874
+ if ( renderContext.stencil ) {
875
+
876
+ layerDescriptor.depthStencilAttachment.stencilLoadOp = depthStencilAttachment.stencilLoadOp;
877
+ layerDescriptor.depthStencilAttachment.stencilStoreOp = depthStencilAttachment.stencilStoreOp;
878
+ layerDescriptor.depthStencilAttachment.stencilClearValue = depthStencilAttachment.stencilClearValue;
879
+
880
+ }
434
881
 
435
- this.updateViewport( renderContext );
882
+ } else {
883
+
884
+ layerDescriptor.depthStencilAttachment = { ...depthStencilAttachment };
885
+
886
+ }
887
+
888
+ renderContextData.layerDescriptors.push( layerDescriptor );
436
889
 
437
890
  }
438
891
 
439
- if ( renderContext.scissor ) {
892
+ }
893
+
894
+ /**
895
+ * This method updates the layer descriptors for each camera in an array camera
896
+ * to prepare for rendering to a depth array texture.
897
+ *
898
+ * @param {RenderContext} renderContext - The render context.
899
+ * @param {Object} renderContextData - The render context data.
900
+ * @param {ArrayCamera} cameras - The array camera.
901
+ *
902
+ */
903
+ _updateDepthLayerDescriptors( renderContext, renderContextData, cameras ) {
904
+
905
+ for ( let i = 0; i < cameras.length; i ++ ) {
906
+
907
+ const layerDescriptor = renderContextData.layerDescriptors[ i ];
908
+
909
+ if ( layerDescriptor.depthStencilAttachment ) {
910
+
911
+ const depthAttachment = layerDescriptor.depthStencilAttachment;
912
+
913
+ if ( renderContext.depth ) {
914
+
915
+ if ( renderContext.clearDepth ) {
916
+
917
+ depthAttachment.depthClearValue = renderContext.clearDepthValue;
918
+ depthAttachment.depthLoadOp = GPULoadOp.Clear;
919
+
920
+ } else {
921
+
922
+ depthAttachment.depthLoadOp = GPULoadOp.Load;
923
+
924
+ }
925
+
926
+ }
927
+
928
+ if ( renderContext.stencil ) {
929
+
930
+ if ( renderContext.clearStencil ) {
931
+
932
+ depthAttachment.stencilClearValue = renderContext.clearStencilValue;
933
+ depthAttachment.stencilLoadOp = GPULoadOp.Clear;
934
+
935
+ } else {
936
+
937
+ depthAttachment.stencilLoadOp = GPULoadOp.Load;
440
938
 
441
- const { x, y, width, height } = renderContext.scissorValue;
939
+ }
940
+
941
+ }
442
942
 
443
- currentPass.setScissorRect( x, y, width, height );
943
+ }
444
944
 
445
945
  }
446
946
 
447
947
  }
448
948
 
949
+ /**
950
+ * This method is executed at the end of a render call and finalizes work
951
+ * after draw calls.
952
+ *
953
+ * @param {RenderContext} renderContext - The render context.
954
+ */
449
955
  finishRender( renderContext ) {
450
956
 
451
957
  const renderContextData = this.get( renderContext );
@@ -463,7 +969,55 @@ class WebGPUBackend extends Backend {
463
969
 
464
970
  }
465
971
 
466
- renderContextData.currentPass.end();
972
+ // shadow arrays - Execute bundles for each layer
973
+
974
+ const encoder = renderContextData.encoder;
975
+
976
+ if ( this._isRenderCameraDepthArray( renderContext ) === true ) {
977
+
978
+ const bundles = [];
979
+
980
+ for ( let i = 0; i < renderContextData.bundleEncoders.length; i ++ ) {
981
+
982
+ const bundleEncoder = renderContextData.bundleEncoders[ i ];
983
+ bundles.push( bundleEncoder.finish() );
984
+
985
+ }
986
+
987
+ for ( let i = 0; i < renderContextData.layerDescriptors.length; i ++ ) {
988
+
989
+ if ( i < bundles.length ) {
990
+
991
+ const layerDescriptor = renderContextData.layerDescriptors[ i ];
992
+ const renderPass = encoder.beginRenderPass( layerDescriptor );
993
+
994
+ if ( renderContext.viewport ) {
995
+
996
+ const { x, y, width, height, minDepth, maxDepth } = renderContext.viewportValue;
997
+ renderPass.setViewport( x, y, width, height, minDepth, maxDepth );
998
+
999
+ }
1000
+
1001
+ if ( renderContext.scissor ) {
1002
+
1003
+ const { x, y, width, height } = renderContext.scissorValue;
1004
+ renderPass.setScissorRect( x, y, width, height );
1005
+
1006
+ }
1007
+
1008
+ renderPass.executeBundles( [ bundles[ i ] ] );
1009
+
1010
+ renderPass.end();
1011
+
1012
+ }
1013
+
1014
+ }
1015
+
1016
+ } else if ( renderContextData.currentPass ) {
1017
+
1018
+ renderContextData.currentPass.end();
1019
+
1020
+ }
467
1021
 
468
1022
  if ( occlusionQueryCount > 0 ) {
469
1023
 
@@ -507,8 +1061,6 @@ class WebGPUBackend extends Backend {
507
1061
 
508
1062
  }
509
1063
 
510
- this.prepareTimestampBuffer( renderContext, renderContextData.encoder );
511
-
512
1064
  this.device.queue.submit( [ renderContextData.encoder.finish() ] );
513
1065
 
514
1066
 
@@ -534,6 +1086,14 @@ class WebGPUBackend extends Backend {
534
1086
 
535
1087
  }
536
1088
 
1089
+ /**
1090
+ * Returns `true` if the given 3D object is fully occluded by other
1091
+ * 3D objects in the scene.
1092
+ *
1093
+ * @param {RenderContext} renderContext - The render context.
1094
+ * @param {Object3D} object - The 3D object to test.
1095
+ * @return {boolean} Whether the 3D object is fully occluded or not.
1096
+ */
537
1097
  isOccluded( renderContext, object ) {
538
1098
 
539
1099
  const renderContextData = this.get( renderContext );
@@ -542,6 +1102,14 @@ class WebGPUBackend extends Backend {
542
1102
 
543
1103
  }
544
1104
 
1105
+ /**
1106
+ * This method processes the result of occlusion queries and writes it
1107
+ * into render context data.
1108
+ *
1109
+ * @async
1110
+ * @param {RenderContext} renderContext - The render context.
1111
+ * @return {Promise} A Promise that resolves when the occlusion query results have been processed.
1112
+ */
545
1113
  async resolveOccludedAsync( renderContext ) {
546
1114
 
547
1115
  const renderContextData = this.get( renderContext );
@@ -564,7 +1132,7 @@ class WebGPUBackend extends Backend {
564
1132
 
565
1133
  for ( let i = 0; i < currentOcclusionQueryObjects.length; i ++ ) {
566
1134
 
567
- if ( results[ i ] !== BigInt( 0 ) ) {
1135
+ if ( results[ i ] === BigInt( 0 ) ) {
568
1136
 
569
1137
  occluded.add( currentOcclusionQueryObjects[ i ] );
570
1138
 
@@ -580,6 +1148,11 @@ class WebGPUBackend extends Backend {
580
1148
 
581
1149
  }
582
1150
 
1151
+ /**
1152
+ * Updates the viewport with the values from the given render context.
1153
+ *
1154
+ * @param {RenderContext} renderContext - The render context.
1155
+ */
583
1156
  updateViewport( renderContext ) {
584
1157
 
585
1158
  const { currentPass } = this.get( renderContext );
@@ -589,13 +1162,58 @@ class WebGPUBackend extends Backend {
589
1162
 
590
1163
  }
591
1164
 
592
- clear( color, depth, stencil, renderTargetData = null ) {
1165
+ /**
1166
+ * Updates the scissor with the values from the given render context.
1167
+ *
1168
+ * @param {RenderContext} renderContext - The render context.
1169
+ */
1170
+ updateScissor( renderContext ) {
1171
+
1172
+ const { currentPass } = this.get( renderContext );
1173
+ const { x, y, width, height } = renderContext.scissorValue;
1174
+
1175
+ currentPass.setScissorRect( x, y, width, height );
1176
+
1177
+ }
1178
+
1179
+ /**
1180
+ * Returns the clear color and alpha into a single
1181
+ * color object.
1182
+ *
1183
+ * @return {Color4} The clear color.
1184
+ */
1185
+ getClearColor() {
1186
+
1187
+ const clearColor = super.getClearColor();
1188
+
1189
+ // only premultiply alpha when alphaMode is "premultiplied"
1190
+
1191
+ if ( this.renderer.alpha === true ) {
1192
+
1193
+ clearColor.r *= clearColor.a;
1194
+ clearColor.g *= clearColor.a;
1195
+ clearColor.b *= clearColor.a;
1196
+
1197
+ }
1198
+
1199
+ return clearColor;
1200
+
1201
+ }
1202
+
1203
+ /**
1204
+ * Performs a clear operation.
1205
+ *
1206
+ * @param {boolean} color - Whether the color buffer should be cleared or not.
1207
+ * @param {boolean} depth - Whether the depth buffer should be cleared or not.
1208
+ * @param {boolean} stencil - Whether the stencil buffer should be cleared or not.
1209
+ * @param {?RenderContext} [renderTargetContext=null] - The render context of the current set render target.
1210
+ */
1211
+ clear( color, depth, stencil, renderTargetContext = null ) {
593
1212
 
594
1213
  const device = this.device;
595
1214
  const renderer = this.renderer;
596
1215
 
597
1216
  let colorAttachments = [];
598
-
599
1217
  let depthStencilAttachment;
600
1218
  let clearValue;
601
1219
 
@@ -605,24 +1223,11 @@ class WebGPUBackend extends Backend {
605
1223
  if ( color ) {
606
1224
 
607
1225
  const clearColor = this.getClearColor();
608
-
609
- if ( this.renderer.alpha === true ) {
610
-
611
- // premultiply alpha
612
-
613
- const a = clearColor.a;
614
-
615
- clearValue = { r: clearColor.r * a, g: clearColor.g * a, b: clearColor.b * a, a: a };
616
-
617
- } else {
618
-
619
- clearValue = { r: clearColor.r, g: clearColor.g, b: clearColor.b, a: clearColor.a };
620
-
621
- }
1226
+ clearValue = { r: clearColor.r, g: clearColor.g, b: clearColor.b, a: clearColor.a };
622
1227
 
623
1228
  }
624
1229
 
625
- if ( renderTargetData === null ) {
1230
+ if ( renderTargetContext === null ) {
626
1231
 
627
1232
  supportsDepth = renderer.depth;
628
1233
  supportsStencil = renderer.stencil;
@@ -649,330 +1254,550 @@ class WebGPUBackend extends Backend {
649
1254
 
650
1255
  } else {
651
1256
 
652
- supportsDepth = renderTargetData.depth;
653
- supportsStencil = renderTargetData.stencil;
1257
+ supportsDepth = renderTargetContext.depth;
1258
+ supportsStencil = renderTargetContext.stencil;
654
1259
 
655
- if ( color ) {
1260
+ const clearConfig = {
1261
+ loadOp: color ? GPULoadOp.Clear : GPULoadOp.Load,
1262
+ clearValue: color ? clearValue : undefined
1263
+ };
656
1264
 
657
- for ( const texture of renderTargetData.textures ) {
1265
+ if ( supportsDepth ) {
658
1266
 
659
- const textureData = this.get( texture );
660
- const textureView = textureData.texture.createView();
1267
+ clearConfig.depthLoadOp = depth ? GPULoadOp.Clear : GPULoadOp.Load;
1268
+ clearConfig.depthClearValue = depth ? renderer.getClearDepth() : undefined;
1269
+ clearConfig.depthStoreOp = GPUStoreOp.Store;
661
1270
 
662
- let view, resolveTarget;
1271
+ }
663
1272
 
664
- if ( textureData.msaaTexture !== undefined ) {
1273
+ if ( supportsStencil ) {
665
1274
 
666
- view = textureData.msaaTexture.createView();
667
- resolveTarget = textureView;
1275
+ clearConfig.stencilLoadOp = stencil ? GPULoadOp.Clear : GPULoadOp.Load;
1276
+ clearConfig.stencilClearValue = stencil ? renderer.getClearStencil() : undefined;
1277
+ clearConfig.stencilStoreOp = GPUStoreOp.Store;
668
1278
 
669
- } else {
1279
+ }
670
1280
 
671
- view = textureView;
672
- resolveTarget = undefined;
1281
+ const descriptor = this._getRenderPassDescriptor( renderTargetContext, clearConfig );
673
1282
 
674
- }
1283
+ colorAttachments = descriptor.colorAttachments;
1284
+ depthStencilAttachment = descriptor.depthStencilAttachment;
675
1285
 
676
- colorAttachments.push( {
677
- view,
678
- resolveTarget,
679
- clearValue,
680
- loadOp: GPULoadOp.Clear,
681
- storeOp: GPUStoreOp.Store
682
- } );
1286
+ }
1287
+
1288
+ if ( supportsDepth && depthStencilAttachment ) {
1289
+
1290
+ if ( depth ) {
1291
+
1292
+ depthStencilAttachment.depthLoadOp = GPULoadOp.Clear;
1293
+ depthStencilAttachment.depthClearValue = renderer.getClearDepth();
1294
+ depthStencilAttachment.depthStoreOp = GPUStoreOp.Store;
1295
+
1296
+ } else {
1297
+
1298
+ depthStencilAttachment.depthLoadOp = GPULoadOp.Load;
1299
+ depthStencilAttachment.depthStoreOp = GPUStoreOp.Store;
1300
+
1301
+ }
1302
+
1303
+ }
1304
+
1305
+ //
1306
+
1307
+ if ( supportsStencil && depthStencilAttachment ) {
1308
+
1309
+ if ( stencil ) {
1310
+
1311
+ depthStencilAttachment.stencilLoadOp = GPULoadOp.Clear;
1312
+ depthStencilAttachment.stencilClearValue = renderer.getClearStencil();
1313
+ depthStencilAttachment.stencilStoreOp = GPUStoreOp.Store;
1314
+
1315
+ } else {
1316
+
1317
+ depthStencilAttachment.stencilLoadOp = GPULoadOp.Load;
1318
+ depthStencilAttachment.stencilStoreOp = GPUStoreOp.Store;
1319
+
1320
+ }
1321
+
1322
+ }
1323
+
1324
+ //
1325
+
1326
+ const encoder = device.createCommandEncoder( { label: 'clear' } );
1327
+ const currentPass = encoder.beginRenderPass( {
1328
+ colorAttachments,
1329
+ depthStencilAttachment
1330
+ } );
1331
+
1332
+ currentPass.end();
1333
+
1334
+ device.queue.submit( [ encoder.finish() ] );
1335
+
1336
+ }
1337
+
1338
+ // compute
1339
+
1340
+ /**
1341
+ * This method is executed at the beginning of a compute call and
1342
+ * prepares the state for upcoming compute tasks.
1343
+ *
1344
+ * @param {Node|Array<Node>} computeGroup - The compute node(s).
1345
+ */
1346
+ beginCompute( computeGroup ) {
1347
+
1348
+ const groupGPU = this.get( computeGroup );
1349
+
1350
+ //
1351
+
1352
+ const descriptor = {
1353
+ label: 'computeGroup_' + computeGroup.id
1354
+ };
1355
+
1356
+ this.initTimestampQuery( TimestampQuery.COMPUTE, this.getTimestampUID( computeGroup ), descriptor );
1357
+
1358
+ groupGPU.cmdEncoderGPU = this.device.createCommandEncoder( { label: 'computeGroup_' + computeGroup.id } );
1359
+
1360
+ groupGPU.passEncoderGPU = groupGPU.cmdEncoderGPU.beginComputePass( descriptor );
1361
+
1362
+ }
1363
+
1364
+ /**
1365
+ * Executes a compute command for the given compute node.
1366
+ *
1367
+ * @param {Node|Array<Node>} computeGroup - The group of compute nodes of a compute call. Can be a single compute node.
1368
+ * @param {Node} computeNode - The compute node.
1369
+ * @param {Array<BindGroup>} bindings - The bindings.
1370
+ * @param {ComputePipeline} pipeline - The compute pipeline.
1371
+ * @param {number|Array<number>|IndirectStorageBufferAttribute} [dispatchSize=null]
1372
+ * - A single number representing count, or
1373
+ * - An array [x, y, z] representing dispatch size, or
1374
+ * - A IndirectStorageBufferAttribute for indirect dispatch size.
1375
+ */
1376
+ compute( computeGroup, computeNode, bindings, pipeline, dispatchSize = null ) {
1377
+
1378
+ const computeNodeData = this.get( computeNode );
1379
+ const { passEncoderGPU } = this.get( computeGroup );
1380
+
1381
+ // pipeline
1382
+
1383
+ const pipelineGPU = this.get( pipeline ).pipeline;
1384
+
1385
+ this.pipelineUtils.setPipeline( passEncoderGPU, pipelineGPU );
1386
+
1387
+ // bind groups
1388
+
1389
+ for ( let i = 0, l = bindings.length; i < l; i ++ ) {
1390
+
1391
+ const bindGroup = bindings[ i ];
1392
+ const bindingsData = this.get( bindGroup );
1393
+
1394
+ passEncoderGPU.setBindGroup( i, bindingsData.group );
1395
+
1396
+ }
1397
+
1398
+ if ( dispatchSize === null ) {
1399
+
1400
+ dispatchSize = computeNode.count;
1401
+
1402
+ }
1403
+
1404
+ // When the dispatchSize is set with a StorageBuffer from the GPU.
1405
+
1406
+ if ( dispatchSize && typeof dispatchSize === 'object' && dispatchSize.isIndirectStorageBufferAttribute ) {
1407
+
1408
+ const dispatchBuffer = this.get( dispatchSize ).buffer;
1409
+
1410
+ passEncoderGPU.dispatchWorkgroupsIndirect( dispatchBuffer, 0 );
1411
+
1412
+ return;
1413
+
1414
+ }
1415
+
1416
+ if ( typeof dispatchSize === 'number' ) {
1417
+
1418
+ // If a single number is given, we calculate the dispatch size based on the workgroup size
1419
+
1420
+ const count = dispatchSize;
1421
+
1422
+ if ( computeNodeData.dispatchSize === undefined || computeNodeData.count !== count ) {
1423
+
1424
+ // cache dispatch size to avoid recalculating it every time
1425
+
1426
+ computeNodeData.dispatchSize = [ 0, 1, 1 ];
1427
+ computeNodeData.count = count;
1428
+
1429
+ const workgroupSize = computeNode.workgroupSize;
1430
+
1431
+ let size = workgroupSize[ 0 ];
1432
+
1433
+ for ( let i = 1; i < workgroupSize.length; i ++ )
1434
+ size *= workgroupSize[ i ];
1435
+
1436
+ const dispatchCount = Math.ceil( count / size );
1437
+
1438
+ //
1439
+
1440
+ const maxComputeWorkgroupsPerDimension = this.device.limits.maxComputeWorkgroupsPerDimension;
1441
+
1442
+ dispatchSize = [ dispatchCount, 1, 1 ];
1443
+
1444
+ if ( dispatchCount > maxComputeWorkgroupsPerDimension ) {
1445
+
1446
+ dispatchSize[ 0 ] = Math.min( dispatchCount, maxComputeWorkgroupsPerDimension );
1447
+ dispatchSize[ 1 ] = Math.ceil( dispatchCount / maxComputeWorkgroupsPerDimension );
683
1448
 
684
1449
  }
685
1450
 
686
- }
1451
+ computeNodeData.dispatchSize = dispatchSize;
1452
+
1453
+ }
1454
+
1455
+ dispatchSize = computeNodeData.dispatchSize;
1456
+
1457
+ }
1458
+
1459
+ //
1460
+
1461
+ passEncoderGPU.dispatchWorkgroups(
1462
+ dispatchSize[ 0 ],
1463
+ dispatchSize[ 1 ] || 1,
1464
+ dispatchSize[ 2 ] || 1
1465
+ );
1466
+
1467
+ }
1468
+
1469
+ /**
1470
+ * This method is executed at the end of a compute call and
1471
+ * finalizes work after compute tasks.
1472
+ *
1473
+ * @param {Node|Array<Node>} computeGroup - The compute node(s).
1474
+ */
1475
+ finishCompute( computeGroup ) {
1476
+
1477
+ const groupData = this.get( computeGroup );
1478
+
1479
+ groupData.passEncoderGPU.end();
1480
+
1481
+ this.device.queue.submit( [ groupData.cmdEncoderGPU.finish() ] );
1482
+
1483
+ }
1484
+
1485
+ // render object
1486
+
1487
+ /**
1488
+ * Executes a draw command for the given render object.
1489
+ *
1490
+ * @param {RenderObject} renderObject - The render object to draw.
1491
+ * @param {Info} info - Holds a series of statistical information about the GPU memory and the rendering process.
1492
+ */
1493
+ draw( renderObject, info ) {
1494
+
1495
+ const { object, material, context, pipeline } = renderObject;
1496
+ const bindings = renderObject.getBindings();
1497
+ const renderContextData = this.get( context );
1498
+ const pipelineData = this.get( pipeline );
1499
+ const pipelineGPU = pipelineData.pipeline;
687
1500
 
688
- if ( supportsDepth || supportsStencil ) {
1501
+ if ( pipelineData.error === true ) return;
689
1502
 
690
- const depthTextureData = this.get( renderTargetData.depthTexture );
1503
+ const index = renderObject.getIndex();
1504
+ const hasIndex = ( index !== null );
691
1505
 
692
- depthStencilAttachment = {
693
- view: depthTextureData.texture.createView()
694
- };
695
1506
 
696
- }
1507
+ const drawParams = renderObject.getDrawParameters();
1508
+ if ( drawParams === null ) return;
697
1509
 
698
- }
1510
+ // pipeline
699
1511
 
700
- //
1512
+ const setPipelineAndBindings = ( passEncoderGPU, currentSets ) => {
701
1513
 
702
- if ( supportsDepth ) {
1514
+ // pipeline
1515
+ this.pipelineUtils.setPipeline( passEncoderGPU, pipelineGPU );
1516
+ currentSets.pipeline = pipelineGPU;
703
1517
 
704
- if ( depth ) {
1518
+ // bind groups
1519
+ const currentBindingGroups = currentSets.bindingGroups;
1520
+ for ( let i = 0, l = bindings.length; i < l; i ++ ) {
705
1521
 
706
- depthStencilAttachment.depthLoadOp = GPULoadOp.Clear;
707
- depthStencilAttachment.depthClearValue = renderer.getClearDepth();
708
- depthStencilAttachment.depthStoreOp = GPUStoreOp.Store;
1522
+ const bindGroup = bindings[ i ];
1523
+ const bindingsData = this.get( bindGroup );
1524
+ if ( currentBindingGroups[ bindGroup.index ] !== bindGroup.id ) {
709
1525
 
710
- } else {
1526
+ passEncoderGPU.setBindGroup( bindGroup.index, bindingsData.group );
1527
+ currentBindingGroups[ bindGroup.index ] = bindGroup.id;
711
1528
 
712
- depthStencilAttachment.depthLoadOp = GPULoadOp.Load;
713
- depthStencilAttachment.depthStoreOp = GPUStoreOp.Store;
1529
+ }
714
1530
 
715
1531
  }
716
1532
 
717
- }
1533
+ // attributes
718
1534
 
719
- //
1535
+ // index
720
1536
 
721
- if ( supportsStencil ) {
1537
+ if ( hasIndex === true ) {
722
1538
 
723
- if ( stencil ) {
1539
+ if ( currentSets.index !== index ) {
724
1540
 
725
- depthStencilAttachment.stencilLoadOp = GPULoadOp.Clear;
726
- depthStencilAttachment.stencilClearValue = renderer.getClearStencil();
727
- depthStencilAttachment.stencilStoreOp = GPUStoreOp.Store;
1541
+ const buffer = this.get( index ).buffer;
1542
+ const indexFormat = ( index.array instanceof Uint16Array ) ? GPUIndexFormat.Uint16 : GPUIndexFormat.Uint32;
728
1543
 
729
- } else {
1544
+ passEncoderGPU.setIndexBuffer( buffer, indexFormat );
730
1545
 
731
- depthStencilAttachment.stencilLoadOp = GPULoadOp.Load;
732
- depthStencilAttachment.stencilStoreOp = GPUStoreOp.Store;
1546
+ currentSets.index = index;
1547
+
1548
+ }
733
1549
 
734
1550
  }
1551
+ // vertex buffers
735
1552
 
736
- }
1553
+ const vertexBuffers = renderObject.getVertexBuffers();
737
1554
 
738
- //
1555
+ for ( let i = 0, l = vertexBuffers.length; i < l; i ++ ) {
739
1556
 
740
- const encoder = device.createCommandEncoder( {} );
741
- const currentPass = encoder.beginRenderPass( {
742
- colorAttachments,
743
- depthStencilAttachment
744
- } );
1557
+ const vertexBuffer = vertexBuffers[ i ];
745
1558
 
746
- currentPass.end();
1559
+ if ( currentSets.attributes[ i ] !== vertexBuffer ) {
747
1560
 
748
- device.queue.submit( [ encoder.finish() ] );
1561
+ const buffer = this.get( vertexBuffer ).buffer;
1562
+ passEncoderGPU.setVertexBuffer( i, buffer );
749
1563
 
750
- }
1564
+ currentSets.attributes[ i ] = vertexBuffer;
751
1565
 
752
- // compute
1566
+ }
753
1567
 
754
- beginCompute( computeGroup ) {
1568
+ }
1569
+ // stencil
755
1570
 
756
- const groupGPU = this.get( computeGroup );
1571
+ if ( context.stencil === true && material.stencilWrite === true && renderContextData.currentStencilRef !== material.stencilRef ) {
757
1572
 
1573
+ passEncoderGPU.setStencilReference( material.stencilRef );
1574
+ renderContextData.currentStencilRef = material.stencilRef;
758
1575
 
759
- const descriptor = {};
1576
+ }
760
1577
 
761
- this.initTimestampQuery( computeGroup, descriptor );
762
1578
 
763
- groupGPU.cmdEncoderGPU = this.device.createCommandEncoder();
1579
+ };
764
1580
 
765
- groupGPU.passEncoderGPU = groupGPU.cmdEncoderGPU.beginComputePass( descriptor );
1581
+ // Define draw function
1582
+ const draw = ( passEncoderGPU, currentSets ) => {
766
1583
 
767
- }
1584
+ setPipelineAndBindings( passEncoderGPU, currentSets );
768
1585
 
769
- compute( computeGroup, computeNode, bindings, pipeline ) {
1586
+ if ( object.isBatchedMesh === true ) {
770
1587
 
771
- const { passEncoderGPU } = this.get( computeGroup );
1588
+ const starts = object._multiDrawStarts;
1589
+ const counts = object._multiDrawCounts;
1590
+ const drawCount = object._multiDrawCount;
1591
+ const drawInstances = object._multiDrawInstances;
772
1592
 
773
- // pipeline
1593
+ if ( drawInstances !== null ) {
774
1594
 
775
- const pipelineGPU = this.get( pipeline ).pipeline;
776
- passEncoderGPU.setPipeline( pipelineGPU );
1595
+ // @deprecated, r174
1596
+ warnOnce( 'WebGPUBackend: renderMultiDrawInstances has been deprecated and will be removed in r184. Append to renderMultiDraw arguments and use indirection.' );
777
1597
 
778
- // bind groups
1598
+ }
779
1599
 
780
- for ( let i = 0, l = bindings.length; i < l; i ++ ) {
1600
+ let bytesPerElement = ( hasIndex === true ) ? index.array.BYTES_PER_ELEMENT : 1;
781
1601
 
782
- const bindGroup = bindings[ i ];
783
- const bindingsData = this.get( bindGroup );
1602
+ if ( material.wireframe ) {
784
1603
 
785
- passEncoderGPU.setBindGroup( i, bindingsData.group );
1604
+ bytesPerElement = object.geometry.attributes.position.count > 65535 ? 4 : 2;
786
1605
 
787
- }
1606
+ }
788
1607
 
789
- const maxComputeWorkgroupsPerDimension = this.device.limits.maxComputeWorkgroupsPerDimension;
1608
+ for ( let i = 0; i < drawCount; i ++ ) {
790
1609
 
791
- const computeNodeData = this.get( computeNode );
1610
+ const count = drawInstances ? drawInstances[ i ] : 1;
1611
+ const firstInstance = count > 1 ? 0 : i;
792
1612
 
793
- if ( computeNodeData.dispatchSize === undefined ) computeNodeData.dispatchSize = { x: 0, y: 1, z: 1 };
1613
+ if ( hasIndex === true ) {
794
1614
 
795
- const { dispatchSize } = computeNodeData;
1615
+ passEncoderGPU.drawIndexed( counts[ i ], count, starts[ i ] / bytesPerElement, 0, firstInstance );
796
1616
 
797
- if ( computeNode.dispatchCount > maxComputeWorkgroupsPerDimension ) {
1617
+ } else {
798
1618
 
799
- dispatchSize.x = Math.min( computeNode.dispatchCount, maxComputeWorkgroupsPerDimension );
800
- dispatchSize.y = Math.ceil( computeNode.dispatchCount / maxComputeWorkgroupsPerDimension );
1619
+ passEncoderGPU.draw( counts[ i ], count, starts[ i ], firstInstance );
801
1620
 
802
- } else {
1621
+ }
803
1622
 
804
- dispatchSize.x = computeNode.dispatchCount;
1623
+ info.update( object, counts[ i ], count );
805
1624
 
806
- }
1625
+ }
807
1626
 
808
- passEncoderGPU.dispatchWorkgroups(
809
- dispatchSize.x,
810
- dispatchSize.y,
811
- dispatchSize.z
812
- );
1627
+ } else if ( hasIndex === true ) {
813
1628
 
814
- }
1629
+ const { vertexCount: indexCount, instanceCount, firstVertex: firstIndex } = drawParams;
815
1630
 
816
- finishCompute( computeGroup ) {
1631
+ const indirect = renderObject.getIndirect();
817
1632
 
818
- const groupData = this.get( computeGroup );
1633
+ if ( indirect !== null ) {
819
1634
 
820
- groupData.passEncoderGPU.end();
1635
+ const buffer = this.get( indirect ).buffer;
1636
+ const indirectOffset = renderObject.getIndirectOffset();
1637
+ const indirectOffsets = Array.isArray( indirectOffset ) ? indirectOffset : [ indirectOffset ];
821
1638
 
822
- this.prepareTimestampBuffer( computeGroup, groupData.cmdEncoderGPU );
1639
+ for ( let i = 0; i < indirectOffsets.length; i ++ ) {
823
1640
 
824
- this.device.queue.submit( [ groupData.cmdEncoderGPU.finish() ] );
1641
+ passEncoderGPU.drawIndexedIndirect( buffer, indirectOffsets[ i ] );
825
1642
 
826
- }
1643
+ }
827
1644
 
828
- // render object
1645
+ } else {
829
1646
 
830
- draw( renderObject, info ) {
1647
+ passEncoderGPU.drawIndexed( indexCount, instanceCount, firstIndex, 0, 0 );
831
1648
 
832
- const { object, context, pipeline } = renderObject;
833
- const bindings = renderObject.getBindings();
834
- const renderContextData = this.get( context );
835
- const pipelineGPU = this.get( pipeline ).pipeline;
836
- const currentSets = renderContextData.currentSets;
837
- const passEncoderGPU = renderContextData.currentPass;
1649
+ }
838
1650
 
839
- const drawParms = renderObject.getDrawParameters();
1651
+ info.update( object, indexCount, instanceCount );
840
1652
 
841
- if ( drawParms === null ) return;
1653
+ } else {
842
1654
 
843
- // pipeline
1655
+ const { vertexCount, instanceCount, firstVertex } = drawParams;
844
1656
 
845
- if ( currentSets.pipeline !== pipelineGPU ) {
1657
+ const indirect = renderObject.getIndirect();
846
1658
 
847
- passEncoderGPU.setPipeline( pipelineGPU );
1659
+ if ( indirect !== null ) {
848
1660
 
849
- currentSets.pipeline = pipelineGPU;
1661
+ const buffer = this.get( indirect ).buffer;
1662
+ const indirectOffset = renderObject.getIndirectOffset();
1663
+ const indirectOffsets = Array.isArray( indirectOffset ) ? indirectOffset : [ indirectOffset ];
850
1664
 
851
- }
1665
+ for ( let i = 0; i < indirectOffsets.length; i ++ ) {
852
1666
 
853
- // bind groups
1667
+ passEncoderGPU.drawIndirect( buffer, indirectOffsets[ i ] );
1668
+
1669
+ }
854
1670
 
855
- const currentBindingGroups = currentSets.bindingGroups;
856
1671
 
857
- for ( let i = 0, l = bindings.length; i < l; i ++ ) {
1672
+ } else {
858
1673
 
859
- const bindGroup = bindings[ i ];
860
- const bindingsData = this.get( bindGroup );
1674
+ passEncoderGPU.draw( vertexCount, instanceCount, firstVertex, 0 );
861
1675
 
862
- if ( currentBindingGroups[ bindGroup.index ] !== bindGroup.id ) {
1676
+ }
863
1677
 
864
- passEncoderGPU.setBindGroup( bindGroup.index, bindingsData.group );
865
- currentBindingGroups[ bindGroup.index ] = bindGroup.id;
1678
+ info.update( object, vertexCount, instanceCount );
866
1679
 
867
1680
  }
868
1681
 
869
- }
1682
+ };
870
1683
 
871
- // attributes
1684
+ if ( renderObject.camera.isArrayCamera && renderObject.camera.cameras.length > 0 ) {
872
1685
 
873
- const index = renderObject.getIndex();
1686
+ const cameraData = this.get( renderObject.camera );
1687
+ const cameras = renderObject.camera.cameras;
1688
+ const cameraIndex = renderObject.getBindingGroup( 'cameraIndex' );
874
1689
 
875
- const hasIndex = ( index !== null );
1690
+ if ( cameraData.indexesGPU === undefined || cameraData.indexesGPU.length !== cameras.length ) {
876
1691
 
877
- // index
1692
+ const bindingsData = this.get( cameraIndex );
1693
+ const indexesGPU = [];
878
1694
 
879
- if ( hasIndex === true ) {
1695
+ const data = new Uint32Array( [ 0, 0, 0, 0 ] );
880
1696
 
881
- if ( currentSets.index !== index ) {
1697
+ for ( let i = 0, len = cameras.length; i < len; i ++ ) {
882
1698
 
883
- const buffer = this.get( index ).buffer;
884
- const indexFormat = ( index.array instanceof Uint16Array ) ? GPUIndexFormat.Uint16 : GPUIndexFormat.Uint32;
1699
+ data[ 0 ] = i;
885
1700
 
886
- passEncoderGPU.setIndexBuffer( buffer, indexFormat );
1701
+ const { layoutGPU } = bindingsData.layout;
887
1702
 
888
- currentSets.index = index;
1703
+ const bindGroupIndex = this.bindingUtils.createBindGroupIndex( data, layoutGPU );
889
1704
 
890
- }
1705
+ indexesGPU.push( bindGroupIndex );
891
1706
 
892
- }
1707
+ }
893
1708
 
894
- // vertex buffers
1709
+ cameraData.indexesGPU = indexesGPU; // TODO: Create a global library for this
895
1710
 
896
- const vertexBuffers = renderObject.getVertexBuffers();
1711
+ }
897
1712
 
898
- for ( let i = 0, l = vertexBuffers.length; i < l; i ++ ) {
1713
+ const pixelRatio = this.renderer.getPixelRatio();
899
1714
 
900
- const vertexBuffer = vertexBuffers[ i ];
1715
+ for ( let i = 0, len = cameras.length; i < len; i ++ ) {
901
1716
 
902
- if ( currentSets.attributes[ i ] !== vertexBuffer ) {
1717
+ const subCamera = cameras[ i ];
903
1718
 
904
- const buffer = this.get( vertexBuffer ).buffer;
905
- passEncoderGPU.setVertexBuffer( i, buffer );
1719
+ if ( object.layers.test( subCamera.layers ) ) {
906
1720
 
907
- currentSets.attributes[ i ] = vertexBuffer;
1721
+ const vp = subCamera.viewport;
908
1722
 
909
- }
910
1723
 
911
- }
912
1724
 
913
- // occlusion queries - handle multiple consecutive draw calls for an object
1725
+ let pass = renderContextData.currentPass;
1726
+ let sets = renderContextData.currentSets;
1727
+ if ( renderContextData.bundleEncoders ) {
914
1728
 
915
- if ( renderContextData.occlusionQuerySet !== undefined ) {
1729
+ const bundleEncoder = renderContextData.bundleEncoders[ i ];
1730
+ const bundleSets = renderContextData.bundleSets[ i ];
1731
+ pass = bundleEncoder;
1732
+ sets = bundleSets;
916
1733
 
917
- const lastObject = renderContextData.lastOcclusionObject;
1734
+ }
918
1735
 
919
- if ( lastObject !== object ) {
920
1736
 
921
- if ( lastObject !== null && lastObject.occlusionTest === true ) {
922
1737
 
923
- passEncoderGPU.endOcclusionQuery();
924
- renderContextData.occlusionQueryIndex ++;
1738
+ if ( vp ) {
925
1739
 
926
- }
1740
+ pass.setViewport(
1741
+ Math.floor( vp.x * pixelRatio ),
1742
+ Math.floor( vp.y * pixelRatio ),
1743
+ Math.floor( vp.width * pixelRatio ),
1744
+ Math.floor( vp.height * pixelRatio ),
1745
+ context.viewportValue.minDepth,
1746
+ context.viewportValue.maxDepth
1747
+ );
927
1748
 
928
- if ( object.occlusionTest === true ) {
1749
+ }
929
1750
 
930
- passEncoderGPU.beginOcclusionQuery( renderContextData.occlusionQueryIndex );
931
- renderContextData.occlusionQueryObjects[ renderContextData.occlusionQueryIndex ] = object;
932
1751
 
933
- }
1752
+ // Set camera index binding for this layer
1753
+ if ( cameraIndex && cameraData.indexesGPU ) {
934
1754
 
935
- renderContextData.lastOcclusionObject = object;
1755
+ pass.setBindGroup( cameraIndex.index, cameraData.indexesGPU[ i ] );
1756
+ sets.bindingGroups[ cameraIndex.index ] = cameraIndex.id;
936
1757
 
937
- }
1758
+ }
1759
+
1760
+ draw( pass, sets );
938
1761
 
939
- }
940
1762
 
941
- // draw
1763
+ }
942
1764
 
943
- if ( object.isBatchedMesh === true ) {
1765
+ }
944
1766
 
945
- const starts = object._multiDrawStarts;
946
- const counts = object._multiDrawCounts;
947
- const drawCount = object._multiDrawCount;
948
- const drawInstances = object._multiDrawInstances;
1767
+ } else {
949
1768
 
950
- const bytesPerElement = hasIndex ? index.array.BYTES_PER_ELEMENT : 1;
1769
+ // Regular single camera rendering
1770
+ if ( renderContextData.currentPass ) {
951
1771
 
952
- for ( let i = 0; i < drawCount; i ++ ) {
1772
+ // Handle occlusion queries
1773
+ if ( renderContextData.occlusionQuerySet !== undefined ) {
953
1774
 
954
- const count = drawInstances ? drawInstances[ i ] : 1;
955
- const firstInstance = count > 1 ? 0 : i;
1775
+ const lastObject = renderContextData.lastOcclusionObject;
1776
+ if ( lastObject !== object ) {
956
1777
 
957
- passEncoderGPU.drawIndexed( counts[ i ], count, starts[ i ] / bytesPerElement, 0, firstInstance );
1778
+ if ( lastObject !== null && lastObject.occlusionTest === true ) {
958
1779
 
959
- }
1780
+ renderContextData.currentPass.endOcclusionQuery();
1781
+ renderContextData.occlusionQueryIndex ++;
960
1782
 
961
- } else if ( hasIndex === true ) {
1783
+ }
962
1784
 
963
- const { vertexCount: indexCount, instanceCount, firstVertex: firstIndex } = drawParms;
1785
+ if ( object.occlusionTest === true ) {
964
1786
 
965
- passEncoderGPU.drawIndexed( indexCount, instanceCount, firstIndex, 0, 0 );
1787
+ renderContextData.currentPass.beginOcclusionQuery( renderContextData.occlusionQueryIndex );
1788
+ renderContextData.occlusionQueryObjects[ renderContextData.occlusionQueryIndex ] = object;
966
1789
 
967
- info.update( object, indexCount, instanceCount );
1790
+ }
968
1791
 
969
- } else {
1792
+ renderContextData.lastOcclusionObject = object;
1793
+
1794
+ }
970
1795
 
971
- const { vertexCount, instanceCount, firstVertex } = drawParms;
1796
+ }
972
1797
 
973
- passEncoderGPU.draw( vertexCount, instanceCount, firstVertex, 0 );
1798
+ draw( renderContextData.currentPass, renderContextData.currentSets );
974
1799
 
975
- info.update( object, vertexCount, instanceCount );
1800
+ }
976
1801
 
977
1802
  }
978
1803
 
@@ -980,6 +1805,12 @@ class WebGPUBackend extends Backend {
980
1805
 
981
1806
  // cache key
982
1807
 
1808
+ /**
1809
+ * Returns `true` if the render pipeline requires an update.
1810
+ *
1811
+ * @param {RenderObject} renderObject - The render object.
1812
+ * @return {boolean} Whether the render pipeline requires an update or not.
1813
+ */
983
1814
  needsRenderUpdate( renderObject ) {
984
1815
 
985
1816
  const data = this.get( renderObject );
@@ -1008,7 +1839,7 @@ class WebGPUBackend extends Backend {
1008
1839
  data.sampleCount !== sampleCount || data.colorSpace !== colorSpace ||
1009
1840
  data.colorFormat !== colorFormat || data.depthStencilFormat !== depthStencilFormat ||
1010
1841
  data.primitiveTopology !== primitiveTopology ||
1011
- data.clippingContextCacheKey !== renderObject.clippingContext.cacheKey
1842
+ data.clippingContextCacheKey !== renderObject.clippingContextCacheKey
1012
1843
  ) {
1013
1844
 
1014
1845
  data.material = material; data.materialVersion = material.version;
@@ -1026,7 +1857,7 @@ class WebGPUBackend extends Backend {
1026
1857
  data.colorFormat = colorFormat;
1027
1858
  data.depthStencilFormat = depthStencilFormat;
1028
1859
  data.primitiveTopology = primitiveTopology;
1029
- data.clippingContextCacheKey = renderObject.clippingContext.cacheKey;
1860
+ data.clippingContextCacheKey = renderObject.clippingContextCacheKey;
1030
1861
 
1031
1862
  needsUpdate = true;
1032
1863
 
@@ -1036,6 +1867,12 @@ class WebGPUBackend extends Backend {
1036
1867
 
1037
1868
  }
1038
1869
 
1870
+ /**
1871
+ * Returns a cache key that is used to identify render pipelines.
1872
+ *
1873
+ * @param {RenderObject} renderObject - The render object.
1874
+ * @return {string} The cache key.
1875
+ */
1039
1876
  getRenderCacheKey( renderObject ) {
1040
1877
 
1041
1878
  const { object, material } = renderObject;
@@ -1043,6 +1880,11 @@ class WebGPUBackend extends Backend {
1043
1880
  const utils = this.utils;
1044
1881
  const renderContext = renderObject.context;
1045
1882
 
1883
+ // meshes with negative scale have a different frontFace render pipeline
1884
+ // descriptor value so the following must be honored in the cache key
1885
+
1886
+ const frontFaceCW = ( object.isMesh && object.matrixWorld.determinant() < 0 );
1887
+
1046
1888
  return [
1047
1889
  material.transparent, material.blending, material.premultipliedAlpha,
1048
1890
  material.blendSrc, material.blendDst, material.blendEquation,
@@ -1053,163 +1895,148 @@ class WebGPUBackend extends Backend {
1053
1895
  material.stencilFail, material.stencilZFail, material.stencilZPass,
1054
1896
  material.stencilFuncMask, material.stencilWriteMask,
1055
1897
  material.side,
1898
+ frontFaceCW,
1056
1899
  utils.getSampleCountRenderContext( renderContext ),
1057
1900
  utils.getCurrentColorSpace( renderContext ), utils.getCurrentColorFormat( renderContext ), utils.getCurrentDepthStencilFormat( renderContext ),
1058
1901
  utils.getPrimitiveTopology( object, material ),
1059
- renderObject.clippingContext.cacheKey
1902
+ renderObject.getGeometryCacheKey(),
1903
+ renderObject.clippingContextCacheKey
1060
1904
  ].join();
1061
1905
 
1062
1906
  }
1063
1907
 
1064
1908
  // textures
1065
1909
 
1066
- createSampler( texture ) {
1067
-
1068
- this.textureUtils.createSampler( texture );
1910
+ /**
1911
+ * Updates a GPU sampler for the given texture.
1912
+ *
1913
+ * @param {Texture} texture - The texture to update the sampler for.
1914
+ * @return {string} The current sampler key.
1915
+ */
1916
+ updateSampler( texture ) {
1069
1917
 
1070
- }
1071
-
1072
- destroySampler( texture ) {
1073
-
1074
- this.textureUtils.destroySampler( texture );
1918
+ return this.textureUtils.updateSampler( texture );
1075
1919
 
1076
1920
  }
1077
1921
 
1922
+ /**
1923
+ * Creates a default texture for the given texture that can be used
1924
+ * as a placeholder until the actual texture is ready for usage.
1925
+ *
1926
+ * @param {Texture} texture - The texture to create a default texture for.
1927
+ * @return {boolean} Whether the sampler has been updated or not.
1928
+ */
1078
1929
  createDefaultTexture( texture ) {
1079
1930
 
1080
- this.textureUtils.createDefaultTexture( texture );
1931
+ return this.textureUtils.createDefaultTexture( texture );
1081
1932
 
1082
1933
  }
1083
1934
 
1935
+ /**
1936
+ * Defines a texture on the GPU for the given texture object.
1937
+ *
1938
+ * @param {Texture} texture - The texture.
1939
+ * @param {Object} [options={}] - Optional configuration parameter.
1940
+ */
1084
1941
  createTexture( texture, options ) {
1085
1942
 
1086
1943
  this.textureUtils.createTexture( texture, options );
1087
1944
 
1088
1945
  }
1089
1946
 
1947
+ /**
1948
+ * Uploads the updated texture data to the GPU.
1949
+ *
1950
+ * @param {Texture} texture - The texture.
1951
+ * @param {Object} [options={}] - Optional configuration parameter.
1952
+ */
1090
1953
  updateTexture( texture, options ) {
1091
1954
 
1092
1955
  this.textureUtils.updateTexture( texture, options );
1093
1956
 
1094
1957
  }
1095
1958
 
1959
+ /**
1960
+ * Generates mipmaps for the given texture.
1961
+ *
1962
+ * @param {Texture} texture - The texture.
1963
+ */
1096
1964
  generateMipmaps( texture ) {
1097
1965
 
1098
1966
  this.textureUtils.generateMipmaps( texture );
1099
1967
 
1100
1968
  }
1101
1969
 
1102
- destroyTexture( texture ) {
1970
+ /**
1971
+ * Destroys the GPU data for the given texture object.
1972
+ *
1973
+ * @param {Texture} texture - The texture.
1974
+ * @param {boolean} [isDefaultTexture=false] - Whether the texture uses a default GPU texture or not.
1975
+ */
1976
+ destroyTexture( texture, isDefaultTexture = false ) {
1103
1977
 
1104
- this.textureUtils.destroyTexture( texture );
1978
+ this.textureUtils.destroyTexture( texture, isDefaultTexture );
1105
1979
 
1106
1980
  }
1107
1981
 
1108
- copyTextureToBuffer( texture, x, y, width, height, faceIndex ) {
1982
+ /**
1983
+ * Returns texture data as a typed array.
1984
+ *
1985
+ * @async
1986
+ * @param {Texture} texture - The texture to copy.
1987
+ * @param {number} x - The x coordinate of the copy origin.
1988
+ * @param {number} y - The y coordinate of the copy origin.
1989
+ * @param {number} width - The width of the copy.
1990
+ * @param {number} height - The height of the copy.
1991
+ * @param {number} faceIndex - The face index.
1992
+ * @return {Promise<TypedArray>} A Promise that resolves with a typed array when the copy operation has finished.
1993
+ */
1994
+ async copyTextureToBuffer( texture, x, y, width, height, faceIndex ) {
1109
1995
 
1110
1996
  return this.textureUtils.copyTextureToBuffer( texture, x, y, width, height, faceIndex );
1111
1997
 
1112
1998
  }
1113
1999
 
1114
-
1115
- initTimestampQuery( renderContext, descriptor ) {
1116
-
1117
- if ( ! this.trackTimestamp ) return;
1118
-
1119
- const renderContextData = this.get( renderContext );
1120
-
1121
- if ( ! renderContextData.timeStampQuerySet ) {
1122
-
1123
- // Create a GPUQuerySet which holds 2 timestamp query results: one for the
1124
- // beginning and one for the end of compute pass execution.
1125
- const timeStampQuerySet = this.device.createQuerySet( { type: 'timestamp', count: 2 } );
1126
-
1127
- const timestampWrites = {
1128
- querySet: timeStampQuerySet,
1129
- beginningOfPassWriteIndex: 0, // Write timestamp in index 0 when pass begins.
1130
- endOfPassWriteIndex: 1, // Write timestamp in index 1 when pass ends.
1131
- };
1132
-
1133
- Object.assign( descriptor, {
1134
- timestampWrites,
1135
- } );
1136
-
1137
- renderContextData.timeStampQuerySet = timeStampQuerySet;
1138
-
1139
- }
1140
-
1141
- }
1142
-
1143
- // timestamp utils
1144
-
1145
- prepareTimestampBuffer( renderContext, encoder ) {
2000
+ /**
2001
+ * Inits a time stamp query for the given render context.
2002
+ *
2003
+ * @param {string} type - The type of the timestamp query (e.g. 'render', 'compute').
2004
+ * @param {number} uid - Unique id for the context (e.g. render context id).
2005
+ * @param {Object} descriptor - The query descriptor.
2006
+ */
2007
+ initTimestampQuery( type, uid, descriptor ) {
1146
2008
 
1147
2009
  if ( ! this.trackTimestamp ) return;
1148
2010
 
1149
- const renderContextData = this.get( renderContext );
1150
-
1151
-
1152
- const size = 2 * BigInt64Array.BYTES_PER_ELEMENT;
2011
+ if ( ! this.timestampQueryPool[ type ] ) {
1153
2012
 
1154
- if ( renderContextData.currentTimestampQueryBuffers === undefined ) {
1155
-
1156
- renderContextData.currentTimestampQueryBuffers = {
1157
- resolveBuffer: this.device.createBuffer( {
1158
- label: 'timestamp resolve buffer',
1159
- size: size,
1160
- usage: GPUBufferUsage.QUERY_RESOLVE | GPUBufferUsage.COPY_SRC,
1161
- } ),
1162
- resultBuffer: this.device.createBuffer( {
1163
- label: 'timestamp result buffer',
1164
- size: size,
1165
- usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ,
1166
- } ),
1167
- isMappingPending: false,
1168
- };
2013
+ // TODO: Variable maxQueries?
2014
+ this.timestampQueryPool[ type ] = new WebGPUTimestampQueryPool( this.device, type, 2048 );
1169
2015
 
1170
2016
  }
1171
2017
 
1172
- const { resolveBuffer, resultBuffer, isMappingPending } = renderContextData.currentTimestampQueryBuffers;
2018
+ const timestampQueryPool = this.timestampQueryPool[ type ];
1173
2019
 
1174
- if ( isMappingPending === true ) return;
2020
+ const baseOffset = timestampQueryPool.allocateQueriesForContext( uid );
1175
2021
 
1176
- encoder.resolveQuerySet( renderContextData.timeStampQuerySet, 0, 2, resolveBuffer, 0 );
1177
- encoder.copyBufferToBuffer( resolveBuffer, 0, resultBuffer, 0, size );
2022
+ descriptor.timestampWrites = {
2023
+ querySet: timestampQueryPool.querySet,
2024
+ beginningOfPassWriteIndex: baseOffset,
2025
+ endOfPassWriteIndex: baseOffset + 1,
2026
+ };
1178
2027
 
1179
2028
  }
1180
2029
 
1181
- async resolveTimestampAsync( renderContext, type = 'render' ) {
1182
-
1183
- if ( ! this.trackTimestamp ) return;
1184
-
1185
- const renderContextData = this.get( renderContext );
1186
-
1187
- if ( renderContextData.currentTimestampQueryBuffers === undefined ) return;
1188
-
1189
- const { resultBuffer, isMappingPending } = renderContextData.currentTimestampQueryBuffers;
1190
-
1191
- if ( isMappingPending === true ) return;
1192
-
1193
- renderContextData.currentTimestampQueryBuffers.isMappingPending = true;
1194
-
1195
- resultBuffer.mapAsync( GPUMapMode.READ ).then( () => {
1196
-
1197
- const times = new BigUint64Array( resultBuffer.getMappedRange() );
1198
- const duration = Number( times[ 1 ] - times[ 0 ] ) / 1000000;
1199
-
1200
-
1201
- this.renderer.info.updateTimestamp( type, duration );
1202
-
1203
- resultBuffer.unmap();
1204
-
1205
- renderContextData.currentTimestampQueryBuffers.isMappingPending = false;
1206
-
1207
- } );
1208
-
1209
- }
1210
2030
 
1211
2031
  // node builder
1212
2032
 
2033
+ /**
2034
+ * Returns a node builder for the given render object.
2035
+ *
2036
+ * @param {RenderObject} object - The render object.
2037
+ * @param {Renderer} renderer - The renderer.
2038
+ * @return {WGSLNodeBuilder} The node builder.
2039
+ */
1213
2040
  createNodeBuilder( object, renderer ) {
1214
2041
 
1215
2042
  return new WGSLNodeBuilder( object, renderer );
@@ -1218,17 +2045,27 @@ class WebGPUBackend extends Backend {
1218
2045
 
1219
2046
  // program
1220
2047
 
2048
+ /**
2049
+ * Creates a shader program from the given programmable stage.
2050
+ *
2051
+ * @param {ProgrammableStage} program - The programmable stage.
2052
+ */
1221
2053
  createProgram( program ) {
1222
2054
 
1223
2055
  const programGPU = this.get( program );
1224
2056
 
1225
2057
  programGPU.module = {
1226
- module: this.device.createShaderModule( { code: program.code, label: program.stage } ),
2058
+ module: this.device.createShaderModule( { code: program.code, label: program.stage + ( program.name !== '' ? `_${ program.name }` : '' ) } ),
1227
2059
  entryPoint: 'main'
1228
2060
  };
1229
2061
 
1230
2062
  }
1231
2063
 
2064
+ /**
2065
+ * Destroys the shader program of the given programmable stage.
2066
+ *
2067
+ * @param {ProgrammableStage} program - The programmable stage.
2068
+ */
1232
2069
  destroyProgram( program ) {
1233
2070
 
1234
2071
  this.delete( program );
@@ -1237,18 +2074,35 @@ class WebGPUBackend extends Backend {
1237
2074
 
1238
2075
  // pipelines
1239
2076
 
2077
+ /**
2078
+ * Creates a render pipeline for the given render object.
2079
+ *
2080
+ * @param {RenderObject} renderObject - The render object.
2081
+ * @param {Array<Promise>} promises - An array of compilation promises which are used in `compileAsync()`.
2082
+ */
1240
2083
  createRenderPipeline( renderObject, promises ) {
1241
2084
 
1242
2085
  this.pipelineUtils.createRenderPipeline( renderObject, promises );
1243
2086
 
1244
2087
  }
1245
2088
 
2089
+ /**
2090
+ * Creates a compute pipeline for the given compute node.
2091
+ *
2092
+ * @param {ComputePipeline} computePipeline - The compute pipeline.
2093
+ * @param {Array<BindGroup>} bindings - The bindings.
2094
+ */
1246
2095
  createComputePipeline( computePipeline, bindings ) {
1247
2096
 
1248
2097
  this.pipelineUtils.createComputePipeline( computePipeline, bindings );
1249
2098
 
1250
2099
  }
1251
2100
 
2101
+ /**
2102
+ * Prepares the state for encoding render bundles.
2103
+ *
2104
+ * @param {RenderContext} renderContext - The render context.
2105
+ */
1252
2106
  beginBundle( renderContext ) {
1253
2107
 
1254
2108
  const renderContextData = this.get( renderContext );
@@ -1261,6 +2115,12 @@ class WebGPUBackend extends Backend {
1261
2115
 
1262
2116
  }
1263
2117
 
2118
+ /**
2119
+ * After processing render bundles this method finalizes related work.
2120
+ *
2121
+ * @param {RenderContext} renderContext - The render context.
2122
+ * @param {RenderBundle} bundle - The render bundle.
2123
+ */
1264
2124
  finishBundle( renderContext, bundle ) {
1265
2125
 
1266
2126
  const renderContextData = this.get( renderContext );
@@ -1277,6 +2137,12 @@ class WebGPUBackend extends Backend {
1277
2137
 
1278
2138
  }
1279
2139
 
2140
+ /**
2141
+ * Adds a render bundle to the render context data.
2142
+ *
2143
+ * @param {RenderContext} renderContext - The render context.
2144
+ * @param {RenderBundle} bundle - The render bundle to add.
2145
+ */
1280
2146
  addBundle( renderContext, bundle ) {
1281
2147
 
1282
2148
  const renderContextData = this.get( renderContext );
@@ -1287,50 +2153,126 @@ class WebGPUBackend extends Backend {
1287
2153
 
1288
2154
  // bindings
1289
2155
 
1290
- createBindings( bindGroup ) {
2156
+ /**
2157
+ * Creates bindings from the given bind group definition.
2158
+ *
2159
+ * @param {BindGroup} bindGroup - The bind group.
2160
+ * @param {Array<BindGroup>} bindings - Array of bind groups.
2161
+ * @param {number} cacheIndex - The cache index.
2162
+ * @param {number} version - The version.
2163
+ */
2164
+ createBindings( bindGroup, bindings, cacheIndex, version ) {
1291
2165
 
1292
- this.bindingUtils.createBindings( bindGroup );
2166
+ this.bindingUtils.createBindings( bindGroup, bindings, cacheIndex, version );
1293
2167
 
1294
2168
  }
1295
2169
 
1296
- updateBindings( bindGroup ) {
2170
+ /**
2171
+ * Updates the given bind group definition.
2172
+ *
2173
+ * @param {BindGroup} bindGroup - The bind group.
2174
+ * @param {Array<BindGroup>} bindings - Array of bind groups.
2175
+ * @param {number} cacheIndex - The cache index.
2176
+ * @param {number} version - The version.
2177
+ */
2178
+ updateBindings( bindGroup, bindings, cacheIndex, version ) {
1297
2179
 
1298
- this.bindingUtils.createBindings( bindGroup );
2180
+ this.bindingUtils.createBindings( bindGroup, bindings, cacheIndex, version );
1299
2181
 
1300
2182
  }
1301
2183
 
2184
+ /**
2185
+ * Updates a buffer binding.
2186
+ *
2187
+ * @param {Buffer} binding - The buffer binding to update.
2188
+ */
1302
2189
  updateBinding( binding ) {
1303
2190
 
1304
2191
  this.bindingUtils.updateBinding( binding );
1305
2192
 
1306
2193
  }
1307
2194
 
2195
+ /**
2196
+ * Delete data associated with the current bind group.
2197
+ *
2198
+ * @param {BindGroup} bindGroup - The bind group.
2199
+ */
2200
+ deleteBindGroupData( bindGroup ) {
2201
+
2202
+ this.bindingUtils.deleteBindGroupData( bindGroup );
2203
+
2204
+ }
2205
+
1308
2206
  // attributes
1309
2207
 
2208
+ /**
2209
+ * Creates the buffer of an indexed shader attribute.
2210
+ *
2211
+ * @param {BufferAttribute} attribute - The indexed buffer attribute.
2212
+ */
1310
2213
  createIndexAttribute( attribute ) {
1311
2214
 
1312
- this.attributeUtils.createAttribute( attribute, GPUBufferUsage.INDEX | GPUBufferUsage.COPY_SRC | GPUBufferUsage.COPY_DST );
2215
+ let usage = GPUBufferUsage.INDEX | GPUBufferUsage.COPY_SRC | GPUBufferUsage.COPY_DST;
2216
+
2217
+ if ( attribute.isStorageBufferAttribute || attribute.isStorageInstancedBufferAttribute ) {
2218
+
2219
+ usage |= GPUBufferUsage.STORAGE;
2220
+
2221
+ }
2222
+
2223
+ this.attributeUtils.createAttribute( attribute, usage );
1313
2224
 
1314
2225
  }
1315
2226
 
2227
+ /**
2228
+ * Creates the GPU buffer of a shader attribute.
2229
+ *
2230
+ * @param {BufferAttribute} attribute - The buffer attribute.
2231
+ */
1316
2232
  createAttribute( attribute ) {
1317
2233
 
1318
2234
  this.attributeUtils.createAttribute( attribute, GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_SRC | GPUBufferUsage.COPY_DST );
1319
2235
 
1320
2236
  }
1321
2237
 
2238
+ /**
2239
+ * Creates the GPU buffer of a storage attribute.
2240
+ *
2241
+ * @param {BufferAttribute} attribute - The buffer attribute.
2242
+ */
1322
2243
  createStorageAttribute( attribute ) {
1323
2244
 
1324
2245
  this.attributeUtils.createAttribute( attribute, GPUBufferUsage.STORAGE | GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_SRC | GPUBufferUsage.COPY_DST );
1325
2246
 
1326
2247
  }
1327
2248
 
2249
+ /**
2250
+ * Creates the GPU buffer of an indirect storage attribute.
2251
+ *
2252
+ * @param {BufferAttribute} attribute - The buffer attribute.
2253
+ */
2254
+ createIndirectStorageAttribute( attribute ) {
2255
+
2256
+ this.attributeUtils.createAttribute( attribute, GPUBufferUsage.STORAGE | GPUBufferUsage.INDIRECT | GPUBufferUsage.COPY_SRC | GPUBufferUsage.COPY_DST );
2257
+
2258
+ }
2259
+
2260
+ /**
2261
+ * Updates the GPU buffer of a shader attribute.
2262
+ *
2263
+ * @param {BufferAttribute} attribute - The buffer attribute to update.
2264
+ */
1328
2265
  updateAttribute( attribute ) {
1329
2266
 
1330
2267
  this.attributeUtils.updateAttribute( attribute );
1331
2268
 
1332
2269
  }
1333
2270
 
2271
+ /**
2272
+ * Destroys the GPU buffer of a shader attribute.
2273
+ *
2274
+ * @param {BufferAttribute} attribute - The buffer attribute to destroy.
2275
+ */
1334
2276
  destroyAttribute( attribute ) {
1335
2277
 
1336
2278
  this.attributeUtils.destroyAttribute( attribute );
@@ -1339,55 +2281,97 @@ class WebGPUBackend extends Backend {
1339
2281
 
1340
2282
  // canvas
1341
2283
 
2284
+ /**
2285
+ * Triggers an update of the default render pass descriptor.
2286
+ */
1342
2287
  updateSize() {
1343
2288
 
1344
- this.colorBuffer = this.textureUtils.getColorBuffer();
1345
- this.defaultRenderPassdescriptor = null;
2289
+ this.delete( this.renderer.getCanvasTarget() );
1346
2290
 
1347
2291
  }
1348
2292
 
1349
2293
  // utils public
1350
2294
 
2295
+ /**
2296
+ * Returns the maximum anisotropy texture filtering value.
2297
+ *
2298
+ * @return {number} The maximum anisotropy texture filtering value.
2299
+ */
1351
2300
  getMaxAnisotropy() {
1352
2301
 
1353
2302
  return 16;
1354
2303
 
1355
2304
  }
1356
2305
 
2306
+ /**
2307
+ * Checks if the given feature is supported by the backend.
2308
+ *
2309
+ * @param {string} name - The feature's name.
2310
+ * @return {boolean} Whether the feature is supported or not.
2311
+ */
1357
2312
  hasFeature( name ) {
1358
2313
 
2314
+ if ( GPUFeatureMap[ name ] !== undefined ) name = GPUFeatureMap[ name ];
2315
+
1359
2316
  return this.device.features.has( name );
1360
2317
 
1361
2318
  }
1362
2319
 
1363
- copyTextureToTexture( srcTexture, dstTexture, srcRegion = null, dstPosition = null, level = 0 ) {
2320
+ /**
2321
+ * Copies data of the given source texture to the given destination texture.
2322
+ *
2323
+ * @param {Texture} srcTexture - The source texture.
2324
+ * @param {Texture} dstTexture - The destination texture.
2325
+ * @param {?(Box3|Box2)} [srcRegion=null] - The region of the source texture to copy.
2326
+ * @param {?(Vector2|Vector3)} [dstPosition=null] - The destination position of the copy.
2327
+ * @param {number} [srcLevel=0] - The mipmap level to copy.
2328
+ * @param {number} [dstLevel=0] - The destination mip level to copy to.
2329
+ */
2330
+ copyTextureToTexture( srcTexture, dstTexture, srcRegion = null, dstPosition = null, srcLevel = 0, dstLevel = 0 ) {
1364
2331
 
1365
2332
  let dstX = 0;
1366
2333
  let dstY = 0;
1367
- let dstLayer = 0;
2334
+ let dstZ = 0;
1368
2335
 
1369
2336
  let srcX = 0;
1370
2337
  let srcY = 0;
1371
- let srcLayer = 0;
2338
+ let srcZ = 0;
1372
2339
 
1373
2340
  let srcWidth = srcTexture.image.width;
1374
2341
  let srcHeight = srcTexture.image.height;
2342
+ let srcDepth = 1;
2343
+
1375
2344
 
1376
2345
  if ( srcRegion !== null ) {
1377
2346
 
1378
- srcX = srcRegion.x;
1379
- srcY = srcRegion.y;
1380
- srcLayer = srcRegion.z || 0;
1381
- srcWidth = srcRegion.width;
1382
- srcHeight = srcRegion.height;
2347
+ if ( srcRegion.isBox3 === true ) {
2348
+
2349
+ srcX = srcRegion.min.x;
2350
+ srcY = srcRegion.min.y;
2351
+ srcZ = srcRegion.min.z;
2352
+ srcWidth = srcRegion.max.x - srcRegion.min.x;
2353
+ srcHeight = srcRegion.max.y - srcRegion.min.y;
2354
+ srcDepth = srcRegion.max.z - srcRegion.min.z;
2355
+
2356
+ } else {
2357
+
2358
+ // Assume it's a Box2
2359
+ srcX = srcRegion.min.x;
2360
+ srcY = srcRegion.min.y;
2361
+ srcWidth = srcRegion.max.x - srcRegion.min.x;
2362
+ srcHeight = srcRegion.max.y - srcRegion.min.y;
2363
+ srcDepth = 1;
2364
+
2365
+ }
1383
2366
 
1384
2367
  }
1385
2368
 
2369
+
1386
2370
  if ( dstPosition !== null ) {
1387
2371
 
1388
2372
  dstX = dstPosition.x;
1389
2373
  dstY = dstPosition.y;
1390
- dstLayer = dstPosition.z || 0;
2374
+ dstZ = dstPosition.z || 0;
1391
2375
 
1392
2376
  }
1393
2377
 
@@ -1399,31 +2383,42 @@ class WebGPUBackend extends Backend {
1399
2383
  encoder.copyTextureToTexture(
1400
2384
  {
1401
2385
  texture: sourceGPU,
1402
- mipLevel: level,
1403
- origin: { x: srcX, y: srcY, z: srcLayer }
2386
+ mipLevel: srcLevel,
2387
+ origin: { x: srcX, y: srcY, z: srcZ }
1404
2388
  },
1405
2389
  {
1406
2390
  texture: destinationGPU,
1407
- mipLevel: level,
1408
- origin: { x: dstX, y: dstY, z: dstLayer }
2391
+ mipLevel: dstLevel,
2392
+ origin: { x: dstX, y: dstY, z: dstZ }
1409
2393
  },
1410
2394
  [
1411
2395
  srcWidth,
1412
2396
  srcHeight,
1413
- 1
2397
+ srcDepth
1414
2398
  ]
1415
2399
  );
1416
2400
 
1417
2401
  this.device.queue.submit( [ encoder.finish() ] );
1418
2402
 
2403
+ if ( dstLevel === 0 && dstTexture.generateMipmaps ) {
2404
+
2405
+ this.textureUtils.generateMipmaps( dstTexture );
2406
+
2407
+ }
2408
+
1419
2409
  }
1420
2410
 
2411
+ /**
2412
+ * Copies the current bound framebuffer to the given texture.
2413
+ *
2414
+ * @param {Texture} texture - The destination texture.
2415
+ * @param {RenderContext} renderContext - The render context.
2416
+ * @param {Vector4} rectangle - A four dimensional vector defining the origin and dimension of the copy.
2417
+ */
1421
2418
  copyFramebufferToTexture( texture, renderContext, rectangle ) {
1422
2419
 
1423
2420
  const renderContextData = this.get( renderContext );
1424
2421
 
1425
- const { encoder, descriptor } = renderContextData;
1426
-
1427
2422
  let sourceGPU = null;
1428
2423
 
1429
2424
  if ( renderContext.renderTarget ) {
@@ -1456,18 +2451,30 @@ class WebGPUBackend extends Backend {
1456
2451
 
1457
2452
  if ( sourceGPU.format !== destinationGPU.format ) {
1458
2453
 
1459
- console.error( 'WebGPUBackend: copyFramebufferToTexture: Source and destination formats do not match.', sourceGPU.format, destinationGPU.format );
2454
+ error( 'WebGPUBackend: copyFramebufferToTexture: Source and destination formats do not match.', sourceGPU.format, destinationGPU.format );
1460
2455
 
1461
2456
  return;
1462
2457
 
1463
2458
  }
1464
2459
 
1465
- renderContextData.currentPass.end();
2460
+ let encoder;
2461
+
2462
+ if ( renderContextData.currentPass ) {
2463
+
2464
+ renderContextData.currentPass.end();
2465
+
2466
+ encoder = renderContextData.encoder;
2467
+
2468
+ } else {
2469
+
2470
+ encoder = this.device.createCommandEncoder( { label: 'copyFramebufferToTexture_' + texture.id } );
2471
+
2472
+ }
1466
2473
 
1467
2474
  encoder.copyTextureToTexture(
1468
2475
  {
1469
2476
  texture: sourceGPU,
1470
- origin: { x: rectangle.x, y: rectangle.y, z: 0 }
2477
+ origin: [ rectangle.x, rectangle.y, 0 ],
1471
2478
  },
1472
2479
  {
1473
2480
  texture: destinationGPU
@@ -1478,19 +2485,101 @@ class WebGPUBackend extends Backend {
1478
2485
  ]
1479
2486
  );
1480
2487
 
1481
- if ( texture.generateMipmaps ) this.textureUtils.generateMipmaps( texture );
2488
+ // mipmaps must be genereated with the same encoder otherwise the copied texture data
2489
+ // might be out-of-sync, see #31768
1482
2490
 
1483
- for ( let i = 0; i < descriptor.colorAttachments.length; i ++ ) {
2491
+ if ( texture.generateMipmaps ) {
1484
2492
 
1485
- descriptor.colorAttachments[ i ].loadOp = GPULoadOp.Load;
2493
+ this.textureUtils.generateMipmaps( texture, encoder );
1486
2494
 
1487
2495
  }
1488
2496
 
1489
- if ( renderContext.depth ) descriptor.depthStencilAttachment.depthLoadOp = GPULoadOp.Load;
1490
- if ( renderContext.stencil ) descriptor.depthStencilAttachment.stencilLoadOp = GPULoadOp.Load;
2497
+ if ( renderContextData.currentPass ) {
1491
2498
 
1492
- renderContextData.currentPass = encoder.beginRenderPass( descriptor );
1493
- renderContextData.currentSets = { attributes: {}, bindingGroups: [], pipeline: null, index: null };
2499
+ const { descriptor } = renderContextData;
2500
+
2501
+ for ( let i = 0; i < descriptor.colorAttachments.length; i ++ ) {
2502
+
2503
+ descriptor.colorAttachments[ i ].loadOp = GPULoadOp.Load;
2504
+
2505
+ }
2506
+
2507
+ if ( renderContext.depth ) descriptor.depthStencilAttachment.depthLoadOp = GPULoadOp.Load;
2508
+ if ( renderContext.stencil ) descriptor.depthStencilAttachment.stencilLoadOp = GPULoadOp.Load;
2509
+
2510
+ renderContextData.currentPass = encoder.beginRenderPass( descriptor );
2511
+ renderContextData.currentSets = { attributes: {}, bindingGroups: [], pipeline: null, index: null };
2512
+
2513
+ if ( renderContext.viewport ) {
2514
+
2515
+ this.updateViewport( renderContext );
2516
+
2517
+ }
2518
+
2519
+ if ( renderContext.scissor ) {
2520
+
2521
+ this.updateScissor( renderContext );
2522
+
2523
+ }
2524
+
2525
+ } else {
2526
+
2527
+ this.device.queue.submit( [ encoder.finish() ] );
2528
+
2529
+ }
2530
+
2531
+ }
2532
+
2533
+ /**
2534
+ * Checks if the given compatibility is supported by the backend.
2535
+ *
2536
+ * @param {string} name - The compatibility name.
2537
+ * @return {boolean} Whether the compatibility is supported or not.
2538
+ */
2539
+ hasCompatibility( name ) {
2540
+
2541
+ if ( this._compatibility[ Compatibility.TEXTURE_COMPARE ] !== undefined ) {
2542
+
2543
+ return this._compatibility[ Compatibility.TEXTURE_COMPARE ];
2544
+
2545
+ }
2546
+
2547
+ return super.hasCompatibility( name );
2548
+
2549
+ }
2550
+
2551
+ dispose() {
2552
+
2553
+ this.bindingUtils.dispose();
2554
+ this.textureUtils.dispose();
2555
+
2556
+ if ( this.occludedResolveCache ) {
2557
+
2558
+ for ( const buffer of this.occludedResolveCache.values() ) {
2559
+
2560
+ buffer.destroy();
2561
+
2562
+ }
2563
+
2564
+ this.occludedResolveCache.clear();
2565
+
2566
+ }
2567
+
2568
+ if ( this.timestampQueryPool ) {
2569
+
2570
+ for ( const queryPool of Object.values( this.timestampQueryPool ) ) {
2571
+
2572
+ if ( queryPool !== null ) queryPool.dispose();
2573
+
2574
+ }
2575
+
2576
+ }
2577
+
2578
+ if ( this.parameters.device === undefined && this.device !== null ) {
2579
+
2580
+ this.device.destroy();
2581
+
2582
+ }
1494
2583
 
1495
2584
  }
1496
2585