super-three 0.177.0 → 0.179.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 (211) hide show
  1. package/README.md +1 -1
  2. package/build/three.cjs +959 -231
  3. package/build/three.core.js +751 -170
  4. package/build/three.core.min.js +1 -1
  5. package/build/three.module.js +210 -64
  6. package/build/three.module.min.js +1 -1
  7. package/build/three.tsl.js +78 -29
  8. package/build/three.tsl.min.js +1 -1
  9. package/build/three.webgpu.js +3269 -1545
  10. package/build/three.webgpu.min.js +1 -1
  11. package/build/three.webgpu.nodes.js +3093 -1545
  12. package/build/three.webgpu.nodes.min.js +1 -1
  13. package/examples/jsm/Addons.js +1 -2
  14. package/examples/jsm/capabilities/WebGL.js +0 -27
  15. package/examples/jsm/capabilities/WebGPU.js +1 -1
  16. package/examples/jsm/controls/ArcballControls.js +1 -1
  17. package/examples/jsm/controls/TransformControls.js +61 -14
  18. package/examples/jsm/csm/CSMShadowNode.js +4 -4
  19. package/examples/jsm/environments/RoomEnvironment.js +8 -3
  20. package/examples/jsm/exporters/USDZExporter.js +676 -299
  21. package/examples/jsm/geometries/RoundedBoxGeometry.js +47 -8
  22. package/examples/jsm/interactive/HTMLMesh.js +5 -3
  23. package/examples/jsm/libs/meshopt_decoder.module.js +75 -58
  24. package/examples/jsm/lights/LightProbeGenerator.js +14 -3
  25. package/examples/jsm/loaders/ColladaLoader.js +1 -1
  26. package/examples/jsm/loaders/EXRLoader.js +210 -22
  27. package/examples/jsm/loaders/FBXLoader.js +2 -2
  28. package/examples/jsm/loaders/MaterialXLoader.js +212 -30
  29. package/examples/jsm/loaders/TTFLoader.js +13 -1
  30. package/examples/jsm/loaders/USDLoader.js +219 -0
  31. package/examples/jsm/loaders/USDZLoader.js +4 -892
  32. package/examples/jsm/loaders/usd/USDAParser.js +741 -0
  33. package/examples/jsm/loaders/usd/USDCParser.js +17 -0
  34. package/examples/jsm/objects/LensflareMesh.js +3 -3
  35. package/examples/jsm/objects/SkyMesh.js +2 -2
  36. package/examples/jsm/physics/RapierPhysics.js +95 -16
  37. package/examples/jsm/postprocessing/GTAOPass.js +10 -9
  38. package/examples/jsm/postprocessing/OutlinePass.js +17 -17
  39. package/examples/jsm/postprocessing/SSAOPass.js +10 -9
  40. package/examples/jsm/shaders/UnpackDepthRGBAShader.js +11 -2
  41. package/examples/jsm/transpiler/AST.js +381 -30
  42. package/examples/jsm/transpiler/GLSLDecoder.js +226 -86
  43. package/examples/jsm/transpiler/Linker.js +327 -0
  44. package/examples/jsm/transpiler/TSLEncoder.js +197 -92
  45. package/examples/jsm/transpiler/Transpiler.js +17 -1
  46. package/examples/jsm/transpiler/TranspilerUtils.js +29 -0
  47. package/examples/jsm/transpiler/WGSLEncoder.js +788 -0
  48. package/examples/jsm/tsl/display/BloomNode.js +8 -7
  49. package/examples/jsm/tsl/display/ChromaticAberrationNode.js +206 -0
  50. package/examples/jsm/tsl/display/GaussianBlurNode.js +8 -10
  51. package/examples/jsm/tsl/display/SSAAPassNode.js +2 -2
  52. package/examples/jsm/tsl/display/{TRAAPassNode.js → TRAANode.js} +181 -172
  53. package/examples/jsm/tsl/display/hashBlur.js +3 -3
  54. package/examples/jsm/tsl/lighting/TiledLightsNode.js +1 -1
  55. package/package.json +1 -1
  56. package/src/Three.Core.js +1 -0
  57. package/src/Three.TSL.js +77 -28
  58. package/src/Three.WebGPU.js +2 -0
  59. package/src/animation/KeyframeTrack.js +1 -1
  60. package/src/animation/tracks/BooleanKeyframeTrack.js +1 -1
  61. package/src/animation/tracks/StringKeyframeTrack.js +1 -1
  62. package/src/cameras/Camera.js +14 -0
  63. package/src/cameras/OrthographicCamera.js +1 -1
  64. package/src/cameras/PerspectiveCamera.js +1 -1
  65. package/src/constants.js +3 -3
  66. package/src/core/BufferAttribute.js +3 -3
  67. package/src/core/Clock.js +2 -8
  68. package/src/core/GLBufferAttribute.js +13 -1
  69. package/src/core/Object3D.js +1 -1
  70. package/{examples/jsm/misc → src/core}/Timer.js +4 -42
  71. package/src/extras/PMREMGenerator.js +11 -0
  72. package/src/extras/core/Path.js +22 -22
  73. package/src/helpers/CameraHelper.js +41 -11
  74. package/src/helpers/SkeletonHelper.js +35 -6
  75. package/src/lights/LightShadow.js +21 -8
  76. package/src/lights/PointLightShadow.js +1 -1
  77. package/src/loaders/FileLoader.js +27 -4
  78. package/src/loaders/ImageBitmapLoader.js +27 -4
  79. package/src/loaders/ImageLoader.js +55 -8
  80. package/src/loaders/Loader.js +14 -0
  81. package/src/loaders/LoadingManager.js +23 -0
  82. package/src/materials/MeshBasicMaterial.js +1 -1
  83. package/src/materials/nodes/Line2NodeMaterial.js +0 -8
  84. package/src/materials/nodes/MeshBasicNodeMaterial.js +4 -3
  85. package/src/materials/nodes/MeshMatcapNodeMaterial.js +1 -1
  86. package/src/materials/nodes/MeshNormalNodeMaterial.js +2 -2
  87. package/src/materials/nodes/MeshPhysicalNodeMaterial.js +2 -1
  88. package/src/materials/nodes/MeshSSSNodeMaterial.js +2 -2
  89. package/src/materials/nodes/NodeMaterial.js +28 -5
  90. package/src/materials/nodes/PointsNodeMaterial.js +5 -0
  91. package/src/materials/nodes/manager/NodeMaterialObserver.js +87 -2
  92. package/src/math/Frustum.js +25 -9
  93. package/src/math/FrustumArray.js +10 -5
  94. package/src/math/Line3.js +129 -2
  95. package/src/math/Matrix4.js +48 -27
  96. package/src/math/Quaternion.js +1 -1
  97. package/src/math/Spherical.js +2 -2
  98. package/src/nodes/Nodes.js +2 -3
  99. package/src/nodes/TSL.js +5 -3
  100. package/src/nodes/accessors/AccessorsUtils.js +7 -8
  101. package/src/nodes/accessors/Bitangent.js +31 -25
  102. package/src/nodes/accessors/Camera.js +12 -12
  103. package/src/nodes/accessors/Normal.js +95 -29
  104. package/src/nodes/accessors/Object3DNode.js +1 -1
  105. package/src/nodes/accessors/Position.js +7 -7
  106. package/src/nodes/accessors/ReferenceNode.js +18 -3
  107. package/src/nodes/accessors/ReflectVector.js +3 -3
  108. package/src/nodes/accessors/SceneNode.js +1 -1
  109. package/src/nodes/accessors/StorageTextureNode.js +1 -1
  110. package/src/nodes/accessors/Tangent.js +25 -17
  111. package/src/nodes/accessors/TangentUtils.js +46 -0
  112. package/src/nodes/accessors/TextureBicubic.js +21 -3
  113. package/src/nodes/accessors/TextureNode.js +12 -0
  114. package/src/nodes/accessors/UniformArrayNode.js +0 -16
  115. package/src/nodes/core/ArrayNode.js +12 -0
  116. package/src/nodes/core/AssignNode.js +3 -0
  117. package/src/nodes/core/CacheNode.js +0 -14
  118. package/src/nodes/core/ContextNode.js +20 -1
  119. package/src/nodes/core/Node.js +15 -3
  120. package/src/nodes/core/NodeBuilder.js +228 -92
  121. package/src/nodes/core/NodeUtils.js +4 -1
  122. package/src/nodes/core/StackNode.js +49 -29
  123. package/src/nodes/core/SubBuildNode.js +89 -0
  124. package/src/nodes/core/UniformNode.js +63 -5
  125. package/src/nodes/core/VarNode.js +91 -2
  126. package/src/nodes/core/VaryingNode.js +6 -4
  127. package/src/nodes/display/BlendModes.js +2 -2
  128. package/src/nodes/display/FrontFacingNode.js +34 -2
  129. package/src/nodes/display/NormalMapNode.js +19 -50
  130. package/src/nodes/display/PassNode.js +157 -9
  131. package/src/nodes/display/ScreenNode.js +0 -26
  132. package/src/nodes/display/ViewportTextureNode.js +67 -7
  133. package/src/nodes/functions/BSDF/BRDF_GGX.js +2 -6
  134. package/src/nodes/functions/BSDF/BRDF_Sheen.js +4 -4
  135. package/src/nodes/functions/PhongLightingModel.js +3 -3
  136. package/src/nodes/functions/PhysicalLightingModel.js +16 -16
  137. package/src/nodes/functions/material/getGeometryRoughness.js +2 -2
  138. package/src/nodes/gpgpu/AtomicFunctionNode.js +1 -1
  139. package/src/nodes/gpgpu/ComputeNode.js +67 -23
  140. package/src/nodes/gpgpu/WorkgroupInfoNode.js +28 -3
  141. package/src/nodes/lighting/EnvironmentNode.js +5 -5
  142. package/src/nodes/lighting/LightsNode.js +4 -4
  143. package/src/nodes/lighting/ProjectorLightNode.js +19 -6
  144. package/src/nodes/lighting/ShadowFilterNode.js +1 -1
  145. package/src/nodes/lighting/ShadowNode.js +2 -2
  146. package/src/nodes/materialx/MaterialXNodes.js +131 -2
  147. package/src/nodes/materialx/lib/mx_noise.js +165 -1
  148. package/src/nodes/math/ConditionalNode.js +1 -20
  149. package/src/nodes/math/MathNode.js +90 -55
  150. package/src/nodes/math/OperatorNode.js +22 -39
  151. package/src/nodes/tsl/TSLBase.js +1 -0
  152. package/src/nodes/tsl/TSLCore.js +114 -55
  153. package/src/nodes/utils/DebugNode.js +1 -1
  154. package/src/nodes/utils/EquirectUV.js +27 -0
  155. package/src/nodes/utils/EventNode.js +83 -0
  156. package/src/nodes/utils/LoopNode.js +0 -17
  157. package/src/nodes/utils/MatcapUV.js +22 -0
  158. package/src/nodes/utils/RTTNode.js +22 -5
  159. package/src/nodes/utils/ReflectorNode.js +11 -4
  160. package/src/nodes/utils/SampleNode.js +81 -0
  161. package/src/nodes/utils/TriplanarTextures.js +65 -0
  162. package/src/objects/BatchedMesh.js +4 -2
  163. package/src/renderers/WebGLRenderer.js +26 -24
  164. package/src/renderers/common/Background.js +2 -2
  165. package/src/renderers/common/Bindings.js +19 -18
  166. package/src/renderers/common/Color4.js +2 -2
  167. package/src/renderers/common/CubeRenderTarget.js +1 -1
  168. package/src/renderers/common/PostProcessing.js +60 -5
  169. package/src/renderers/common/RenderObject.js +68 -3
  170. package/src/renderers/common/Renderer.js +19 -16
  171. package/src/renderers/common/SampledTexture.js +3 -71
  172. package/src/renderers/common/Sampler.js +79 -0
  173. package/src/renderers/common/Storage3DTexture.js +100 -0
  174. package/src/renderers/common/StorageArrayTexture.js +84 -0
  175. package/src/renderers/common/StorageTexture.js +19 -0
  176. package/src/renderers/common/Textures.js +19 -3
  177. package/src/renderers/common/XRManager.js +31 -12
  178. package/src/renderers/common/XRRenderTarget.js +21 -4
  179. package/src/renderers/common/extras/PMREMGenerator.js +1 -1
  180. package/src/renderers/common/nodes/NodeSampledTexture.js +0 -12
  181. package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +20 -2
  182. package/src/renderers/shaders/ShaderLib/depth.glsl.js +11 -2
  183. package/src/renderers/webgl/WebGLAttributes.js +4 -0
  184. package/src/renderers/webgl/WebGLCapabilities.js +2 -2
  185. package/src/renderers/webgl/WebGLProgram.js +12 -6
  186. package/src/renderers/webgl/WebGLPrograms.js +6 -4
  187. package/src/renderers/webgl/WebGLShadowMap.js +11 -1
  188. package/src/renderers/webgl/WebGLState.js +4 -4
  189. package/src/renderers/webgl/WebGLTextures.js +19 -7
  190. package/src/renderers/webgl-fallback/WebGLBackend.js +103 -72
  191. package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +3 -5
  192. package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +4 -0
  193. package/src/renderers/webgl-fallback/utils/WebGLState.js +4 -4
  194. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +2 -0
  195. package/src/renderers/webgpu/WebGPUBackend.js +63 -16
  196. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +64 -79
  197. package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +6 -0
  198. package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +45 -31
  199. package/src/renderers/webgpu/utils/WebGPUConstants.js +7 -1
  200. package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +5 -5
  201. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +12 -65
  202. package/src/renderers/webgpu/utils/WebGPUUtils.js +2 -17
  203. package/src/renderers/webxr/WebXRDepthSensing.js +6 -10
  204. package/src/renderers/webxr/WebXRManager.js +68 -6
  205. package/src/textures/ExternalTexture.js +45 -0
  206. package/src/textures/FramebufferTexture.js +2 -2
  207. package/src/textures/Source.js +11 -1
  208. package/src/textures/VideoTexture.js +30 -2
  209. package/src/nodes/utils/EquirectUVNode.js +0 -65
  210. package/src/nodes/utils/MatcapUVNode.js +0 -49
  211. package/src/nodes/utils/TriplanarTexturesNode.js +0 -148
