super-three 0.171.0 → 0.173.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 (455) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1 -1
  3. package/build/three.cjs +594 -427
  4. package/build/three.core.js +515 -81
  5. package/build/three.core.min.js +2 -2
  6. package/build/three.module.js +79 -350
  7. package/build/three.module.min.js +2 -2
  8. package/build/three.tsl.js +20 -7
  9. package/build/three.tsl.min.js +2 -2
  10. package/build/three.webgpu.js +29362 -3427
  11. package/build/three.webgpu.min.js +2 -2
  12. package/build/three.webgpu.nodes.js +29361 -3427
  13. package/build/three.webgpu.nodes.min.js +2 -2
  14. package/examples/jsm/Addons.js +0 -5
  15. package/examples/jsm/animation/CCDIKSolver.js +9 -7
  16. package/examples/jsm/capabilities/WebGPU.js +1 -1
  17. package/examples/jsm/controls/ArcballControls.js +48 -37
  18. package/examples/jsm/controls/OrbitControls.js +5 -4
  19. package/examples/jsm/csm/CSMShadowNode.js +16 -11
  20. package/examples/jsm/curves/NURBSCurve.js +1 -1
  21. package/examples/jsm/curves/NURBSUtils.js +3 -0
  22. package/examples/jsm/effects/OutlineEffect.js +1 -1
  23. package/examples/jsm/exporters/GLTFExporter.js +34 -29
  24. package/examples/jsm/exporters/KTX2Exporter.js +1 -1
  25. package/examples/jsm/exporters/PLYExporter.js +2 -2
  26. package/examples/jsm/geometries/TextGeometry.js +1 -12
  27. package/examples/jsm/helpers/TextureHelperGPU.js +15 -5
  28. package/examples/jsm/helpers/VertexNormalsHelper.js +2 -0
  29. package/examples/jsm/interactive/InteractiveGroup.js +108 -51
  30. package/examples/jsm/libs/demuxer_mp4.js +109 -0
  31. package/examples/jsm/lights/LightProbeGenerator.js +3 -3
  32. package/examples/jsm/lines/webgpu/LineSegments2.js +15 -6
  33. package/examples/jsm/loaders/3MFLoader.js +6 -3
  34. package/examples/jsm/loaders/BVHLoader.js +1 -1
  35. package/examples/jsm/loaders/ColladaLoader.js +5 -5
  36. package/examples/jsm/loaders/DDSLoader.js +42 -0
  37. package/examples/jsm/loaders/GCodeLoader.js +4 -2
  38. package/examples/jsm/loaders/GLTFLoader.js +22 -4
  39. package/examples/jsm/loaders/KTX2Loader.js +6 -1
  40. package/examples/jsm/loaders/KTXLoader.js +4 -4
  41. package/examples/jsm/loaders/LDrawLoader.js +1 -1
  42. package/examples/jsm/loaders/LottieLoader.js +1 -1
  43. package/examples/jsm/loaders/MTLLoader.js +1 -0
  44. package/examples/jsm/loaders/NRRDLoader.js +1 -1
  45. package/examples/jsm/loaders/PLYLoader.js +7 -7
  46. package/examples/jsm/loaders/PVRLoader.js +1 -1
  47. package/examples/jsm/loaders/SVGLoader.js +2 -2
  48. package/examples/jsm/loaders/TDSLoader.js +1 -2
  49. package/examples/jsm/loaders/VRMLLoader.js +7 -7
  50. package/examples/jsm/loaders/lwo/IFFParser.js +4 -4
  51. package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +1 -1
  52. package/examples/jsm/materials/MeshGouraudMaterial.js +2 -0
  53. package/examples/jsm/math/ConvexHull.js +1 -1
  54. package/examples/jsm/math/OBB.js +17 -0
  55. package/examples/jsm/misc/GPUComputationRenderer.js +6 -7
  56. package/examples/jsm/misc/ProgressiveLightMap.js +4 -3
  57. package/examples/jsm/misc/ProgressiveLightMapGPU.js +14 -13
  58. package/examples/jsm/misc/Volume.js +27 -17
  59. package/examples/jsm/misc/VolumeSlice.js +7 -5
  60. package/examples/jsm/modifiers/CurveModifier.js +10 -8
  61. package/examples/jsm/modifiers/CurveModifierGPU.js +9 -7
  62. package/examples/jsm/modifiers/SimplifyModifier.js +2 -2
  63. package/examples/jsm/objects/GroundedSkybox.js +4 -4
  64. package/examples/jsm/objects/Sky.js +2 -2
  65. package/examples/jsm/objects/SkyMesh.js +3 -3
  66. package/examples/jsm/objects/Water2.js +1 -1
  67. package/examples/jsm/objects/Water2Mesh.js +2 -2
  68. package/examples/jsm/objects/WaterMesh.js +29 -24
  69. package/examples/jsm/physics/JoltPhysics.js +7 -7
  70. package/examples/jsm/physics/RapierPhysics.js +4 -4
  71. package/examples/jsm/postprocessing/BloomPass.js +2 -2
  72. package/examples/jsm/postprocessing/EffectComposer.js +1 -2
  73. package/examples/jsm/postprocessing/OutlinePass.js +4 -4
  74. package/examples/jsm/postprocessing/OutputPass.js +2 -0
  75. package/examples/jsm/postprocessing/SAOPass.js +1 -2
  76. package/examples/jsm/postprocessing/SMAAPass.js +1 -3
  77. package/examples/jsm/postprocessing/SSAOPass.js +2 -4
  78. package/examples/jsm/postprocessing/SSRPass.js +2 -4
  79. package/examples/jsm/postprocessing/UnrealBloomPass.js +2 -2
  80. package/examples/jsm/renderers/SVGRenderer.js +6 -4
  81. package/examples/jsm/shaders/BokehShader2.js +1 -1
  82. package/examples/jsm/shaders/GodRaysShader.js +3 -3
  83. package/examples/jsm/shaders/OutputShader.js +5 -1
  84. package/examples/jsm/shaders/SobelOperatorShader.js +1 -1
  85. package/examples/jsm/transpiler/GLSLDecoder.js +2 -2
  86. package/examples/jsm/transpiler/TSLEncoder.js +2 -0
  87. package/examples/jsm/tsl/display/AfterImageNode.js +93 -4
  88. package/examples/jsm/tsl/display/AnaglyphPassNode.js +46 -2
  89. package/examples/jsm/tsl/display/AnamorphicNode.js +118 -5
  90. package/examples/jsm/tsl/display/BleachBypass.js +10 -0
  91. package/examples/jsm/tsl/display/BloomNode.js +233 -26
  92. package/examples/jsm/tsl/display/DenoiseNode.js +141 -25
  93. package/examples/jsm/tsl/display/DepthOfFieldNode.js +80 -1
  94. package/examples/jsm/tsl/display/DotScreenNode.js +50 -5
  95. package/examples/jsm/tsl/display/FXAANode.js +52 -3
  96. package/examples/jsm/tsl/display/FilmNode.js +47 -1
  97. package/examples/jsm/tsl/display/GTAONode.js +210 -14
  98. package/examples/jsm/tsl/display/GaussianBlurNode.js +152 -8
  99. package/examples/jsm/tsl/display/LensflareNode.js +131 -13
  100. package/examples/jsm/tsl/display/Lut3DNode.js +55 -1
  101. package/examples/jsm/tsl/display/MotionBlur.js +12 -2
  102. package/examples/jsm/tsl/display/OutlineNode.js +343 -26
  103. package/examples/jsm/tsl/display/ParallaxBarrierPassNode.js +36 -2
  104. package/examples/jsm/tsl/display/PixelationPassNode.js +142 -9
  105. package/examples/jsm/tsl/display/RGBShiftNode.js +49 -2
  106. package/examples/jsm/tsl/display/SMAANode.js +187 -46
  107. package/examples/jsm/tsl/display/SSAAPassNode.js +110 -25
  108. package/examples/jsm/tsl/display/SSRNode.js +194 -21
  109. package/examples/jsm/tsl/display/Sepia.js +9 -0
  110. package/examples/jsm/tsl/display/SobelOperatorNode.js +54 -4
  111. package/examples/jsm/tsl/display/StereoCompositePassNode.js +79 -3
  112. package/examples/jsm/tsl/display/StereoPassNode.js +41 -3
  113. package/examples/jsm/tsl/display/TRAAPassNode.js +116 -21
  114. package/examples/jsm/tsl/display/TransitionNode.js +71 -6
  115. package/examples/jsm/tsl/display/hashBlur.js +14 -3
  116. package/examples/jsm/tsl/lighting/TiledLightsNode.js +40 -34
  117. package/examples/jsm/utils/BufferGeometryUtils.js +1 -1
  118. package/examples/jsm/utils/CameraUtils.js +4 -1
  119. package/examples/jsm/utils/GeometryUtils.js +22 -19
  120. package/examples/jsm/utils/SceneUtils.js +2 -2
  121. package/examples/jsm/webxr/XRControllerModelFactory.js +6 -1
  122. package/examples/jsm/webxr/XREstimatedLight.js +1 -1
  123. package/package.json +8 -3
  124. package/src/Three.Core.js +4 -0
  125. package/src/Three.Legacy.js +0 -21
  126. package/src/Three.TSL.js +18 -5
  127. package/src/Three.WebGPU.Nodes.js +2 -2
  128. package/src/Three.WebGPU.js +2 -2
  129. package/src/animation/PropertyBinding.js +2 -2
  130. package/src/cameras/ArrayCamera.js +1 -0
  131. package/src/cameras/PerspectiveCamera.js +18 -2
  132. package/src/constants.js +6 -1
  133. package/src/core/BufferAttribute.js +4 -0
  134. package/src/core/EventDispatcher.js +8 -6
  135. package/src/core/RenderTarget.js +18 -0
  136. package/src/core/RenderTarget3D.js +22 -0
  137. package/src/core/RenderTargetArray.js +22 -0
  138. package/src/extras/Earcut.js +1 -1
  139. package/src/extras/ImageUtils.js +1 -11
  140. package/src/extras/PMREMGenerator.js +20 -0
  141. package/src/extras/TextureUtils.js +6 -0
  142. package/src/helpers/CameraHelper.js +16 -13
  143. package/src/loaders/nodes/NodeLoader.js +59 -0
  144. package/src/loaders/nodes/NodeMaterialLoader.js +45 -0
  145. package/src/loaders/nodes/NodeObjectLoader.js +61 -0
  146. package/src/materials/nodes/Line2NodeMaterial.js +128 -34
  147. package/src/materials/nodes/LineBasicNodeMaterial.js +17 -2
  148. package/src/materials/nodes/LineDashedNodeMaterial.js +78 -5
  149. package/src/materials/nodes/MeshBasicNodeMaterial.js +56 -0
  150. package/src/materials/nodes/MeshLambertNodeMaterial.js +35 -0
  151. package/src/materials/nodes/MeshMatcapNodeMaterial.js +22 -2
  152. package/src/materials/nodes/MeshNormalNodeMaterial.js +21 -2
  153. package/src/materials/nodes/MeshPhongNodeMaterial.js +64 -1
  154. package/src/materials/nodes/MeshPhysicalNodeMaterial.js +269 -0
  155. package/src/materials/nodes/MeshSSSNodeMaterial.js +97 -6
  156. package/src/materials/nodes/MeshStandardNodeMaterial.js +78 -0
  157. package/src/materials/nodes/MeshToonNodeMaterial.js +28 -0
  158. package/src/materials/nodes/NodeMaterial.js +476 -23
  159. package/src/materials/nodes/NodeMaterials.js +0 -1
  160. package/src/materials/nodes/PointsNodeMaterial.js +121 -10
  161. package/src/materials/nodes/ShadowNodeMaterial.js +29 -0
  162. package/src/materials/nodes/SpriteNodeMaterial.js +78 -20
  163. package/src/materials/nodes/VolumeNodeMaterial.js +80 -4
  164. package/src/materials/nodes/manager/NodeMaterialObserver.js +95 -0
  165. package/src/nodes/Nodes.js +5 -6
  166. package/src/nodes/TSL.js +6 -3
  167. package/src/nodes/accessors/AccessorsUtils.js +27 -0
  168. package/src/nodes/accessors/Arrays.js +47 -6
  169. package/src/nodes/accessors/BatchNode.js +42 -6
  170. package/src/nodes/accessors/Bitangent.js +37 -0
  171. package/src/nodes/accessors/BufferAttributeNode.js +178 -5
  172. package/src/nodes/accessors/BufferNode.js +63 -0
  173. package/src/nodes/accessors/BuiltinNode.js +38 -0
  174. package/src/nodes/accessors/Camera.js +113 -3
  175. package/src/nodes/accessors/ClippingNode.js +71 -2
  176. package/src/nodes/accessors/CubeTextureNode.js +64 -0
  177. package/src/nodes/accessors/InstanceNode.js +85 -2
  178. package/src/nodes/accessors/InstancedMeshNode.js +28 -3
  179. package/src/nodes/accessors/Lights.js +50 -1
  180. package/src/nodes/accessors/MaterialNode.js +306 -12
  181. package/src/nodes/accessors/MaterialProperties.js +7 -0
  182. package/src/nodes/accessors/MaterialReferenceNode.js +53 -13
  183. package/src/nodes/accessors/ModelNode.js +100 -5
  184. package/src/nodes/accessors/ModelViewProjectionNode.js +10 -38
  185. package/src/nodes/accessors/MorphNode.js +48 -4
  186. package/src/nodes/accessors/Normal.js +65 -5
  187. package/src/nodes/accessors/Object3DNode.js +101 -1
  188. package/src/nodes/accessors/PointUVNode.js +26 -0
  189. package/src/nodes/accessors/Position.js +56 -7
  190. package/src/nodes/accessors/ReferenceBaseNode.js +186 -0
  191. package/src/nodes/accessors/ReferenceNode.js +201 -2
  192. package/src/nodes/accessors/ReflectVector.js +24 -0
  193. package/src/nodes/accessors/RendererReferenceNode.js +46 -1
  194. package/src/nodes/accessors/SceneNode.js +54 -0
  195. package/src/nodes/accessors/SkinningNode.js +127 -1
  196. package/src/nodes/accessors/StorageBufferNode.js +209 -8
  197. package/src/nodes/accessors/StorageTextureNode.js +118 -0
  198. package/src/nodes/accessors/Tangent.js +38 -2
  199. package/src/nodes/accessors/Texture3DNode.js +91 -7
  200. package/src/nodes/accessors/TextureBicubic.js +12 -2
  201. package/src/nodes/accessors/TextureNode.js +316 -10
  202. package/src/nodes/accessors/TextureSizeNode.js +42 -0
  203. package/src/nodes/accessors/UV.js +10 -1
  204. package/src/nodes/accessors/UniformArrayNode.js +231 -25
  205. package/src/nodes/accessors/UserDataNode.js +46 -0
  206. package/src/nodes/accessors/VelocityNode.js +80 -0
  207. package/src/nodes/accessors/VertexColorNode.js +39 -2
  208. package/src/nodes/code/CodeNode.js +95 -1
  209. package/src/nodes/code/ExpressionNode.js +28 -0
  210. package/src/nodes/code/FunctionCallNode.js +37 -0
  211. package/src/nodes/code/FunctionNode.js +45 -0
  212. package/src/nodes/code/ScriptableNode.js +223 -1
  213. package/src/nodes/code/ScriptableValueNode.js +85 -1
  214. package/src/nodes/core/ArrayNode.js +125 -0
  215. package/src/nodes/core/AssignNode.js +48 -2
  216. package/src/nodes/core/AttributeNode.js +43 -0
  217. package/src/nodes/core/BypassNode.js +47 -2
  218. package/src/nodes/core/CacheNode.js +53 -2
  219. package/src/nodes/core/ConstNode.js +32 -0
  220. package/src/nodes/core/ContextNode.js +65 -0
  221. package/src/nodes/core/IndexNode.js +68 -7
  222. package/src/nodes/core/InputNode.js +48 -0
  223. package/src/nodes/core/LightingModel.js +60 -0
  224. package/src/nodes/core/MRTNode.js +66 -0
  225. package/src/nodes/core/Node.js +350 -12
  226. package/src/nodes/core/NodeAttribute.js +38 -0
  227. package/src/nodes/core/NodeBuilder.js +1166 -26
  228. package/src/nodes/core/NodeCache.js +41 -2
  229. package/src/nodes/core/NodeCode.js +31 -0
  230. package/src/nodes/core/NodeFrame.js +123 -2
  231. package/src/nodes/core/NodeFunction.js +46 -0
  232. package/src/nodes/core/NodeFunctionInput.js +44 -0
  233. package/src/nodes/core/NodeParser.js +11 -0
  234. package/src/nodes/core/NodeUniform.js +52 -0
  235. package/src/nodes/core/NodeUtils.js +152 -1
  236. package/src/nodes/core/NodeVar.js +47 -1
  237. package/src/nodes/core/NodeVarying.js +28 -0
  238. package/src/nodes/core/OutputStructNode.js +51 -10
  239. package/src/nodes/core/ParameterNode.js +28 -0
  240. package/src/nodes/core/PropertyNode.js +232 -0
  241. package/src/nodes/core/StackNode.js +98 -1
  242. package/src/nodes/core/StructNode.js +121 -0
  243. package/src/nodes/core/StructType.js +13 -0
  244. package/src/nodes/core/StructTypeNode.js +105 -6
  245. package/src/nodes/core/TempNode.js +31 -5
  246. package/src/nodes/core/UniformGroupNode.js +82 -7
  247. package/src/nodes/core/UniformNode.js +66 -0
  248. package/src/nodes/core/VarNode.js +146 -7
  249. package/src/nodes/core/VaryingNode.js +100 -3
  250. package/src/nodes/core/constants.js +36 -0
  251. package/src/nodes/display/BlendModes.js +88 -1
  252. package/src/nodes/display/BumpMapNode.js +37 -0
  253. package/src/nodes/display/ColorAdjustment.js +53 -11
  254. package/src/nodes/display/ColorSpaceFunctions.js +16 -0
  255. package/src/nodes/display/ColorSpaceNode.js +82 -0
  256. package/src/nodes/display/FrontFacingNode.js +29 -0
  257. package/src/nodes/display/NormalMapNode.js +43 -0
  258. package/src/nodes/display/PassNode.js +300 -7
  259. package/src/nodes/display/PosterizeNode.js +33 -0
  260. package/src/nodes/display/RenderOutputNode.js +66 -1
  261. package/src/nodes/display/ScreenNode.js +96 -0
  262. package/src/nodes/display/ToneMappingFunctions.js +58 -10
  263. package/src/nodes/display/ToneMappingNode.js +55 -2
  264. package/src/nodes/display/ToonOutlinePassNode.js +73 -0
  265. package/src/nodes/display/ViewportDepthNode.js +122 -8
  266. package/src/nodes/display/ViewportDepthTextureNode.js +23 -0
  267. package/src/nodes/display/ViewportSharedTextureNode.js +23 -0
  268. package/src/nodes/display/ViewportTextureNode.js +57 -0
  269. package/src/nodes/fog/Fog.js +110 -0
  270. package/src/nodes/functions/BasicLightingModel.js +24 -0
  271. package/src/nodes/functions/PhongLightingModel.js +34 -2
  272. package/src/nodes/functions/PhysicalLightingModel.js +167 -8
  273. package/src/nodes/functions/ShadowMaskModel.js +23 -0
  274. package/src/nodes/functions/ToonLightingModel.js +20 -0
  275. package/src/nodes/functions/material/getAlphaHashThreshold.js +1 -3
  276. package/src/nodes/functions/material/getParallaxCorrectNormal.js +16 -1
  277. package/src/nodes/geometry/RangeNode.js +54 -2
  278. package/src/nodes/gpgpu/AtomicFunctionNode.js +174 -2
  279. package/src/nodes/gpgpu/BarrierNode.js +47 -0
  280. package/src/nodes/gpgpu/ComputeBuiltinNode.js +134 -0
  281. package/src/nodes/gpgpu/ComputeNode.js +106 -2
  282. package/src/nodes/gpgpu/WorkgroupInfoNode.js +115 -6
  283. package/src/nodes/lighting/AONode.js +18 -0
  284. package/src/nodes/lighting/AmbientLightNode.js +10 -0
  285. package/src/nodes/lighting/AnalyticLightNode.js +97 -2
  286. package/src/nodes/lighting/BasicEnvironmentNode.js +19 -0
  287. package/src/nodes/lighting/BasicLightMapNode.js +17 -0
  288. package/src/nodes/lighting/DirectionalLightNode.js +10 -0
  289. package/src/nodes/lighting/EnvironmentNode.js +18 -0
  290. package/src/nodes/lighting/HemisphereLightNode.js +31 -0
  291. package/src/nodes/lighting/IESSpotLightNode.js +11 -0
  292. package/src/nodes/lighting/IrradianceNode.js +17 -0
  293. package/src/nodes/lighting/LightProbeNode.js +20 -0
  294. package/src/nodes/lighting/LightUtils.js +12 -0
  295. package/src/nodes/lighting/LightingContextNode.js +48 -0
  296. package/src/nodes/lighting/LightingNode.js +15 -6
  297. package/src/nodes/lighting/LightsNode.js +132 -1
  298. package/src/nodes/lighting/PointLightNode.js +32 -1
  299. package/src/nodes/lighting/PointShadowNode.js +54 -1
  300. package/src/nodes/lighting/RectAreaLightNode.js +44 -6
  301. package/src/nodes/lighting/ShadowBaseNode.js +93 -0
  302. package/src/nodes/lighting/ShadowNode.js +241 -35
  303. package/src/nodes/lighting/SpotLightNode.js +43 -0
  304. package/src/nodes/math/ConditionalNode.js +78 -4
  305. package/src/nodes/math/Hash.js +9 -0
  306. package/src/nodes/math/MathNode.js +627 -11
  307. package/src/nodes/math/MathUtils.js +45 -1
  308. package/src/nodes/math/OperatorNode.js +329 -18
  309. package/src/nodes/math/TriNoise3D.js +18 -7
  310. package/src/nodes/parsers/GLSLNodeFunction.js +16 -0
  311. package/src/nodes/parsers/GLSLNodeParser.js +11 -0
  312. package/src/nodes/pmrem/PMREMNode.js +133 -0
  313. package/src/nodes/pmrem/PMREMUtils.js +2 -2
  314. package/src/nodes/procedural/Checker.js +9 -0
  315. package/src/nodes/shapes/Shapes.js +33 -0
  316. package/src/nodes/tsl/TSLBase.js +3 -2
  317. package/src/nodes/tsl/TSLCore.js +22 -2
  318. package/src/nodes/utils/ArrayElementNode.js +39 -3
  319. package/src/nodes/utils/ConvertNode.js +31 -0
  320. package/src/nodes/utils/CubeMapNode.js +78 -0
  321. package/src/nodes/utils/Discard.js +16 -0
  322. package/src/nodes/utils/EquirectUVNode.js +31 -1
  323. package/src/nodes/utils/FlipNode.js +38 -0
  324. package/src/nodes/utils/FunctionOverloadingNode.js +53 -1
  325. package/src/nodes/utils/JoinNode.js +25 -0
  326. package/src/nodes/utils/LoopNode.js +82 -2
  327. package/src/nodes/utils/MatcapUVNode.js +17 -0
  328. package/src/nodes/utils/MaxMipLevelNode.js +49 -0
  329. package/src/nodes/utils/MemberNode.js +68 -0
  330. package/src/nodes/utils/Oscillators.js +33 -0
  331. package/src/nodes/utils/Packing.js +17 -0
  332. package/src/nodes/utils/PostProcessingUtils.js +28 -23
  333. package/src/nodes/utils/RTTNode.js +123 -2
  334. package/src/nodes/utils/ReflectorNode.js +174 -4
  335. package/src/nodes/utils/RemapNode.js +79 -0
  336. package/src/nodes/utils/RotateNode.js +41 -0
  337. package/src/nodes/utils/SetNode.js +44 -1
  338. package/src/nodes/utils/SplitNode.js +55 -3
  339. package/src/nodes/utils/SpriteSheetUVNode.js +46 -0
  340. package/src/nodes/utils/SpriteUtils.js +17 -0
  341. package/src/nodes/utils/StorageArrayElementNode.js +54 -0
  342. package/src/nodes/utils/Timer.js +40 -0
  343. package/src/nodes/utils/TriplanarTexturesNode.js +84 -0
  344. package/src/nodes/utils/UVUtils.js +20 -0
  345. package/src/nodes/utils/ViewportUtils.js +13 -0
  346. package/src/objects/BatchedMesh.js +2 -3
  347. package/src/objects/ClippingGroup.js +49 -0
  348. package/src/objects/Line.js +6 -6
  349. package/src/renderers/WebGLRenderer.js +30 -4
  350. package/src/renderers/common/Animation.js +85 -0
  351. package/src/renderers/common/Attributes.js +36 -0
  352. package/src/renderers/common/Backend.js +502 -44
  353. package/src/renderers/common/Background.js +48 -1
  354. package/src/renderers/common/BindGroup.js +43 -0
  355. package/src/renderers/common/Binding.js +35 -0
  356. package/src/renderers/common/Bindings.js +93 -1
  357. package/src/renderers/common/Buffer.js +49 -0
  358. package/src/renderers/common/BufferUtils.js +27 -0
  359. package/src/renderers/common/BundleGroup.js +57 -0
  360. package/src/renderers/common/ChainMap.js +45 -6
  361. package/src/renderers/common/ClippingContext.js +108 -15
  362. package/src/renderers/common/Color4.js +40 -0
  363. package/src/renderers/common/ComputePipeline.js +24 -0
  364. package/src/renderers/common/CubeRenderTarget.js +13 -0
  365. package/src/renderers/common/DataMap.js +37 -1
  366. package/src/renderers/common/Geometries.js +91 -14
  367. package/src/renderers/common/IndirectStorageBufferAttribute.js +25 -2
  368. package/src/renderers/common/Info.js +78 -35
  369. package/src/renderers/common/Lighting.js +34 -6
  370. package/src/renderers/common/Pipeline.js +22 -0
  371. package/src/renderers/common/Pipelines.js +148 -5
  372. package/src/renderers/common/PostProcessing.js +99 -11
  373. package/src/renderers/common/ProgrammableStage.js +60 -2
  374. package/src/renderers/common/QuadMesh.js +54 -5
  375. package/src/renderers/common/RenderBundle.js +14 -8
  376. package/src/renderers/common/RenderBundles.js +39 -10
  377. package/src/renderers/common/RenderContext.js +201 -2
  378. package/src/renderers/common/RenderContexts.js +59 -6
  379. package/src/renderers/common/RenderList.js +178 -0
  380. package/src/renderers/common/RenderLists.js +40 -3
  381. package/src/renderers/common/RenderObject.js +400 -17
  382. package/src/renderers/common/RenderObjects.js +103 -7
  383. package/src/renderers/common/RenderPipeline.js +24 -0
  384. package/src/renderers/common/Renderer.js +1170 -86
  385. package/src/renderers/common/RendererUtils.js +193 -0
  386. package/src/renderers/common/SampledTexture.js +120 -0
  387. package/src/renderers/common/Sampler.js +30 -0
  388. package/src/renderers/common/StorageBuffer.js +24 -0
  389. package/src/renderers/common/StorageBufferAttribute.js +31 -2
  390. package/src/renderers/common/StorageInstancedBufferAttribute.js +31 -2
  391. package/src/renderers/common/StorageTexture.js +38 -0
  392. package/src/renderers/common/Textures.js +97 -7
  393. package/src/renderers/common/TimestampQueryPool.js +39 -0
  394. package/src/renderers/common/Uniform.js +225 -3
  395. package/src/renderers/common/UniformBuffer.js +19 -0
  396. package/src/renderers/common/UniformsGroup.js +141 -2
  397. package/src/renderers/common/XRManager.js +1193 -0
  398. package/src/renderers/common/XRRenderTarget.js +74 -0
  399. package/src/renderers/common/extras/PMREMGenerator.js +76 -10
  400. package/src/renderers/common/nodes/NodeBuilderState.js +99 -5
  401. package/src/renderers/common/nodes/NodeLibrary.js +89 -0
  402. package/src/renderers/common/nodes/NodeSampledTexture.js +90 -2
  403. package/src/renderers/common/nodes/NodeSampler.js +28 -0
  404. package/src/renderers/common/nodes/NodeStorageBuffer.js +35 -0
  405. package/src/renderers/common/nodes/NodeUniform.js +243 -2
  406. package/src/renderers/common/nodes/NodeUniformBuffer.js +29 -0
  407. package/src/renderers/common/nodes/NodeUniformsGroup.js +31 -18
  408. package/src/renderers/common/nodes/Nodes.js +352 -78
  409. package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +2 -2
  410. package/src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js +7 -7
  411. package/src/renderers/webgl/WebGLBackground.js +4 -0
  412. package/src/renderers/webgl-fallback/WebGLBackend.js +819 -116
  413. package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +347 -18
  414. package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +58 -1
  415. package/src/renderers/webgl-fallback/utils/WebGLCapabilities.js +28 -0
  416. package/src/renderers/webgl-fallback/utils/WebGLExtensions.js +45 -0
  417. package/src/renderers/webgl-fallback/utils/WebGLState.js +323 -11
  418. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +168 -22
  419. package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +359 -0
  420. package/src/renderers/webgl-fallback/utils/WebGLUtils.js +43 -0
  421. package/src/renderers/webgpu/WebGPUBackend.js +578 -164
  422. package/src/renderers/webgpu/WebGPURenderer.Nodes.js +36 -0
  423. package/src/renderers/webgpu/WebGPURenderer.js +36 -0
  424. package/src/renderers/webgpu/nodes/BasicNodeLibrary.js +20 -8
  425. package/src/renderers/webgpu/nodes/StandardNodeLibrary.js +21 -8
  426. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +674 -52
  427. package/src/renderers/webgpu/nodes/WGSLNodeFunction.js +17 -0
  428. package/src/renderers/webgpu/nodes/WGSLNodeParser.js +11 -0
  429. package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +95 -14
  430. package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +94 -1
  431. package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +102 -3
  432. package/src/renderers/webgpu/utils/WebGPUTexturePassUtils.js +98 -1
  433. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +262 -18
  434. package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +274 -0
  435. package/src/renderers/webgpu/utils/WebGPUUtils.js +116 -4
  436. package/src/renderers/webxr/WebXRDepthSensing.js +1 -1
  437. package/src/renderers/webxr/WebXRManager.js +19 -2
  438. package/src/textures/Data3DTexture.js +2 -2
  439. package/src/textures/Texture.js +4 -0
  440. package/src/textures/VideoFrameTexture.js +35 -0
  441. package/examples/jsm/animation/MMDAnimationHelper.js +0 -1209
  442. package/examples/jsm/animation/MMDPhysics.js +0 -1408
  443. package/examples/jsm/exporters/MMDExporter.js +0 -223
  444. package/examples/jsm/geometries/InstancedPointsGeometry.js +0 -176
  445. package/examples/jsm/libs/mmdparser.module.js +0 -11530
  446. package/examples/jsm/loaders/MMDLoader.js +0 -2298
  447. package/examples/jsm/objects/InstancedPoints.js +0 -19
  448. package/examples/jsm/shaders/MMDToonShader.js +0 -134
  449. package/src/materials/nodes/InstancedPointsNodeMaterial.js +0 -156
  450. package/src/nodes/accessors/InstancedPointsMaterialNode.js +0 -24
  451. package/src/nodes/core/UniformGroup.js +0 -13
  452. package/src/nodes/fog/FogExp2Node.js +0 -35
  453. package/src/nodes/fog/FogNode.js +0 -50
  454. package/src/nodes/fog/FogRangeNode.js +0 -36
  455. package/src/renderers/common/PostProcessingUtils.js +0 -86
