@plastic-software/three 0.183.4 → 0.184.1

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 (277) hide show
  1. package/build/three.cjs +775 -287
  2. package/build/three.core.js +372 -110
  3. package/build/three.core.min.js +1 -1
  4. package/build/three.module.js +428 -181
  5. package/build/three.module.min.js +1 -1
  6. package/build/three.tsl.js +7 -1
  7. package/build/three.tsl.min.js +1 -1
  8. package/build/three.webgpu.js +2979 -1281
  9. package/build/three.webgpu.min.js +1 -1
  10. package/build/three.webgpu.nodes.js +2942 -1281
  11. package/build/three.webgpu.nodes.min.js +1 -1
  12. package/examples/jsm/Addons.js +11 -0
  13. package/examples/jsm/animation/CCDIKSolver.js +5 -1
  14. package/examples/jsm/controls/ArcballControls.js +4 -1
  15. package/examples/jsm/controls/DragControls.js +2 -2
  16. package/examples/jsm/controls/FirstPersonControls.js +58 -54
  17. package/examples/jsm/controls/FlyControls.js +4 -0
  18. package/examples/jsm/controls/OrbitControls.js +2 -2
  19. package/examples/jsm/controls/TrackballControls.js +2 -2
  20. package/examples/jsm/controls/TransformControls.js +34 -2
  21. package/examples/jsm/csm/CSMShadowNode.js +6 -2
  22. package/examples/jsm/exporters/GLTFExporter.js +21 -5
  23. package/examples/jsm/geometries/TextGeometry.js +18 -0
  24. package/examples/jsm/helpers/LightProbeGridHelper.js +221 -0
  25. package/examples/jsm/inspector/Extension.js +13 -0
  26. package/examples/jsm/inspector/Inspector.js +169 -114
  27. package/examples/jsm/inspector/RendererInspector.js +2 -2
  28. package/examples/jsm/inspector/extensions/extensions.json +6 -0
  29. package/examples/jsm/inspector/extensions/tsl-graph/TSLGraphEditor.js +916 -0
  30. package/examples/jsm/inspector/extensions/tsl-graph/TSLGraphLoader.js +281 -0
  31. package/examples/jsm/inspector/tabs/Memory.js +128 -0
  32. package/examples/jsm/inspector/tabs/Parameters.js +34 -2
  33. package/examples/jsm/inspector/tabs/Performance.js +2 -2
  34. package/examples/jsm/inspector/tabs/Settings.js +264 -0
  35. package/examples/jsm/inspector/tabs/Timeline.js +1611 -0
  36. package/examples/jsm/inspector/tabs/Viewer.js +105 -3
  37. package/examples/jsm/inspector/ui/Graph.js +2 -2
  38. package/examples/jsm/inspector/ui/List.js +1 -1
  39. package/examples/jsm/inspector/ui/Profiler.js +273 -176
  40. package/examples/jsm/inspector/ui/Style.js +64 -10
  41. package/examples/jsm/inspector/ui/Tab.js +39 -7
  42. package/examples/jsm/inspector/ui/Values.js +39 -2
  43. package/examples/jsm/inspector/ui/utils.js +13 -0
  44. package/examples/jsm/interaction/InteractionManager.js +226 -0
  45. package/examples/jsm/libs/meshopt_decoder.module.js +8 -8
  46. package/examples/jsm/lighting/DynamicLighting.js +82 -0
  47. package/examples/jsm/lighting/LightProbeGrid.js +651 -0
  48. package/examples/jsm/lines/LineMaterial.js +1 -1
  49. package/examples/jsm/loaders/EXRLoader.js +682 -43
  50. package/examples/jsm/loaders/FBXLoader.js +233 -33
  51. package/examples/jsm/loaders/GLTFLoader.js +24 -7
  52. package/examples/jsm/loaders/HDRLoader.js +1 -1
  53. package/examples/jsm/loaders/KTX2Loader.js +8 -2
  54. package/examples/jsm/loaders/LDrawLoader.js +39 -47
  55. package/examples/jsm/loaders/SVGLoader.js +1 -1
  56. package/examples/jsm/loaders/VTKLoader.js +5 -1
  57. package/examples/jsm/loaders/collada/ColladaComposer.js +101 -7
  58. package/examples/jsm/loaders/collada/ColladaParser.js +19 -4
  59. package/examples/jsm/loaders/usd/USDAParser.js +6 -0
  60. package/examples/jsm/loaders/usd/USDCParser.js +26 -0
  61. package/examples/jsm/loaders/usd/USDComposer.js +656 -103
  62. package/examples/jsm/misc/GPUComputationRenderer.js +2 -0
  63. package/examples/jsm/misc/RollerCoaster.js +42 -4
  64. package/examples/jsm/modifiers/TessellateModifier.js +1 -1
  65. package/examples/jsm/objects/Reflector.js +73 -25
  66. package/examples/jsm/objects/Sky.js +14 -2
  67. package/examples/jsm/objects/SkyMesh.js +23 -6
  68. package/examples/jsm/renderers/Projector.js +18 -38
  69. package/examples/jsm/renderers/SVGRenderer.js +6 -25
  70. package/examples/jsm/transpiler/GLSLDecoder.js +2 -2
  71. package/examples/jsm/tsl/WebGLNodesHandler.js +605 -0
  72. package/examples/jsm/tsl/display/AfterImageNode.js +10 -0
  73. package/examples/jsm/tsl/display/AnamorphicNode.js +11 -0
  74. package/examples/jsm/tsl/display/BilateralBlurNode.js +10 -0
  75. package/examples/jsm/tsl/display/ChromaticAberrationNode.js +3 -36
  76. package/examples/jsm/tsl/display/FSR1Node.js +477 -0
  77. package/examples/jsm/tsl/display/GTAONode.js +2 -1
  78. package/examples/jsm/tsl/display/GaussianBlurNode.js +10 -0
  79. package/examples/jsm/tsl/display/GodraysNode.js +2 -11
  80. package/examples/jsm/tsl/display/OutlineNode.js +66 -16
  81. package/examples/jsm/tsl/display/SSGINode.js +0 -4
  82. package/examples/jsm/tsl/display/SharpenNode.js +283 -0
  83. package/examples/jsm/tsl/display/TAAUNode.js +835 -0
  84. package/examples/jsm/tsl/display/TRAANode.js +48 -7
  85. package/examples/jsm/tsl/lighting/DynamicLightsNode.js +300 -0
  86. package/examples/jsm/tsl/lighting/data/AmbientLightDataNode.js +61 -0
  87. package/examples/jsm/tsl/lighting/data/DirectionalLightDataNode.js +111 -0
  88. package/examples/jsm/tsl/lighting/data/HemisphereLightDataNode.js +99 -0
  89. package/examples/jsm/tsl/lighting/data/PointLightDataNode.js +134 -0
  90. package/examples/jsm/tsl/lighting/data/SpotLightDataNode.js +161 -0
  91. package/examples/jsm/tsl/math/Bayer.js +13 -2
  92. package/examples/jsm/utils/BufferGeometryUtils.js +2 -3
  93. package/examples/jsm/utils/ColorUtils.js +76 -0
  94. package/examples/jsm/utils/SkeletonUtils.js +14 -8
  95. package/examples/jsm/webxr/XRHandMeshModel.js +36 -10
  96. package/examples/jsm/webxr/XRHandModelFactory.js +2 -1
  97. package/package.json +4 -4
  98. package/src/Three.Core.js +1 -0
  99. package/src/Three.TSL.js +6 -0
  100. package/src/Three.WebGPU.Nodes.js +3 -0
  101. package/src/Three.WebGPU.js +6 -0
  102. package/src/animation/AnimationAction.js +11 -1
  103. package/src/audio/AudioContext.js +2 -2
  104. package/src/constants.js +1 -1
  105. package/src/core/BufferAttribute.js +13 -1
  106. package/src/core/Clock.js +1 -1
  107. package/src/core/Object3D.js +1 -5
  108. package/src/core/RenderTarget.js +1 -0
  109. package/src/extras/curves/CatmullRomCurve3.js +3 -2
  110. package/src/loaders/AudioLoader.js +11 -1
  111. package/src/loaders/DataTextureLoader.js +6 -4
  112. package/src/loaders/FileLoader.js +1 -2
  113. package/src/loaders/ImageBitmapLoader.js +4 -6
  114. package/src/loaders/MaterialLoader.js +1 -1
  115. package/src/loaders/ObjectLoader.js +25 -4
  116. package/src/loaders/nodes/NodeObjectLoader.js +18 -0
  117. package/src/materials/MeshToonMaterial.js +1 -1
  118. package/src/materials/nodes/Line2NodeMaterial.js +27 -0
  119. package/src/materials/nodes/NodeMaterial.js +0 -27
  120. package/src/materials/nodes/manager/NodeMaterialObserver.js +188 -89
  121. package/src/math/Line3.js +3 -0
  122. package/src/math/Matrix2.js +13 -9
  123. package/src/math/Matrix3.js +13 -9
  124. package/src/math/Matrix4.js +13 -9
  125. package/src/math/Plane.js +4 -3
  126. package/src/math/Triangle.js +1 -1
  127. package/src/math/Vector2.js +11 -7
  128. package/src/math/Vector3.js +12 -8
  129. package/src/math/Vector4.js +13 -9
  130. package/src/nodes/Nodes.js +0 -1
  131. package/src/nodes/TSL.js +1 -1
  132. package/src/nodes/accessors/BufferAttributeNode.js +9 -3
  133. package/src/nodes/accessors/CubeTextureNode.js +7 -1
  134. package/src/nodes/accessors/MaterialProperties.js +2 -5
  135. package/src/nodes/accessors/Object3DNode.js +1 -1
  136. package/src/nodes/accessors/ReferenceBaseNode.js +2 -2
  137. package/src/nodes/accessors/ReferenceNode.js +4 -4
  138. package/src/nodes/accessors/SceneProperties.js +2 -8
  139. package/src/nodes/accessors/StorageBufferNode.js +10 -4
  140. package/src/nodes/accessors/StorageTextureNode.js +4 -9
  141. package/src/nodes/accessors/TextureNode.js +10 -2
  142. package/src/nodes/accessors/UniformArrayNode.js +2 -2
  143. package/src/nodes/code/FunctionCallNode.js +1 -1
  144. package/src/nodes/code/FunctionNode.js +1 -1
  145. package/src/nodes/core/ArrayNode.js +1 -1
  146. package/src/nodes/core/AssignNode.js +1 -1
  147. package/src/nodes/core/AttributeNode.js +1 -1
  148. package/src/nodes/core/BypassNode.js +1 -1
  149. package/src/nodes/core/ContextNode.js +1 -1
  150. package/src/nodes/core/IndexNode.js +2 -1
  151. package/src/nodes/core/InputNode.js +1 -1
  152. package/src/nodes/core/InspectorNode.js +1 -1
  153. package/src/nodes/core/IsolateNode.js +1 -1
  154. package/src/nodes/core/Node.js +83 -12
  155. package/src/nodes/core/NodeBuilder.js +117 -16
  156. package/src/nodes/core/NodeUtils.js +1 -1
  157. package/src/nodes/core/OutputStructNode.js +1 -1
  158. package/src/nodes/core/ParameterNode.js +1 -1
  159. package/src/nodes/core/StackNode.js +1 -1
  160. package/src/nodes/core/StructNode.js +1 -1
  161. package/src/nodes/core/StructTypeNode.js +1 -1
  162. package/src/nodes/core/SubBuildNode.js +1 -1
  163. package/src/nodes/core/UniformGroupNode.js +36 -6
  164. package/src/nodes/core/VarNode.js +1 -1
  165. package/src/nodes/core/VaryingNode.js +1 -1
  166. package/src/nodes/display/NormalMapNode.js +2 -2
  167. package/src/nodes/display/PassNode.js +27 -7
  168. package/src/nodes/display/RenderOutputNode.js +4 -4
  169. package/src/nodes/display/ScreenNode.js +1 -1
  170. package/src/nodes/display/ViewportDepthTextureNode.js +11 -15
  171. package/src/nodes/display/ViewportTextureNode.js +18 -7
  172. package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated_Anisotropic.js +2 -2
  173. package/src/nodes/geometry/RangeNode.js +1 -1
  174. package/src/nodes/gpgpu/AtomicFunctionNode.js +1 -1
  175. package/src/nodes/gpgpu/BarrierNode.js +9 -0
  176. package/src/nodes/gpgpu/ComputeBuiltinNode.js +1 -1
  177. package/src/nodes/gpgpu/ComputeNode.js +69 -44
  178. package/src/nodes/gpgpu/SubgroupFunctionNode.js +1 -1
  179. package/src/nodes/lighting/LightsNode.js +6 -27
  180. package/src/nodes/lighting/ShadowNode.js +24 -2
  181. package/src/nodes/math/BitcastNode.js +1 -1
  182. package/src/nodes/math/ConditionalNode.js +1 -1
  183. package/src/nodes/math/MathNode.js +73 -1
  184. package/src/nodes/math/OperatorNode.js +1 -1
  185. package/src/nodes/math/PackFloatNode.js +1 -1
  186. package/src/nodes/math/UnpackFloatNode.js +1 -1
  187. package/src/nodes/tsl/TSLBase.js +1 -1
  188. package/src/nodes/tsl/TSLCore.js +21 -3
  189. package/src/nodes/utils/ArrayElementNode.js +1 -1
  190. package/src/nodes/utils/ConvertNode.js +1 -1
  191. package/src/nodes/utils/DebugNode.js +1 -1
  192. package/src/nodes/utils/EventNode.js +30 -0
  193. package/src/nodes/utils/FlipNode.js +1 -1
  194. package/src/nodes/utils/FunctionOverloadingNode.js +1 -1
  195. package/src/nodes/utils/JoinNode.js +1 -1
  196. package/src/nodes/utils/MemberNode.js +1 -1
  197. package/src/nodes/utils/Remap.js +48 -0
  198. package/src/nodes/utils/RotateNode.js +1 -1
  199. package/src/nodes/utils/SetNode.js +1 -1
  200. package/src/nodes/utils/SplitNode.js +1 -1
  201. package/src/objects/BatchedMesh.js +17 -2
  202. package/src/objects/InstancedMesh.js +19 -3
  203. package/src/objects/SkinnedMesh.js +26 -9
  204. package/src/renderers/WebGLRenderer.js +147 -48
  205. package/src/renderers/common/Animation.js +3 -3
  206. package/src/renderers/common/Attributes.js +15 -1
  207. package/src/renderers/common/Backend.js +0 -8
  208. package/src/renderers/common/Background.js +2 -2
  209. package/src/renderers/common/BindGroup.js +1 -8
  210. package/src/renderers/common/Bindings.js +2 -2
  211. package/src/renderers/common/ComputePipeline.js +1 -1
  212. package/src/renderers/common/CubeRenderTarget.js +1 -1
  213. package/src/renderers/common/Info.js +333 -4
  214. package/src/renderers/common/InspectorBase.js +6 -1
  215. package/src/renderers/common/Pipelines.js +36 -3
  216. package/src/renderers/common/ReadbackBuffer.js +78 -0
  217. package/src/renderers/common/RenderBundle.js +3 -1
  218. package/src/renderers/common/RenderBundles.js +5 -2
  219. package/src/renderers/common/RenderObject.js +2 -2
  220. package/src/renderers/common/RenderObjects.js +3 -3
  221. package/src/renderers/common/RenderPipeline.js +35 -6
  222. package/src/renderers/common/Renderer.js +232 -53
  223. package/src/renderers/common/Textures.js +72 -3
  224. package/src/renderers/common/UniformsGroup.js +1 -1
  225. package/src/renderers/common/XRManager.js +34 -27
  226. package/src/renderers/common/extras/PMREMGenerator.js +23 -15
  227. package/src/renderers/common/nodes/NodeBuilderState.js +1 -1
  228. package/src/renderers/common/nodes/NodeManager.js +230 -99
  229. package/src/renderers/shaders/ShaderChunk/envmap_common_pars_fragment.glsl.js +0 -1
  230. package/src/renderers/shaders/ShaderChunk/envmap_fragment.glsl.js +1 -1
  231. package/src/renderers/shaders/ShaderChunk/lightprobes_pars_fragment.glsl.js +80 -0
  232. package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +8 -0
  233. package/src/renderers/shaders/ShaderChunk/lights_pars_begin.glsl.js +2 -0
  234. package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +1 -3
  235. package/src/renderers/shaders/ShaderChunk/normal_fragment_maps.glsl.js +7 -0
  236. package/src/renderers/shaders/ShaderChunk/premultiplied_alpha_fragment.glsl.js +0 -1
  237. package/src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl.js +12 -2
  238. package/src/renderers/shaders/ShaderChunk.js +2 -0
  239. package/src/renderers/shaders/ShaderLib/backgroundCube.glsl.js +1 -2
  240. package/src/renderers/shaders/ShaderLib.js +0 -1
  241. package/src/renderers/shaders/UniformsLib.js +7 -2
  242. package/src/renderers/shaders/UniformsUtils.js +27 -5
  243. package/src/renderers/webgl/WebGLAnimation.js +2 -1
  244. package/src/renderers/webgl/WebGLBackground.js +13 -13
  245. package/src/renderers/webgl/WebGLBufferRenderer.js +0 -32
  246. package/src/renderers/webgl/WebGLCapabilities.js +6 -0
  247. package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +0 -32
  248. package/src/renderers/webgl/WebGLMaterials.js +12 -13
  249. package/src/renderers/webgl/WebGLOutput.js +4 -1
  250. package/src/renderers/webgl/WebGLProgram.js +4 -0
  251. package/src/renderers/webgl/WebGLPrograms.js +21 -4
  252. package/src/renderers/webgl/WebGLRenderStates.js +13 -2
  253. package/src/renderers/webgl/WebGLState.js +43 -0
  254. package/src/renderers/webgl/WebGLTextures.js +129 -26
  255. package/src/renderers/webgl/WebGLUniformsGroups.js +19 -0
  256. package/src/renderers/webgl-fallback/WebGLBackend.js +106 -65
  257. package/src/renderers/webgl-fallback/WebGLBufferRenderer.js +0 -41
  258. package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +29 -51
  259. package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +53 -19
  260. package/src/renderers/webgl-fallback/utils/WebGLCapabilities.js +25 -0
  261. package/src/renderers/webgl-fallback/utils/WebGLState.js +42 -1
  262. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +63 -50
  263. package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +1 -1
  264. package/src/renderers/webgpu/WebGPUBackend.js +160 -146
  265. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +55 -33
  266. package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +103 -17
  267. package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +1 -1
  268. package/src/renderers/webgpu/utils/WebGPUCapabilities.js +48 -0
  269. package/src/renderers/webgpu/utils/WebGPUConstants.js +8 -0
  270. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +91 -17
  271. package/src/renderers/webgpu/utils/WebGPUUtils.js +18 -2
  272. package/src/renderers/webxr/WebXRController.js +12 -0
  273. package/src/textures/HTMLTexture.js +74 -0
  274. package/src/textures/Source.js +1 -1
  275. package/src/textures/Texture.js +13 -2
  276. package/src/utils.js +23 -1
  277. package/src/nodes/utils/RemapNode.js +0 -125