@@ -13,11 +13,8 @@ import { WebGLBufferRenderer } from './WebGLBufferRenderer.js';
13
13
 
14
14
  import { warnOnce } from '../../utils.js';
15
15
  import { WebGLCoordinateSystem } from '../../constants.js';
16
- import { Vector2 } from '../../math/Vector2.js';
17
16
  import WebGLTimestampQueryPool from './utils/WebGLTimestampQueryPool.js';
18
17
 
19
- const _drawingBufferSize = /*@__PURE__*/ new Vector2();
20
-
21
18
  /**
22
19
  * A backend implementation targeting WebGL 2.
23
20
  *
@@ -183,7 +180,7 @@ class WebGLBackend extends Backend {
183
180
  * A unique collection of bindings.
184
181
  *
185
182
  * @private
186
- * @type {WeakSet}
183
+ * @type {WeakSet<Array<BindGroup>>}
187
184
  */
188
185
  this._knownBindings = new WeakSet();
189
186
 
@@ -364,13 +361,13 @@ class WebGLBackend extends Backend {
364
361
 
365
362
  // The multisample_render_to_texture extension doesn't work properly if there
366
363
  // are midframe flushes and an external depth texture.
367
- if ( ( this.extensions.has( 'WEBGL_multisampled_render_to_texture' ) === true ) && renderTarget.autoAllocateDepthBuffer === true && renderTarget.multiview === false ) {
364
+ if ( ( this.extensions.has( 'WEBGL_multisampled_render_to_texture' ) === true ) && renderTarget._autoAllocateDepthBuffer === true && renderTarget.multiview === false ) {
368
365
 
369
366
  console.warn( 'THREE.WebGLBackend: Render-to-texture extension was disabled because an external texture was provided' );
370
367
 
371
368
  }
372
369
 
373
- renderTarget.autoAllocateDepthBuffer = false;
370
+ renderTarget._autoAllocateDepthBuffer = false;
374
371
 
375
372
  }
376
373
 
@@ -455,7 +452,7 @@ class WebGLBackend extends Backend {
455
452
 
456
453
  } else {
457
454
 
458
- const { width, height } = this.getDrawingBufferSize( _drawingBufferSize );
455
+ const { width, height } = this.getDrawingBufferSize();
459
456
  state.viewport( 0, 0, width, height );
460
457
 
461
458
  }
@@ -543,29 +540,60 @@ class WebGLBackend extends Backend {
543
540
  }
544
541
 
545
542
  this._currentContext = previousContext;
543
+ const renderTarget = renderContext.renderTarget;
546
544
 
547
- if ( renderContext.textures !== null && renderContext.renderTarget ) {
548
-
549
- const renderTargetContextData = this.get( renderContext.renderTarget );
545
+ if ( renderContext.textures !== null && renderTarget ) {
550
546
 
551
- const { resolveDepthBuffer, samples } = renderContext.renderTarget;
547
+ const renderTargetContextData = this.get( renderTarget );
552
548
 
553
- if ( samples > 0 && this._useMultisampledExtension( renderContext.renderTarget ) === false ) {
549
+ if ( renderTarget.samples > 0 && this._useMultisampledExtension( renderTarget ) === false ) {
554
550
 
555
551
  const fb = renderTargetContextData.framebuffers[ renderContext.getCacheKey() ];
556
552
 
557
- const mask = gl.COLOR_BUFFER_BIT;
553
+ let mask = gl.COLOR_BUFFER_BIT;
554
+
555
+ if ( renderTarget.resolveDepthBuffer ) {
556
+
557
+ if ( renderTarget.depthBuffer ) mask |= gl.DEPTH_BUFFER_BIT;
558
+ if ( renderTarget.stencilBuffer && renderTarget.resolveStencilBuffer ) mask |= gl.STENCIL_BUFFER_BIT;
559
+
560
+ }
558
561
 
559
562
  const msaaFrameBuffer = renderTargetContextData.msaaFrameBuffer;
563
+ const msaaRenderbuffers = renderTargetContextData.msaaRenderbuffers;
560
564
 
561
565
  const textures = renderContext.textures;
566
+ const isMRT = textures.length > 1;
562
567
 
563
568
  state.bindFramebuffer( gl.READ_FRAMEBUFFER, msaaFrameBuffer );
564
569
  state.bindFramebuffer( gl.DRAW_FRAMEBUFFER, fb );
565
570
 
571
+ if ( isMRT ) {
572
+
573
+ // blitFramebuffer() can only copy/resolve the first color attachment of a framebuffer. When using MRT,
574
+ // the engine temporarily removes all attachments and then configures each attachment for the resolve.
575
+
576
+ for ( let i = 0; i < textures.length; i ++ ) {
577
+
578
+ gl.framebufferRenderbuffer( gl.READ_FRAMEBUFFER, gl.COLOR_ATTACHMENT0 + i, gl.RENDERBUFFER, null );
579
+ gl.framebufferTexture2D( gl.DRAW_FRAMEBUFFER, gl.COLOR_ATTACHMENT0 + i, gl.TEXTURE_2D, null, 0 );
580
+
581
+ }
582
+
583
+ }
584
+
566
585
  for ( let i = 0; i < textures.length; i ++ ) {
567
586
 
568
- // TODO Add support for MRT
587
+ if ( isMRT ) {
588
+
589
+ // configure attachment for resolve
590
+
591
+ const { textureGPU } = this.get( textures[ i ] );
592
+
593
+ gl.framebufferRenderbuffer( gl.READ_FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, msaaRenderbuffers[ i ] );
594
+ gl.framebufferTexture2D( gl.DRAW_FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, textureGPU, 0 );
595
+
596
+ }
569
597
 
570
598
  if ( renderContext.scissor ) {
571
599
 
@@ -575,27 +603,36 @@ class WebGLBackend extends Backend {
575
603
 
576
604
  gl.blitFramebuffer( x, viewY, x + width, viewY + height, x, viewY, x + width, viewY + height, mask, gl.NEAREST );
577
605
 
578
- if ( this._supportsInvalidateFramebuffer === true ) {
606
+ } else {
579
607
 
580
- gl.invalidateSubFramebuffer( gl.READ_FRAMEBUFFER, renderTargetContextData.invalidationArray, x, viewY, width, height );
608
+ gl.blitFramebuffer( 0, 0, renderContext.width, renderContext.height, 0, 0, renderContext.width, renderContext.height, mask, gl.NEAREST );
581
609
 
582
- }
610
+ }
583
611
 
584
- } else {
612
+ }
585
613
 
586
- gl.blitFramebuffer( 0, 0, renderContext.width, renderContext.height, 0, 0, renderContext.width, renderContext.height, mask, gl.NEAREST );
614
+ if ( isMRT ) {
587
615
 
588
- if ( this._supportsInvalidateFramebuffer === true ) {
616
+ // restore attachments
589
617
 
590
- gl.invalidateFramebuffer( gl.READ_FRAMEBUFFER, renderTargetContextData.invalidationArray );
618
+ for ( let i = 0; i < textures.length; i ++ ) {
591
619
 
592
- }
620
+ const { textureGPU } = this.get( textures[ i ] );
621
+
622
+ gl.framebufferRenderbuffer( gl.READ_FRAMEBUFFER, gl.COLOR_ATTACHMENT0 + i, gl.RENDERBUFFER, msaaRenderbuffers[ i ] );
623
+ gl.framebufferTexture2D( gl.DRAW_FRAMEBUFFER, gl.COLOR_ATTACHMENT0 + i, gl.TEXTURE_2D, textureGPU, 0 );
593
624
 
594
625
  }
595
626
 
596
627
  }
597
628
 
598
- } else if ( resolveDepthBuffer === false && renderTargetContextData.framebuffers ) {
629
+ if ( this._supportsInvalidateFramebuffer === true ) {
630
+
631
+ gl.invalidateFramebuffer( gl.READ_FRAMEBUFFER, renderTargetContextData.invalidationArray );
632
+
633
+ }
634
+
635
+ } else if ( renderTarget.resolveDepthBuffer === false && renderTargetContextData.framebuffers ) {
599
636
 
600
637
  const fb = renderTargetContextData.framebuffers[ renderContext.getCacheKey() ];
601
638
  state.bindFramebuffer( gl.DRAW_FRAMEBUFFER, fb );
@@ -615,7 +652,7 @@ class WebGLBackend extends Backend {
615
652
 
616
653
  } else {
617
654
 
618
- const { width, height } = this.getDrawingBufferSize( _drawingBufferSize );
655
+ const { width, height } = this.getDrawingBufferSize();
619
656
  state.viewport( 0, 0, width, height );
620
657
 
621
658
  }
@@ -875,8 +912,9 @@ class WebGLBackend extends Backend {
875
912
  * @param {Node} computeNode - The compute node.
876
913
  * @param {Array<BindGroup>} bindings - The bindings.
877
914
  * @param {ComputePipeline} pipeline - The compute pipeline.
915
+ * @param {number|null} [count=null] - The count of compute invocations. If `null`, the count is determined by the compute node.
878
916
  */
879
- compute( computeGroup, computeNode, bindings, pipeline ) {
917
+ compute( computeGroup, computeNode, bindings, pipeline, count = null ) {
880
918
 
881
919
  const { state, gl } = this;
882
920
 
@@ -896,7 +934,7 @@ class WebGLBackend extends Backend {
896
934
 
897
935
  if ( vaoGPU === undefined ) {
898
936
 
899
- this._createVao( attributes );
937
+ this.vaoCache[ vaoKey ] = this._createVao( attributes );
900
938
 
901
939
  } else {
902
940
 
@@ -913,13 +951,23 @@ class WebGLBackend extends Backend {
913
951
  gl.bindTransformFeedback( gl.TRANSFORM_FEEDBACK, transformFeedbackGPU );
914
952
  gl.beginTransformFeedback( gl.POINTS );
915
953
 
954
+ count = ( count !== null ) ? count : computeNode.count;
955
+
956
+ if ( Array.isArray( count ) ) {
957
+
958
+ warnOnce( 'WebGLBackend.compute(): The count parameter must be a single number, not an array.' );
959
+
960
+ count = count[ 0 ];
961
+
962
+ }
963
+
916
964
  if ( attributes[ 0 ].isStorageInstancedBufferAttribute ) {
917
965
 
918
- gl.drawArraysInstanced( gl.POINTS, 0, 1, computeNode.count );
966
+ gl.drawArraysInstanced( gl.POINTS, 0, 1, count );
919
967
 
920
968
  } else {
921
969
 
922
- gl.drawArrays( gl.POINTS, 0, computeNode.count );
970
+ gl.drawArrays( gl.POINTS, 0, count );
923
971
 
924
972
  }
925
973
 
@@ -932,7 +980,7 @@ class WebGLBackend extends Backend {
932
980
 
933
981
  const dualAttributeData = transformBuffers[ i ];
934
982
 
935
- if ( dualAttributeData.pbo ) {
983
+ if ( dualAttributeData.pbo && this.has( dualAttributeData.pbo ) ) {
936
984
 
937
985
  this.textureUtils.copyBufferToTexture( dualAttributeData.transformBuffer, dualAttributeData.pbo );
938
986
 
@@ -1014,28 +1062,23 @@ class WebGLBackend extends Backend {
1014
1062
 
1015
1063
  // vertex state
1016
1064
 
1017
- const renderObjectData = this.get( renderObject );
1065
+ const attributes = renderObject.getAttributes();
1066
+ const attributesData = this.get( attributes );
1018
1067
 
1019
- let vaoGPU = renderObjectData.staticVao;
1068
+ let vaoGPU = attributesData.vaoGPU;
1020
1069
 
1021
- if ( vaoGPU === undefined || renderObjectData.geometryId !== renderObject.geometry.id ) {
1070
+ if ( vaoGPU === undefined ) {
1022
1071
 
1023
- const vaoKey = this._getVaoKey( renderObject.getAttributes() );
1072
+ const vaoKey = this._getVaoKey( attributes );
1024
1073
 
1025
1074
  vaoGPU = this.vaoCache[ vaoKey ];
1026
1075
 
1027
1076
  if ( vaoGPU === undefined ) {
1028
1077
 
1029
- let staticVao;
1030
-
1031
- ( { vaoGPU, staticVao } = this._createVao( renderObject.getAttributes() ) );
1078
+ vaoGPU = this._createVao( attributes );
1032
1079
 
1033
- if ( staticVao ) {
1034
-
1035
- renderObjectData.staticVao = vaoGPU;
1036
- renderObjectData.geometryId = renderObject.geometry.id;
1037
-
1038
- }
1080
+ this.vaoCache[ vaoKey ] = vaoGPU;
1081
+ attributesData.vaoGPU = vaoGPU;
1039
1082
 
1040
1083
  }
1041
1084
 
@@ -1539,7 +1582,9 @@ class WebGLBackend extends Backend {
1539
1582
  _getShaderErrors( gl, shader, type ) {
1540
1583
 
1541
1584
  const status = gl.getShaderParameter( shader, gl.COMPILE_STATUS );
1542
- const errors = gl.getShaderInfoLog( shader ).trim();
1585
+
1586
+ const shaderInfoLog = gl.getShaderInfoLog( shader ) || '';
1587
+ const errors = shaderInfoLog.trim();
1543
1588
 
1544
1589
  if ( status && errors === '' ) return '';
1545
1590
 
@@ -1571,11 +1616,11 @@ class WebGLBackend extends Backend {
1571
1616
 
1572
1617
  const gl = this.gl;
1573
1618
 
1574
- const programLog = gl.getProgramInfoLog( programGPU ).trim();
1619
+ const programInfoLog = gl.getProgramInfoLog( programGPU ) || '';
1620
+ const programLog = programInfoLog.trim();
1575
1621
 
1576
1622
  if ( gl.getProgramParameter( programGPU, gl.LINK_STATUS ) === false ) {
1577
1623
 
1578
-
1579
1624
  if ( typeof this.renderer.debug.onShaderError === 'function' ) {
1580
1625
 
1581
1626
  this.renderer.debug.onShaderError( gl, programGPU, glVertexShader, glFragmentShader );
@@ -2002,7 +2047,7 @@ class WebGLBackend extends Backend {
2002
2047
  const isRenderTarget3D = renderTarget.isRenderTarget3D === true;
2003
2048
  const isRenderTargetArray = renderTarget.depth > 1;
2004
2049
  const isXRRenderTarget = renderTarget.isXRRenderTarget === true;
2005
- const hasExternalTextures = ( isXRRenderTarget === true && renderTarget.hasExternalTextures === true );
2050
+ const _hasExternalTextures = ( isXRRenderTarget === true && renderTarget._hasExternalTextures === true );
2006
2051
 
2007
2052
  let msaaFb = renderTargetContextData.msaaFrameBuffer;
2008
2053
  let depthRenderbuffer = renderTargetContextData.depthRenderbuffer;
@@ -2019,7 +2064,7 @@ class WebGLBackend extends Backend {
2019
2064
 
2020
2065
  fb = renderTargetContextData.cubeFramebuffers[ cacheKey ];
2021
2066
 
2022
- } else if ( isXRRenderTarget && hasExternalTextures === false ) {
2067
+ } else if ( isXRRenderTarget && _hasExternalTextures === false ) {
2023
2068
 
2024
2069
  fb = this._xrFramebuffer;
2025
2070
 
@@ -2089,13 +2134,11 @@ class WebGLBackend extends Backend {
2089
2134
 
2090
2135
  }
2091
2136
 
2092
- state.drawBuffers( descriptor, fb );
2093
-
2094
2137
  }
2095
2138
 
2096
2139
  const depthStyle = stencilBuffer ? gl.DEPTH_STENCIL_ATTACHMENT : gl.DEPTH_ATTACHMENT;
2097
2140
 
2098
- if ( renderTarget.autoAllocateDepthBuffer === true ) {
2141
+ if ( renderTarget._autoAllocateDepthBuffer === true ) {
2099
2142
 
2100
2143
  const renderbuffer = gl.createRenderbuffer();
2101
2144
  this.textureUtils.setupRenderBufferStorage( renderbuffer, descriptor, 0, useMultisampledRTT );
@@ -2120,7 +2163,7 @@ class WebGLBackend extends Backend {
2120
2163
 
2121
2164
  multiviewExt.framebufferTextureMultisampleMultiviewOVR( gl.FRAMEBUFFER, depthStyle, textureData.textureGPU, 0, samples, 0, 2 );
2122
2165
 
2123
- } else if ( hasExternalTextures && useMultisampledRTT ) {
2166
+ } else if ( _hasExternalTextures && useMultisampledRTT ) {
2124
2167
 
2125
2168
  multisampledRTTExt.framebufferTexture2DMultisampleEXT( gl.FRAMEBUFFER, depthStyle, gl.TEXTURE_2D, textureData.textureGPU, 0, samples );
2126
2169
 
@@ -2171,7 +2214,7 @@ class WebGLBackend extends Backend {
2171
2214
 
2172
2215
  // rebind external XR textures
2173
2216
 
2174
- if ( isXRRenderTarget || useMultisampledRTT || renderTarget.multiview ) {
2217
+ if ( ( isXRRenderTarget || useMultisampledRTT || renderTarget.multiview ) && ( renderTarget._isOpaqueFramebuffer !== true ) ) {
2175
2218
 
2176
2219
  state.bindFramebuffer( gl.FRAMEBUFFER, fb );
2177
2220
 
@@ -2197,7 +2240,7 @@ class WebGLBackend extends Backend {
2197
2240
 
2198
2241
  const depthStyle = stencilBuffer ? gl.DEPTH_STENCIL_ATTACHMENT : gl.DEPTH_ATTACHMENT;
2199
2242
 
2200
- if ( renderTarget.autoAllocateDepthBuffer === true ) {
2243
+ if ( renderTarget._autoAllocateDepthBuffer === true ) {
2201
2244
 
2202
2245
  const renderbuffer = renderTargetContextData.xrDepthRenderbuffer;
2203
2246
  gl.bindRenderbuffer( gl.RENDERBUFFER, renderbuffer );
@@ -2249,13 +2292,6 @@ class WebGLBackend extends Backend {
2249
2292
 
2250
2293
  invalidationArray.push( gl.COLOR_ATTACHMENT0 + i );
2251
2294
 
2252
- if ( depthBuffer ) {
2253
-
2254
- const depthStyle = stencilBuffer ? gl.DEPTH_STENCIL_ATTACHMENT : gl.DEPTH_ATTACHMENT;
2255
- invalidationArray.push( depthStyle );
2256
-
2257
- }
2258
-
2259
2295
  const texture = descriptor.textures[ i ];
2260
2296
  const textureData = this.get( texture );
2261
2297
 
@@ -2265,10 +2301,12 @@ class WebGLBackend extends Backend {
2265
2301
 
2266
2302
  }
2267
2303
 
2304
+ gl.bindRenderbuffer( gl.RENDERBUFFER, null );
2305
+
2268
2306
  renderTargetContextData.msaaFrameBuffer = msaaFb;
2269
2307
  renderTargetContextData.msaaRenderbuffers = msaaRenderbuffers;
2270
2308
 
2271
- if ( depthRenderbuffer === undefined ) {
2309
+ if ( depthBuffer && depthRenderbuffer === undefined ) {
2272
2310
 
2273
2311
  depthRenderbuffer = gl.createRenderbuffer();
2274
2312
  this.textureUtils.setupRenderBufferStorage( depthRenderbuffer, descriptor, samples );
@@ -2292,6 +2330,8 @@ class WebGLBackend extends Backend {
2292
2330
 
2293
2331
  }
2294
2332
 
2333
+ state.drawBuffers( descriptor, fb );
2334
+
2295
2335
  }
2296
2336
 
2297
2337
  state.bindFramebuffer( gl.FRAMEBUFFER, currentFrameBuffer );
@@ -2333,9 +2373,6 @@ class WebGLBackend extends Backend {
2333
2373
  const { gl } = this;
2334
2374
 
2335
2375
  const vaoGPU = gl.createVertexArray();
2336
- let key = '';
2337
-
2338
- let staticVao = true;
2339
2376
 
2340
2377
  gl.bindVertexArray( vaoGPU );
2341
2378
 
@@ -2344,13 +2381,9 @@ class WebGLBackend extends Backend {
2344
2381
  const attribute = attributes[ i ];
2345
2382
  const attributeData = this.get( attribute );
2346
2383
 
2347
- key += ':' + attributeData.id;
2348
-
2349
2384
  gl.bindBuffer( gl.ARRAY_BUFFER, attributeData.bufferGPU );
2350
2385
  gl.enableVertexAttribArray( i );
2351
2386
 
2352
- if ( attribute.isStorageBufferAttribute || attribute.isStorageInstancedBufferAttribute ) staticVao = false;
2353
-
2354
2387
  let stride, offset;
2355
2388
 
2356
2389
  if ( attribute.isInterleavedBufferAttribute === true ) {
@@ -2389,9 +2422,7 @@ class WebGLBackend extends Backend {
2389
2422
 
2390
2423
  gl.bindBuffer( gl.ARRAY_BUFFER, null );
2391
2424
 
2392
- this.vaoCache[ key ] = vaoGPU;
2393
-
2394
- return { vaoGPU, staticVao };
2425
+ return vaoGPU;
2395
2426
 
2396
2427
  }
2397
2428
 
@@ -2528,7 +2559,7 @@ class WebGLBackend extends Backend {
2528
2559
 
2529
2560
  }
2530
2561
 
2531
- return renderTarget.samples > 0 && this.extensions.has( 'WEBGL_multisampled_render_to_texture' ) === true && renderTarget.autoAllocateDepthBuffer !== false;
2562
+ return renderTarget.samples > 0 && this.extensions.has( 'WEBGL_multisampled_render_to_texture' ) === true && renderTarget._autoAllocateDepthBuffer !== false;
2532
2563
 
2533
2564
  }
2534
2565
 
@@ -30,9 +30,7 @@ const interpolationTypeMap = {
30
30
  };
31
31
 
32
32
  const interpolationModeMap = {
33
- 'centroid': 'centroid',
34
- 'flat first': 'flat',
35
- 'flat either': 'flat'
33
+ 'centroid': 'centroid'
36
34
  };
37
35
 
38
36
  const defaultPrecisions = `
@@ -251,7 +249,7 @@ ${ flowData.code }
251
249
  attribute.pboNode = pbo;
252
250
  attribute.pbo = pbo.value;
253
251
 
254
- this.getUniformFromNode( attribute.pboNode, 'texture', this.shaderStage, this.context.label );
252
+ this.getUniformFromNode( attribute.pboNode, 'texture', this.shaderStage, this.context.nodeName );
255
253
 
256
254
  }
257
255
 
@@ -295,7 +293,7 @@ ${ flowData.code }
295
293
 
296
294
  }
297
295
 
298
- const nodeUniform = this.getUniformFromNode( attribute.pboNode, 'texture', this.shaderStage, this.context.label );
296
+ const nodeUniform = this.getUniformFromNode( attribute.pboNode, 'texture', this.shaderStage, this.context.nodeName );
299
297
  const textureName = this.getPropertyName( nodeUniform );
300
298
 
301
299
  this.increaseUsage( indexNode ); // force cache generate to be used as index in x,y
@@ -114,6 +114,10 @@ class WebGLAttributeUtils {
114
114
 
115
115
  type = gl.FLOAT;
116
116
 
117
+ } else if ( typeof Float16Array !== 'undefined' && array instanceof Float16Array ) {
118
+
119
+ type = gl.HALF_FLOAT;
120
+
117
121
  } else if ( array instanceof Uint16Array ) {
118
122
 
119
123
  if ( attribute.isFloat16BufferAttribute ) {
@@ -339,7 +339,7 @@ class WebGLState {
339
339
  break;
340
340
 
341
341
  case MultiplyBlending:
342
- gl.blendFuncSeparate( gl.ZERO, gl.SRC_COLOR, gl.ZERO, gl.SRC_ALPHA );
342
+ gl.blendFuncSeparate( gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA, gl.ZERO, gl.ONE );
343
343
  break;
344
344
 
345
345
  default:
@@ -357,15 +357,15 @@ class WebGLState {
357
357
  break;
358
358
 
359
359
  case AdditiveBlending:
360
- gl.blendFunc( gl.SRC_ALPHA, gl.ONE );
360
+ gl.blendFuncSeparate( gl.SRC_ALPHA, gl.ONE, gl.ONE, gl.ONE );
361
361
  break;
362
362
 
363
363
  case SubtractiveBlending:
364
- gl.blendFuncSeparate( gl.ZERO, gl.ONE_MINUS_SRC_COLOR, gl.ZERO, gl.ONE );
364
+ console.error( 'THREE.WebGLState: SubtractiveBlending requires material.premultipliedAlpha = true' );
365
365
  break;
366
366
 
367
367
  case MultiplyBlending:
368
- gl.blendFunc( gl.ZERO, gl.SRC_COLOR );
368
+ console.error( 'THREE.WebGLState: MultiplyBlending requires material.premultipliedAlpha = true' );
369
369
  break;
370
370
 
371
371
  default:
@@ -1021,6 +1021,8 @@ class WebGLTextureUtils {
1021
1021
 
1022
1022
  }
1023
1023
 
1024
+ gl.bindRenderbuffer( gl.RENDERBUFFER, null );
1025
+
1024
1026
  }
1025
1027
 
1026
1028
  /**
@@ -1236,7 +1236,7 @@ class WebGPUBackend extends Backend {
1236
1236
 
1237
1237
  }
1238
1238
 
1239
- if ( supportsDepth && depthStencilAttachment && depthStencilAttachment.depthLoadOp === undefined ) {
1239
+ if ( supportsDepth && depthStencilAttachment ) {
1240
1240
 
1241
1241
  if ( depth ) {
1242
1242
 
@@ -1255,7 +1255,7 @@ class WebGPUBackend extends Backend {
1255
1255
 
1256
1256
  //
1257
1257
 
1258
- if ( supportsStencil && depthStencilAttachment && depthStencilAttachment.stencilLoadOp === undefined ) {
1258
+ if ( supportsStencil && depthStencilAttachment ) {
1259
1259
 
1260
1260
  if ( stencil ) {
1261
1261
 
@@ -1298,7 +1298,6 @@ class WebGPUBackend extends Backend {
1298
1298
 
1299
1299
  const groupGPU = this.get( computeGroup );
1300
1300
 
1301
-
1302
1301
  const descriptor = {
1303
1302
  label: 'computeGroup_' + computeGroup.id
1304
1303
  };
@@ -1318,9 +1317,11 @@ class WebGPUBackend extends Backend {
1318
1317
  * @param {Node} computeNode - The compute node.
1319
1318
  * @param {Array<BindGroup>} bindings - The bindings.
1320
1319
  * @param {ComputePipeline} pipeline - The compute pipeline.
1320
+ * @param {Array<number>|number} [dispatchSizeOrCount=null] - Array with [ x, y, z ] values for dispatch or a single number for the count.
1321
1321
  */
1322
- compute( computeGroup, computeNode, bindings, pipeline ) {
1322
+ compute( computeGroup, computeNode, bindings, pipeline, dispatchSizeOrCount = null ) {
1323
1323
 
1324
+ const computeNodeData = this.get( computeNode );
1324
1325
  const { passEncoderGPU } = this.get( computeGroup );
1325
1326
 
1326
1327
  // pipeline
@@ -1340,29 +1341,67 @@ class WebGPUBackend extends Backend {
1340
1341
 
1341
1342
  }
1342
1343
 
1343
- const maxComputeWorkgroupsPerDimension = this.device.limits.maxComputeWorkgroupsPerDimension;
1344
+ let dispatchSize;
1344
1345
 
1345
- const computeNodeData = this.get( computeNode );
1346
+ if ( dispatchSizeOrCount === null ) {
1347
+
1348
+ dispatchSizeOrCount = computeNode.count;
1349
+
1350
+ }
1351
+
1352
+ if ( typeof dispatchSizeOrCount === 'number' ) {
1353
+
1354
+ // If a single number is given, we calculate the dispatch size based on the workgroup size
1355
+
1356
+ const count = dispatchSizeOrCount;
1357
+
1358
+ if ( computeNodeData.dispatchSize === undefined || computeNodeData.count !== count ) {
1359
+
1360
+ // cache dispatch size to avoid recalculating it every time
1361
+
1362
+ computeNodeData.dispatchSize = [ 0, 1, 1 ];
1363
+ computeNodeData.count = count;
1364
+
1365
+ const workgroupSize = computeNode.workgroupSize;
1366
+
1367
+ let size = workgroupSize[ 0 ];
1368
+
1369
+ for ( let i = 1; i < workgroupSize.length; i ++ )
1370
+ size *= workgroupSize[ i ];
1346
1371
 
1347
- if ( computeNodeData.dispatchSize === undefined ) computeNodeData.dispatchSize = { x: 0, y: 1, z: 1 };
1372
+ const dispatchCount = Math.ceil( count / size );
1348
1373
 
1349
- const { dispatchSize } = computeNodeData;
1374
+ //
1350
1375
 
1351
- if ( computeNode.dispatchCount > maxComputeWorkgroupsPerDimension ) {
1376
+ const maxComputeWorkgroupsPerDimension = this.device.limits.maxComputeWorkgroupsPerDimension;
1352
1377
 
1353
- dispatchSize.x = Math.min( computeNode.dispatchCount, maxComputeWorkgroupsPerDimension );
1354
- dispatchSize.y = Math.ceil( computeNode.dispatchCount / maxComputeWorkgroupsPerDimension );
1378
+ dispatchSize = [ dispatchCount, 1, 1 ];
1379
+
1380
+ if ( dispatchCount > maxComputeWorkgroupsPerDimension ) {
1381
+
1382
+ dispatchSize[ 0 ] = Math.min( dispatchCount, maxComputeWorkgroupsPerDimension );
1383
+ dispatchSize[ 1 ] = Math.ceil( dispatchCount / maxComputeWorkgroupsPerDimension );
1384
+
1385
+ }
1386
+
1387
+ computeNodeData.dispatchSize = dispatchSize;
1388
+
1389
+ }
1390
+
1391
+ dispatchSize = computeNodeData.dispatchSize;
1355
1392
 
1356
1393
  } else {
1357
1394
 
1358
- dispatchSize.x = computeNode.dispatchCount;
1395
+ dispatchSize = dispatchSizeOrCount;
1359
1396
 
1360
1397
  }
1361
1398
 
1399
+ //
1400
+
1362
1401
  passEncoderGPU.dispatchWorkgroups(
1363
- dispatchSize.x,
1364
- dispatchSize.y,
1365
- dispatchSize.z
1402
+ dispatchSize[ 0 ],
1403
+ dispatchSize[ 1 ] || 1,
1404
+ dispatchSize[ 2 ] || 1
1366
1405
  );
1367
1406
 
1368
1407
  }
@@ -2092,7 +2131,15 @@ class WebGPUBackend extends Backend {
2092
2131
  */
2093
2132
  createIndexAttribute( attribute ) {
2094
2133
 
2095
- this.attributeUtils.createAttribute( attribute, GPUBufferUsage.INDEX | GPUBufferUsage.COPY_SRC | GPUBufferUsage.COPY_DST );
2134
+ let usage = GPUBufferUsage.INDEX | GPUBufferUsage.COPY_SRC | GPUBufferUsage.COPY_DST;
2135
+
2136
+ if ( attribute.isStorageBufferAttribute || attribute.isStorageInstancedBufferAttribute ) {
2137
+
2138
+ usage |= GPUBufferUsage.STORAGE;
2139
+
2140
+ }
2141
+
2142
+ this.attributeUtils.createAttribute( attribute, usage );
2096
2143
 
2097
2144
  }
2098
2145