@plastic-software/three 0.167.3 → 0.174.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 (748) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1 -1
  3. package/build/three.cjs +36277 -24023
  4. package/build/three.core.js +48830 -0
  5. package/build/three.core.min.js +6 -0
  6. package/build/three.module.js +10175 -46743
  7. package/build/three.module.min.js +2 -2
  8. package/build/three.tsl.js +550 -0
  9. package/build/three.tsl.min.js +6 -0
  10. package/build/three.webgpu.js +44348 -50670
  11. package/build/three.webgpu.min.js +2 -2
  12. package/build/three.webgpu.nodes.js +70301 -0
  13. package/build/three.webgpu.nodes.min.js +6 -0
  14. package/examples/jsm/Addons.js +3 -15
  15. package/examples/jsm/animation/AnimationClipCreator.js +1 -1
  16. package/examples/jsm/animation/CCDIKSolver.js +61 -11
  17. package/examples/jsm/capabilities/WebGL.js +27 -21
  18. package/examples/jsm/capabilities/WebGPU.js +1 -10
  19. package/examples/jsm/controls/ArcballControls.js +262 -231
  20. package/examples/jsm/controls/DragControls.js +1 -1
  21. package/examples/jsm/controls/FirstPersonControls.js +175 -163
  22. package/examples/jsm/controls/FlyControls.js +194 -188
  23. package/examples/jsm/controls/OrbitControls.js +801 -777
  24. package/examples/jsm/controls/PointerLockControls.js +26 -20
  25. package/examples/jsm/controls/TrackballControls.js +469 -448
  26. package/examples/jsm/controls/TransformControls.js +119 -68
  27. package/examples/jsm/csm/CSM.js +2 -2
  28. package/examples/jsm/csm/CSMFrustum.js +7 -4
  29. package/examples/jsm/csm/CSMHelper.js +2 -0
  30. package/examples/jsm/csm/CSMShadowNode.js +442 -0
  31. package/examples/jsm/curves/NURBSCurve.js +33 -2
  32. package/examples/jsm/curves/NURBSUtils.js +3 -0
  33. package/examples/jsm/effects/AnaglyphEffect.js +6 -13
  34. package/examples/jsm/effects/OutlineEffect.js +1 -1
  35. package/examples/jsm/effects/ParallaxBarrierEffect.js +17 -11
  36. package/examples/jsm/effects/StereoEffect.js +6 -1
  37. package/examples/jsm/exporters/DRACOExporter.js +4 -2
  38. package/examples/jsm/exporters/EXRExporter.js +19 -11
  39. package/examples/jsm/exporters/GLTFExporter.js +181 -109
  40. package/examples/jsm/exporters/KTX2Exporter.js +54 -23
  41. package/examples/jsm/exporters/OBJExporter.js +5 -1
  42. package/examples/jsm/exporters/PLYExporter.js +11 -9
  43. package/examples/jsm/exporters/USDZExporter.js +50 -11
  44. package/examples/jsm/geometries/DecalGeometry.js +73 -21
  45. package/examples/jsm/geometries/TextGeometry.js +1 -12
  46. package/examples/jsm/helpers/LightProbeHelper.js +43 -44
  47. package/examples/jsm/helpers/LightProbeHelperGPU.js +65 -0
  48. package/examples/jsm/helpers/TextureHelperGPU.js +185 -0
  49. package/examples/jsm/helpers/VertexNormalsHelper.js +2 -0
  50. package/examples/jsm/interactive/HTMLMesh.js +1 -0
  51. package/examples/jsm/interactive/InteractiveGroup.js +108 -51
  52. package/examples/jsm/interactive/SelectionHelper.js +3 -1
  53. package/examples/jsm/libs/basis/basis_transcoder.js +8 -10
  54. package/examples/jsm/libs/basis/basis_transcoder.wasm +0 -0
  55. package/examples/jsm/libs/demuxer_mp4.js +109 -0
  56. package/examples/jsm/libs/ktx-parse.module.js +1 -1
  57. package/examples/jsm/lighting/TiledLighting.js +18 -0
  58. package/examples/jsm/lights/LightProbeGenerator.js +26 -12
  59. package/examples/jsm/lights/RectAreaLightTexturesLib.js +1 -1
  60. package/examples/jsm/lines/LineGeometry.js +25 -0
  61. package/examples/jsm/lines/LineMaterial.js +0 -1
  62. package/examples/jsm/lines/LineSegmentsGeometry.js +2 -0
  63. package/examples/jsm/lines/webgpu/Line2.js +2 -1
  64. package/examples/jsm/lines/webgpu/LineSegments2.js +16 -21
  65. package/examples/jsm/lines/webgpu/Wireframe.js +57 -0
  66. package/examples/jsm/loaders/3DMLoader.js +1 -0
  67. package/examples/jsm/loaders/3MFLoader.js +104 -2
  68. package/examples/jsm/loaders/BVHLoader.js +1 -1
  69. package/examples/jsm/loaders/ColladaLoader.js +15 -12
  70. package/examples/jsm/loaders/DDSLoader.js +42 -0
  71. package/examples/jsm/loaders/DRACOLoader.js +3 -1
  72. package/examples/jsm/loaders/FBXLoader.js +71 -22
  73. package/examples/jsm/loaders/GCodeLoader.js +4 -2
  74. package/examples/jsm/loaders/GLTFLoader.js +29 -14
  75. package/examples/jsm/loaders/KTX2Loader.js +160 -58
  76. package/examples/jsm/loaders/KTXLoader.js +4 -4
  77. package/examples/jsm/loaders/LDrawLoader.js +22 -136
  78. package/examples/jsm/loaders/LottieLoader.js +2 -1
  79. package/examples/jsm/loaders/MTLLoader.js +27 -7
  80. package/examples/jsm/loaders/MaterialXLoader.js +40 -14
  81. package/examples/jsm/loaders/NRRDLoader.js +1 -1
  82. package/examples/jsm/loaders/OBJLoader.js +5 -3
  83. package/examples/jsm/loaders/PCDLoader.js +14 -13
  84. package/examples/jsm/loaders/PDBLoader.js +3 -2
  85. package/examples/jsm/loaders/PLYLoader.js +15 -12
  86. package/examples/jsm/loaders/PVRLoader.js +1 -1
  87. package/examples/jsm/loaders/STLLoader.js +3 -2
  88. package/examples/jsm/loaders/SVGLoader.js +2 -2
  89. package/examples/jsm/loaders/TDSLoader.js +17 -18
  90. package/examples/jsm/loaders/VRMLLoader.js +17 -17
  91. package/examples/jsm/loaders/VTKLoader.js +4 -3
  92. package/examples/jsm/loaders/XYZLoader.js +3 -2
  93. package/examples/jsm/loaders/lwo/IFFParser.js +4 -4
  94. package/examples/jsm/materials/LDrawConditionalLineMaterial.js +143 -0
  95. package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +114 -0
  96. package/examples/jsm/materials/MeshGouraudMaterial.js +2 -0
  97. package/examples/jsm/math/ColorSpaces.js +76 -0
  98. package/examples/jsm/math/ConvexHull.js +1 -1
  99. package/examples/jsm/math/OBB.js +17 -0
  100. package/examples/jsm/misc/GPUComputationRenderer.js +6 -7
  101. package/examples/jsm/misc/ProgressiveLightMap.js +54 -41
  102. package/examples/jsm/misc/ProgressiveLightMapGPU.js +294 -0
  103. package/examples/jsm/misc/Timer.js +27 -12
  104. package/examples/jsm/misc/Volume.js +28 -18
  105. package/examples/jsm/misc/VolumeSlice.js +19 -16
  106. package/examples/jsm/modifiers/CurveModifier.js +10 -8
  107. package/examples/jsm/modifiers/CurveModifierGPU.js +235 -0
  108. package/examples/jsm/modifiers/SimplifyModifier.js +2 -2
  109. package/examples/jsm/objects/GroundedSkybox.js +4 -4
  110. package/examples/jsm/objects/LensflareMesh.js +324 -0
  111. package/examples/jsm/objects/Reflector.js +5 -2
  112. package/examples/jsm/objects/Sky.js +2 -2
  113. package/examples/jsm/objects/SkyMesh.js +14 -14
  114. package/examples/jsm/objects/Water2.js +1 -1
  115. package/examples/jsm/objects/Water2Mesh.js +11 -9
  116. package/examples/jsm/objects/WaterMesh.js +38 -33
  117. package/examples/jsm/physics/JoltPhysics.js +8 -8
  118. package/examples/jsm/physics/RapierPhysics.js +5 -5
  119. package/examples/jsm/postprocessing/AfterimagePass.js +14 -3
  120. package/examples/jsm/postprocessing/BloomPass.js +2 -2
  121. package/examples/jsm/postprocessing/EffectComposer.js +1 -2
  122. package/examples/jsm/postprocessing/OutlinePass.js +37 -51
  123. package/examples/jsm/postprocessing/OutputPass.js +2 -0
  124. package/examples/jsm/postprocessing/SAOPass.js +1 -2
  125. package/examples/jsm/postprocessing/SMAAPass.js +1 -3
  126. package/examples/jsm/postprocessing/SSAARenderPass.js +3 -1
  127. package/examples/jsm/postprocessing/SSAOPass.js +2 -4
  128. package/examples/jsm/postprocessing/SSRPass.js +8 -4
  129. package/examples/jsm/postprocessing/UnrealBloomPass.js +2 -2
  130. package/examples/jsm/renderers/CSS2DRenderer.js +6 -3
  131. package/examples/jsm/renderers/CSS3DRenderer.js +7 -4
  132. package/examples/jsm/renderers/SVGRenderer.js +6 -4
  133. package/examples/jsm/shaders/BokehShader2.js +1 -1
  134. package/examples/jsm/shaders/FXAAShader.js +225 -224
  135. package/examples/jsm/shaders/GodRaysShader.js +3 -3
  136. package/examples/jsm/shaders/OutputShader.js +6 -2
  137. package/examples/jsm/shaders/SobelOperatorShader.js +1 -1
  138. package/examples/jsm/transpiler/AST.js +12 -2
  139. package/examples/jsm/transpiler/GLSLDecoder.js +77 -31
  140. package/examples/jsm/transpiler/ShaderToyDecoder.js +3 -3
  141. package/examples/jsm/transpiler/TSLEncoder.js +96 -21
  142. package/examples/jsm/tsl/display/AfterImageNode.js +243 -0
  143. package/examples/jsm/tsl/display/AnaglyphPassNode.js +106 -0
  144. package/examples/jsm/tsl/display/AnamorphicNode.js +257 -0
  145. package/{src/nodes/display/BleachBypassNode.js → examples/jsm/tsl/display/BleachBypass.js} +11 -6
  146. package/{src/nodes → examples/jsm/tsl}/display/BloomNode.js +252 -67
  147. package/examples/jsm/tsl/display/DenoiseNode.js +332 -0
  148. package/{src/nodes → examples/jsm/tsl}/display/DepthOfFieldNode.js +92 -14
  149. package/examples/jsm/tsl/display/DotScreenNode.js +103 -0
  150. package/examples/jsm/tsl/display/FXAANode.js +364 -0
  151. package/examples/jsm/tsl/display/FilmNode.js +100 -0
  152. package/examples/jsm/tsl/display/GTAONode.js +521 -0
  153. package/examples/jsm/tsl/display/GaussianBlurNode.js +393 -0
  154. package/examples/jsm/tsl/display/LensflareNode.js +278 -0
  155. package/examples/jsm/tsl/display/Lut3DNode.js +108 -0
  156. package/examples/jsm/tsl/display/MotionBlur.js +33 -0
  157. package/examples/jsm/tsl/display/OutlineNode.js +750 -0
  158. package/examples/jsm/tsl/display/ParallaxBarrierPassNode.js +88 -0
  159. package/{src/nodes → examples/jsm/tsl}/display/PixelationPassNode.js +160 -28
  160. package/examples/jsm/tsl/display/RGBShiftNode.js +95 -0
  161. package/examples/jsm/tsl/display/SMAANode.js +767 -0
  162. package/examples/jsm/tsl/display/SSAAPassNode.js +357 -0
  163. package/examples/jsm/tsl/display/SSRNode.js +538 -0
  164. package/examples/jsm/tsl/display/Sepia.js +24 -0
  165. package/{src/nodes → examples/jsm/tsl}/display/SobelOperatorNode.js +66 -20
  166. package/examples/jsm/tsl/display/StereoCompositePassNode.js +184 -0
  167. package/examples/jsm/tsl/display/StereoPassNode.js +119 -0
  168. package/examples/jsm/tsl/display/TRAAPassNode.js +451 -0
  169. package/examples/jsm/tsl/display/TransitionNode.js +140 -0
  170. package/examples/jsm/tsl/display/hashBlur.js +34 -0
  171. package/examples/jsm/tsl/lighting/TiledLightsNode.js +395 -0
  172. package/examples/jsm/tsl/math/Bayer.js +18 -0
  173. package/examples/jsm/tsl/utils/Raymarching.js +65 -0
  174. package/examples/jsm/utils/BufferGeometryUtils.js +2 -2
  175. package/examples/jsm/utils/CameraUtils.js +4 -1
  176. package/examples/jsm/utils/GeometryCompressionUtils.js +38 -123
  177. package/examples/jsm/utils/GeometryUtils.js +22 -19
  178. package/examples/jsm/utils/SceneOptimizer.js +410 -0
  179. package/examples/jsm/utils/SceneUtils.js +2 -2
  180. package/examples/jsm/utils/ShadowMapViewer.js +3 -8
  181. package/examples/jsm/utils/ShadowMapViewerGPU.js +201 -0
  182. package/examples/jsm/utils/SkeletonUtils.js +84 -66
  183. package/examples/jsm/utils/UVsDebug.js +1 -1
  184. package/examples/jsm/utils/{TextureUtils.js → WebGLTextureUtils.js} +1 -0
  185. package/examples/jsm/utils/WebGPUTextureUtils.js +64 -0
  186. package/examples/jsm/webxr/OculusHandPointerModel.js +21 -21
  187. package/examples/jsm/webxr/Text2D.js +6 -6
  188. package/examples/jsm/webxr/XRControllerModelFactory.js +7 -2
  189. package/examples/jsm/webxr/XREstimatedLight.js +1 -1
  190. package/package.json +14 -9
  191. package/src/Three.Core.js +182 -0
  192. package/src/Three.Legacy.js +0 -21
  193. package/src/Three.TSL.js +543 -0
  194. package/src/Three.WebGPU.Nodes.js +23 -0
  195. package/src/Three.WebGPU.js +13 -184
  196. package/src/Three.js +1 -176
  197. package/src/animation/AnimationClip.js +2 -2
  198. package/src/animation/AnimationObjectGroup.js +2 -2
  199. package/src/animation/AnimationUtils.js +1 -1
  200. package/src/animation/PropertyBinding.js +2 -2
  201. package/src/audio/Audio.js +379 -2
  202. package/src/audio/AudioAnalyser.js +58 -1
  203. package/src/audio/AudioContext.js +15 -0
  204. package/src/audio/AudioListener.js +76 -0
  205. package/src/audio/PositionalAudio.js +107 -0
  206. package/src/cameras/ArrayCamera.js +29 -0
  207. package/src/cameras/Camera.js +47 -0
  208. package/src/cameras/CubeCamera.js +66 -0
  209. package/src/cameras/OrthographicCamera.js +109 -0
  210. package/src/cameras/PerspectiveCamera.js +173 -34
  211. package/src/cameras/StereoCamera.js +48 -2
  212. package/src/constants.js +6 -6
  213. package/src/core/BufferAttribute.js +4 -9
  214. package/src/core/BufferGeometry.js +48 -8
  215. package/src/core/Clock.js +1 -1
  216. package/src/core/EventDispatcher.js +52 -8
  217. package/src/core/InterleavedBuffer.js +4 -13
  218. package/src/core/Object3D.js +573 -3
  219. package/src/core/RenderTarget.js +22 -4
  220. package/src/core/RenderTarget3D.js +22 -0
  221. package/src/core/RenderTargetArray.js +22 -0
  222. package/src/extras/Controls.js +104 -0
  223. package/src/extras/DataUtils.js +48 -8
  224. package/src/extras/Earcut.js +18 -7
  225. package/src/extras/ImageUtils.js +18 -11
  226. package/src/extras/PMREMGenerator.js +40 -9
  227. package/src/extras/ShapeUtils.js +24 -2
  228. package/src/extras/TextureUtils.js +96 -10
  229. package/src/extras/core/Curve.js +153 -53
  230. package/src/extras/core/CurvePath.js +63 -22
  231. package/src/extras/core/Interpolations.js +29 -3
  232. package/src/extras/core/Path.js +134 -1
  233. package/src/extras/core/Shape.js +66 -3
  234. package/src/extras/core/ShapePath.js +76 -0
  235. package/src/extras/curves/ArcCurve.js +22 -0
  236. package/src/extras/curves/CatmullRomCurve3.js +89 -18
  237. package/src/extras/curves/CubicBezierCurve.js +67 -0
  238. package/src/extras/curves/CubicBezierCurve3.js +50 -0
  239. package/src/extras/curves/EllipseCurve.js +102 -0
  240. package/src/extras/curves/LineCurve.js +36 -0
  241. package/src/extras/curves/LineCurve3.js +36 -0
  242. package/src/extras/curves/QuadraticBezierCurve.js +59 -0
  243. package/src/extras/curves/QuadraticBezierCurve3.js +43 -0
  244. package/src/extras/curves/SplineCurve.js +48 -0
  245. package/src/geometries/BoxGeometry.js +38 -0
  246. package/src/geometries/CapsuleGeometry.js +34 -0
  247. package/src/geometries/CircleGeometry.js +40 -0
  248. package/src/geometries/ConeGeometry.js +38 -0
  249. package/src/geometries/CylinderGeometry.js +50 -4
  250. package/src/geometries/DodecahedronGeometry.js +32 -0
  251. package/src/geometries/EdgesGeometry.js +30 -2
  252. package/src/geometries/ExtrudeGeometry.js +52 -0
  253. package/src/geometries/IcosahedronGeometry.js +32 -0
  254. package/src/geometries/LatheGeometry.js +43 -3
  255. package/src/geometries/OctahedronGeometry.js +32 -0
  256. package/src/geometries/PlaneGeometry.js +34 -0
  257. package/src/geometries/PolyhedronGeometry.js +29 -0
  258. package/src/geometries/RingGeometry.js +36 -0
  259. package/src/geometries/ShapeGeometry.js +37 -0
  260. package/src/geometries/SphereGeometry.js +37 -0
  261. package/src/geometries/TetrahedronGeometry.js +32 -0
  262. package/src/geometries/TorusGeometry.js +35 -0
  263. package/src/geometries/TorusKnotGeometry.js +38 -0
  264. package/src/geometries/TubeGeometry.js +49 -0
  265. package/src/geometries/WireframeGeometry.js +32 -0
  266. package/src/helpers/ArrowHelper.js +60 -3
  267. package/src/helpers/AxesHelper.js +28 -0
  268. package/src/helpers/Box3Helper.js +28 -0
  269. package/src/helpers/BoxHelper.js +43 -7
  270. package/src/helpers/CameraHelper.js +61 -18
  271. package/src/helpers/DirectionalLightHelper.js +52 -0
  272. package/src/helpers/GridHelper.js +26 -0
  273. package/src/helpers/HemisphereLightHelper.js +39 -0
  274. package/src/helpers/PlaneHelper.js +33 -0
  275. package/src/helpers/PointLightHelper.js +43 -0
  276. package/src/helpers/PolarGridHelper.js +30 -0
  277. package/src/helpers/SkeletonHelper.js +39 -2
  278. package/src/helpers/SpotLightHelper.js +40 -0
  279. package/src/lights/AmbientLight.js +25 -0
  280. package/src/lights/DirectionalLight.js +57 -0
  281. package/src/lights/DirectionalLightShadow.js +15 -0
  282. package/src/lights/HemisphereLight.js +32 -0
  283. package/src/lights/Light.js +36 -0
  284. package/src/lights/LightProbe.js +43 -0
  285. package/src/lights/LightShadow.js +159 -0
  286. package/src/lights/PointLight.js +59 -0
  287. package/src/lights/PointLightShadow.js +21 -0
  288. package/src/lights/RectAreaLight.js +59 -0
  289. package/src/lights/SpotLight.js +102 -0
  290. package/src/lights/SpotLightShadow.js +24 -2
  291. package/src/lights/webgpu/IESSpotLight.js +21 -0
  292. package/src/loaders/Loader.js +132 -0
  293. package/src/loaders/MaterialLoader.js +7 -1
  294. package/src/loaders/nodes/NodeLoader.js +189 -0
  295. package/src/loaders/nodes/NodeMaterialLoader.js +108 -0
  296. package/src/loaders/nodes/NodeObjectLoader.js +151 -0
  297. package/src/materials/LineDashedMaterial.js +0 -1
  298. package/src/materials/Material.js +469 -7
  299. package/src/materials/MeshPhongMaterial.js +1 -1
  300. package/src/materials/MeshPhysicalMaterial.js +2 -2
  301. package/src/materials/MeshStandardMaterial.js +2 -2
  302. package/src/{nodes/materials → materials/nodes}/Line2NodeMaterial.js +192 -82
  303. package/src/materials/nodes/LineBasicNodeMaterial.js +46 -0
  304. package/src/materials/nodes/LineDashedNodeMaterial.js +132 -0
  305. package/src/materials/nodes/MeshBasicNodeMaterial.js +133 -0
  306. package/src/materials/nodes/MeshLambertNodeMaterial.js +82 -0
  307. package/src/materials/nodes/MeshMatcapNodeMaterial.js +77 -0
  308. package/src/materials/nodes/MeshNormalNodeMaterial.js +67 -0
  309. package/src/materials/nodes/MeshPhongNodeMaterial.js +141 -0
  310. package/src/materials/nodes/MeshPhysicalNodeMaterial.js +517 -0
  311. package/src/materials/nodes/MeshSSSNodeMaterial.js +175 -0
  312. package/src/materials/nodes/MeshStandardNodeMaterial.js +186 -0
  313. package/src/materials/nodes/MeshToonNodeMaterial.js +66 -0
  314. package/src/materials/nodes/NodeMaterial.js +1180 -0
  315. package/src/{nodes/materials/Materials.js → materials/nodes/NodeMaterials.js} +3 -2
  316. package/src/materials/nodes/PointsNodeMaterial.js +153 -0
  317. package/src/materials/nodes/ShadowNodeMaterial.js +67 -0
  318. package/src/materials/nodes/SpriteNodeMaterial.js +198 -0
  319. package/src/materials/nodes/VolumeNodeMaterial.js +72 -0
  320. package/src/materials/nodes/manager/NodeMaterialObserver.js +509 -0
  321. package/src/math/Box2.js +177 -0
  322. package/src/math/Box3.js +243 -0
  323. package/src/math/Color.js +343 -0
  324. package/src/math/ColorManagement.js +143 -102
  325. package/src/math/Cylindrical.js +65 -6
  326. package/src/math/Euler.js +137 -4
  327. package/src/math/Frustum.js +83 -0
  328. package/src/math/Interpolant.js +87 -8
  329. package/src/math/Line3.js +96 -2
  330. package/src/math/MathUtils.js +182 -19
  331. package/src/math/Matrix2.js +70 -0
  332. package/src/math/Matrix3.js +229 -4
  333. package/src/math/Matrix4.js +368 -3
  334. package/src/math/Plane.js +164 -2
  335. package/src/math/Quaternion.js +265 -9
  336. package/src/math/Ray.js +160 -0
  337. package/src/math/Sphere.js +147 -0
  338. package/src/math/Spherical.js +73 -11
  339. package/src/math/SphericalHarmonics3.js +112 -14
  340. package/src/math/Triangle.js +230 -2
  341. package/src/math/Vector2.js +396 -10
  342. package/src/math/Vector3.js +550 -13
  343. package/src/math/Vector4.js +415 -9
  344. package/src/math/interpolants/CubicInterpolant.js +10 -1
  345. package/src/math/interpolants/DiscreteInterpolant.js +10 -2
  346. package/src/math/interpolants/LinearInterpolant.js +13 -0
  347. package/src/math/interpolants/QuaternionLinearInterpolant.js +10 -1
  348. package/src/nodes/Nodes.js +84 -166
  349. package/src/nodes/TSL.js +167 -0
  350. package/src/nodes/accessors/AccessorsUtils.js +39 -10
  351. package/src/nodes/accessors/Arrays.js +68 -0
  352. package/src/nodes/accessors/BatchNode.js +93 -26
  353. package/src/nodes/accessors/Bitangent.js +54 -0
  354. package/src/nodes/accessors/BufferAttributeNode.js +189 -11
  355. package/src/nodes/accessors/BufferNode.js +70 -5
  356. package/src/nodes/accessors/BuiltinNode.js +63 -0
  357. package/src/nodes/accessors/Camera.js +129 -0
  358. package/src/nodes/accessors/ClippingNode.js +152 -43
  359. package/src/nodes/accessors/CubeTextureNode.js +76 -13
  360. package/src/nodes/accessors/InstanceNode.js +118 -35
  361. package/src/nodes/accessors/InstancedMeshNode.js +50 -0
  362. package/src/nodes/accessors/Lights.js +129 -0
  363. package/src/nodes/accessors/MaterialNode.js +394 -58
  364. package/src/nodes/accessors/MaterialProperties.js +57 -1
  365. package/src/nodes/accessors/MaterialReferenceNode.js +60 -18
  366. package/src/nodes/accessors/ModelNode.js +159 -12
  367. package/src/nodes/accessors/ModelViewProjectionNode.js +10 -36
  368. package/src/nodes/accessors/MorphNode.js +60 -13
  369. package/src/nodes/accessors/Normal.js +156 -0
  370. package/src/nodes/accessors/Object3DNode.js +154 -35
  371. package/src/nodes/accessors/PointUVNode.js +35 -6
  372. package/src/nodes/accessors/Position.js +64 -0
  373. package/src/nodes/accessors/ReferenceBaseNode.js +357 -0
  374. package/src/nodes/accessors/ReferenceNode.js +243 -6
  375. package/src/nodes/accessors/ReflectVector.js +36 -0
  376. package/src/nodes/accessors/RendererReferenceNode.js +57 -7
  377. package/src/nodes/accessors/SceneNode.js +98 -6
  378. package/src/nodes/accessors/SkinningNode.js +214 -21
  379. package/src/nodes/accessors/StorageBufferNode.js +288 -28
  380. package/src/nodes/accessors/StorageTextureNode.js +139 -12
  381. package/src/nodes/accessors/Tangent.js +62 -0
  382. package/src/nodes/accessors/Texture3DNode.js +98 -12
  383. package/src/nodes/accessors/{TextureBicubicNode.js → TextureBicubic.js} +14 -34
  384. package/src/nodes/accessors/TextureNode.js +347 -34
  385. package/src/nodes/accessors/TextureSizeNode.js +51 -9
  386. package/src/nodes/accessors/UV.js +11 -0
  387. package/src/nodes/accessors/UniformArrayNode.js +241 -32
  388. package/src/nodes/accessors/UserDataNode.js +55 -7
  389. package/src/nodes/accessors/VelocityNode.js +223 -0
  390. package/src/nodes/accessors/VertexColorNode.js +45 -6
  391. package/src/nodes/code/CodeNode.js +108 -8
  392. package/src/nodes/code/ExpressionNode.js +38 -7
  393. package/src/nodes/code/FunctionCallNode.js +62 -11
  394. package/src/nodes/code/FunctionNode.js +54 -24
  395. package/src/nodes/code/ScriptableNode.js +241 -17
  396. package/src/nodes/code/ScriptableValueNode.js +93 -8
  397. package/src/nodes/core/ArrayNode.js +142 -0
  398. package/src/nodes/core/AssignNode.js +60 -12
  399. package/src/nodes/core/AttributeNode.js +55 -22
  400. package/src/nodes/core/BypassNode.js +59 -11
  401. package/src/nodes/core/CacheNode.js +64 -10
  402. package/src/nodes/core/ConstNode.js +38 -3
  403. package/src/nodes/core/ContextNode.js +87 -12
  404. package/src/nodes/core/IndexNode.js +102 -10
  405. package/src/nodes/core/InputNode.js +55 -3
  406. package/src/nodes/core/LightingModel.js +65 -5
  407. package/src/nodes/core/MRTNode.js +81 -7
  408. package/src/nodes/core/Node.js +368 -50
  409. package/src/nodes/core/NodeAttribute.js +38 -0
  410. package/src/nodes/core/NodeBuilder.js +1317 -83
  411. package/src/nodes/core/NodeCache.js +41 -2
  412. package/src/nodes/core/NodeCode.js +31 -0
  413. package/src/nodes/core/NodeFrame.js +123 -2
  414. package/src/nodes/core/NodeFunction.js +46 -0
  415. package/src/nodes/core/NodeFunctionInput.js +44 -0
  416. package/src/nodes/core/NodeParser.js +11 -0
  417. package/src/nodes/core/NodeUniform.js +52 -0
  418. package/src/nodes/core/NodeUtils.js +226 -6
  419. package/src/nodes/core/NodeVar.js +47 -1
  420. package/src/nodes/core/NodeVarying.js +28 -0
  421. package/src/nodes/core/OutputStructNode.js +61 -17
  422. package/src/nodes/core/ParameterNode.js +34 -4
  423. package/src/nodes/core/PropertyNode.js +296 -32
  424. package/src/nodes/core/StackNode.js +108 -8
  425. package/src/nodes/core/StructNode.js +120 -0
  426. package/src/nodes/core/StructType.js +13 -0
  427. package/src/nodes/core/StructTypeNode.js +116 -9
  428. package/src/nodes/core/TempNode.js +37 -7
  429. package/src/nodes/core/UniformGroupNode.js +98 -17
  430. package/src/nodes/core/UniformNode.js +72 -4
  431. package/src/nodes/core/VarNode.js +170 -13
  432. package/src/nodes/core/VaryingNode.js +109 -8
  433. package/src/nodes/core/constants.js +40 -0
  434. package/src/nodes/display/BlendModes.js +193 -0
  435. package/src/nodes/display/BumpMapNode.js +47 -10
  436. package/src/nodes/display/ColorAdjustment.js +141 -0
  437. package/src/nodes/display/ColorSpaceFunctions.js +54 -0
  438. package/src/nodes/display/ColorSpaceNode.js +147 -68
  439. package/src/nodes/display/FrontFacingNode.js +39 -6
  440. package/src/nodes/display/NormalMapNode.js +55 -13
  441. package/src/nodes/display/PassNode.js +420 -19
  442. package/src/nodes/display/PosterizeNode.js +40 -7
  443. package/src/nodes/display/RenderOutputNode.js +81 -13
  444. package/src/nodes/display/ScreenNode.js +286 -0
  445. package/src/nodes/display/ToneMappingFunctions.js +242 -0
  446. package/src/nodes/display/ToneMappingNode.js +68 -175
  447. package/src/nodes/display/ToonOutlinePassNode.js +183 -0
  448. package/src/nodes/display/ViewportDepthNode.js +210 -36
  449. package/src/nodes/display/ViewportDepthTextureNode.js +32 -9
  450. package/src/nodes/display/ViewportSharedTextureNode.js +32 -9
  451. package/src/nodes/display/ViewportTextureNode.js +68 -11
  452. package/src/nodes/fog/Fog.js +113 -0
  453. package/src/nodes/functions/BSDF/BRDF_GGX.js +4 -4
  454. package/src/nodes/functions/BSDF/BRDF_Lambert.js +2 -2
  455. package/src/nodes/functions/BSDF/BRDF_Sheen.js +6 -6
  456. package/src/nodes/functions/BSDF/DFGApprox.js +2 -2
  457. package/src/nodes/functions/BSDF/D_GGX.js +2 -2
  458. package/src/nodes/functions/BSDF/D_GGX_Anisotropic.js +3 -3
  459. package/src/nodes/functions/BSDF/EnvironmentBRDF.js +2 -2
  460. package/src/nodes/functions/BSDF/F_Schlick.js +2 -2
  461. package/src/nodes/functions/BSDF/LTC.js +50 -6
  462. package/src/nodes/functions/BSDF/Schlick_to_F0.js +2 -2
  463. package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated.js +2 -2
  464. package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated_Anisotropic.js +2 -2
  465. package/src/nodes/functions/BasicLightingModel.js +27 -6
  466. package/src/nodes/functions/PhongLightingModel.js +38 -8
  467. package/src/nodes/functions/PhysicalLightingModel.js +215 -51
  468. package/src/nodes/functions/ShadowMaskModel.js +24 -1
  469. package/src/nodes/functions/ToonLightingModel.js +24 -5
  470. package/src/nodes/functions/VolumetricLightingModel.js +183 -0
  471. package/src/nodes/functions/material/getAlphaHashThreshold.js +68 -0
  472. package/src/nodes/functions/material/getGeometryRoughness.js +10 -4
  473. package/src/nodes/functions/material/getParallaxCorrectNormal.js +37 -0
  474. package/src/nodes/functions/material/getRoughness.js +2 -2
  475. package/src/nodes/functions/material/getShIrradianceAt.js +28 -0
  476. package/src/nodes/geometry/RangeNode.js +62 -7
  477. package/src/nodes/gpgpu/AtomicFunctionNode.js +280 -0
  478. package/src/nodes/gpgpu/BarrierNode.js +89 -0
  479. package/src/nodes/gpgpu/ComputeBuiltinNode.js +227 -0
  480. package/src/nodes/gpgpu/ComputeNode.js +124 -9
  481. package/src/nodes/gpgpu/WorkgroupInfoNode.js +208 -0
  482. package/src/nodes/lighting/AONode.js +24 -3
  483. package/src/nodes/lighting/AmbientLightNode.js +16 -8
  484. package/src/nodes/lighting/AnalyticLightNode.js +151 -231
  485. package/src/nodes/lighting/BasicEnvironmentNode.js +25 -3
  486. package/src/nodes/lighting/BasicLightMapNode.js +25 -5
  487. package/src/nodes/lighting/DirectionalLightNode.js +19 -20
  488. package/src/nodes/lighting/EnvironmentNode.js +34 -17
  489. package/src/nodes/lighting/HemisphereLightNode.js +42 -11
  490. package/src/nodes/lighting/IESSpotLightNode.js +18 -9
  491. package/src/nodes/lighting/IrradianceNode.js +23 -3
  492. package/src/nodes/lighting/LightProbeNode.js +29 -36
  493. package/src/nodes/lighting/LightUtils.js +12 -4
  494. package/src/nodes/lighting/LightingContextNode.js +70 -21
  495. package/src/nodes/lighting/LightingNode.js +22 -9
  496. package/src/nodes/lighting/LightsNode.js +309 -86
  497. package/src/nodes/lighting/PointLightNode.js +66 -32
  498. package/src/nodes/lighting/PointShadowNode.js +306 -0
  499. package/src/nodes/lighting/RectAreaLightNode.js +61 -25
  500. package/src/nodes/lighting/ShadowBaseNode.js +92 -0
  501. package/src/nodes/lighting/ShadowNode.js +812 -0
  502. package/src/nodes/lighting/SpotLightNode.js +73 -31
  503. package/src/nodes/materialx/MaterialXNodes.js +2 -2
  504. package/src/nodes/materialx/lib/mx_hsv.js +27 -22
  505. package/src/nodes/materialx/lib/mx_noise.js +70 -70
  506. package/src/nodes/materialx/lib/mx_transform_color.js +2 -2
  507. package/src/nodes/math/ConditionalNode.js +230 -0
  508. package/src/nodes/math/Hash.js +21 -0
  509. package/src/nodes/math/MathNode.js +812 -131
  510. package/src/nodes/math/MathUtils.js +47 -8
  511. package/src/nodes/math/OperatorNode.js +410 -66
  512. package/src/nodes/math/TriNoise3D.js +32 -32
  513. package/src/nodes/parsers/GLSLNodeFunction.js +16 -0
  514. package/src/nodes/parsers/GLSLNodeParser.js +11 -0
  515. package/src/nodes/pmrem/PMREMNode.js +188 -28
  516. package/src/nodes/pmrem/PMREMUtils.js +24 -24
  517. package/src/nodes/procedural/Checker.js +22 -0
  518. package/src/nodes/shapes/Shapes.js +32 -0
  519. package/src/nodes/tsl/TSLBase.js +31 -0
  520. package/src/nodes/{shadernode/ShaderNode.js → tsl/TSLCore.js} +114 -98
  521. package/src/nodes/utils/ArrayElementNode.js +45 -5
  522. package/src/nodes/utils/ConvertNode.js +39 -4
  523. package/src/nodes/utils/CubeMapNode.js +88 -8
  524. package/src/nodes/utils/Discard.js +24 -0
  525. package/src/nodes/utils/EquirectUVNode.js +39 -7
  526. package/src/nodes/utils/FlipNode.js +106 -0
  527. package/src/nodes/utils/FunctionOverloadingNode.js +61 -6
  528. package/src/nodes/utils/JoinNode.js +31 -3
  529. package/src/nodes/utils/LoopNode.js +95 -9
  530. package/src/nodes/utils/MatcapUVNode.js +27 -8
  531. package/src/nodes/utils/MaxMipLevelNode.js +57 -6
  532. package/src/nodes/utils/MemberNode.js +68 -0
  533. package/src/nodes/utils/Oscillators.js +41 -0
  534. package/src/nodes/utils/Packing.js +21 -0
  535. package/src/nodes/utils/PostProcessingUtils.js +95 -0
  536. package/src/nodes/utils/RTTNode.js +141 -9
  537. package/src/nodes/utils/ReflectorNode.js +295 -21
  538. package/src/nodes/utils/RemapNode.js +93 -10
  539. package/src/nodes/utils/RotateNode.js +48 -13
  540. package/src/nodes/utils/SetNode.js +50 -4
  541. package/src/nodes/utils/SplitNode.js +62 -6
  542. package/src/nodes/utils/SpriteSheetUVNode.js +56 -7
  543. package/src/nodes/utils/SpriteUtils.js +21 -5
  544. package/src/nodes/utils/StorageArrayElementNode.js +64 -12
  545. package/src/nodes/utils/Timer.js +73 -0
  546. package/src/nodes/utils/TriplanarTexturesNode.js +96 -10
  547. package/src/nodes/utils/UVUtils.js +27 -9
  548. package/src/nodes/utils/ViewportUtils.js +16 -4
  549. package/src/objects/BatchedMesh.js +808 -281
  550. package/src/objects/Bone.js +24 -0
  551. package/src/objects/ClippingGroup.js +68 -0
  552. package/src/objects/Group.js +24 -0
  553. package/src/objects/InstancedMesh.js +120 -2
  554. package/src/objects/LOD.js +120 -5
  555. package/src/objects/Line.js +89 -6
  556. package/src/objects/LineLoop.js +20 -0
  557. package/src/objects/LineSegments.js +18 -0
  558. package/src/objects/Mesh.js +82 -23
  559. package/src/objects/Points.js +62 -0
  560. package/src/objects/Skeleton.js +107 -2
  561. package/src/objects/SkinnedMesh.js +99 -5
  562. package/src/objects/Sprite.js +54 -0
  563. package/src/renderers/WebGLRenderer.js +274 -157
  564. package/src/renderers/common/Animation.js +109 -12
  565. package/src/renderers/common/Attributes.js +40 -0
  566. package/src/renderers/common/Backend.js +504 -44
  567. package/src/renderers/common/Background.js +67 -9
  568. package/src/renderers/common/BindGroup.js +45 -1
  569. package/src/renderers/common/Binding.js +35 -0
  570. package/src/renderers/common/Bindings.js +136 -19
  571. package/src/renderers/common/Buffer.js +49 -0
  572. package/src/renderers/common/BufferUtils.js +25 -0
  573. package/src/renderers/common/BundleGroup.js +83 -0
  574. package/src/renderers/common/ChainMap.js +45 -6
  575. package/src/renderers/common/ClippingContext.js +175 -80
  576. package/src/renderers/common/Color4.js +40 -0
  577. package/src/renderers/common/ComputePipeline.js +24 -0
  578. package/src/renderers/common/Constants.js +2 -1
  579. package/src/renderers/common/CubeRenderTarget.js +22 -3
  580. package/src/renderers/common/DataMap.js +37 -1
  581. package/src/renderers/common/Geometries.js +111 -14
  582. package/src/renderers/common/IndirectStorageBufferAttribute.js +38 -0
  583. package/src/renderers/common/Info.js +78 -35
  584. package/src/renderers/common/Lighting.js +73 -0
  585. package/src/renderers/common/Pipeline.js +22 -0
  586. package/src/renderers/common/Pipelines.js +148 -5
  587. package/src/renderers/common/PostProcessing.js +112 -11
  588. package/src/renderers/common/ProgrammableStage.js +60 -2
  589. package/src/renderers/common/QuadMesh.js +56 -5
  590. package/src/renderers/common/RenderBundle.js +14 -8
  591. package/src/renderers/common/RenderBundles.js +39 -10
  592. package/src/renderers/common/RenderContext.js +205 -7
  593. package/src/renderers/common/RenderContexts.js +59 -6
  594. package/src/renderers/common/RenderList.js +230 -21
  595. package/src/renderers/common/RenderLists.js +45 -6
  596. package/src/renderers/common/RenderObject.js +552 -41
  597. package/src/renderers/common/RenderObjects.js +118 -9
  598. package/src/renderers/common/RenderPipeline.js +24 -0
  599. package/src/renderers/common/Renderer.js +1537 -239
  600. package/src/renderers/common/RendererUtils.js +191 -0
  601. package/src/renderers/common/SampledTexture.js +132 -3
  602. package/src/renderers/common/Sampler.js +30 -0
  603. package/src/renderers/common/StorageBuffer.js +24 -0
  604. package/src/renderers/common/StorageBufferAttribute.js +31 -2
  605. package/src/renderers/common/StorageInstancedBufferAttribute.js +31 -2
  606. package/src/renderers/common/StorageTexture.js +38 -0
  607. package/src/renderers/common/Textures.js +142 -32
  608. package/src/renderers/common/TimestampQueryPool.js +98 -0
  609. package/src/renderers/common/Uniform.js +225 -3
  610. package/src/renderers/common/UniformBuffer.js +19 -0
  611. package/src/renderers/common/UniformsGroup.js +157 -6
  612. package/src/renderers/common/XRManager.js +1185 -0
  613. package/src/renderers/common/XRRenderTarget.js +74 -0
  614. package/src/renderers/common/extras/PMREMGenerator.js +211 -53
  615. package/src/renderers/common/nodes/NodeBuilderState.js +100 -6
  616. package/src/renderers/common/nodes/NodeLibrary.js +194 -0
  617. package/src/renderers/common/nodes/NodeSampledTexture.js +92 -4
  618. package/src/renderers/common/nodes/NodeSampler.js +28 -0
  619. package/src/renderers/common/nodes/NodeStorageBuffer.js +37 -3
  620. package/src/renderers/common/nodes/NodeUniform.js +285 -2
  621. package/src/renderers/common/nodes/NodeUniformBuffer.js +29 -0
  622. package/src/renderers/common/nodes/NodeUniformsGroup.js +31 -18
  623. package/src/renderers/common/nodes/Nodes.js +390 -70
  624. package/src/renderers/shaders/ShaderChunk/colorspace_pars_fragment.glsl.js +4 -24
  625. package/src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl.js +8 -0
  626. package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +2 -2
  627. package/src/renderers/shaders/ShaderChunk/map_fragment.glsl.js +2 -2
  628. package/src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl.js +2 -2
  629. package/src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js +7 -7
  630. package/src/renderers/shaders/ShaderLib/points.glsl.js +2 -0
  631. package/src/renderers/shaders/ShaderLib/sprite.glsl.js +2 -4
  632. package/src/renderers/webgl/WebGLAttributes.js +45 -14
  633. package/src/renderers/webgl/WebGLBackground.js +24 -1
  634. package/src/renderers/webgl/WebGLBufferRenderer.js +2 -6
  635. package/src/renderers/webgl/WebGLCapabilities.js +2 -0
  636. package/src/renderers/webgl/WebGLGeometries.js +0 -28
  637. package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +2 -6
  638. package/src/renderers/webgl/WebGLProgram.js +27 -29
  639. package/src/renderers/webgl/WebGLPrograms.js +24 -16
  640. package/src/renderers/webgl/WebGLState.js +68 -11
  641. package/src/renderers/webgl/WebGLTextures.js +49 -10
  642. package/src/renderers/webgl-fallback/WebGLBackend.js +1055 -238
  643. package/src/renderers/webgl-fallback/WebGLBufferRenderer.js +5 -10
  644. package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +425 -48
  645. package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +64 -1
  646. package/src/renderers/webgl-fallback/utils/WebGLCapabilities.js +28 -0
  647. package/src/renderers/webgl-fallback/utils/WebGLExtensions.js +45 -0
  648. package/src/renderers/webgl-fallback/utils/WebGLState.js +419 -14
  649. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +281 -59
  650. package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +367 -0
  651. package/src/renderers/webgl-fallback/utils/WebGLUtils.js +43 -0
  652. package/src/renderers/webgpu/WebGPUBackend.js +816 -236
  653. package/src/renderers/webgpu/WebGPURenderer.Nodes.js +78 -0
  654. package/src/renderers/webgpu/WebGPURenderer.js +45 -6
  655. package/src/renderers/webgpu/nodes/BasicNodeLibrary.js +63 -0
  656. package/src/renderers/webgpu/nodes/StandardNodeLibrary.js +97 -0
  657. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +954 -147
  658. package/src/renderers/webgpu/nodes/WGSLNodeFunction.js +29 -4
  659. package/src/renderers/webgpu/nodes/WGSLNodeParser.js +11 -0
  660. package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +147 -31
  661. package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +213 -31
  662. package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +146 -28
  663. package/src/renderers/webgpu/utils/WebGPUTexturePassUtils.js +161 -7
  664. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +333 -50
  665. package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +287 -0
  666. package/src/renderers/webgpu/utils/WebGPUUtils.js +131 -3
  667. package/src/renderers/webxr/WebXRDepthSensing.js +1 -1
  668. package/src/renderers/webxr/WebXRManager.js +54 -32
  669. package/src/scenes/Fog.js +60 -0
  670. package/src/scenes/FogExp2.js +51 -0
  671. package/src/scenes/Scene.js +87 -0
  672. package/src/textures/Data3DTexture.js +2 -2
  673. package/src/textures/DepthTexture.js +2 -0
  674. package/src/textures/Source.js +2 -2
  675. package/src/textures/Texture.js +368 -5
  676. package/src/textures/VideoFrameTexture.js +35 -0
  677. package/src/utils.js +33 -1
  678. package/examples/jsm/animation/MMDAnimationHelper.js +0 -1207
  679. package/examples/jsm/animation/MMDPhysics.js +0 -1406
  680. package/examples/jsm/cameras/CinematicCamera.js +0 -208
  681. package/examples/jsm/controls/Controls.js +0 -32
  682. package/examples/jsm/exporters/MMDExporter.js +0 -217
  683. package/examples/jsm/geometries/InstancedPointsGeometry.js +0 -174
  684. package/examples/jsm/geometries/SDFGeometryGenerator.js +0 -144
  685. package/examples/jsm/libs/mmdparser.module.js +0 -11530
  686. package/examples/jsm/loaders/LogLuvLoader.js +0 -606
  687. package/examples/jsm/loaders/MMDLoader.js +0 -2295
  688. package/examples/jsm/loaders/TiltLoader.js +0 -520
  689. package/examples/jsm/objects/InstancedPoints.js +0 -21
  690. package/examples/jsm/shaders/MMDToonShader.js +0 -134
  691. package/examples/jsm/utils/GPUStatsPanel.js +0 -95
  692. package/examples/jsm/utils/PackedPhongMaterial.js +0 -178
  693. package/src/nodes/accessors/BitangentNode.js +0 -13
  694. package/src/nodes/accessors/CameraNode.js +0 -19
  695. package/src/nodes/accessors/InstancedPointsMaterialNode.js +0 -21
  696. package/src/nodes/accessors/NormalNode.js +0 -14
  697. package/src/nodes/accessors/PositionNode.js +0 -10
  698. package/src/nodes/accessors/ReflectVectorNode.js +0 -10
  699. package/src/nodes/accessors/TangentNode.js +0 -23
  700. package/src/nodes/accessors/UVNode.js +0 -3
  701. package/src/nodes/core/NodeKeywords.js +0 -80
  702. package/src/nodes/core/UniformGroup.js +0 -13
  703. package/src/nodes/display/AfterImageNode.js +0 -152
  704. package/src/nodes/display/AnamorphicNode.js +0 -145
  705. package/src/nodes/display/BlendModeNode.js +0 -128
  706. package/src/nodes/display/ColorAdjustmentNode.js +0 -104
  707. package/src/nodes/display/DenoiseNode.js +0 -198
  708. package/src/nodes/display/DotScreenNode.js +0 -75
  709. package/src/nodes/display/FXAANode.js +0 -327
  710. package/src/nodes/display/FilmNode.js +0 -52
  711. package/src/nodes/display/GTAONode.js +0 -324
  712. package/src/nodes/display/GaussianBlurNode.js +0 -207
  713. package/src/nodes/display/Lut3DNode.js +0 -53
  714. package/src/nodes/display/RGBShiftNode.js +0 -49
  715. package/src/nodes/display/SepiaNode.js +0 -18
  716. package/src/nodes/display/TransitionNode.js +0 -76
  717. package/src/nodes/display/ViewportNode.js +0 -137
  718. package/src/nodes/fog/FogExp2Node.js +0 -34
  719. package/src/nodes/fog/FogNode.js +0 -48
  720. package/src/nodes/fog/FogRangeNode.js +0 -35
  721. package/src/nodes/lighting/LightNode.js +0 -57
  722. package/src/nodes/loaders/NodeLoader.js +0 -110
  723. package/src/nodes/loaders/NodeMaterialLoader.js +0 -60
  724. package/src/nodes/loaders/NodeObjectLoader.js +0 -71
  725. package/src/nodes/materials/InstancedPointsNodeMaterial.js +0 -162
  726. package/src/nodes/materials/LineBasicNodeMaterial.js +0 -28
  727. package/src/nodes/materials/LineDashedNodeMaterial.js +0 -55
  728. package/src/nodes/materials/MeshBasicNodeMaterial.js +0 -73
  729. package/src/nodes/materials/MeshLambertNodeMaterial.js +0 -43
  730. package/src/nodes/materials/MeshMatcapNodeMaterial.js +0 -53
  731. package/src/nodes/materials/MeshNormalNodeMaterial.js +0 -40
  732. package/src/nodes/materials/MeshPhongNodeMaterial.js +0 -74
  733. package/src/nodes/materials/MeshPhysicalNodeMaterial.js +0 -244
  734. package/src/nodes/materials/MeshSSSNodeMaterial.js +0 -84
  735. package/src/nodes/materials/MeshStandardNodeMaterial.js +0 -104
  736. package/src/nodes/materials/MeshToonNodeMaterial.js +0 -34
  737. package/src/nodes/materials/NodeMaterial.js +0 -680
  738. package/src/nodes/materials/PointsNodeMaterial.js +0 -39
  739. package/src/nodes/materials/ShadowNodeMaterial.js +0 -34
  740. package/src/nodes/materials/SpriteNodeMaterial.js +0 -90
  741. package/src/nodes/materials/VolumeNodeMaterial.js +0 -106
  742. package/src/nodes/math/CondNode.js +0 -139
  743. package/src/nodes/math/HashNode.js +0 -34
  744. package/src/nodes/procedural/CheckerNode.js +0 -42
  745. package/src/nodes/utils/DiscardNode.js +0 -28
  746. package/src/nodes/utils/OscNode.js +0 -81
  747. package/src/nodes/utils/PackingNode.js +0 -55
  748. package/src/nodes/utils/TimerNode.js +0 -94