@@ -10,12 +10,15 @@ import Backend from '../common/Backend.js';
10
10
  import WebGPUUtils from './utils/WebGPUUtils.js';
11
11
  import WebGPUAttributeUtils from './utils/WebGPUAttributeUtils.js';
12
12
  import WebGPUBindingUtils from './utils/WebGPUBindingUtils.js';
13
+ import WebGPUCapabilities from './utils/WebGPUCapabilities.js';
13
14
  import WebGPUPipelineUtils from './utils/WebGPUPipelineUtils.js';
14
15
  import WebGPUTextureUtils from './utils/WebGPUTextureUtils.js';
15
16
 
16
17
  import { WebGPUCoordinateSystem, TimestampQuery, REVISION, HalfFloatType, Compatibility } from '../../constants.js';
17
18
  import WebGPUTimestampQueryPool from './utils/WebGPUTimestampQueryPool.js';
18
- import { warnOnce, error } from '../../utils.js';
19
+ import { error } from '../../utils.js';
20
+
21
+ const _clearValue = { r: 0, g: 0, b: 0, a: 1 };
19
22
 
20
23
  /**
21
24
  * A backend implementation targeting WebGPU.
@@ -116,6 +119,14 @@ class WebGPUBackend extends Backend {
116
119
  */
117
120
  this.bindingUtils = new WebGPUBindingUtils( this );