@@ -14,15 +14,44 @@ import WebGPUPipelineUtils from './utils/WebGPUPipelineUtils.js';
14
14
  import WebGPUTextureUtils from './utils/WebGPUTextureUtils.js';
15
15
 
16
16
  import { WebGPUCoordinateSystem } from '../../constants.js';
17
-
18
- //
19
-
17
+ import WebGPUTimestampQueryPool from './utils/WebGPUTimestampQueryPool.js';
18
+
19
+ /**
20
+ * A backend implementation targeting WebGPU.
21
+ *
22
+ * @private
23
+ * @augments Backend
24
+ */
20
25
  class WebGPUBackend extends Backend {
21
26
 
27
+ /**
28
+ * Constructs a new WebGPU backend.
29
+ *
30
+ * @param {Object} parameters - The configuration parameter.
31
+ * @param {Boolean} [parameters.logarithmicDepthBuffer=false] - Whether logarithmic depth buffer is enabled or not.
32
+ * @param {Boolean} [parameters.alpha=true] - Whether the default framebuffer (which represents the final contents of the canvas) should be transparent or opaque.
33
+ * @param {Boolean} [parameters.depth=true] - Whether the default framebuffer should have a depth buffer or not.
34
+ * @param {Boolean} [parameters.stencil=false] - Whether the default framebuffer should have a stencil buffer or not.
35
+ * @param {Boolean} [parameters.antialias=false] - Whether MSAA as the default anti-aliasing should be enabled or not.
36
+ * @param {Number} [parameters.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.
37
+ * @param {Boolean} [parameters.forceWebGL=false] - If set to `true`, the renderer uses a WebGL 2 backend no matter if WebGPU is supported or not.
38
+ * @param {Boolean} [parameters.trackTimestamp=false] - Whether to track timestamps with a Timestamp Query API or not.
39
+ * @param {String} [parameters.powerPreference=undefined] - The power preference.
40
+ * @param {Object} [parameters.requiredLimits=undefined] - Specifies the limits that are required by the device request. The request will fail if the adapter cannot provide these limits.
41
+ * @param {GPUDevice} [parameters.device=undefined] - If there is an existing GPU device on app level, it can be passed to the renderer as a parameter.
42
+ * @param {Number} [parameters.outputType=undefined] - Texture type for output to canvas. By default, device's preferred format is used; other formats may incur overhead.
43
+ */
22
44
  constructor( parameters = {} ) {
23
45
 
24
46
  super( parameters );
25
47
 
48
+ /**
49
+ * This flag can be used for type testing.
50
+ *
51
+ * @type {Boolean}
52
+ * @readonly
53
+ * @default true
54
+ */
26
55
  this.isWebGPUBackend = true;
27
56
 
28
57
  // some parameters require default values other than "undefined"
@@ -30,22 +59,101 @@ class WebGPUBackend extends Backend {
30
59
 
31
60
  this.parameters.requiredLimits = ( parameters.requiredLimits === undefined ) ? {} : parameters.requiredLimits;
32
61
 
62
+ /**
63
+ * Whether to track timestamps with a Timestamp Query API or not.
64
+ *
65
+ * @type {Boolean}
66
+ * @default false
67
+ */
33
68
  this.trackTimestamp = ( parameters.trackTimestamp === true );
34
69
 
70
+ /**
71
+ * A reference to the device.
72
+ *
73
+ * @type {GPUDevice?}
74
+ * @default null
75
+ */
35
76
  this.device = null;
77
+
78
+ /**
79
+ * A reference to the context.
80
+ *
81
+ * @type {GPUCanvasContext?}
82
+ * @default null
83
+ */
36
84
  this.context = null;
85
+
86
+ /**
87
+ * A reference to the color attachment of the default framebuffer.
88
+ *
89
+ * @type {GPUTexture?}
90
+ * @default null
91
+ */
37
92
  this.colorBuffer = null;
93
+
94
+ /**
95
+ * A reference to the default render pass descriptor.
96
+ *
97
+ * @type {Object?}
98
+ * @default null
99
+ */
38
100
  this.defaultRenderPassdescriptor = null;
39
101
 
102
+ /**
103
+ * A reference to a backend module holding common utility functions.
104
+ *
105
+ * @type {WebGPUUtils}
106
+ */
40
107
  this.utils = new WebGPUUtils( this );
108
+
109
+ /**
110
+ * A reference to a backend module holding shader attribute-related
111
+ * utility functions.
112
+ *
113
+ * @type {WebGPUAttributeUtils}
114
+ */
41
115
  this.attributeUtils = new WebGPUAttributeUtils( this );
116
+
117
+ /**
118
+ * A reference to a backend module holding shader binding-related
119
+ * utility functions.
120
+ *
121
+ * @type {WebGPUBindingUtils}
122
+ */
42
123
  this.bindingUtils = new WebGPUBindingUtils( this );
124
+
125
+ /**
126
+ * A reference to a backend module holding shader pipeline-related
127
+ * utility functions.
128
+ *
129
+ * @type {WebGPUPipelineUtils}
130
+ */
43
131
  this.pipelineUtils = new WebGPUPipelineUtils( this );
132
+
133
+ /**
134
+ * A reference to a backend module holding shader texture-related
135
+ * utility functions.
136
+ *
137
+ * @type {WebGPUTextureUtils}
138
+ */
44
139
  this.textureUtils = new WebGPUTextureUtils( this );
140
+
141
+ /**
142
+ * A map that manages the resolve buffers for occlusion queries.
143
+ *
144
+ * @type {Map<Number,GPUBuffer>}
145
+ */
45
146
  this.occludedResolveCache = new Map();
46
147
 
47
148
  }
48
149
 
150
+ /**
151
+ * Initializes the backend so it is ready for usage.
152
+ *
153
+ * @async
154
+ * @param {Renderer} renderer - The renderer.
155
+ * @return {Promise} A Promise that resolves when the backend has been initialized.
156
+ */
49
157
  async init( renderer ) {
50
158
 
51
159
  await super.init( renderer );
@@ -134,24 +242,53 @@ class WebGPUBackend extends Backend {
134
242
 
135
243
  }
136
244
 
245
+ /**
246
+ * The coordinate system of the backend.
247
+ *
248
+ * @type {Number}
249
+ * @readonly
250
+ */
137
251
  get coordinateSystem() {
138
252
 
139
253
  return WebGPUCoordinateSystem;
140
254
 
141
255
  }
142
256
 
257
+ /**
258
+ * This method performs a readback operation by moving buffer data from
259
+ * a storage buffer attribute from the GPU to the CPU.
260
+ *
261
+ * @async
262
+ * @param {StorageBufferAttribute} attribute - The storage buffer attribute.
263
+ * @return {Promise<ArrayBuffer>} A promise that resolves with the buffer data when the data are ready.
264
+ */
143
265
  async getArrayBufferAsync( attribute ) {
144
266
 
145
267
  return await this.attributeUtils.getArrayBufferAsync( attribute );
146
268
 
147
269
  }
148
270
 
271
+ /**
272
+ * Returns the backend's rendering context.
273
+ *
274
+ * @return {GPUCanvasContext} The rendering context.
275
+ */
149
276
  getContext() {
150
277
 
151
278
  return this.context;
152
279
 
153
280
  }
154
281
 
282
+ /**
283
+ * Returns the default render pass descriptor.
284
+ *
285
+ * In WebGPU, the default framebuffer must be configured
286
+ * like custom framebuffers so the backend needs a render
287
+ * pass descriptor even when rendering directly to screen.
288
+ *
289
+ * @private
290
+ * @return {Object} The render pass descriptor.
291
+ */
155
292
  _getDefaultRenderPassDescriptor() {
156
293
 
157
294
  let descriptor = this.defaultRenderPassdescriptor;
@@ -206,7 +343,15 @@ class WebGPUBackend extends Backend {
206
343
 
207
344
  }
208
345
 
209
- _getRenderPassDescriptor( renderContext ) {
346
+ /**
347
+ * Returns the render pass descriptor for the given render context.
348
+ *
349
+ * @private
350
+ * @param {RenderContext} renderContext - The render context.
351
+ * @param {Object} colorAttachmentsConfig - Configuration object for the color attachments.
352
+ * @return {Object} The render pass descriptor.
353
+ */
354
+ _getRenderPassDescriptor( renderContext, colorAttachmentsConfig = {} ) {
210
355
 
211
356
  const renderTarget = renderContext.renderTarget;
212
357
  const renderTargetData = this.get( renderTarget );
@@ -216,8 +361,11 @@ class WebGPUBackend extends Backend {
216
361
  if ( descriptors === undefined ||
217
362
  renderTargetData.width !== renderTarget.width ||
218
363
  renderTargetData.height !== renderTarget.height ||
364
+ renderTargetData.dimensions !== renderTarget.dimensions ||
219
365
  renderTargetData.activeMipmapLevel !== renderTarget.activeMipmapLevel ||
220
- renderTargetData.samples !== renderTarget.samples
366
+ renderTargetData.activeCubeFace !== renderContext.activeCubeFace ||
367
+ renderTargetData.samples !== renderTarget.samples ||
368
+ renderTargetData.loadOp !== colorAttachmentsConfig.loadOp
221
369
  ) {
222
370
 
223
371
  descriptors = {};
@@ -247,16 +395,37 @@ class WebGPUBackend extends Backend {
247
395
  const textures = renderContext.textures;
248
396
  const colorAttachments = [];
249
397
 
398
+ let sliceIndex;
399
+
250
400
  for ( let i = 0; i < textures.length; i ++ ) {
251
401
 
252
402
  const textureData = this.get( textures[ i ] );
253
403
 
254
- const textureView = textureData.texture.createView( {
404
+ const viewDescriptor = {
405
+ label: `colorAttachment_${ i }`,
255
406
  baseMipLevel: renderContext.activeMipmapLevel,
256
407
  mipLevelCount: 1,
257
408
  baseArrayLayer: renderContext.activeCubeFace,
409
+ arrayLayerCount: 1,
258
410
  dimension: GPUTextureViewDimension.TwoD
259
- } );
411
+ };
412
+
413
+ if ( renderTarget.isRenderTarget3D ) {
414
+
415
+ sliceIndex = renderContext.activeCubeFace;
416
+
417
+ viewDescriptor.baseArrayLayer = 0;
418
+ viewDescriptor.dimension = GPUTextureViewDimension.ThreeD;
419
+ viewDescriptor.depthOrArrayLayers = textures[ i ].image.depth;
420
+
421
+ } else if ( renderTarget.isRenderTargetArray ) {
422
+
423
+ viewDescriptor.dimension = GPUTextureViewDimension.TwoDArray;
424
+ viewDescriptor.depthOrArrayLayers = textures[ i ].image.depth;
425
+
426
+ }
427
+
428
+ const textureView = textureData.texture.createView( viewDescriptor );
260
429
 
261
430
  let view, resolveTarget;
262
431
 
@@ -274,9 +443,11 @@ class WebGPUBackend extends Backend {
274
443
 
275
444
  colorAttachments.push( {
276
445
  view,
446
+ depthSlice: sliceIndex,
277
447
  resolveTarget,
278
448
  loadOp: GPULoadOp.Load,
279
- storeOp: GPUStoreOp.Store
449
+ storeOp: GPUStoreOp.Store,
450
+ ...colorAttachmentsConfig
280
451
  } );
281
452
 
282
453
  }
@@ -302,7 +473,11 @@ class WebGPUBackend extends Backend {
302
473
  renderTargetData.width = renderTarget.width;
303
474
  renderTargetData.height = renderTarget.height;
304
475
  renderTargetData.samples = renderTarget.samples;
305
- renderTargetData.activeMipmapLevel = renderTarget.activeMipmapLevel;
476
+ renderTargetData.activeMipmapLevel = renderContext.activeMipmapLevel;
477
+ renderTargetData.activeCubeFace = renderContext.activeCubeFace;
478
+ renderTargetData.dimensions = renderTarget.dimensions;
479
+ renderTargetData.depthSlice = sliceIndex;
480
+ renderTargetData.loadOp = colorAttachments[ 0 ].loadOp;
306
481
 
307
482
  }
308
483
 
@@ -310,6 +485,12 @@ class WebGPUBackend extends Backend {
310
485
 
311
486
  }
312
487
 
488
+ /**
489
+ * This method is executed at the beginning of a render call and prepares
490
+ * the WebGPU state for upcoming render calls
491
+ *
492
+ * @param {RenderContext} renderContext - The render context.
493
+ */
313
494
  beginRender( renderContext ) {
314
495
 
315
496
  const renderContextData = this.get( renderContext );
@@ -350,7 +531,7 @@ class WebGPUBackend extends Backend {
350
531
 
351
532
  } else {
352
533
 
353
- descriptor = this._getRenderPassDescriptor( renderContext );
534
+ descriptor = this._getRenderPassDescriptor( renderContext, { loadOp: GPULoadOp.Load } );
354
535
 
355
536
  }
356
537
 
@@ -469,6 +650,12 @@ class WebGPUBackend extends Backend {
469
650
 
470
651
  }
471
652
 
653
+ /**
654
+ * This method is executed at the end of a render call and finalizes work
655
+ * after draw calls.
656
+ *
657
+ * @param {RenderContext} renderContext - The render context.
658
+ */
472
659
  finishRender( renderContext ) {
473
660
 
474
661
  const renderContextData = this.get( renderContext );
@@ -530,8 +717,6 @@ class WebGPUBackend extends Backend {
530
717
 
531
718
  }
532
719
 
533
- this.prepareTimestampBuffer( renderContext, renderContextData.encoder );
534
-
535
720
  this.device.queue.submit( [ renderContextData.encoder.finish() ] );
536
721
 
537
722
 
@@ -557,6 +742,14 @@ class WebGPUBackend extends Backend {
557
742
 
558
743
  }
559
744
 
745
+ /**
746
+ * Returns `true` if the given 3D object is fully occluded by other
747
+ * 3D objects in the scene.
748
+ *
749
+ * @param {RenderContext} renderContext - The render context.
750
+ * @param {Object3D} object - The 3D object to test.
751
+ * @return {Boolean} Whether the 3D object is fully occluded or not.
752
+ */
560
753
  isOccluded( renderContext, object ) {
561
754
 
562
755
  const renderContextData = this.get( renderContext );
@@ -565,6 +758,14 @@ class WebGPUBackend extends Backend {
565
758
 
566
759
  }
567
760
 
761
+ /**
762
+ * This method processes the result of occlusion queries and writes it
763
+ * into render context data.
764
+ *
765
+ * @async
766
+ * @param {RenderContext} renderContext - The render context.
767
+ * @return {Promise} A Promise that resolves when the occlusion query results have been processed.
768
+ */
568
769
  async resolveOccludedAsync( renderContext ) {
569
770
 
570
771
  const renderContextData = this.get( renderContext );
@@ -587,7 +788,7 @@ class WebGPUBackend extends Backend {
587
788
 
588
789
  for ( let i = 0; i < currentOcclusionQueryObjects.length; i ++ ) {
589
790
 
590
- if ( results[ i ] !== BigInt( 0 ) ) {
791
+ if ( results[ i ] === BigInt( 0 ) ) {
591
792
 
592
793
  occluded.add( currentOcclusionQueryObjects[ i ] );
593
794
 
@@ -603,6 +804,11 @@ class WebGPUBackend extends Backend {
603
804
 
604
805
  }
605
806
 
807
+ /**
808
+ * Updates the viewport with the values from the given render context.
809
+ *
810
+ * @param {RenderContext} renderContext - The render context.
811
+ */
606
812
  updateViewport( renderContext ) {
607
813
 
608
814
  const { currentPass } = this.get( renderContext );
@@ -612,7 +818,15 @@ class WebGPUBackend extends Backend {
612
818
 
613
819
  }
614
820
 
615
- clear( color, depth, stencil, renderTargetData = null ) {
821
+ /**
822
+ * Performs a clear operation.
823
+ *
824
+ * @param {Boolean} color - Whether the color buffer should be cleared or not.
825
+ * @param {Boolean} depth - Whether the depth buffer should be cleared or not.
826
+ * @param {Boolean} stencil - Whether the stencil buffer should be cleared or not.
827
+ * @param {RenderContext?} [renderTargetContext=null] - The render context of the current set render target.
828
+ */
829
+ clear( color, depth, stencil, renderTargetContext = null ) {
616
830
 
617
831
  const device = this.device;
618
832
  const renderer = this.renderer;
@@ -645,7 +859,7 @@ class WebGPUBackend extends Backend {
645
859
 
646
860
  }
647
861
 
648
- if ( renderTargetData === null ) {
862
+ if ( renderTargetContext === null ) {
649
863
 
650
864
  supportsDepth = renderer.depth;
651
865
  supportsStencil = renderer.stencil;
@@ -672,45 +886,20 @@ class WebGPUBackend extends Backend {
672
886
 
673
887
  } else {
674
888
 
675
- supportsDepth = renderTargetData.depth;
676
- supportsStencil = renderTargetData.stencil;
889
+ supportsDepth = renderTargetContext.depth;
890
+ supportsStencil = renderTargetContext.stencil;
677
891
 
678
892
  if ( color ) {
679
893
 
680
- for ( const texture of renderTargetData.textures ) {
681
-
682
- const textureData = this.get( texture );
683
- const textureView = textureData.texture.createView();
684
-
685
- let view, resolveTarget;
686
-
687
- if ( textureData.msaaTexture !== undefined ) {
688
-
689
- view = textureData.msaaTexture.createView();
690
- resolveTarget = textureView;
691
-
692
- } else {
693
-
694
- view = textureView;
695
- resolveTarget = undefined;
696
-
697
- }
698
-
699
- colorAttachments.push( {
700
- view,
701
- resolveTarget,
702
- clearValue,
703
- loadOp: GPULoadOp.Clear,
704
- storeOp: GPUStoreOp.Store
705
- } );
894
+ const descriptor = this._getRenderPassDescriptor( renderTargetContext, { loadOp: GPULoadOp.Clear, clearValue } );
706
895
 
707
- }
896
+ colorAttachments = descriptor.colorAttachments;
708
897
 
709
898
  }
710
899
 
711
900
  if ( supportsDepth || supportsStencil ) {
712
901
 
713
- const depthTextureData = this.get( renderTargetData.depthTexture );
902
+ const depthTextureData = this.get( renderTargetContext.depthTexture );
714
903
 
715
904
  depthStencilAttachment = {
716
905
  view: depthTextureData.texture.createView()
@@ -760,7 +949,7 @@ class WebGPUBackend extends Backend {
760
949
 
761
950
  //
762
951
 
763
- const encoder = device.createCommandEncoder( {} );
952
+ const encoder = device.createCommandEncoder( { label: 'clear' } );
764
953
  const currentPass = encoder.beginRenderPass( {
765
954
  colorAttachments,
766
955
  depthStencilAttachment
@@ -774,21 +963,37 @@ class WebGPUBackend extends Backend {
774
963
 
775
964
  // compute
776
965
 
966
+ /**
967
+ * This method is executed at the beginning of a compute call and
968
+ * prepares the state for upcoming compute tasks.
969
+ *
970
+ * @param {Node|Array<Node>} computeGroup - The compute node(s).
971
+ */
777
972
  beginCompute( computeGroup ) {
778
973
 
779
974
  const groupGPU = this.get( computeGroup );
780
975
 
781
976
 
782
- const descriptor = {};
977
+ const descriptor = {
978
+ label: 'computeGroup_' + computeGroup.id
979
+ };
783
980
 
784
981
  this.initTimestampQuery( computeGroup, descriptor );
785
982
 
786
- groupGPU.cmdEncoderGPU = this.device.createCommandEncoder();
983
+ groupGPU.cmdEncoderGPU = this.device.createCommandEncoder( { label: 'computeGroup_' + computeGroup.id } );
787
984
 
788
985
  groupGPU.passEncoderGPU = groupGPU.cmdEncoderGPU.beginComputePass( descriptor );
789
986
 
790
987
  }
791
988
 
989
+ /**
990
+ * Executes a compute command for the given compute node.
991
+ *
992
+ * @param {Node|Array<Node>} computeGroup - The group of compute nodes of a compute call. Can be a single compute node.
993
+ * @param {Node} computeNode - The compute node.
994
+ * @param {Array<BindGroup>} bindings - The bindings.
995
+ * @param {ComputePipeline} pipeline - The compute pipeline.
996
+ */
792
997
  compute( computeGroup, computeNode, bindings, pipeline ) {
793
998
 
794
999
  const { passEncoderGPU } = this.get( computeGroup );
@@ -836,18 +1041,29 @@ class WebGPUBackend extends Backend {
836
1041
 
837
1042
  }
838
1043
 
1044
+ /**
1045
+ * This method is executed at the end of a compute call and
1046
+ * finalizes work after compute tasks.
1047
+ *
1048
+ * @param {Node|Array<Node>} computeGroup - The compute node(s).
1049
+ */
839
1050
  finishCompute( computeGroup ) {
840
1051
 
841
1052
  const groupData = this.get( computeGroup );
842
1053
 
843
1054
  groupData.passEncoderGPU.end();
844
1055
 
845
- this.prepareTimestampBuffer( computeGroup, groupData.cmdEncoderGPU );
846
-
847
1056
  this.device.queue.submit( [ groupData.cmdEncoderGPU.finish() ] );
848
1057
 
849
1058
  }
850
1059
 
1060
+ /**
1061
+ * Can be used to synchronize CPU operations with GPU tasks. So when this method is called,
1062
+ * the CPU waits for the GPU to complete its operation (e.g. a compute task).
1063
+ *
1064
+ * @async
1065
+ * @return {Promise} A Promise that resolves when synchronization has been finished.
1066
+ */
851
1067
  async waitForGPU() {
852
1068
 
853
1069
  await this.device.queue.onSubmittedWorkDone();
@@ -856,6 +1072,12 @@ class WebGPUBackend extends Backend {
856
1072
 
857
1073
  // render object
858
1074
 
1075
+ /**
1076
+ * Executes a draw command for the given render object.
1077
+ *
1078
+ * @param {RenderObject} renderObject - The render object to draw.
1079
+ * @param {Info} info - Holds a series of statistical information about the GPU memory and the rendering process.
1080
+ */
859
1081
  draw( renderObject, info ) {
860
1082
 
861
1083
  const { object, context, pipeline } = renderObject;
@@ -969,63 +1191,133 @@ class WebGPUBackend extends Backend {
969
1191
 
970
1192
  // draw
971
1193
 
972
- if ( object.isBatchedMesh === true ) {
1194
+ const draw = () => {
973
1195
 
974
- const starts = object._multiDrawStarts;
975
- const counts = object._multiDrawCounts;
976
- const drawCount = object._multiDrawCount;
977
- const drawInstances = object._multiDrawInstances;
1196
+ if ( object.isBatchedMesh === true ) {
978
1197
 
979
- const bytesPerElement = hasIndex ? index.array.BYTES_PER_ELEMENT : 1;
1198
+ const starts = object._multiDrawStarts;
1199
+ const counts = object._multiDrawCounts;
1200
+ const drawCount = object._multiDrawCount;
1201
+ const drawInstances = object._multiDrawInstances;
980
1202
 
981
- for ( let i = 0; i < drawCount; i ++ ) {
1203
+ for ( let i = 0; i < drawCount; i ++ ) {
982
1204
 
983
- const count = drawInstances ? drawInstances[ i ] : 1;
984
- const firstInstance = count > 1 ? 0 : i;
1205
+ const count = drawInstances ? drawInstances[ i ] : 1;
1206
+ const firstInstance = count > 1 ? 0 : i;
985
1207
 
986
- passEncoderGPU.drawIndexed( counts[ i ], count, starts[ i ] / bytesPerElement, 0, firstInstance );
1208
+ if ( hasIndex === true ) {
987
1209
 
988
- }
1210
+ passEncoderGPU.drawIndexed( counts[ i ], count, starts[ i ] / index.array.BYTES_PER_ELEMENT, 0, firstInstance );
1211
+
1212
+ } else {
1213
+
1214
+ passEncoderGPU.draw( counts[ i ], count, starts[ i ], firstInstance );
1215
+
1216
+ }
1217
+
1218
+ }
1219
+
1220
+ } else if ( hasIndex === true ) {
1221
+
1222
+ const { vertexCount: indexCount, instanceCount, firstVertex: firstIndex } = drawParams;
1223
+
1224
+ const indirect = renderObject.getIndirect();
1225
+
1226
+ if ( indirect !== null ) {
989
1227
 
990
- } else if ( hasIndex === true ) {
1228
+ const buffer = this.get( indirect ).buffer;
991
1229
 
992
- const { vertexCount: indexCount, instanceCount, firstVertex: firstIndex } = drawParams;
1230
+ passEncoderGPU.drawIndexedIndirect( buffer, 0 );
993
1231
 
994
- const indirect = renderObject.getIndirect();
1232
+ } else {
995
1233
 
996
- if ( indirect !== null ) {
1234
+ passEncoderGPU.drawIndexed( indexCount, instanceCount, firstIndex, 0, 0 );
997
1235
 
998
- const buffer = this.get( indirect ).buffer;
1236
+ }
999
1237
 
1000
- passEncoderGPU.drawIndexedIndirect( buffer, 0 );
1238
+ info.update( object, indexCount, instanceCount );
1001
1239
 
1002
1240
  } else {
1003
1241
 
1004
- passEncoderGPU.drawIndexed( indexCount, instanceCount, firstIndex, 0, 0 );
1242
+ const { vertexCount, instanceCount, firstVertex } = drawParams;
1243
+
1244
+ const indirect = renderObject.getIndirect();
1245
+
1246
+ if ( indirect !== null ) {
1247
+
1248
+ const buffer = this.get( indirect ).buffer;
1249
+
1250
+ passEncoderGPU.drawIndirect( buffer, 0 );
1251
+
1252
+ } else {
1253
+
1254
+ passEncoderGPU.draw( vertexCount, instanceCount, firstVertex, 0 );
1255
+
1256
+ }
1257
+
1258
+ info.update( object, vertexCount, instanceCount );
1005
1259
 
1006
1260
  }
1007
1261
 
1008
- info.update( object, indexCount, instanceCount );
1262
+ };
1009
1263
 
1010
- } else {
1264
+ if ( renderObject.camera.isArrayCamera && renderObject.camera.cameras.length > 0 ) {
1011
1265
 
1012
- const { vertexCount, instanceCount, firstVertex } = drawParams;
1266
+ const cameraData = this.get( renderObject.camera );
1267
+ const cameras = renderObject.camera.cameras;
1268
+ const cameraIndex = renderObject.getBindingGroup( 'cameraIndex' );
1013
1269
 
1014
- const indirect = renderObject.getIndirect();
1270
+ if ( cameraData.indexesGPU === undefined || cameraData.indexesGPU.length !== cameras.length ) {
1015
1271
 
1016
- if ( indirect !== null ) {
1272
+ const bindingsData = this.get( cameraIndex );
1273
+ const indexesGPU = [];
1017
1274
 
1018
- const buffer = this.get( indirect ).buffer;
1275
+ const data = new Uint32Array( [ 0, 0, 0, 0 ] );
1019
1276
 
1020
- passEncoderGPU.drawIndirect( buffer, 0 );
1277
+ for ( let i = 0, len = cameras.length; i < len; i ++ ) {
1021
1278
 
1022
- } else {
1279
+ data[ 0 ] = i;
1280
+
1281
+ const bindGroupIndex = this.bindingUtils.createBindGroupIndex( data, bindingsData.layout );
1023
1282
 
1024
- passEncoderGPU.draw( vertexCount, instanceCount, firstVertex, 0 );
1283
+ indexesGPU.push( bindGroupIndex );
1284
+
1285
+ }
1286
+
1287
+ cameraData.indexesGPU = indexesGPU; // TODO: Create a global library for this
1288
+
1289
+ }
1290
+
1291
+ const pixelRatio = this.renderer.getPixelRatio();
1292
+
1293
+ for ( let i = 0, len = cameras.length; i < len; i ++ ) {
1294
+
1295
+ const subCamera = cameras[ i ];
1296
+
1297
+ if ( object.layers.test( subCamera.layers ) ) {
1298
+
1299
+ const vp = subCamera.viewport;
1300
+
1301
+ passEncoderGPU.setViewport(
1302
+ Math.floor( vp.x * pixelRatio ),
1303
+ Math.floor( vp.y * pixelRatio ),
1304
+ Math.floor( vp.width * pixelRatio ),
1305
+ Math.floor( vp.height * pixelRatio ),
1306
+ context.viewportValue.minDepth,
1307
+ context.viewportValue.maxDepth
1308
+ );
1309
+
1310
+ passEncoderGPU.setBindGroup( cameraIndex.index, cameraData.indexesGPU[ i ] );
1311
+
1312
+ draw();
1313
+
1314
+ }
1025
1315
 
1026
1316
  }
1027
1317
 
1028
- info.update( object, vertexCount, instanceCount );
1318
+ } else {
1319
+
1320
+ draw();
1029
1321
 
1030
1322
  }
1031
1323
 
@@ -1033,6 +1325,12 @@ class WebGPUBackend extends Backend {
1033
1325
 
1034
1326
  // cache key
1035
1327
 
1328
+ /**
1329
+ * Returns `true` if the render pipeline requires an update.
1330
+ *
1331
+ * @param {RenderObject} renderObject - The render object.
1332
+ * @return {Boolean} Whether the render pipeline requires an update or not.
1333
+ */
1036
1334
  needsRenderUpdate( renderObject ) {
1037
1335
 
1038
1336
  const data = this.get( renderObject );
@@ -1089,6 +1387,12 @@ class WebGPUBackend extends Backend {
1089
1387
 
1090
1388
  }
1091
1389
 
1390
+ /**
1391
+ * Returns a cache key that is used to identify render pipelines.
1392
+ *
1393
+ * @param {RenderObject} renderObject - The render object.
1394
+ * @return {String} The cache key.
1395
+ */
1092
1396
  getRenderCacheKey( renderObject ) {
1093
1397
 
1094
1398
  const { object, material } = renderObject;
@@ -1117,155 +1421,145 @@ class WebGPUBackend extends Backend {
1117
1421
 
1118
1422
  // textures
1119
1423
 
1424
+ /**
1425
+ * Creates a GPU sampler for the given texture.
1426
+ *
1427
+ * @param {Texture} texture - The texture to create the sampler for.
1428
+ */
1120
1429
  createSampler( texture ) {
1121
1430
 
1122
1431
  this.textureUtils.createSampler( texture );
1123
1432
 
1124
1433
  }
1125
1434
 
1435
+ /**
1436
+ * Destroys the GPU sampler for the given texture.
1437
+ *
1438
+ * @param {Texture} texture - The texture to destroy the sampler for.
1439
+ */
1126
1440
  destroySampler( texture ) {
1127
1441
 
1128
1442
  this.textureUtils.destroySampler( texture );
1129
1443
 
1130
1444
  }
1131
1445
 
1446
+ /**
1447
+ * Creates a default texture for the given texture that can be used
1448
+ * as a placeholder until the actual texture is ready for usage.
1449
+ *
1450
+ * @param {Texture} texture - The texture to create a default texture for.
1451
+ */
1132
1452
  createDefaultTexture( texture ) {
1133
1453
 
1134
1454
  this.textureUtils.createDefaultTexture( texture );
1135
1455
 
1136
1456
  }
1137
1457
 
1458
+ /**
1459
+ * Defines a texture on the GPU for the given texture object.
1460
+ *
1461
+ * @param {Texture} texture - The texture.
1462
+ * @param {Object} [options={}] - Optional configuration parameter.
1463
+ */
1138
1464
  createTexture( texture, options ) {
1139
1465
 
1140
1466
  this.textureUtils.createTexture( texture, options );
1141
1467
 
1142
1468
  }
1143
1469
 
1470
+ /**
1471
+ * Uploads the updated texture data to the GPU.
1472
+ *
1473
+ * @param {Texture} texture - The texture.
1474
+ * @param {Object} [options={}] - Optional configuration parameter.
1475
+ */
1144
1476
  updateTexture( texture, options ) {
1145
1477
 
1146
1478
  this.textureUtils.updateTexture( texture, options );
1147
1479
 
1148
1480
  }
1149
1481
 
1482
+ /**
1483
+ * Generates mipmaps for the given texture.
1484
+ *
1485
+ * @param {Texture} texture - The texture.
1486
+ */
1150
1487
  generateMipmaps( texture ) {
1151
1488
 
1152
1489
  this.textureUtils.generateMipmaps( texture );
1153
1490
 
1154
1491
  }
1155
1492
 
1493
+ /**
1494
+ * Destroys the GPU data for the given texture object.
1495
+ *
1496
+ * @param {Texture} texture - The texture.
1497
+ */
1156
1498
  destroyTexture( texture ) {
1157
1499
 
1158
1500
  this.textureUtils.destroyTexture( texture );
1159
1501
 
1160
1502
  }
1161
1503
 
1162
- copyTextureToBuffer( texture, x, y, width, height, faceIndex ) {
1504
+ /**
1505
+ * Returns texture data as a typed array.
1506
+ *
1507
+ * @async
1508
+ * @param {Texture} texture - The texture to copy.
1509
+ * @param {Number} x - The x coordinate of the copy origin.
1510
+ * @param {Number} y - The y coordinate of the copy origin.
1511
+ * @param {Number} width - The width of the copy.
1512
+ * @param {Number} height - The height of the copy.
1513
+ * @param {Number} faceIndex - The face index.
1514
+ * @return {Promise<TypedArray>} A Promise that resolves with a typed array when the copy operation has finished.
1515
+ */
1516
+ async copyTextureToBuffer( texture, x, y, width, height, faceIndex ) {
1163
1517
 
1164
1518
  return this.textureUtils.copyTextureToBuffer( texture, x, y, width, height, faceIndex );
1165
1519
 
1166
1520
  }
1167
1521
 
1168
-
1522
+ /**
1523
+ * Inits a time stamp query for the given render context.
1524
+ *
1525
+ * @param {RenderContext} renderContext - The render context.
1526
+ * @param {Object} descriptor - The query descriptor.
1527
+ */
1169
1528
  initTimestampQuery( renderContext, descriptor ) {
1170
1529
 
1171
1530
  if ( ! this.trackTimestamp ) return;
1172
1531
 
1173
- const renderContextData = this.get( renderContext );
1174
-
1175
- if ( ! renderContextData.timeStampQuerySet ) {
1176
-
1177
-
1178
- const type = renderContext.isComputeNode ? 'compute' : 'render';
1179
- const timeStampQuerySet = this.device.createQuerySet( { type: 'timestamp', count: 2, label: `timestamp_${type}_${renderContext.id}` } );
1180
-
1181
- const timestampWrites = {
1182
- querySet: timeStampQuerySet,
1183
- beginningOfPassWriteIndex: 0, // Write timestamp in index 0 when pass begins.
1184
- endOfPassWriteIndex: 1, // Write timestamp in index 1 when pass ends.
1185
- };
1532
+ const type = renderContext.isComputeNode ? 'compute' : 'render';
1186
1533
 
1187
- Object.assign( descriptor, { timestampWrites } );
1534
+ if ( ! this.timestampQueryPool[ type ] ) {
1188
1535
 
1189
- renderContextData.timeStampQuerySet = timeStampQuerySet;
1536
+ // TODO: Variable maxQueries?
1537
+ this.timestampQueryPool[ type ] = new WebGPUTimestampQueryPool( this.device, type, 2048 );
1190
1538
 
1191
1539
  }
1192
1540
 
1193
- }
1194
-
1195
- // timestamp utils
1196
-
1197
- prepareTimestampBuffer( renderContext, encoder ) {
1198
-
1199
- if ( ! this.trackTimestamp ) return;
1200
-
1201
- const renderContextData = this.get( renderContext );
1202
-
1541
+ const timestampQueryPool = this.timestampQueryPool[ type ];
1203
1542
 
1204
- const size = 2 * BigInt64Array.BYTES_PER_ELEMENT;
1543
+ const baseOffset = timestampQueryPool.allocateQueriesForContext( renderContext );
1205
1544
 
1206
- if ( renderContextData.currentTimestampQueryBuffers === undefined ) {
1207
-
1208
- renderContextData.currentTimestampQueryBuffers = {
1209
- resolveBuffer: this.device.createBuffer( {
1210
- label: 'timestamp resolve buffer',
1211
- size: size,
1212
- usage: GPUBufferUsage.QUERY_RESOLVE | GPUBufferUsage.COPY_SRC,
1213
- } ),
1214
- resultBuffer: this.device.createBuffer( {
1215
- label: 'timestamp result buffer',
1216
- size: size,
1217
- usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ,
1218
- } )
1219
- };
1220
-
1221
- }
1222
-
1223
- const { resolveBuffer, resultBuffer } = renderContextData.currentTimestampQueryBuffers;
1224
-
1225
-
1226
- encoder.resolveQuerySet( renderContextData.timeStampQuerySet, 0, 2, resolveBuffer, 0 );
1227
-
1228
- if ( resultBuffer.mapState === 'unmapped' ) {
1229
-
1230
- encoder.copyBufferToBuffer( resolveBuffer, 0, resultBuffer, 0, size );
1231
-
1232
- }
1545
+ descriptor.timestampWrites = {
1546
+ querySet: timestampQueryPool.querySet,
1547
+ beginningOfPassWriteIndex: baseOffset,
1548
+ endOfPassWriteIndex: baseOffset + 1,
1549
+ };
1233
1550
 
1234
1551
  }
1235
1552
 
1236
- async resolveTimestampAsync( renderContext, type = 'render' ) {
1237
-
1238
- if ( ! this.trackTimestamp ) return;
1239
-
1240
- const renderContextData = this.get( renderContext );
1241
-
1242
- if ( renderContextData.currentTimestampQueryBuffers === undefined ) return;
1243
-
1244
- const { resultBuffer } = renderContextData.currentTimestampQueryBuffers;
1245
-
1246
- await this.device.queue.onSubmittedWorkDone();
1247
-
1248
- if ( resultBuffer.mapState === 'unmapped' ) {
1249
-
1250
- resultBuffer.mapAsync( GPUMapMode.READ ).then( () => {
1251
-
1252
- const times = new BigUint64Array( resultBuffer.getMappedRange() );
1253
- const duration = Number( times[ 1 ] - times[ 0 ] ) / 1000000;
1254
-
1255
-
1256
- this.renderer.info.updateTimestamp( type, duration );
1257
-
1258
- resultBuffer.unmap();
1259
-
1260
-
1261
- } );
1262
-
1263
- }
1264
-
1265
- }
1266
1553
 
1267
1554
  // node builder
1268
1555
 
1556
+ /**
1557
+ * Returns a node builder for the given render object.
1558
+ *
1559
+ * @param {RenderObject} object - The render object.
1560
+ * @param {Renderer} renderer - The renderer.
1561
+ * @return {WGSLNodeBuilder} The node builder.
1562
+ */
1269
1563
  createNodeBuilder( object, renderer ) {
1270
1564
 
1271
1565
  return new WGSLNodeBuilder( object, renderer );
@@ -1274,17 +1568,27 @@ class WebGPUBackend extends Backend {
1274
1568
 
1275
1569
  // program
1276
1570
 
1571
+ /**
1572
+ * Creates a shader program from the given programmable stage.
1573
+ *
1574
+ * @param {ProgrammableStage} program - The programmable stage.
1575
+ */
1277
1576
  createProgram( program ) {
1278
1577
 
1279
1578
  const programGPU = this.get( program );
1280
1579
 
1281
1580
  programGPU.module = {
1282
- module: this.device.createShaderModule( { code: program.code, label: program.stage } ),
1581
+ module: this.device.createShaderModule( { code: program.code, label: program.stage + ( program.name !== '' ? `_${ program.name }` : '' ) } ),
1283
1582
  entryPoint: 'main'
1284
1583
  };
1285
1584
 
1286
1585
  }
1287
1586
 
1587
+ /**
1588
+ * Destroys the shader program of the given programmable stage.
1589
+ *
1590
+ * @param {ProgrammableStage} program - The programmable stage.
1591
+ */
1288
1592
  destroyProgram( program ) {
1289
1593
 
1290
1594
  this.delete( program );
@@ -1293,18 +1597,35 @@ class WebGPUBackend extends Backend {
1293
1597
 
1294
1598
  // pipelines
1295
1599
 
1600
+ /**
1601
+ * Creates a render pipeline for the given render object.
1602
+ *
1603
+ * @param {RenderObject} renderObject - The render object.
1604
+ * @param {Array<Promise>} promises - An array of compilation promises which are used in `compileAsync()`.
1605
+ */
1296
1606
  createRenderPipeline( renderObject, promises ) {
1297
1607
 
1298
1608
  this.pipelineUtils.createRenderPipeline( renderObject, promises );
1299
1609
 
1300
1610
  }
1301
1611
 
1612
+ /**
1613
+ * Creates a compute pipeline for the given compute node.
1614
+ *
1615
+ * @param {ComputePipeline} computePipeline - The compute pipeline.
1616
+ * @param {Array<BindGroup>} bindings - The bindings.
1617
+ */
1302
1618
  createComputePipeline( computePipeline, bindings ) {
1303
1619
 
1304
1620
  this.pipelineUtils.createComputePipeline( computePipeline, bindings );
1305
1621
 
1306
1622
  }
1307
1623
 
1624
+ /**
1625
+ * Prepares the state for encoding render bundles.
1626
+ *
1627
+ * @param {RenderContext} renderContext - The render context.
1628
+ */
1308
1629
  beginBundle( renderContext ) {
1309
1630
 
1310
1631
  const renderContextData = this.get( renderContext );
@@ -1317,6 +1638,12 @@ class WebGPUBackend extends Backend {
1317
1638
 
1318
1639
  }
1319
1640
 
1641
+ /**
1642
+ * After processing render bundles this method finalizes related work.
1643
+ *
1644
+ * @param {RenderContext} renderContext - The render context.
1645
+ * @param {RenderBundle} bundle - The render bundle.
1646
+ */
1320
1647
  finishBundle( renderContext, bundle ) {
1321
1648
 
1322
1649
  const renderContextData = this.get( renderContext );
@@ -1333,6 +1660,12 @@ class WebGPUBackend extends Backend {
1333
1660
 
1334
1661
  }
1335
1662
 
1663
+ /**
1664
+ * Adds a render bundle to the render context data.
1665
+ *
1666
+ * @param {RenderContext} renderContext - The render context.
1667
+ * @param {RenderBundle} bundle - The render bundle to add.
1668
+ */
1336
1669
  addBundle( renderContext, bundle ) {
1337
1670
 
1338
1671
  const renderContextData = this.get( renderContext );
@@ -1343,18 +1676,39 @@ class WebGPUBackend extends Backend {
1343
1676
 
1344
1677
  // bindings
1345
1678
 
1679
+ /**
1680
+ * Creates bindings from the given bind group definition.
1681
+ *
1682
+ * @param {BindGroup} bindGroup - The bind group.
1683
+ * @param {Array<BindGroup>} bindings - Array of bind groups.
1684
+ * @param {Number} cacheIndex - The cache index.
1685
+ * @param {Number} version - The version.
1686
+ */
1346
1687
  createBindings( bindGroup, bindings, cacheIndex, version ) {
1347
1688
 
1348
1689
  this.bindingUtils.createBindings( bindGroup, bindings, cacheIndex, version );
1349
1690
 
1350
1691
  }
1351
1692
 
1693
+ /**
1694
+ * Updates the given bind group definition.
1695
+ *
1696
+ * @param {BindGroup} bindGroup - The bind group.
1697
+ * @param {Array<BindGroup>} bindings - Array of bind groups.
1698
+ * @param {Number} cacheIndex - The cache index.
1699
+ * @param {Number} version - The version.
1700
+ */
1352
1701
  updateBindings( bindGroup, bindings, cacheIndex, version ) {
1353
1702
 
1354
1703
  this.bindingUtils.createBindings( bindGroup, bindings, cacheIndex, version );
1355
1704
 
1356
1705
  }
1357
1706
 
1707
+ /**
1708
+ * Updates a buffer binding.
1709
+ *
1710
+ * @param {Buffer} binding - The buffer binding to update.
1711
+ */
1358
1712
  updateBinding( binding ) {
1359
1713
 
1360
1714
  this.bindingUtils.updateBinding( binding );
@@ -1363,36 +1717,66 @@ class WebGPUBackend extends Backend {
1363
1717
 
1364
1718
  // attributes
1365
1719
 
1720
+ /**
1721
+ * Creates the buffer of an indexed shader attribute.
1722
+ *
1723
+ * @param {BufferAttribute} attribute - The indexed buffer attribute.
1724
+ */
1366
1725
  createIndexAttribute( attribute ) {
1367
1726
 
1368
1727
  this.attributeUtils.createAttribute( attribute, GPUBufferUsage.INDEX | GPUBufferUsage.COPY_SRC | GPUBufferUsage.COPY_DST );
1369
1728
 
1370
1729
  }
1371
1730
 
1731
+ /**
1732
+ * Creates the GPU buffer of a shader attribute.
1733
+ *
1734
+ * @param {BufferAttribute} attribute - The buffer attribute.
1735
+ */
1372
1736
  createAttribute( attribute ) {
1373
1737
 
1374
1738
  this.attributeUtils.createAttribute( attribute, GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_SRC | GPUBufferUsage.COPY_DST );
1375
1739
 
1376
1740
  }
1377
1741
 
1742
+ /**
1743
+ * Creates the GPU buffer of a storage attribute.
1744
+ *
1745
+ * @param {BufferAttribute} attribute - The buffer attribute.
1746
+ */
1378
1747
  createStorageAttribute( attribute ) {
1379
1748
 
1380
1749
  this.attributeUtils.createAttribute( attribute, GPUBufferUsage.STORAGE | GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_SRC | GPUBufferUsage.COPY_DST );
1381
1750
 
1382
1751
  }
1383
1752
 
1753
+ /**
1754
+ * Creates the GPU buffer of an indirect storage attribute.
1755
+ *
1756
+ * @param {BufferAttribute} attribute - The buffer attribute.
1757
+ */
1384
1758
  createIndirectStorageAttribute( attribute ) {
1385
1759
 
1386
1760
  this.attributeUtils.createAttribute( attribute, GPUBufferUsage.STORAGE | GPUBufferUsage.INDIRECT | GPUBufferUsage.COPY_SRC | GPUBufferUsage.COPY_DST );
1387
1761
 
1388
1762
  }
1389
1763
 
1764
+ /**
1765
+ * Updates the GPU buffer of a shader attribute.
1766
+ *
1767
+ * @param {BufferAttribute} attribute - The buffer attribute to update.
1768
+ */
1390
1769
  updateAttribute( attribute ) {
1391
1770
 
1392
1771
  this.attributeUtils.updateAttribute( attribute );
1393
1772
 
1394
1773
  }
1395
1774
 
1775
+ /**
1776
+ * Destroys the GPU buffer of a shader attribute.
1777
+ *
1778
+ * @param {BufferAttribute} attribute - The buffer attribute to destroy.
1779
+ */
1396
1780
  destroyAttribute( attribute ) {
1397
1781
 
1398
1782
  this.attributeUtils.destroyAttribute( attribute );
@@ -1401,6 +1785,9 @@ class WebGPUBackend extends Backend {
1401
1785
 
1402
1786
  // canvas
1403
1787
 
1788
+ /**
1789
+ * Triggers an update of the default render pass descriptor.
1790
+ */
1404
1791
  updateSize() {
1405
1792
 
1406
1793
  this.colorBuffer = this.textureUtils.getColorBuffer();
@@ -1410,18 +1797,38 @@ class WebGPUBackend extends Backend {
1410
1797
 
1411
1798
  // utils public
1412
1799
 
1800
+ /**
1801
+ * Returns the maximum anisotropy texture filtering value.
1802
+ *
1803
+ * @return {Number} The maximum anisotropy texture filtering value.
1804
+ */
1413
1805
  getMaxAnisotropy() {
1414
1806
 
1415
1807
  return 16;
1416
1808
 
1417
1809
  }
1418
1810
 
1811
+ /**
1812
+ * Checks if the given feature is supported by the backend.
1813
+ *
1814
+ * @param {String} name - The feature's name.
1815
+ * @return {Boolean} Whether the feature is supported or not.
1816
+ */
1419
1817
  hasFeature( name ) {
1420
1818
 
1421
1819
  return this.device.features.has( name );
1422
1820
 
1423
1821
  }
1424
1822
 
1823
+ /**
1824
+ * Copies data of the given source texture to the given destination texture.
1825
+ *
1826
+ * @param {Texture} srcTexture - The source texture.
1827
+ * @param {Texture} dstTexture - The destination texture.
1828
+ * @param {Vector4?} [srcRegion=null] - The region of the source texture to copy.
1829
+ * @param {(Vector2|Vector3)?} [dstPosition=null] - The destination position of the copy.
1830
+ * @param {Number} [level=0] - The mip level to copy.
1831
+ */
1425
1832
  copyTextureToTexture( srcTexture, dstTexture, srcRegion = null, dstPosition = null, level = 0 ) {
1426
1833
 
1427
1834
  let dstX = 0;
@@ -1480,6 +1887,13 @@ class WebGPUBackend extends Backend {
1480
1887
 
1481
1888
  }
1482
1889
 
1890
+ /**
1891
+ * Copies the current bound framebuffer to the given texture.
1892
+ *
1893
+ * @param {Texture} texture - The destination texture.
1894
+ * @param {RenderContext} renderContext - The render context.
1895
+ * @param {Vector4} rectangle - A four dimensional vector defining the origin and dimension of the copy.
1896
+ */
1483
1897
  copyFramebufferToTexture( texture, renderContext, rectangle ) {
1484
1898
 
1485
1899
  const renderContextData = this.get( renderContext );