@@ -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, GPUTextureFormat, GPULoadOp, GPUStoreOp, GPUIndexFormat, GPUTextureViewDimension } from './utils/WebGPUConstants.js';
5
+ import { GPUFeatureName, GPULoadOp, GPUStoreOp, GPUIndexFormat, GPUTextureViewDimension } from './utils/WebGPUConstants.js';
6
6
 
7
7
  import WGSLNodeBuilder from './nodes/WGSLNodeBuilder.js';
8
8
  import Backend from '../common/Backend.js';
@@ -14,15 +14,45 @@ 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
+ import { warnOnce } from '../../utils.js';
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
+ * Constructs a new WebGPU backend.
30
+ *
31
+ * @param {Object} parameters - The configuration parameter.
32
+ * @param {boolean} [parameters.logarithmicDepthBuffer=false] - Whether logarithmic depth buffer is enabled or not.
33
+ * @param {boolean} [parameters.alpha=true] - Whether the default framebuffer (which represents the final contents of the canvas) should be transparent or opaque.
34
+ * @param {boolean} [parameters.depth=true] - Whether the default framebuffer should have a depth buffer or not.
35
+ * @param {boolean} [parameters.stencil=false] - Whether the default framebuffer should have a stencil buffer or not.
36
+ * @param {boolean} [parameters.antialias=false] - Whether MSAA as the default anti-aliasing should be enabled or not.
37
+ * @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.
38
+ * @param {boolean} [parameters.forceWebGL=false] - If set to `true`, the renderer uses a WebGL 2 backend no matter if WebGPU is supported or not.
39
+ * @param {boolean} [parameters.trackTimestamp=false] - Whether to track timestamps with a Timestamp Query API or not.
40
+ * @param {string} [parameters.powerPreference=undefined] - The power preference.
41
+ * @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.
42
+ * @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.
43
+ * @param {number} [parameters.outputType=undefined] - Texture type for output to canvas. By default, device's preferred format is used; other formats may incur overhead.
44
+ */
22
45
  constructor( parameters = {} ) {
23
46
 
24
47
  super( parameters );
25
48
 
49
+ /**
50
+ * This flag can be used for type testing.
51
+ *
52
+ * @type {boolean}
53
+ * @readonly
54
+ * @default true
55
+ */
26
56
  this.isWebGPUBackend = true;
27
57
 
28
58
  // some parameters require default values other than "undefined"
@@ -30,22 +60,101 @@ class WebGPUBackend extends Backend {
30
60
 
31
61
  this.parameters.requiredLimits = ( parameters.requiredLimits === undefined ) ? {} : parameters.requiredLimits;
32
62
 
63
+ /**
64
+ * Whether to track timestamps with a Timestamp Query API or not.
65
+ *
66
+ * @type {boolean}
67
+ * @default false
68
+ */
33
69
  this.trackTimestamp = ( parameters.trackTimestamp === true );
34
70
 
71
+ /**
72
+ * A reference to the device.
73
+ *
74
+ * @type {?GPUDevice}
75
+ * @default null
76
+ */
35
77
  this.device = null;
78
+
79
+ /**
80
+ * A reference to the context.
81
+ *
82
+ * @type {?GPUCanvasContext}
83
+ * @default null
84
+ */
36
85
  this.context = null;
86
+
87
+ /**
88
+ * A reference to the color attachment of the default framebuffer.
89
+ *
90
+ * @type {?GPUTexture}
91
+ * @default null
92
+ */
37
93
  this.colorBuffer = null;
94
+
95
+ /**
96
+ * A reference to the default render pass descriptor.
97
+ *
98
+ * @type {?Object}
99
+ * @default null
100
+ */
38
101
  this.defaultRenderPassdescriptor = null;
39
102
 
103
+ /**
104
+ * A reference to a backend module holding common utility functions.
105
+ *
106
+ * @type {WebGPUUtils}
107
+ */
40
108
  this.utils = new WebGPUUtils( this );
109
+
110
+ /**
111
+ * A reference to a backend module holding shader attribute-related
112
+ * utility functions.
113
+ *
114
+ * @type {WebGPUAttributeUtils}
115
+ */
41
116
  this.attributeUtils = new WebGPUAttributeUtils( this );
117
+
118
+ /**
119
+ * A reference to a backend module holding shader binding-related
120
+ * utility functions.
121
+ *
122
+ * @type {WebGPUBindingUtils}
123
+ */
42
124
  this.bindingUtils = new WebGPUBindingUtils( this );
125
+
126
+ /**
127
+ * A reference to a backend module holding shader pipeline-related
128
+ * utility functions.
129
+ *
130
+ * @type {WebGPUPipelineUtils}
131
+ */
43
132
  this.pipelineUtils = new WebGPUPipelineUtils( this );
133
+
134
+ /**
135
+ * A reference to a backend module holding shader texture-related
136
+ * utility functions.
137
+ *
138
+ * @type {WebGPUTextureUtils}
139
+ */
44
140
  this.textureUtils = new WebGPUTextureUtils( this );
141
+
142
+ /**
143
+ * A map that manages the resolve buffers for occlusion queries.
144
+ *
145
+ * @type {Map<number,GPUBuffer>}
146
+ */
45
147
  this.occludedResolveCache = new Map();
46
148
 
47
149
  }
48
150
 
151
+ /**
152
+ * Initializes the backend so it is ready for usage.
153
+ *
154
+ * @async
155
+ * @param {Renderer} renderer - The renderer.
156
+ * @return {Promise} A Promise that resolves when the backend has been initialized.
157
+ */
49
158
  async init( renderer ) {
50
159
 
51
160
  await super.init( renderer );
@@ -64,7 +173,7 @@ class WebGPUBackend extends Backend {
64
173
  powerPreference: parameters.powerPreference
65
174
  };
66
175
 
67
- const adapter = await navigator.gpu.requestAdapter( adapterOptions );
176
+ const adapter = ( typeof navigator !== 'undefined' ) ? await navigator.gpu.requestAdapter( adapterOptions ) : null;
68
177
 
69
178
  if ( adapter === null ) {
70
179
 
@@ -101,6 +210,19 @@ class WebGPUBackend extends Backend {
101
210
 
102
211
  }
103
212
 
213
+ device.lost.then( ( info ) => {
214
+
215
+ const deviceLossInfo = {
216
+ api: 'WebGPU',
217
+ message: info.message || 'Unknown reason',
218
+ reason: info.reason || null,
219
+ originalEvent: info
220
+ };
221
+
222
+ renderer.onDeviceLost( deviceLossInfo );
223
+
224
+ } );
225
+
104
226
  const context = ( parameters.context !== undefined ) ? parameters.context : renderer.domElement.getContext( 'webgpu' );
105
227
 
106
228
  this.device = device;
@@ -108,9 +230,11 @@ class WebGPUBackend extends Backend {
108
230
 
109
231
  const alphaMode = parameters.alpha ? 'premultiplied' : 'opaque';
110
232
 
233
+ this.trackTimestamp = this.trackTimestamp && this.hasFeature( GPUFeatureName.TimestampQuery );
234
+
111
235
  this.context.configure( {
112
236
  device: this.device,
113
- format: GPUTextureFormat.BGRA8Unorm,
237
+ format: this.utils.getPreferredCanvasFormat(),
114
238
  usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_SRC,
115
239
  alphaMode: alphaMode
116
240
  } );
@@ -119,24 +243,53 @@ class WebGPUBackend extends Backend {
119
243
 
120
244
  }
121
245
 
246
+ /**
247
+ * The coordinate system of the backend.
248
+ *
249
+ * @type {number}
250
+ * @readonly
251
+ */
122
252
  get coordinateSystem() {
123
253
 
124
254
  return WebGPUCoordinateSystem;
125
255
 
126
256
  }
127
257
 
258
+ /**
259
+ * This method performs a readback operation by moving buffer data from
260
+ * a storage buffer attribute from the GPU to the CPU.
261
+ *
262
+ * @async
263
+ * @param {StorageBufferAttribute} attribute - The storage buffer attribute.
264
+ * @return {Promise<ArrayBuffer>} A promise that resolves with the buffer data when the data are ready.
265
+ */
128
266
  async getArrayBufferAsync( attribute ) {
129
267
 
130
268
  return await this.attributeUtils.getArrayBufferAsync( attribute );
131
269
 
132
270
  }
133
271
 
272
+ /**
273
+ * Returns the backend's rendering context.
274
+ *
275
+ * @return {GPUCanvasContext} The rendering context.
276
+ */
134
277
  getContext() {
135
278
 
136
279
  return this.context;
137
280
 
138
281
  }
139
282
 
283
+ /**
284
+ * Returns the default render pass descriptor.
285
+ *
286
+ * In WebGPU, the default framebuffer must be configured
287
+ * like custom framebuffers so the backend needs a render
288
+ * pass descriptor even when rendering directly to screen.
289
+ *
290
+ * @private
291
+ * @return {Object} The render pass descriptor.
292
+ */
140
293
  _getDefaultRenderPassDescriptor() {
141
294
 
142
295
  let descriptor = this.defaultRenderPassdescriptor;
@@ -149,11 +302,16 @@ class WebGPUBackend extends Backend {
149
302
  colorAttachments: [ {
150
303
  view: null
151
304
  } ],
152
- depthStencilAttachment: {
153
- view: this.textureUtils.getDepthBuffer( renderer.depth, renderer.stencil ).createView()
154
- }
155
305
  };
156
306
 
307
+ if ( this.renderer.depth === true || this.renderer.stencil === true ) {
308
+
309
+ descriptor.depthStencilAttachment = {
310
+ view: this.textureUtils.getDepthBuffer( renderer.depth, renderer.stencil ).createView()
311
+ };
312
+
313
+ }
314
+
157
315
  const colorAttachment = descriptor.colorAttachments[ 0 ];
158
316
 
159
317
  if ( this.renderer.samples > 0 ) {
@@ -186,7 +344,15 @@ class WebGPUBackend extends Backend {
186
344
 
187
345
  }
188
346
 
189
- _getRenderPassDescriptor( renderContext ) {
347
+ /**
348
+ * Returns the render pass descriptor for the given render context.
349
+ *
350
+ * @private
351
+ * @param {RenderContext} renderContext - The render context.
352
+ * @param {Object} colorAttachmentsConfig - Configuration object for the color attachments.
353
+ * @return {Object} The render pass descriptor.
354
+ */
355
+ _getRenderPassDescriptor( renderContext, colorAttachmentsConfig = {} ) {
190
356
 
191
357
  const renderTarget = renderContext.renderTarget;
192
358
  const renderTargetData = this.get( renderTarget );
@@ -196,8 +362,11 @@ class WebGPUBackend extends Backend {
196
362
  if ( descriptors === undefined ||
197
363
  renderTargetData.width !== renderTarget.width ||
198
364
  renderTargetData.height !== renderTarget.height ||
365
+ renderTargetData.dimensions !== renderTarget.dimensions ||
199
366
  renderTargetData.activeMipmapLevel !== renderTarget.activeMipmapLevel ||
200
- renderTargetData.samples !== renderTarget.samples
367
+ renderTargetData.activeCubeFace !== renderContext.activeCubeFace ||
368
+ renderTargetData.samples !== renderTarget.samples ||
369
+ renderTargetData.loadOp !== colorAttachmentsConfig.loadOp
201
370
  ) {
202
371
 
203
372
  descriptors = {};
@@ -227,16 +396,37 @@ class WebGPUBackend extends Backend {
227
396
  const textures = renderContext.textures;
228
397
  const colorAttachments = [];
229
398
 
399
+ let sliceIndex;
400
+
230
401
  for ( let i = 0; i < textures.length; i ++ ) {
231
402
 
232
403
  const textureData = this.get( textures[ i ] );
233
404
 
234
- const textureView = textureData.texture.createView( {
405
+ const viewDescriptor = {
406
+ label: `colorAttachment_${ i }`,
235
407
  baseMipLevel: renderContext.activeMipmapLevel,
236
408
  mipLevelCount: 1,
237
409
  baseArrayLayer: renderContext.activeCubeFace,
410
+ arrayLayerCount: 1,
238
411
  dimension: GPUTextureViewDimension.TwoD
239
- } );
412
+ };
413
+
414
+ if ( renderTarget.isRenderTarget3D ) {
415
+
416
+ sliceIndex = renderContext.activeCubeFace;
417
+
418
+ viewDescriptor.baseArrayLayer = 0;
419
+ viewDescriptor.dimension = GPUTextureViewDimension.ThreeD;
420
+ viewDescriptor.depthOrArrayLayers = textures[ i ].image.depth;
421
+
422
+ } else if ( renderTarget.isRenderTargetArray ) {
423
+
424
+ viewDescriptor.dimension = GPUTextureViewDimension.TwoDArray;
425
+ viewDescriptor.depthOrArrayLayers = textures[ i ].image.depth;
426
+
427
+ }
428
+
429
+ const textureView = textureData.texture.createView( viewDescriptor );
240
430
 
241
431
  let view, resolveTarget;
242
432
 
@@ -252,32 +442,53 @@ class WebGPUBackend extends Backend {
252
442
 
253
443
  }
254
444
 
445
+ // only apply the user-defined clearValue to the first color attachment like in beginRender()
446
+
447
+ let clearValue = { r: 0, g: 0, b: 0, a: 1 };
448
+
449
+ if ( i === 0 && colorAttachmentsConfig.clearValue ) {
450
+
451
+ clearValue = colorAttachmentsConfig.clearValue;
452
+
453
+ }
454
+
255
455
  colorAttachments.push( {
256
456
  view,
457
+ depthSlice: sliceIndex,
257
458
  resolveTarget,
258
- loadOp: GPULoadOp.Load,
259
- storeOp: GPUStoreOp.Store
459
+ loadOp: colorAttachmentsConfig.loadOP || GPULoadOp.Load,
460
+ storeOp: colorAttachmentsConfig.storeOP || GPUStoreOp.Store,
461
+ clearValue: clearValue
260
462
  } );
261
463
 
262
464
  }
263
465
 
264
- const depthTextureData = this.get( renderContext.depthTexture );
265
-
266
- const depthStencilAttachment = {
267
- view: depthTextureData.texture.createView()
268
- };
269
466
 
270
467
  descriptor = {
271
468
  colorAttachments,
272
- depthStencilAttachment
273
469
  };
274
470
 
471
+ if ( renderContext.depth ) {
472
+
473
+ const depthTextureData = this.get( renderContext.depthTexture );
474
+
475
+ const depthStencilAttachment = {
476
+ view: depthTextureData.texture.createView()
477
+ };
478
+ descriptor.depthStencilAttachment = depthStencilAttachment;
479
+
480
+ }
481
+
275
482
  descriptors[ cacheKey ] = descriptor;
276
483
 
277
484
  renderTargetData.width = renderTarget.width;
278
485
  renderTargetData.height = renderTarget.height;
279
486
  renderTargetData.samples = renderTarget.samples;
280
- renderTargetData.activeMipmapLevel = renderTarget.activeMipmapLevel;
487
+ renderTargetData.activeMipmapLevel = renderContext.activeMipmapLevel;
488
+ renderTargetData.activeCubeFace = renderContext.activeCubeFace;
489
+ renderTargetData.dimensions = renderTarget.dimensions;
490
+ renderTargetData.depthSlice = sliceIndex;
491
+ renderTargetData.loadOp = colorAttachments[ 0 ].loadOp;
281
492
 
282
493
  }
283
494
 
@@ -285,6 +496,12 @@ class WebGPUBackend extends Backend {
285
496
 
286
497
  }
287
498
 
499
+ /**
500
+ * This method is executed at the beginning of a render call and prepares
501
+ * the WebGPU state for upcoming render calls
502
+ *
503
+ * @param {RenderContext} renderContext - The render context.
504
+ */
288
505
  beginRender( renderContext ) {
289
506
 
290
507
  const renderContextData = this.get( renderContext );
@@ -307,7 +524,7 @@ class WebGPUBackend extends Backend {
307
524
 
308
525
  //
309
526
 
310
- occlusionQuerySet = device.createQuerySet( { type: 'occlusion', count: occlusionQueryCount } );
527
+ occlusionQuerySet = device.createQuerySet( { type: 'occlusion', count: occlusionQueryCount, label: `occlusionQuerySet_${ renderContext.id }` } );
311
528
 
312
529
  renderContextData.occlusionQuerySet = occlusionQuerySet;
313
530
  renderContextData.occlusionQueryIndex = 0;
@@ -325,7 +542,7 @@ class WebGPUBackend extends Backend {
325
542
 
326
543
  } else {
327
544
 
328
- descriptor = this._getRenderPassDescriptor( renderContext );
545
+ descriptor = this._getRenderPassDescriptor( renderContext, { loadOp: GPULoadOp.Load } );
329
546
 
330
547
  }
331
548
 
@@ -345,7 +562,7 @@ class WebGPUBackend extends Backend {
345
562
 
346
563
  if ( renderContext.clearColor ) {
347
564
 
348
- colorAttachment.clearValue = renderContext.clearColorValue;
565
+ colorAttachment.clearValue = i === 0 ? renderContext.clearColorValue : { r: 0, g: 0, b: 0, a: 1 };
349
566
  colorAttachment.loadOp = GPULoadOp.Clear;
350
567
  colorAttachment.storeOp = GPUStoreOp.Store;
351
568
 
@@ -423,7 +640,8 @@ class WebGPUBackend extends Backend {
423
640
  renderContextData.descriptor = descriptor;
424
641
  renderContextData.encoder = encoder;
425
642
  renderContextData.currentPass = currentPass;
426
- renderContextData.currentSets = { attributes: {} };
643
+ renderContextData.currentSets = { attributes: {}, bindingGroups: [], pipeline: null, index: null };
644
+ renderContextData.renderBundles = [];
427
645
 
428
646
  //
429
647
 
@@ -437,20 +655,25 @@ class WebGPUBackend extends Backend {
437
655
 
438
656
  const { x, y, width, height } = renderContext.scissorValue;
439
657
 
440
- currentPass.setScissorRect( x, renderContext.height - height - y, width, height );
658
+ currentPass.setScissorRect( x, y, width, height );
441
659
 
442
660
  }
443
661
 
444
662
  }
445
663
 
664
+ /**
665
+ * This method is executed at the end of a render call and finalizes work
666
+ * after draw calls.
667
+ *
668
+ * @param {RenderContext} renderContext - The render context.
669
+ */
446
670
  finishRender( renderContext ) {
447
671
 
448
672
  const renderContextData = this.get( renderContext );
449
673
  const occlusionQueryCount = renderContext.occlusionQueryCount;
450
674
 
451
- if ( renderContextData.renderBundles !== undefined && renderContextData.renderBundles.length > 0 ) {
675
+ if ( renderContextData.renderBundles.length > 0 ) {
452
676
 
453
- renderContextData.registerBundlesPhase = false;
454
677
  renderContextData.currentPass.executeBundles( renderContextData.renderBundles );
455
678
 
456
679
  }
@@ -505,8 +728,6 @@ class WebGPUBackend extends Backend {
505
728
 
506
729
  }
507
730
 
508
- this.prepareTimestampBuffer( renderContext, renderContextData.encoder );
509
-
510
731
  this.device.queue.submit( [ renderContextData.encoder.finish() ] );
511
732
 
512
733
 
@@ -532,6 +753,14 @@ class WebGPUBackend extends Backend {
532
753
 
533
754
  }
534
755
 
756
+ /**
757
+ * Returns `true` if the given 3D object is fully occluded by other
758
+ * 3D objects in the scene.
759
+ *
760
+ * @param {RenderContext} renderContext - The render context.
761
+ * @param {Object3D} object - The 3D object to test.
762
+ * @return {boolean} Whether the 3D object is fully occluded or not.
763
+ */
535
764
  isOccluded( renderContext, object ) {
536
765
 
537
766
  const renderContextData = this.get( renderContext );
@@ -540,6 +769,14 @@ class WebGPUBackend extends Backend {
540
769
 
541
770
  }
542
771
 
772
+ /**
773
+ * This method processes the result of occlusion queries and writes it
774
+ * into render context data.
775
+ *
776
+ * @async
777
+ * @param {RenderContext} renderContext - The render context.
778
+ * @return {Promise} A Promise that resolves when the occlusion query results have been processed.
779
+ */
543
780
  async resolveOccludedAsync( renderContext ) {
544
781
 
545
782
  const renderContextData = this.get( renderContext );
@@ -562,7 +799,7 @@ class WebGPUBackend extends Backend {
562
799
 
563
800
  for ( let i = 0; i < currentOcclusionQueryObjects.length; i ++ ) {
564
801
 
565
- if ( results[ i ] !== BigInt( 0 ) ) {
802
+ if ( results[ i ] === BigInt( 0 ) ) {
566
803
 
567
804
  occluded.add( currentOcclusionQueryObjects[ i ] );
568
805
 
@@ -578,16 +815,53 @@ class WebGPUBackend extends Backend {
578
815
 
579
816
  }
580
817
 
818
+ /**
819
+ * Updates the viewport with the values from the given render context.
820
+ *
821
+ * @param {RenderContext} renderContext - The render context.
822
+ */
581
823
  updateViewport( renderContext ) {
582
824
 
583
825
  const { currentPass } = this.get( renderContext );
584
826
  const { x, y, width, height, minDepth, maxDepth } = renderContext.viewportValue;
585
827
 
586
- currentPass.setViewport( x, renderContext.height - height - y, width, height, minDepth, maxDepth );
828
+ currentPass.setViewport( x, y, width, height, minDepth, maxDepth );
829
+
830
+ }
831
+
832
+ /**
833
+ * Returns the clear color and alpha into a single
834
+ * color object.
835
+ *
836
+ * @return {Color4} The clear color.
837
+ */
838
+ getClearColor() {
839
+
840
+ const clearColor = super.getClearColor();
841
+
842
+ // only premultiply alpha when alphaMode is "premultiplied"
843
+
844
+ if ( this.renderer.alpha === true ) {
845
+
846
+ clearColor.r *= clearColor.a;
847
+ clearColor.g *= clearColor.a;
848
+ clearColor.b *= clearColor.a;
849
+
850
+ }
851
+
852
+ return clearColor;
587
853
 
588
854
  }
589
855
 
590
- clear( color, depth, stencil, renderTargetData = null ) {
856
+ /**
857
+ * Performs a clear operation.
858
+ *
859
+ * @param {boolean} color - Whether the color buffer should be cleared or not.
860
+ * @param {boolean} depth - Whether the depth buffer should be cleared or not.
861
+ * @param {boolean} stencil - Whether the stencil buffer should be cleared or not.
862
+ * @param {?RenderContext} [renderTargetContext=null] - The render context of the current set render target.
863
+ */
864
+ clear( color, depth, stencil, renderTargetContext = null ) {
591
865
 
592
866
  const device = this.device;
593
867
  const renderer = this.renderer;
@@ -603,12 +877,11 @@ class WebGPUBackend extends Backend {
603
877
  if ( color ) {
604
878
 
605
879
  const clearColor = this.getClearColor();
606
-
607
880
  clearValue = { r: clearColor.r, g: clearColor.g, b: clearColor.b, a: clearColor.a };
608
881
 
609
882
  }
610
883
 
611
- if ( renderTargetData === null ) {
884
+ if ( renderTargetContext === null ) {
612
885
 
613
886
  supportsDepth = renderer.depth;
614
887
  supportsStencil = renderer.stencil;
@@ -635,45 +908,20 @@ class WebGPUBackend extends Backend {
635
908
 
636
909
  } else {
637
910
 
638
- supportsDepth = renderTargetData.depth;
639
- supportsStencil = renderTargetData.stencil;
911
+ supportsDepth = renderTargetContext.depth;
912
+ supportsStencil = renderTargetContext.stencil;
640
913
 
641
914
  if ( color ) {
642
915
 
643
- for ( const texture of renderTargetData.textures ) {
644
-
645
- const textureData = this.get( texture );
646
- const textureView = textureData.texture.createView();
647
-
648
- let view, resolveTarget;
649
-
650
- if ( textureData.msaaTexture !== undefined ) {
651
-
652
- view = textureData.msaaTexture.createView();
653
- resolveTarget = textureView;
654
-
655
- } else {
656
-
657
- view = textureView;
658
- resolveTarget = undefined;
659
-
660
- }
661
-
662
- colorAttachments.push( {
663
- view,
664
- resolveTarget,
665
- clearValue,
666
- loadOp: GPULoadOp.Clear,
667
- storeOp: GPUStoreOp.Store
668
- } );
916
+ const descriptor = this._getRenderPassDescriptor( renderTargetContext, { loadOp: GPULoadOp.Clear, clearValue } );
669
917
 
670
- }
918
+ colorAttachments = descriptor.colorAttachments;
671
919
 
672
920
  }
673
921
 
674
922
  if ( supportsDepth || supportsStencil ) {
675
923
 
676
- const depthTextureData = this.get( renderTargetData.depthTexture );
924
+ const depthTextureData = this.get( renderTargetContext.depthTexture );
677
925
 
678
926
  depthStencilAttachment = {
679
927
  view: depthTextureData.texture.createView()
@@ -723,7 +971,7 @@ class WebGPUBackend extends Backend {
723
971
 
724
972
  //
725
973
 
726
- const encoder = device.createCommandEncoder( {} );
974
+ const encoder = device.createCommandEncoder( { label: 'clear' } );
727
975
  const currentPass = encoder.beginRenderPass( {
728
976
  colorAttachments,
729
977
  depthStencilAttachment
@@ -737,21 +985,37 @@ class WebGPUBackend extends Backend {
737
985
 
738
986
  // compute
739
987
 
988
+ /**
989
+ * This method is executed at the beginning of a compute call and
990
+ * prepares the state for upcoming compute tasks.
991
+ *
992
+ * @param {Node|Array<Node>} computeGroup - The compute node(s).
993
+ */
740
994
  beginCompute( computeGroup ) {
741
995
 
742
996
  const groupGPU = this.get( computeGroup );
743
997
 
744
998
 
745
- const descriptor = {};
999
+ const descriptor = {
1000
+ label: 'computeGroup_' + computeGroup.id
1001
+ };
746
1002
 
747
1003
  this.initTimestampQuery( computeGroup, descriptor );
748
1004
 
749
- groupGPU.cmdEncoderGPU = this.device.createCommandEncoder();
1005
+ groupGPU.cmdEncoderGPU = this.device.createCommandEncoder( { label: 'computeGroup_' + computeGroup.id } );
750
1006
 
751
1007
  groupGPU.passEncoderGPU = groupGPU.cmdEncoderGPU.beginComputePass( descriptor );
752
1008
 
753
1009
  }
754
1010
 
1011
+ /**
1012
+ * Executes a compute command for the given compute node.
1013
+ *
1014
+ * @param {Node|Array<Node>} computeGroup - The group of compute nodes of a compute call. Can be a single compute node.
1015
+ * @param {Node} computeNode - The compute node.
1016
+ * @param {Array<BindGroup>} bindings - The bindings.
1017
+ * @param {ComputePipeline} pipeline - The compute pipeline.
1018
+ */
755
1019
  compute( computeGroup, computeNode, bindings, pipeline ) {
756
1020
 
757
1021
  const { passEncoderGPU } = this.get( computeGroup );
@@ -799,43 +1063,55 @@ class WebGPUBackend extends Backend {
799
1063
 
800
1064
  }
801
1065
 
1066
+ /**
1067
+ * This method is executed at the end of a compute call and
1068
+ * finalizes work after compute tasks.
1069
+ *
1070
+ * @param {Node|Array<Node>} computeGroup - The compute node(s).
1071
+ */
802
1072
  finishCompute( computeGroup ) {
803
1073
 
804
1074
  const groupData = this.get( computeGroup );
805
1075
 
806
1076
  groupData.passEncoderGPU.end();
807
1077
 
808
- this.prepareTimestampBuffer( computeGroup, groupData.cmdEncoderGPU );
809
-
810
1078
  this.device.queue.submit( [ groupData.cmdEncoderGPU.finish() ] );
811
1079
 
812
1080
  }
813
1081
 
814
- // render object
815
-
816
- draw( renderObject, info ) {
1082
+ /**
1083
+ * Can be used to synchronize CPU operations with GPU tasks. So when this method is called,
1084
+ * the CPU waits for the GPU to complete its operation (e.g. a compute task).
1085
+ *
1086
+ * @async
1087
+ * @return {Promise} A Promise that resolves when synchronization has been finished.
1088
+ */
1089
+ async waitForGPU() {
817
1090
 
818
- const { object, geometry, context, pipeline } = renderObject;
1091
+ await this.device.queue.onSubmittedWorkDone();
819
1092
 
820
- const bindings = renderObject.getBindings();
821
- const contextData = this.get( context );
822
- const pipelineGPU = this.get( pipeline ).pipeline;
823
- const currentSets = contextData.currentSets;
1093
+ }
824
1094
 
825
- const renderObjectData = this.get( renderObject );
1095
+ // render object
826
1096
 
827
- const { bundleEncoder, renderBundle, lastPipelineGPU } = renderObjectData;
1097
+ /**
1098
+ * Executes a draw command for the given render object.
1099
+ *
1100
+ * @param {RenderObject} renderObject - The render object to draw.
1101
+ * @param {Info} info - Holds a series of statistical information about the GPU memory and the rendering process.
1102
+ */
1103
+ draw( renderObject, info ) {
828
1104
 
1105
+ const { object, material, context, pipeline } = renderObject;
1106
+ const bindings = renderObject.getBindings();
829
1107
  const renderContextData = this.get( context );
1108
+ const pipelineGPU = this.get( pipeline ).pipeline;
1109
+ const currentSets = renderContextData.currentSets;
1110
+ const passEncoderGPU = renderContextData.currentPass;
830
1111
 
831
- if ( renderContextData.registerBundlesPhase === true && bundleEncoder !== undefined && lastPipelineGPU === pipelineGPU ) {
832
-
833
- renderContextData.renderBundles.push( renderBundle );
834
- return;
835
-
836
- }
1112
+ const drawParams = renderObject.getDrawParameters();
837
1113
 
838
- const passEncoderGPU = this.renderer._currentRenderBundle ? this.createBundleEncoder( context, renderObject ) : contextData.currentPass;
1114
+ if ( drawParams === null ) return;
839
1115
 
840
1116
  // pipeline
841
1117
 
@@ -849,12 +1125,19 @@ class WebGPUBackend extends Backend {
849
1125
 
850
1126
  // bind groups
851
1127
 
1128
+ const currentBindingGroups = currentSets.bindingGroups;
1129
+
852
1130
  for ( let i = 0, l = bindings.length; i < l; i ++ ) {
853
1131
 
854
1132
  const bindGroup = bindings[ i ];
855
1133
  const bindingsData = this.get( bindGroup );
856
1134
 
857
- passEncoderGPU.setBindGroup( bindGroup.index, bindingsData.group );
1135
+ if ( currentBindingGroups[ bindGroup.index ] !== bindGroup.id ) {
1136
+
1137
+ passEncoderGPU.setBindGroup( bindGroup.index, bindingsData.group );
1138
+ currentBindingGroups[ bindGroup.index ] = bindGroup.id;
1139
+
1140
+ }
858
1141
 
859
1142
  }
860
1143
 
@@ -902,83 +1185,179 @@ class WebGPUBackend extends Backend {
902
1185
 
903
1186
  // occlusion queries - handle multiple consecutive draw calls for an object
904
1187
 
905
- if ( contextData.occlusionQuerySet !== undefined ) {
1188
+ if ( renderContextData.occlusionQuerySet !== undefined ) {
906
1189
 
907
- const lastObject = contextData.lastOcclusionObject;
1190
+ const lastObject = renderContextData.lastOcclusionObject;
908
1191
 
909
1192
  if ( lastObject !== object ) {
910
1193
 
911
1194
  if ( lastObject !== null && lastObject.occlusionTest === true ) {
912
1195
 
913
1196
  passEncoderGPU.endOcclusionQuery();
914
- contextData.occlusionQueryIndex ++;
1197
+ renderContextData.occlusionQueryIndex ++;
915
1198
 
916
1199
  }
917
1200
 
918
1201
  if ( object.occlusionTest === true ) {
919
1202
 
920
- passEncoderGPU.beginOcclusionQuery( contextData.occlusionQueryIndex );
921
- contextData.occlusionQueryObjects[ contextData.occlusionQueryIndex ] = object;
1203
+ passEncoderGPU.beginOcclusionQuery( renderContextData.occlusionQueryIndex );
1204
+ renderContextData.occlusionQueryObjects[ renderContextData.occlusionQueryIndex ] = object;
922
1205
 
923
1206
  }
924
1207
 
925
- contextData.lastOcclusionObject = object;
1208
+ renderContextData.lastOcclusionObject = object;
926
1209
 
927
1210
  }
928
1211
 
929
1212
  }
930
1213
 
1214
+ // stencil
1215
+
1216
+ if ( context.stencil === true && material.stencilWrite === true && renderContextData.currentStencilRef !== material.stencilRef ) {
1217
+
1218
+ passEncoderGPU.setStencilReference( material.stencilRef );
1219
+ renderContextData.currentStencilRef = material.stencilRef;
1220
+
1221
+ }
1222
+
931
1223
  // draw
932
1224
 
933
- const drawRange = renderObject.drawRange;
934
- const firstVertex = drawRange.start;
1225
+ const draw = () => {
1226
+
1227
+ if ( object.isBatchedMesh === true ) {
1228
+
1229
+ const starts = object._multiDrawStarts;
1230
+ const counts = object._multiDrawCounts;
1231
+ const drawCount = object._multiDrawCount;
1232
+ const drawInstances = object._multiDrawInstances;
1233
+
1234
+ if ( drawInstances !== null ) {
1235
+
1236
+ // @deprecated, r174
1237
+ warnOnce( 'THREE.WebGPUBackend: renderMultiDrawInstances has been deprecated and will be removed in r184. Append to renderMultiDraw arguments and use indirection.' );
1238
+
1239
+ }
1240
+
1241
+ for ( let i = 0; i < drawCount; i ++ ) {
935
1242
 
936
- const instanceCount = this.getInstanceCount( renderObject );
937
- if ( instanceCount === 0 ) return;
1243
+ const count = drawInstances ? drawInstances[ i ] : 1;
1244
+ const firstInstance = count > 1 ? 0 : i;
938
1245
 
939
- if ( object.isBatchedMesh === true ) {
1246
+ if ( hasIndex === true ) {
940
1247
 
941
- const starts = object._multiDrawStarts;
942
- const counts = object._multiDrawCounts;
943
- const drawCount = object._multiDrawCount;
944
- const drawInstances = object._multiDrawInstances;
1248
+ passEncoderGPU.drawIndexed( counts[ i ], count, starts[ i ] / index.array.BYTES_PER_ELEMENT, 0, firstInstance );
945
1249
 
946
- const bytesPerElement = index.bytesPerElement || 1;
1250
+ } else {
1251
+
1252
+ passEncoderGPU.draw( counts[ i ], count, starts[ i ], firstInstance );
1253
+
1254
+ }
1255
+
1256
+ info.update( object, counts[ i ], count );
1257
+
1258
+ }
1259
+
1260
+ } else if ( hasIndex === true ) {
947
1261
 
948
- for ( let i = 0; i < drawCount; i ++ ) {
1262
+ const { vertexCount: indexCount, instanceCount, firstVertex: firstIndex } = drawParams;
949
1263
 
950
- const count = drawInstances ? drawInstances[ i ] : 1;
951
- const firstInstance = count > 1 ? 0 : i;
1264
+ const indirect = renderObject.getIndirect();
952
1265
 
953
- passEncoderGPU.drawIndexed( counts[ i ] / bytesPerElement, count, starts[ i ] / 4, 0, firstInstance );
1266
+ if ( indirect !== null ) {
1267
+
1268
+ const buffer = this.get( indirect ).buffer;
1269
+
1270
+ passEncoderGPU.drawIndexedIndirect( buffer, 0 );
1271
+
1272
+ } else {
1273
+
1274
+ passEncoderGPU.drawIndexed( indexCount, instanceCount, firstIndex, 0, 0 );
1275
+
1276
+ }
1277
+
1278
+ info.update( object, indexCount, instanceCount );
1279
+
1280
+ } else {
1281
+
1282
+ const { vertexCount, instanceCount, firstVertex } = drawParams;
1283
+
1284
+ const indirect = renderObject.getIndirect();
1285
+
1286
+ if ( indirect !== null ) {
1287
+
1288
+ const buffer = this.get( indirect ).buffer;
1289
+
1290
+ passEncoderGPU.drawIndirect( buffer, 0 );
1291
+
1292
+ } else {
1293
+
1294
+ passEncoderGPU.draw( vertexCount, instanceCount, firstVertex, 0 );
1295
+
1296
+ }
1297
+
1298
+ info.update( object, vertexCount, instanceCount );
954
1299
 
955
1300
  }
956
1301
 
957
- } else if ( hasIndex === true ) {
1302
+ };
958
1303
 
959
- const indexCount = ( drawRange.count !== Infinity ) ? drawRange.count : index.count;
1304
+ if ( renderObject.camera.isArrayCamera && renderObject.camera.cameras.length > 0 ) {
960
1305
 
961
- passEncoderGPU.drawIndexed( indexCount, instanceCount, firstVertex, 0, 0 );
1306
+ const cameraData = this.get( renderObject.camera );
1307
+ const cameras = renderObject.camera.cameras;
1308
+ const cameraIndex = renderObject.getBindingGroup( 'cameraIndex' );
962
1309
 
963
- info.update( object, indexCount, instanceCount );
1310
+ if ( cameraData.indexesGPU === undefined || cameraData.indexesGPU.length !== cameras.length ) {
964
1311
 
965
- } else {
1312
+ const bindingsData = this.get( cameraIndex );
1313
+ const indexesGPU = [];
966
1314
 
967
- const positionAttribute = geometry.attributes.position;
968
- const vertexCount = ( drawRange.count !== Infinity ) ? drawRange.count : positionAttribute.count;
1315
+ const data = new Uint32Array( [ 0, 0, 0, 0 ] );
969
1316
 
970
- passEncoderGPU.draw( vertexCount, instanceCount, firstVertex, 0 );
1317
+ for ( let i = 0, len = cameras.length; i < len; i ++ ) {
971
1318
 
972
- info.update( object, vertexCount, instanceCount );
1319
+ data[ 0 ] = i;
973
1320
 
974
- }
1321
+ const bindGroupIndex = this.bindingUtils.createBindGroupIndex( data, bindingsData.layout );
1322
+
1323
+ indexesGPU.push( bindGroupIndex );
1324
+
1325
+ }
1326
+
1327
+ cameraData.indexesGPU = indexesGPU; // TODO: Create a global library for this
1328
+
1329
+ }
1330
+
1331
+ const pixelRatio = this.renderer.getPixelRatio();
975
1332
 
976
- if ( this.renderer._currentRenderBundle ) {
1333
+ for ( let i = 0, len = cameras.length; i < len; i ++ ) {
977
1334
 
978
- const renderBundle = passEncoderGPU.finish();
979
- renderObjectData.lastPipelineGPU = pipelineGPU;
980
- renderObjectData.renderBundle = renderBundle;
981
- renderObjectData.bundleEncoder = passEncoderGPU;
1335
+ const subCamera = cameras[ i ];
1336
+
1337
+ if ( object.layers.test( subCamera.layers ) ) {
1338
+
1339
+ const vp = subCamera.viewport;
1340
+
1341
+ passEncoderGPU.setViewport(
1342
+ Math.floor( vp.x * pixelRatio ),
1343
+ Math.floor( vp.y * pixelRatio ),
1344
+ Math.floor( vp.width * pixelRatio ),
1345
+ Math.floor( vp.height * pixelRatio ),
1346
+ context.viewportValue.minDepth,
1347
+ context.viewportValue.maxDepth
1348
+ );
1349
+
1350
+ passEncoderGPU.setBindGroup( cameraIndex.index, cameraData.indexesGPU[ i ] );
1351
+
1352
+ draw();
1353
+
1354
+ }
1355
+
1356
+ }
1357
+
1358
+ } else {
1359
+
1360
+ draw();
982
1361
 
983
1362
  }
984
1363
 
@@ -986,6 +1365,12 @@ class WebGPUBackend extends Backend {
986
1365
 
987
1366
  // cache key
988
1367
 
1368
+ /**
1369
+ * Returns `true` if the render pipeline requires an update.
1370
+ *
1371
+ * @param {RenderObject} renderObject - The render object.
1372
+ * @return {boolean} Whether the render pipeline requires an update or not.
1373
+ */
989
1374
  needsRenderUpdate( renderObject ) {
990
1375
 
991
1376
  const data = this.get( renderObject );
@@ -1014,7 +1399,7 @@ class WebGPUBackend extends Backend {
1014
1399
  data.sampleCount !== sampleCount || data.colorSpace !== colorSpace ||
1015
1400
  data.colorFormat !== colorFormat || data.depthStencilFormat !== depthStencilFormat ||
1016
1401
  data.primitiveTopology !== primitiveTopology ||
1017
- data.clippingContextVersion !== renderObject.clippingContextVersion
1402
+ data.clippingContextCacheKey !== renderObject.clippingContextCacheKey
1018
1403
  ) {
1019
1404
 
1020
1405
  data.material = material; data.materialVersion = material.version;
@@ -1032,7 +1417,7 @@ class WebGPUBackend extends Backend {
1032
1417
  data.colorFormat = colorFormat;
1033
1418
  data.depthStencilFormat = depthStencilFormat;
1034
1419
  data.primitiveTopology = primitiveTopology;
1035
- data.clippingContextVersion = renderObject.clippingContextVersion;
1420
+ data.clippingContextCacheKey = renderObject.clippingContextCacheKey;
1036
1421
 
1037
1422
  needsUpdate = true;
1038
1423
 
@@ -1042,6 +1427,12 @@ class WebGPUBackend extends Backend {
1042
1427
 
1043
1428
  }
1044
1429
 
1430
+ /**
1431
+ * Returns a cache key that is used to identify render pipelines.
1432
+ *
1433
+ * @param {RenderObject} renderObject - The render object.
1434
+ * @return {string} The cache key.
1435
+ */
1045
1436
  getRenderCacheKey( renderObject ) {
1046
1437
 
1047
1438
  const { object, material } = renderObject;
@@ -1062,159 +1453,153 @@ class WebGPUBackend extends Backend {
1062
1453
  utils.getSampleCountRenderContext( renderContext ),
1063
1454
  utils.getCurrentColorSpace( renderContext ), utils.getCurrentColorFormat( renderContext ), utils.getCurrentDepthStencilFormat( renderContext ),
1064
1455
  utils.getPrimitiveTopology( object, material ),
1065
- renderObject.clippingContextVersion
1456
+ renderObject.getGeometryCacheKey(),
1457
+ renderObject.clippingContextCacheKey
1066
1458
  ].join();
1067
1459
 
1068
1460
  }
1069
1461
 
1070
1462
  // textures
1071
1463
 
1464
+ /**
1465
+ * Creates a GPU sampler for the given texture.
1466
+ *
1467
+ * @param {Texture} texture - The texture to create the sampler for.
1468
+ */
1072
1469
  createSampler( texture ) {
1073
1470
 
1074
1471
  this.textureUtils.createSampler( texture );
1075
1472
 
1076
1473
  }
1077
1474
 
1475
+ /**
1476
+ * Destroys the GPU sampler for the given texture.
1477
+ *
1478
+ * @param {Texture} texture - The texture to destroy the sampler for.
1479
+ */
1078
1480
  destroySampler( texture ) {
1079
1481
 
1080
1482
  this.textureUtils.destroySampler( texture );
1081
1483
 
1082
1484
  }
1083
1485
 
1486
+ /**
1487
+ * Creates a default texture for the given texture that can be used
1488
+ * as a placeholder until the actual texture is ready for usage.
1489
+ *
1490
+ * @param {Texture} texture - The texture to create a default texture for.
1491
+ */
1084
1492
  createDefaultTexture( texture ) {
1085
1493
 
1086
1494
  this.textureUtils.createDefaultTexture( texture );
1087
1495
 
1088
1496
  }
1089
1497
 
1498
+ /**
1499
+ * Defines a texture on the GPU for the given texture object.
1500
+ *
1501
+ * @param {Texture} texture - The texture.
1502
+ * @param {Object} [options={}] - Optional configuration parameter.
1503
+ */
1090
1504
  createTexture( texture, options ) {
1091
1505
 
1092
1506
  this.textureUtils.createTexture( texture, options );
1093
1507
 
1094
1508
  }
1095
1509
 
1510
+ /**
1511
+ * Uploads the updated texture data to the GPU.
1512
+ *
1513
+ * @param {Texture} texture - The texture.
1514
+ * @param {Object} [options={}] - Optional configuration parameter.
1515
+ */
1096
1516
  updateTexture( texture, options ) {
1097
1517
 
1098
1518
  this.textureUtils.updateTexture( texture, options );
1099
1519
 
1100
1520
  }
1101
1521
 
1522
+ /**
1523
+ * Generates mipmaps for the given texture.
1524
+ *
1525
+ * @param {Texture} texture - The texture.
1526
+ */
1102
1527
  generateMipmaps( texture ) {
1103
1528
 
1104
1529
  this.textureUtils.generateMipmaps( texture );
1105
1530
 
1106
1531
  }
1107
1532
 
1533
+ /**
1534
+ * Destroys the GPU data for the given texture object.
1535
+ *
1536
+ * @param {Texture} texture - The texture.
1537
+ */
1108
1538
  destroyTexture( texture ) {
1109
1539
 
1110
1540
  this.textureUtils.destroyTexture( texture );
1111
1541
 
1112
1542
  }
1113
1543
 
1114
- copyTextureToBuffer( texture, x, y, width, height ) {
1115
-
1116
- return this.textureUtils.copyTextureToBuffer( texture, x, y, width, height );
1544
+ /**
1545
+ * Returns texture data as a typed array.
1546
+ *
1547
+ * @async
1548
+ * @param {Texture} texture - The texture to copy.
1549
+ * @param {number} x - The x coordinate of the copy origin.
1550
+ * @param {number} y - The y coordinate of the copy origin.
1551
+ * @param {number} width - The width of the copy.
1552
+ * @param {number} height - The height of the copy.
1553
+ * @param {number} faceIndex - The face index.
1554
+ * @return {Promise<TypedArray>} A Promise that resolves with a typed array when the copy operation has finished.
1555
+ */
1556
+ async copyTextureToBuffer( texture, x, y, width, height, faceIndex ) {
1557
+
1558
+ return this.textureUtils.copyTextureToBuffer( texture, x, y, width, height, faceIndex );
1117
1559
 
1118
1560
  }
1119
1561
 
1120
-
1562
+ /**
1563
+ * Inits a time stamp query for the given render context.
1564
+ *
1565
+ * @param {RenderContext} renderContext - The render context.
1566
+ * @param {Object} descriptor - The query descriptor.
1567
+ */
1121
1568
  initTimestampQuery( renderContext, descriptor ) {
1122
1569
 
1123
- if ( ! this.hasFeature( GPUFeatureName.TimestampQuery ) || ! this.trackTimestamp ) return;
1124
-
1125
- const renderContextData = this.get( renderContext );
1126
-
1127
- if ( ! renderContextData.timeStampQuerySet ) {
1128
-
1129
- // Create a GPUQuerySet which holds 2 timestamp query results: one for the
1130
- // beginning and one for the end of compute pass execution.
1131
- const timeStampQuerySet = this.device.createQuerySet( { type: 'timestamp', count: 2 } );
1132
-
1133
- const timestampWrites = {
1134
- querySet: timeStampQuerySet,
1135
- beginningOfPassWriteIndex: 0, // Write timestamp in index 0 when pass begins.
1136
- endOfPassWriteIndex: 1, // Write timestamp in index 1 when pass ends.
1137
- };
1138
-
1139
- Object.assign( descriptor, {
1140
- timestampWrites,
1141
- } );
1142
-
1143
- renderContextData.timeStampQuerySet = timeStampQuerySet;
1570
+ if ( ! this.trackTimestamp ) return;
1144
1571
 
1145
- }
1146
-
1147
- }
1148
-
1149
- // timestamp utils
1572
+ const type = renderContext.isComputeNode ? 'compute' : 'render';
1150
1573
 
1151
- prepareTimestampBuffer( renderContext, encoder ) {
1574
+ if ( ! this.timestampQueryPool[ type ] ) {
1152
1575
 
1153
- if ( ! this.hasFeature( GPUFeatureName.TimestampQuery ) || ! this.trackTimestamp ) return;
1154
-
1155
- const renderContextData = this.get( renderContext );
1156
-
1157
- const size = 2 * BigInt64Array.BYTES_PER_ELEMENT;
1158
-
1159
- if ( renderContextData.currentTimestampQueryBuffers === undefined ) {
1160
-
1161
- renderContextData.currentTimestampQueryBuffers = {
1162
- resolveBuffer: this.device.createBuffer( {
1163
- label: 'timestamp resolve buffer',
1164
- size: size,
1165
- usage: GPUBufferUsage.QUERY_RESOLVE | GPUBufferUsage.COPY_SRC,
1166
- } ),
1167
- resultBuffer: this.device.createBuffer( {
1168
- label: 'timestamp result buffer',
1169
- size: size,
1170
- usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ,
1171
- } ),
1172
- isMappingPending: false,
1173
- };
1576
+ // TODO: Variable maxQueries?
1577
+ this.timestampQueryPool[ type ] = new WebGPUTimestampQueryPool( this.device, type, 2048 );
1174
1578
 
1175
1579
  }
1176
1580
 
1177
- const { resolveBuffer, resultBuffer, isMappingPending } = renderContextData.currentTimestampQueryBuffers;
1581
+ const timestampQueryPool = this.timestampQueryPool[ type ];
1178
1582
 
1179
- if ( isMappingPending === true ) return;
1583
+ const baseOffset = timestampQueryPool.allocateQueriesForContext( renderContext );
1180
1584
 
1181
- encoder.resolveQuerySet( renderContextData.timeStampQuerySet, 0, 2, resolveBuffer, 0 );
1182
- encoder.copyBufferToBuffer( resolveBuffer, 0, resultBuffer, 0, size );
1585
+ descriptor.timestampWrites = {
1586
+ querySet: timestampQueryPool.querySet,
1587
+ beginningOfPassWriteIndex: baseOffset,
1588
+ endOfPassWriteIndex: baseOffset + 1,
1589
+ };
1183
1590
 
1184
1591
  }
1185
1592
 
1186
- async resolveTimestampAsync( renderContext, type = 'render' ) {
1187
-
1188
- if ( ! this.hasFeature( GPUFeatureName.TimestampQuery ) || ! this.trackTimestamp ) return;
1189
-
1190
- const renderContextData = this.get( renderContext );
1191
-
1192
- if ( renderContextData.currentTimestampQueryBuffers === undefined ) return;
1193
-
1194
- const { resultBuffer, isMappingPending } = renderContextData.currentTimestampQueryBuffers;
1195
-
1196
- if ( isMappingPending === true ) return;
1197
-
1198
- renderContextData.currentTimestampQueryBuffers.isMappingPending = true;
1199
-
1200
- resultBuffer.mapAsync( GPUMapMode.READ ).then( () => {
1201
-
1202
- const times = new BigUint64Array( resultBuffer.getMappedRange() );
1203
- const duration = Number( times[ 1 ] - times[ 0 ] ) / 1000000;
1204
-
1205
-
1206
- this.renderer.info.updateTimestamp( type, duration );
1207
-
1208
- resultBuffer.unmap();
1209
-
1210
- renderContextData.currentTimestampQueryBuffers.isMappingPending = false;
1211
-
1212
- } );
1213
-
1214
- }
1215
1593
 
1216
1594
  // node builder
1217
1595
 
1596
+ /**
1597
+ * Returns a node builder for the given render object.
1598
+ *
1599
+ * @param {RenderObject} object - The render object.
1600
+ * @param {Renderer} renderer - The renderer.
1601
+ * @return {WGSLNodeBuilder} The node builder.
1602
+ */
1218
1603
  createNodeBuilder( object, renderer ) {
1219
1604
 
1220
1605
  return new WGSLNodeBuilder( object, renderer );
@@ -1223,17 +1608,27 @@ class WebGPUBackend extends Backend {
1223
1608
 
1224
1609
  // program
1225
1610
 
1611
+ /**
1612
+ * Creates a shader program from the given programmable stage.
1613
+ *
1614
+ * @param {ProgrammableStage} program - The programmable stage.
1615
+ */
1226
1616
  createProgram( program ) {
1227
1617
 
1228
1618
  const programGPU = this.get( program );
1229
1619
 
1230
1620
  programGPU.module = {
1231
- module: this.device.createShaderModule( { code: program.code, label: program.stage } ),
1621
+ module: this.device.createShaderModule( { code: program.code, label: program.stage + ( program.name !== '' ? `_${ program.name }` : '' ) } ),
1232
1622
  entryPoint: 'main'
1233
1623
  };
1234
1624
 
1235
1625
  }
1236
1626
 
1627
+ /**
1628
+ * Destroys the shader program of the given programmable stage.
1629
+ *
1630
+ * @param {ProgrammableStage} program - The programmable stage.
1631
+ */
1237
1632
  destroyProgram( program ) {
1238
1633
 
1239
1634
  this.delete( program );
@@ -1242,38 +1637,118 @@ class WebGPUBackend extends Backend {
1242
1637
 
1243
1638
  // pipelines
1244
1639
 
1640
+ /**
1641
+ * Creates a render pipeline for the given render object.
1642
+ *
1643
+ * @param {RenderObject} renderObject - The render object.
1644
+ * @param {Array<Promise>} promises - An array of compilation promises which are used in `compileAsync()`.
1645
+ */
1245
1646
  createRenderPipeline( renderObject, promises ) {
1246
1647
 
1247
1648
  this.pipelineUtils.createRenderPipeline( renderObject, promises );
1248
1649
 
1249
1650
  }
1250
1651
 
1652
+ /**
1653
+ * Creates a compute pipeline for the given compute node.
1654
+ *
1655
+ * @param {ComputePipeline} computePipeline - The compute pipeline.
1656
+ * @param {Array<BindGroup>} bindings - The bindings.
1657
+ */
1251
1658
  createComputePipeline( computePipeline, bindings ) {
1252
1659
 
1253
1660
  this.pipelineUtils.createComputePipeline( computePipeline, bindings );
1254
1661
 
1255
1662
  }
1256
1663
 
1257
- createBundleEncoder( renderContext, renderObject ) {
1664
+ /**
1665
+ * Prepares the state for encoding render bundles.
1666
+ *
1667
+ * @param {RenderContext} renderContext - The render context.
1668
+ */
1669
+ beginBundle( renderContext ) {
1670
+
1671
+ const renderContextData = this.get( renderContext );
1672
+
1673
+ renderContextData._currentPass = renderContextData.currentPass;
1674
+ renderContextData._currentSets = renderContextData.currentSets;
1675
+
1676
+ renderContextData.currentSets = { attributes: {}, bindingGroups: [], pipeline: null, index: null };
1677
+ renderContextData.currentPass = this.pipelineUtils.createBundleEncoder( renderContext );
1678
+
1679
+ }
1680
+
1681
+ /**
1682
+ * After processing render bundles this method finalizes related work.
1683
+ *
1684
+ * @param {RenderContext} renderContext - The render context.
1685
+ * @param {RenderBundle} bundle - The render bundle.
1686
+ */
1687
+ finishBundle( renderContext, bundle ) {
1688
+
1689
+ const renderContextData = this.get( renderContext );
1690
+
1691
+ const bundleEncoder = renderContextData.currentPass;
1692
+ const bundleGPU = bundleEncoder.finish();
1693
+
1694
+ this.get( bundle ).bundleGPU = bundleGPU;
1258
1695
 
1259
- return this.pipelineUtils.createBundleEncoder( renderContext, renderObject );
1696
+ // restore render pass state
1697
+
1698
+ renderContextData.currentSets = renderContextData._currentSets;
1699
+ renderContextData.currentPass = renderContextData._currentPass;
1700
+
1701
+ }
1702
+
1703
+ /**
1704
+ * Adds a render bundle to the render context data.
1705
+ *
1706
+ * @param {RenderContext} renderContext - The render context.
1707
+ * @param {RenderBundle} bundle - The render bundle to add.
1708
+ */
1709
+ addBundle( renderContext, bundle ) {
1710
+
1711
+ const renderContextData = this.get( renderContext );
1712
+
1713
+ renderContextData.renderBundles.push( this.get( bundle ).bundleGPU );
1260
1714
 
1261
1715
  }
1262
1716
 
1263
1717
  // bindings
1264
1718
 
1265
- createBindings( bindGroup ) {
1719
+ /**
1720
+ * Creates bindings from the given bind group definition.
1721
+ *
1722
+ * @param {BindGroup} bindGroup - The bind group.
1723
+ * @param {Array<BindGroup>} bindings - Array of bind groups.
1724
+ * @param {number} cacheIndex - The cache index.
1725
+ * @param {number} version - The version.
1726
+ */
1727
+ createBindings( bindGroup, bindings, cacheIndex, version ) {
1266
1728
 
1267
- this.bindingUtils.createBindings( bindGroup );
1729
+ this.bindingUtils.createBindings( bindGroup, bindings, cacheIndex, version );
1268
1730
 
1269
1731
  }
1270
1732
 
1271
- updateBindings( bindGroup ) {
1733
+ /**
1734
+ * Updates the given bind group definition.
1735
+ *
1736
+ * @param {BindGroup} bindGroup - The bind group.
1737
+ * @param {Array<BindGroup>} bindings - Array of bind groups.
1738
+ * @param {number} cacheIndex - The cache index.
1739
+ * @param {number} version - The version.
1740
+ */
1741
+ updateBindings( bindGroup, bindings, cacheIndex, version ) {
1272
1742
 
1273
- this.bindingUtils.createBindings( bindGroup );
1743
+ this.bindingUtils.createBindings( bindGroup, bindings, cacheIndex, version );
1274
1744
 
1275
1745
  }
1276
1746
 
1747
+ /**
1748
+ * Updates a buffer binding.
1749
+ *
1750
+ * @param {Buffer} binding - The buffer binding to update.
1751
+ */
1277
1752
  updateBinding( binding ) {
1278
1753
 
1279
1754
  this.bindingUtils.updateBinding( binding );
@@ -1282,30 +1757,66 @@ class WebGPUBackend extends Backend {
1282
1757
 
1283
1758
  // attributes
1284
1759
 
1760
+ /**
1761
+ * Creates the buffer of an indexed shader attribute.
1762
+ *
1763
+ * @param {BufferAttribute} attribute - The indexed buffer attribute.
1764
+ */
1285
1765
  createIndexAttribute( attribute ) {
1286
1766
 
1287
1767
  this.attributeUtils.createAttribute( attribute, GPUBufferUsage.INDEX | GPUBufferUsage.COPY_SRC | GPUBufferUsage.COPY_DST );
1288
1768
 
1289
1769
  }
1290
1770
 
1771
+ /**
1772
+ * Creates the GPU buffer of a shader attribute.
1773
+ *
1774
+ * @param {BufferAttribute} attribute - The buffer attribute.
1775
+ */
1291
1776
  createAttribute( attribute ) {
1292
1777
 
1293
1778
  this.attributeUtils.createAttribute( attribute, GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_SRC | GPUBufferUsage.COPY_DST );
1294
1779
 
1295
1780
  }
1296
1781
 
1782
+ /**
1783
+ * Creates the GPU buffer of a storage attribute.
1784
+ *
1785
+ * @param {BufferAttribute} attribute - The buffer attribute.
1786
+ */
1297
1787
  createStorageAttribute( attribute ) {
1298
1788
 
1299
1789
  this.attributeUtils.createAttribute( attribute, GPUBufferUsage.STORAGE | GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_SRC | GPUBufferUsage.COPY_DST );
1300
1790
 
1301
1791
  }
1302
1792
 
1793
+ /**
1794
+ * Creates the GPU buffer of an indirect storage attribute.
1795
+ *
1796
+ * @param {BufferAttribute} attribute - The buffer attribute.
1797
+ */
1798
+ createIndirectStorageAttribute( attribute ) {
1799
+
1800
+ this.attributeUtils.createAttribute( attribute, GPUBufferUsage.STORAGE | GPUBufferUsage.INDIRECT | GPUBufferUsage.COPY_SRC | GPUBufferUsage.COPY_DST );
1801
+
1802
+ }
1803
+
1804
+ /**
1805
+ * Updates the GPU buffer of a shader attribute.
1806
+ *
1807
+ * @param {BufferAttribute} attribute - The buffer attribute to update.
1808
+ */
1303
1809
  updateAttribute( attribute ) {
1304
1810
 
1305
1811
  this.attributeUtils.updateAttribute( attribute );
1306
1812
 
1307
1813
  }
1308
1814
 
1815
+ /**
1816
+ * Destroys the GPU buffer of a shader attribute.
1817
+ *
1818
+ * @param {BufferAttribute} attribute - The buffer attribute to destroy.
1819
+ */
1309
1820
  destroyAttribute( attribute ) {
1310
1821
 
1311
1822
  this.attributeUtils.destroyAttribute( attribute );
@@ -1314,6 +1825,9 @@ class WebGPUBackend extends Backend {
1314
1825
 
1315
1826
  // canvas
1316
1827
 
1828
+ /**
1829
+ * Triggers an update of the default render pass descriptor.
1830
+ */
1317
1831
  updateSize() {
1318
1832
 
1319
1833
  this.colorBuffer = this.textureUtils.getColorBuffer();
@@ -1323,25 +1837,47 @@ class WebGPUBackend extends Backend {
1323
1837
 
1324
1838
  // utils public
1325
1839
 
1840
+ /**
1841
+ * Returns the maximum anisotropy texture filtering value.
1842
+ *
1843
+ * @return {number} The maximum anisotropy texture filtering value.
1844
+ */
1326
1845
  getMaxAnisotropy() {
1327
1846
 
1328
1847
  return 16;
1329
1848
 
1330
1849
  }
1331
1850
 
1851
+ /**
1852
+ * Checks if the given feature is supported by the backend.
1853
+ *
1854
+ * @param {string} name - The feature's name.
1855
+ * @return {boolean} Whether the feature is supported or not.
1856
+ */
1332
1857
  hasFeature( name ) {
1333
1858
 
1334
1859
  return this.device.features.has( name );
1335
1860
 
1336
1861
  }
1337
1862
 
1863
+ /**
1864
+ * Copies data of the given source texture to the given destination texture.
1865
+ *
1866
+ * @param {Texture} srcTexture - The source texture.
1867
+ * @param {Texture} dstTexture - The destination texture.
1868
+ * @param {?Vector4} [srcRegion=null] - The region of the source texture to copy.
1869
+ * @param {?(Vector2|Vector3)} [dstPosition=null] - The destination position of the copy.
1870
+ * @param {number} [level=0] - The mip level to copy.
1871
+ */
1338
1872
  copyTextureToTexture( srcTexture, dstTexture, srcRegion = null, dstPosition = null, level = 0 ) {
1339
1873
 
1340
1874
  let dstX = 0;
1341
1875
  let dstY = 0;
1876
+ let dstLayer = 0;
1342
1877
 
1343
1878
  let srcX = 0;
1344
1879
  let srcY = 0;
1880
+ let srcLayer = 0;
1345
1881
 
1346
1882
  let srcWidth = srcTexture.image.width;
1347
1883
  let srcHeight = srcTexture.image.height;
@@ -1350,6 +1886,7 @@ class WebGPUBackend extends Backend {
1350
1886
 
1351
1887
  srcX = srcRegion.x;
1352
1888
  srcY = srcRegion.y;
1889
+ srcLayer = srcRegion.z || 0;
1353
1890
  srcWidth = srcRegion.width;
1354
1891
  srcHeight = srcRegion.height;
1355
1892
 
@@ -1359,6 +1896,7 @@ class WebGPUBackend extends Backend {
1359
1896
 
1360
1897
  dstX = dstPosition.x;
1361
1898
  dstY = dstPosition.y;
1899
+ dstLayer = dstPosition.z || 0;
1362
1900
 
1363
1901
  }
1364
1902
 
@@ -1371,16 +1909,17 @@ class WebGPUBackend extends Backend {
1371
1909
  {
1372
1910
  texture: sourceGPU,
1373
1911
  mipLevel: level,
1374
- origin: { x: srcX, y: srcY, z: 0 }
1912
+ origin: { x: srcX, y: srcY, z: srcLayer }
1375
1913
  },
1376
1914
  {
1377
1915
  texture: destinationGPU,
1378
1916
  mipLevel: level,
1379
- origin: { x: dstX, y: dstY, z: 0 }
1917
+ origin: { x: dstX, y: dstY, z: dstLayer }
1380
1918
  },
1381
1919
  [
1382
1920
  srcWidth,
1383
- srcHeight
1921
+ srcHeight,
1922
+ 1
1384
1923
  ]
1385
1924
  );
1386
1925
 
@@ -1388,12 +1927,17 @@ class WebGPUBackend extends Backend {
1388
1927
 
1389
1928
  }
1390
1929
 
1391
- copyFramebufferToTexture( texture, renderContext ) {
1930
+ /**
1931
+ * Copies the current bound framebuffer to the given texture.
1932
+ *
1933
+ * @param {Texture} texture - The destination texture.
1934
+ * @param {RenderContext} renderContext - The render context.
1935
+ * @param {Vector4} rectangle - A four dimensional vector defining the origin and dimension of the copy.
1936
+ */
1937
+ copyFramebufferToTexture( texture, renderContext, rectangle ) {
1392
1938
 
1393
1939
  const renderContextData = this.get( renderContext );
1394
1940
 
1395
- const { encoder, descriptor } = renderContextData;
1396
-
1397
1941
  let sourceGPU = null;
1398
1942
 
1399
1943
  if ( renderContext.renderTarget ) {
@@ -1432,35 +1976,71 @@ class WebGPUBackend extends Backend {
1432
1976
 
1433
1977
  }
1434
1978
 
1435
- renderContextData.currentPass.end();
1979
+ let encoder;
1980
+
1981
+ if ( renderContextData.currentPass ) {
1982
+
1983
+ renderContextData.currentPass.end();
1984
+
1985
+ encoder = renderContextData.encoder;
1986
+
1987
+ } else {
1988
+
1989
+ encoder = this.device.createCommandEncoder( { label: 'copyFramebufferToTexture_' + texture.id } );
1990
+
1991
+ }
1436
1992
 
1437
1993
  encoder.copyTextureToTexture(
1438
1994
  {
1439
1995
  texture: sourceGPU,
1440
- origin: { x: 0, y: 0, z: 0 }
1996
+ origin: [ rectangle.x, rectangle.y, 0 ],
1441
1997
  },
1442
1998
  {
1443
1999
  texture: destinationGPU
1444
2000
  },
1445
2001
  [
1446
- texture.image.width,
1447
- texture.image.height
2002
+ rectangle.z,
2003
+ rectangle.w
1448
2004
  ]
1449
2005
  );
1450
2006
 
1451
2007
  if ( texture.generateMipmaps ) this.textureUtils.generateMipmaps( texture );
1452
2008
 
1453
- for ( let i = 0; i < descriptor.colorAttachments.length; i ++ ) {
2009
+ if ( renderContextData.currentPass ) {
1454
2010
 
1455
- descriptor.colorAttachments[ i ].loadOp = GPULoadOp.Load;
2011
+ const { descriptor } = renderContextData;
1456
2012
 
1457
- }
2013
+ for ( let i = 0; i < descriptor.colorAttachments.length; i ++ ) {
2014
+
2015
+ descriptor.colorAttachments[ i ].loadOp = GPULoadOp.Load;
2016
+
2017
+ }
2018
+
2019
+ if ( renderContext.depth ) descriptor.depthStencilAttachment.depthLoadOp = GPULoadOp.Load;
2020
+ if ( renderContext.stencil ) descriptor.depthStencilAttachment.stencilLoadOp = GPULoadOp.Load;
2021
+
2022
+ renderContextData.currentPass = encoder.beginRenderPass( descriptor );
2023
+ renderContextData.currentSets = { attributes: {}, bindingGroups: [], pipeline: null, index: null };
2024
+
2025
+ if ( renderContext.viewport ) {
2026
+
2027
+ this.updateViewport( renderContext );
2028
+
2029
+ }
2030
+
2031
+ if ( renderContext.scissor ) {
1458
2032
 
1459
- if ( renderContext.depth ) descriptor.depthStencilAttachment.depthLoadOp = GPULoadOp.Load;
1460
- if ( renderContext.stencil ) descriptor.depthStencilAttachment.stencilLoadOp = GPULoadOp.Load;
2033
+ const { x, y, width, height } = renderContext.scissorValue;
1461
2034
 
1462
- renderContextData.currentPass = encoder.beginRenderPass( descriptor );
1463
- renderContextData.currentSets = { attributes: {} };
2035
+ renderContextData.currentPass.setScissorRect( x, y, width, height );
2036
+
2037
+ }
2038
+
2039
+ } else {
2040
+
2041
+ this.device.queue.submit( [ encoder.finish() ] );
2042
+
2043
+ }
1464
2044
 
1465
2045
  }
1466
2046