118
121
 
122
+ /**
123
+ * A reference to a backend module holding device capability related
124
+ * utility functions.
125
+ *
126
+ * @type {WebGPUCapabilities}
127
+ */
128
+ this.capabilities = new WebGPUCapabilities( this );
129
+
119
130
  /**
120
131
  * A reference to a backend module holding shader pipeline-related
121
132
  * utility functions.
@@ -314,15 +325,20 @@ class WebGPUBackend extends Backend {
314
325
 
315
326
  /**
316
327
  * This method performs a readback operation by moving buffer data from
317
- * a storage buffer attribute from the GPU to the CPU.
328
+ * a storage buffer attribute from the GPU to the CPU. ReadbackBuffer can
329
+ * be used to retain and reuse handles to the intermediate buffers and prevent
330
+ * new allocation.
318
331
  *
319
332
  * @async
320
- * @param {StorageBufferAttribute} attribute - The storage buffer attribute.
321
- * @return {Promise<ArrayBuffer>} A promise that resolves with the buffer data when the data are ready.
333
+ * @param {BufferAttribute} attribute - The storage buffer attribute to read frm.
334
+ * @param {number} count - The offset from which to start reading the
335
+ * @param {number} offset - The storage buffer attribute.
336
+ * @param {ReadbackBuffer|ArrayBuffer} target - The storage buffer attribute.
337
+ * @return {Promise<ArrayBuffer|ReadbackBuffer>} A promise that resolves with the buffer data when the data are ready.
322
338
  */
323
- async getArrayBufferAsync( attribute ) {
339
+ async getArrayBufferAsync( attribute, target = null, offset = 0, count = - 1 ) {
324
340
 
325
- return await this.attributeUtils.getArrayBufferAsync( attribute );
341
+ return await this.attributeUtils.getArrayBufferAsync( attribute, target, offset, count );
326
342
 
327
343
  }
328
344
 
@@ -673,7 +689,21 @@ class WebGPUBackend extends Backend {
673
689
 
674
690
  if ( renderContext.clearColor ) {
675
691
 
676
- colorAttachment.clearValue = i === 0 ? renderContext.clearColorValue : { r: 0, g: 0, b: 0, a: 1 };
692
+ if ( i === 0 ) {
693
+
694
+ colorAttachment.clearValue = renderContext.clearColorValue;
695
+
696
+ } else {
697
+
698
+ _clearValue.r = 0;
699
+ _clearValue.g = 0;
700
+ _clearValue.b = 0;
701
+ _clearValue.a = 1;
702
+
703
+ colorAttachment.clearValue = _clearValue;
704
+
705
+ }
706
+
677
707
  colorAttachment.loadOp = GPULoadOp.Clear;
678
708
 
679
709
  } else {
@@ -1215,7 +1245,6 @@ class WebGPUBackend extends Backend {
1215
1245
 
1216
1246
  let colorAttachments = [];
1217
1247
  let depthStencilAttachment;
1218
- let clearValue;
1219
1248
 
1220
1249
  let supportsDepth;
1221
1250
  let supportsStencil;
@@ -1223,7 +1252,11 @@ class WebGPUBackend extends Backend {
1223
1252
  if ( color ) {
1224
1253
 
1225
1254
  const clearColor = this.getClearColor();
1226
- clearValue = { r: clearColor.r, g: clearColor.g, b: clearColor.b, a: clearColor.a };
1255
+
1256
+ _clearValue.r = clearColor.r;
1257
+ _clearValue.g = clearColor.g;
1258
+ _clearValue.b = clearColor.b;
1259
+ _clearValue.a = clearColor.a;
1227
1260
 
1228
1261
  }
1229
1262
 
@@ -1240,7 +1273,7 @@ class WebGPUBackend extends Backend {
1240
1273
 
1241
1274
  const colorAttachment = colorAttachments[ 0 ];
1242
1275
 
1243
- colorAttachment.clearValue = clearValue;
1276
+ colorAttachment.clearValue = _clearValue;
1244
1277
  colorAttachment.loadOp = GPULoadOp.Clear;
1245
1278
  colorAttachment.storeOp = GPUStoreOp.Store;
1246
1279
 
@@ -1259,7 +1292,7 @@ class WebGPUBackend extends Backend {
1259
1292
 
1260
1293
  const clearConfig = {
1261
1294
  loadOp: color ? GPULoadOp.Clear : GPULoadOp.Load,
1262
- clearValue: color ? clearValue : undefined
1295
+ clearValue: color ? _clearValue : undefined
1263
1296
  };
1264
1297
 
1265
1298
  if ( supportsDepth ) {
@@ -1397,13 +1430,13 @@ class WebGPUBackend extends Backend {
1397
1430
 
1398
1431
  if ( dispatchSize === null ) {
1399
1432
 
1400
- dispatchSize = computeNode.count;
1433
+ dispatchSize = computeNode.dispatchSize || computeNode.count;
1401
1434
 
1402
1435
  }
1403
1436
 
1404
1437
  // When the dispatchSize is set with a StorageBuffer from the GPU.
1405
1438
 
1406
- if ( dispatchSize && typeof dispatchSize === 'object' && dispatchSize.isIndirectStorageBufferAttribute ) {
1439
+ if ( dispatchSize && dispatchSize.isIndirectStorageBufferAttribute ) {
1407
1440
 
1408
1441
  const dispatchBuffer = this.get( dispatchSize ).buffer;
1409
1442
 
@@ -1482,204 +1515,201 @@ class WebGPUBackend extends Backend {
1482
1515
 
1483
1516
  }
1484
1517
 
1485
- // render object
1486
-
1487
1518
  /**
1488
- * Executes a draw command for the given render object.
1519
+ * Internal draw function that performs the draw with the given pass encoder.
1489
1520
  *
1490
- * @param {RenderObject} renderObject - The render object to draw.
1521
+ * @private
1522
+ * @param {RenderObject} renderObject - The render object.
1491
1523
  * @param {Info} info - Holds a series of statistical information about the GPU memory and the rendering process.
1524
+ * @param {Object} renderContextData - The render context data object, holding current pass state and occlusion query tracking.
1525
+ * @param {GPURenderPipeline} pipelineGPU - The GPU render pipeline.
1526
+ * @param {Array<BindGroup>} bindings - The bind groups.
1527
+ * @param {Array<BufferAttribute>} vertexBuffers - The vertex buffers.
1528
+ * @param {{vertexCount: number, firstVertex: number, instanceCount: number, firstInstance: number}} drawParams - The draw parameters.
1529
+ * @param {GPURenderPassEncoder|GPURenderBundleEncoder} passEncoderGPU - The GPU pass encoder used for recording draw commands.
1530
+ * @param {Object} currentSets - Tracking object for currently set pipeline, attributes, bind groups, and index state.
1492
1531
  */
1493
- draw( renderObject, info ) {
1494
-
1495
- const { object, material, context, pipeline } = renderObject;
1496
- const bindings = renderObject.getBindings();
1497
- const renderContextData = this.get( context );
1498
- const pipelineData = this.get( pipeline );
1499
- const pipelineGPU = pipelineData.pipeline;
1532
+ _draw( renderObject, info, renderContextData, pipelineGPU, bindings, vertexBuffers, drawParams, passEncoderGPU, currentSets ) {
1500
1533
 
1501
- if ( pipelineData.error === true ) return;
1534
+ const { object, material, context } = renderObject;
1502
1535
 
1503
1536
  const index = renderObject.getIndex();
1504
1537
  const hasIndex = ( index !== null );
1505
1538
 
1506
-
1507
- const drawParams = renderObject.getDrawParameters();
1508
- if ( drawParams === null ) return;
1509
-
1510
1539
  // pipeline
1540
+ this.pipelineUtils.setPipeline( passEncoderGPU, pipelineGPU );
1541
+ currentSets.pipeline = pipelineGPU;
1511
1542
 
1512
- const setPipelineAndBindings = ( passEncoderGPU, currentSets ) => {
1513
-
1514
- // pipeline
1515
- this.pipelineUtils.setPipeline( passEncoderGPU, pipelineGPU );
1516
- currentSets.pipeline = pipelineGPU;
1517
-
1518
- // bind groups
1519
- const currentBindingGroups = currentSets.bindingGroups;
1520
- for ( let i = 0, l = bindings.length; i < l; i ++ ) {
1521
-
1522
- const bindGroup = bindings[ i ];
1523
- const bindingsData = this.get( bindGroup );
1524
- if ( currentBindingGroups[ bindGroup.index ] !== bindGroup.id ) {
1543
+ // bind groups
1544
+ const currentBindingGroups = currentSets.bindingGroups;
1545
+ for ( let i = 0, l = bindings.length; i < l; i ++ ) {
1525
1546
 
1526
- passEncoderGPU.setBindGroup( bindGroup.index, bindingsData.group );
1527
- currentBindingGroups[ bindGroup.index ] = bindGroup.id;
1547
+ const bindGroup = bindings[ i ];
1548
+ const bindingsData = this.get( bindGroup );
1549
+ if ( currentBindingGroups[ i ] !== bindGroup.id ) {
1528
1550
 
1529
- }
1551
+ passEncoderGPU.setBindGroup( i, bindingsData.group );
1552
+ currentBindingGroups[ i ] = bindGroup.id;
1530
1553
 
1531
1554
  }
1532
1555
 
1533
- // attributes
1556
+ }
1534
1557
 
1535
- // index
1558
+ // attributes
1536
1559
 
1537
- if ( hasIndex === true ) {
1560
+ // index
1538
1561
 
1539
- if ( currentSets.index !== index ) {
1562
+ if ( hasIndex === true ) {
1540
1563
 
1541
- const buffer = this.get( index ).buffer;
1542
- const indexFormat = ( index.array instanceof Uint16Array ) ? GPUIndexFormat.Uint16 : GPUIndexFormat.Uint32;
1564
+ if ( currentSets.index !== index ) {
1543
1565
 
1544
- passEncoderGPU.setIndexBuffer( buffer, indexFormat );
1566
+ const buffer = this.get( index ).buffer;
1567
+ const indexFormat = ( index.array instanceof Uint16Array ) ? GPUIndexFormat.Uint16 : GPUIndexFormat.Uint32;
1545
1568
 
1546
- currentSets.index = index;
1569
+ passEncoderGPU.setIndexBuffer( buffer, indexFormat );
1547
1570
 
1548
- }
1571
+ currentSets.index = index;
1549
1572
 
1550
1573
  }
1551
- // vertex buffers
1552
-
1553
- const vertexBuffers = renderObject.getVertexBuffers();
1554
1574
 
1555
- for ( let i = 0, l = vertexBuffers.length; i < l; i ++ ) {
1575
+ }
1556
1576
 
1557
- const vertexBuffer = vertexBuffers[ i ];
1577
+ for ( let i = 0, l = vertexBuffers.length; i < l; i ++ ) {
1558
1578
 
1559
- if ( currentSets.attributes[ i ] !== vertexBuffer ) {
1579
+ const vertexBuffer = vertexBuffers[ i ];
1560
1580
 
1561
- const buffer = this.get( vertexBuffer ).buffer;
1562
- passEncoderGPU.setVertexBuffer( i, buffer );
1581
+ if ( currentSets.attributes[ i ] !== vertexBuffer ) {
1563
1582
 
1564
- currentSets.attributes[ i ] = vertexBuffer;
1583
+ const buffer = this.get( vertexBuffer ).buffer;
1584
+ passEncoderGPU.setVertexBuffer( i, buffer );
1565
1585
 
1566
- }
1586
+ currentSets.attributes[ i ] = vertexBuffer;
1567
1587
 
1568
1588
  }
1569
- // stencil
1570
1589
 
1571
- if ( context.stencil === true && material.stencilWrite === true && renderContextData.currentStencilRef !== material.stencilRef ) {
1590
+ }
1591
+ // stencil
1572
1592
 
1573
- passEncoderGPU.setStencilReference( material.stencilRef );
1574
- renderContextData.currentStencilRef = material.stencilRef;
1593
+ if ( context.stencil === true && material.stencilWrite === true && renderContextData.currentStencilRef !== material.stencilRef ) {
1575
1594
 
1576
- }
1595
+ passEncoderGPU.setStencilReference( material.stencilRef );
1596
+ renderContextData.currentStencilRef = material.stencilRef;
1577
1597
 
1598
+ }
1578
1599
 
1579
- };
1600
+ if ( object.isBatchedMesh === true ) {
1580
1601
 
1581
- // Define draw function
1582
- const draw = ( passEncoderGPU, currentSets ) => {
1602
+ const starts = object._multiDrawStarts;
1603
+ const counts = object._multiDrawCounts;
1604
+ const drawCount = object._multiDrawCount;
1583
1605
 
1584
- setPipelineAndBindings( passEncoderGPU, currentSets );
1606
+ let bytesPerElement = ( hasIndex === true ) ? index.array.BYTES_PER_ELEMENT : 1;
1585
1607
 
1586
- if ( object.isBatchedMesh === true ) {
1608
+ if ( material.wireframe ) {
1587
1609
 
1588
- const starts = object._multiDrawStarts;
1589
- const counts = object._multiDrawCounts;
1590
- const drawCount = object._multiDrawCount;
1591
- const drawInstances = object._multiDrawInstances;
1610
+ bytesPerElement = object.geometry.attributes.position.count > 65535 ? 4 : 2;
1592
1611
 
1593
- if ( drawInstances !== null ) {
1612
+ }
1594
1613
 
1595
- // @deprecated, r174
1596
- warnOnce( 'WebGPUBackend: renderMultiDrawInstances has been deprecated and will be removed in r184. Append to renderMultiDraw arguments and use indirection.' );
1614
+ for ( let i = 0; i < drawCount; i ++ ) {
1597
1615
 
1598
- }
1616
+ if ( hasIndex === true ) {
1599
1617
 
1600
- let bytesPerElement = ( hasIndex === true ) ? index.array.BYTES_PER_ELEMENT : 1;
1618
+ passEncoderGPU.drawIndexed( counts[ i ], 1, starts[ i ] / bytesPerElement, 0, i );
1601
1619
 
1602
- if ( material.wireframe ) {
1620
+ } else {
1603
1621
 
1604
- bytesPerElement = object.geometry.attributes.position.count > 65535 ? 4 : 2;
1622
+ passEncoderGPU.draw( counts[ i ], 1, starts[ i ], i );
1605
1623
 
1606
1624
  }
1607
1625
 
1608
- for ( let i = 0; i < drawCount; i ++ ) {
1626
+ info.update( object, counts[ i ], 1 );
1609
1627
 
1610
- const count = drawInstances ? drawInstances[ i ] : 1;
1611
- const firstInstance = count > 1 ? 0 : i;
1628
+ }
1612
1629
 
1613
- if ( hasIndex === true ) {
1630
+ } else if ( hasIndex === true ) {
1614
1631
 
1615
- passEncoderGPU.drawIndexed( counts[ i ], count, starts[ i ] / bytesPerElement, 0, firstInstance );
1632
+ const { vertexCount: indexCount, instanceCount, firstVertex: firstIndex } = drawParams;
1616
1633
 
1617
- } else {
1634
+ const indirect = renderObject.getIndirect();
1618
1635
 
1619
- passEncoderGPU.draw( counts[ i ], count, starts[ i ], firstInstance );
1636
+ if ( indirect !== null ) {
1620
1637
 
1621
- }
1638
+ const buffer = this.get( indirect ).buffer;
1639
+ const indirectOffset = renderObject.getIndirectOffset();
1640
+ const indirectOffsets = Array.isArray( indirectOffset ) ? indirectOffset : [ indirectOffset ];
1641
+
1642
+ for ( let i = 0; i < indirectOffsets.length; i ++ ) {
1622
1643
 
1623
- info.update( object, counts[ i ], count );
1644
+ passEncoderGPU.drawIndexedIndirect( buffer, indirectOffsets[ i ] );
1624
1645
 
1625
1646
  }
1626
1647
 
1627
- } else if ( hasIndex === true ) {
1648
+ } else {
1649
+
1650
+ passEncoderGPU.drawIndexed( indexCount, instanceCount, firstIndex, 0, 0 );
1628
1651
 
1629
- const { vertexCount: indexCount, instanceCount, firstVertex: firstIndex } = drawParams;
1652
+ }
1630
1653
 
1631
- const indirect = renderObject.getIndirect();
1654
+ info.update( object, indexCount, instanceCount );
1632
1655
 
1633
- if ( indirect !== null ) {
1656
+ } else {
1634
1657
 
1635
- const buffer = this.get( indirect ).buffer;
1636
- const indirectOffset = renderObject.getIndirectOffset();
1637
- const indirectOffsets = Array.isArray( indirectOffset ) ? indirectOffset : [ indirectOffset ];
1658
+ const { vertexCount, instanceCount, firstVertex } = drawParams;
1638
1659
 
1639
- for ( let i = 0; i < indirectOffsets.length; i ++ ) {
1660
+ const indirect = renderObject.getIndirect();
1640
1661
 
1641
- passEncoderGPU.drawIndexedIndirect( buffer, indirectOffsets[ i ] );
1662
+ if ( indirect !== null ) {
1642
1663
 
1643
- }
1664
+ const buffer = this.get( indirect ).buffer;
1665
+ const indirectOffset = renderObject.getIndirectOffset();
1666
+ const indirectOffsets = Array.isArray( indirectOffset ) ? indirectOffset : [ indirectOffset ];
1644
1667
 
1645
- } else {
1668
+ for ( let i = 0; i < indirectOffsets.length; i ++ ) {
1646
1669
 
1647
- passEncoderGPU.drawIndexed( indexCount, instanceCount, firstIndex, 0, 0 );
1670
+ passEncoderGPU.drawIndirect( buffer, indirectOffsets[ i ] );
1648
1671
 
1649
1672
  }
1650
1673
 
1651
- info.update( object, indexCount, instanceCount );
1652
1674
 
1653
1675
  } else {
1654
1676
 
1655
- const { vertexCount, instanceCount, firstVertex } = drawParams;
1677
+ passEncoderGPU.draw( vertexCount, instanceCount, firstVertex, 0 );
1656
1678
 
1657
- const indirect = renderObject.getIndirect();
1658
-
1659
- if ( indirect !== null ) {
1679
+ }
1660
1680
 
1661
- const buffer = this.get( indirect ).buffer;
1662
- const indirectOffset = renderObject.getIndirectOffset();
1663
- const indirectOffsets = Array.isArray( indirectOffset ) ? indirectOffset : [ indirectOffset ];
1681
+ info.update( object, vertexCount, instanceCount );
1664
1682
 
1665
- for ( let i = 0; i < indirectOffsets.length; i ++ ) {
1683
+ }
1666
1684
 
1667
- passEncoderGPU.drawIndirect( buffer, indirectOffsets[ i ] );
1685
+ }
1668
1686
 
1669
- }
1687
+ // render object
1670
1688
 
1689
+ /**
1690
+ * Executes a draw command for the given render object.
1691
+ *
1692
+ * @param {RenderObject} renderObject - The render object to draw.
1693
+ * @param {Info} info - Holds a series of statistical information about the GPU memory and the rendering process.
1694
+ */
1695
+ draw( renderObject, info ) {
1671
1696
 
1672
- } else {
1697
+ const { object, context, pipeline } = renderObject;
1698
+ const renderContextData = this.get( context );
1699
+ const pipelineData = this.get( pipeline );
1700
+ const pipelineGPU = pipelineData.pipeline;
1673
1701
 
1674
- passEncoderGPU.draw( vertexCount, instanceCount, firstVertex, 0 );
1702
+ // Skip if pipeline has error
1703
+ if ( pipelineData.error === true ) return;
1675
1704
 
1676
- }
1705
+ const drawParams = renderObject.getDrawParameters();
1706
+ if ( drawParams === null ) return;
1677
1707
 
1678
- info.update( object, vertexCount, instanceCount );
1708
+ const bindings = renderObject.getBindings();
1679
1709
 
1680
- }
1710
+ // vertex buffers
1681
1711
 
1682
- };
1712
+ const vertexBuffers = renderObject.getVertexBuffers();
1683
1713
 
1684
1714
  if ( renderObject.camera.isArrayCamera && renderObject.camera.cameras.length > 0 ) {
1685
1715
 
@@ -1720,8 +1750,6 @@ class WebGPUBackend extends Backend {
1720
1750
 
1721
1751
  const vp = subCamera.viewport;
1722
1752
 
1723
-
1724
-
1725
1753
  let pass = renderContextData.currentPass;
1726
1754
  let sets = renderContextData.currentSets;
1727
1755
  if ( renderContextData.bundleEncoders ) {
@@ -1733,8 +1761,6 @@ class WebGPUBackend extends Backend {
1733
1761
 
1734
1762
  }
1735
1763
 
1736
-
1737
-
1738
1764
  if ( vp ) {
1739
1765
 
1740
1766
  pass.setViewport(
@@ -1748,17 +1774,16 @@ class WebGPUBackend extends Backend {
1748
1774
 
1749
1775
  }
1750
1776
 
1751
-
1752
1777
  // Set camera index binding for this layer
1753
1778
  if ( cameraIndex && cameraData.indexesGPU ) {
1754
1779
 
1755
- pass.setBindGroup( cameraIndex.index, cameraData.indexesGPU[ i ] );
1756
- sets.bindingGroups[ cameraIndex.index ] = cameraIndex.id;
1780
+ const indexPos = bindings.indexOf( cameraIndex );
1781
+ pass.setBindGroup( indexPos, cameraData.indexesGPU[ i ] );
1782
+ sets.bindingGroups[ indexPos ] = cameraIndex.id;
1757
1783
 
1758
1784
  }
1759
1785
 
1760
- draw( pass, sets );
1761
-
1786
+ this._draw( renderObject, info, renderContextData, pipelineGPU, bindings, vertexBuffers, drawParams, pass, sets );
1762
1787
 
1763
1788
  }
1764
1789
 
@@ -1795,7 +1820,7 @@ class WebGPUBackend extends Backend {
1795
1820
 
1796
1821
  }
1797
1822
 
1798
- draw( renderContextData.currentPass, renderContextData.currentSets );
1823
+ this._draw( renderObject, info, renderContextData, pipelineGPU, bindings, vertexBuffers, drawParams, renderContextData.currentPass, renderContextData.currentSets );
1799
1824
 
1800
1825
  }
1801
1826
 
@@ -2292,17 +2317,6 @@ class WebGPUBackend extends Backend {
2292
2317
 
2293
2318
  // utils public
2294
2319
 
2295
- /**
2296
- * Returns the maximum anisotropy texture filtering value.
2297
- *
2298
- * @return {number} The maximum anisotropy texture filtering value.
2299
- */
2300
- getMaxAnisotropy() {
2301
-
2302
- return 16;
2303
-
2304
- }
2305
-
2306
2320
  /**
2307
2321
  * Checks if the given feature is supported by the backend.
2308
2322
  *
@@ -2538,9 +2552,9 @@ class WebGPUBackend extends Backend {
2538
2552
  */
2539
2553
  hasCompatibility( name ) {
2540
2554
 
2541
- if ( this._compatibility[ Compatibility.TEXTURE_COMPARE ] !== undefined ) {
2555
+ if ( this._compatibility[ name ] !== undefined ) {
2542
2556
 
2543
- return this._compatibility[ Compatibility.TEXTURE_COMPARE ];
2557
+ return this._compatibility[ name ];
2544
2558
 
2545
2559
  }
2546
2560