@plastic-software/three 0.179.0 → 0.180.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 (173) hide show
  1. package/build/three.cjs +167 -107
  2. package/build/three.core.js +112 -20
  3. package/build/three.core.min.js +1 -1
  4. package/build/three.module.js +56 -90
  5. package/build/three.module.min.js +1 -1
  6. package/build/three.tsl.js +30 -5
  7. package/build/three.tsl.min.js +1 -1
  8. package/build/three.webgpu.js +2896 -1048
  9. package/build/three.webgpu.min.js +1 -1
  10. package/build/three.webgpu.nodes.js +2896 -1048
  11. package/build/three.webgpu.nodes.min.js +1 -1
  12. package/examples/jsm/Addons.js +1 -1
  13. package/examples/jsm/controls/ArcballControls.js +7 -7
  14. package/examples/jsm/controls/DragControls.js +6 -56
  15. package/examples/jsm/controls/FirstPersonControls.js +2 -2
  16. package/examples/jsm/controls/PointerLockControls.js +0 -8
  17. package/examples/jsm/exporters/GLTFExporter.js +30 -22
  18. package/examples/jsm/exporters/KTX2Exporter.js +4 -2
  19. package/examples/jsm/exporters/PLYExporter.js +1 -1
  20. package/examples/jsm/libs/ktx-parse.module.js +1 -1
  21. package/examples/jsm/lines/Line2.js +3 -3
  22. package/examples/jsm/lines/LineGeometry.js +1 -1
  23. package/examples/jsm/lines/LineSegments2.js +2 -2
  24. package/examples/jsm/lines/Wireframe.js +2 -2
  25. package/examples/jsm/lines/WireframeGeometry2.js +1 -1
  26. package/examples/jsm/lines/webgpu/LineSegments2.js +1 -1
  27. package/examples/jsm/lines/webgpu/Wireframe.js +1 -1
  28. package/examples/jsm/loaders/ColladaLoader.js +1 -1
  29. package/examples/jsm/loaders/EXRLoader.js +5 -5
  30. package/examples/jsm/loaders/GLTFLoader.js +9 -5
  31. package/examples/jsm/loaders/HDRCubeTextureLoader.js +5 -5
  32. package/examples/jsm/loaders/HDRLoader.js +486 -0
  33. package/examples/jsm/loaders/KTX2Loader.js +112 -32
  34. package/examples/jsm/loaders/RGBELoader.js +7 -473
  35. package/examples/jsm/loaders/TTFLoader.js +4 -4
  36. package/examples/jsm/loaders/UltraHDRLoader.js +1 -1
  37. package/examples/jsm/loaders/lwo/IFFParser.js +1 -1
  38. package/examples/jsm/materials/WoodNodeMaterial.js +533 -0
  39. package/examples/jsm/math/ColorSpaces.js +19 -1
  40. package/examples/jsm/math/ConvexHull.js +2 -2
  41. package/examples/jsm/math/Lut.js +2 -2
  42. package/examples/jsm/misc/MD2CharacterComplex.js +1 -1
  43. package/examples/jsm/misc/ProgressiveLightMap.js +1 -1
  44. package/examples/jsm/misc/Volume.js +1 -1
  45. package/examples/jsm/postprocessing/OutlinePass.js +1 -1
  46. package/examples/jsm/postprocessing/SSRPass.js +37 -8
  47. package/examples/jsm/shaders/UnpackDepthRGBAShader.js +1 -1
  48. package/examples/jsm/transpiler/GLSLDecoder.js +22 -19
  49. package/examples/jsm/transpiler/TSLEncoder.js +2 -10
  50. package/examples/jsm/transpiler/WGSLEncoder.js +24 -0
  51. package/examples/jsm/tsl/display/AnamorphicNode.js +27 -4
  52. package/examples/jsm/tsl/display/BloomNode.js +3 -3
  53. package/examples/jsm/tsl/display/ChromaticAberrationNode.js +2 -1
  54. package/examples/jsm/tsl/display/DepthOfFieldNode.js +439 -90
  55. package/examples/jsm/tsl/display/GTAONode.js +8 -0
  56. package/examples/jsm/tsl/display/GaussianBlurNode.js +47 -35
  57. package/examples/jsm/tsl/display/OutlineNode.js +2 -2
  58. package/examples/jsm/tsl/display/SSRNode.js +180 -65
  59. package/examples/jsm/tsl/display/TRAANode.js +1 -1
  60. package/examples/jsm/tsl/display/boxBlur.js +64 -0
  61. package/examples/jsm/tsl/display/hashBlur.js +15 -18
  62. package/examples/jsm/utils/BufferGeometryUtils.js +1 -1
  63. package/examples/jsm/utils/ShadowMapViewerGPU.js +12 -5
  64. package/examples/jsm/webxr/OculusHandModel.js +1 -1
  65. package/package.json +1 -1
  66. package/src/Three.Core.js +1 -0
  67. package/src/Three.TSL.js +29 -4
  68. package/src/animation/AnimationClip.js +17 -2
  69. package/src/constants.js +11 -3
  70. package/src/core/BufferGeometry.js +2 -2
  71. package/src/extras/TextureUtils.js +2 -1
  72. package/src/extras/lib/earcut.js +1 -1
  73. package/src/lights/webgpu/ProjectorLight.js +1 -1
  74. package/src/materials/Material.js +12 -0
  75. package/src/materials/MeshDistanceMaterial.js +1 -1
  76. package/src/materials/nodes/PointsNodeMaterial.js +81 -28
  77. package/src/materials/nodes/SpriteNodeMaterial.js +3 -15
  78. package/src/materials/nodes/manager/NodeMaterialObserver.js +1 -1
  79. package/src/math/ColorManagement.js +7 -1
  80. package/src/nodes/Nodes.js +3 -0
  81. package/src/nodes/TSL.js +3 -0
  82. package/src/nodes/accessors/BufferNode.js +1 -1
  83. package/src/nodes/accessors/Camera.js +133 -7
  84. package/src/nodes/accessors/ClippingNode.js +6 -5
  85. package/src/nodes/accessors/CubeTextureNode.js +2 -2
  86. package/src/nodes/accessors/InstanceNode.js +3 -1
  87. package/src/nodes/accessors/Object3DNode.js +1 -1
  88. package/src/nodes/accessors/ReferenceBaseNode.js +1 -1
  89. package/src/nodes/accessors/ReferenceNode.js +1 -1
  90. package/src/nodes/accessors/Texture3DNode.js +13 -0
  91. package/src/nodes/accessors/TextureNode.js +71 -19
  92. package/src/nodes/code/FunctionCallNode.js +19 -0
  93. package/src/nodes/code/FunctionNode.js +23 -0
  94. package/src/nodes/core/AssignNode.js +4 -3
  95. package/src/nodes/core/ContextNode.js +24 -0
  96. package/src/nodes/core/Node.js +16 -20
  97. package/src/nodes/core/NodeBuilder.js +48 -14
  98. package/src/nodes/core/NodeFrame.js +1 -1
  99. package/src/nodes/core/NodeUniform.js +1 -1
  100. package/src/nodes/core/NodeUtils.js +1 -2
  101. package/src/nodes/core/StackNode.js +29 -4
  102. package/src/nodes/core/StructNode.js +5 -5
  103. package/src/nodes/core/StructTypeNode.js +1 -0
  104. package/src/nodes/core/SubBuildNode.js +2 -2
  105. package/src/nodes/core/UniformNode.js +16 -9
  106. package/src/nodes/core/VarNode.js +0 -21
  107. package/src/nodes/display/FrontFacingNode.js +4 -8
  108. package/src/nodes/display/PassNode.js +1 -1
  109. package/src/nodes/display/ScreenNode.js +42 -13
  110. package/src/nodes/display/ViewportDepthTextureNode.js +16 -4
  111. package/src/nodes/display/ViewportSharedTextureNode.js +12 -0
  112. package/src/nodes/display/ViewportTextureNode.js +42 -12
  113. package/src/nodes/gpgpu/SubgroupFunctionNode.js +430 -0
  114. package/src/nodes/lighting/LightsNode.js +1 -1
  115. package/src/nodes/math/BitcastNode.js +156 -0
  116. package/src/nodes/math/ConditionalNode.js +18 -2
  117. package/src/nodes/math/MathNode.js +3 -15
  118. package/src/nodes/math/OperatorNode.js +4 -3
  119. package/src/nodes/tsl/TSLCore.js +432 -152
  120. package/src/nodes/utils/JoinNode.js +3 -1
  121. package/src/nodes/utils/MemberNode.js +58 -7
  122. package/src/nodes/utils/RTTNode.js +1 -1
  123. package/src/nodes/utils/ReflectorNode.js +51 -7
  124. package/src/nodes/utils/SampleNode.js +12 -2
  125. package/src/nodes/utils/SplitNode.js +11 -0
  126. package/src/nodes/utils/Timer.js +0 -47
  127. package/src/objects/BatchedMesh.js +2 -2
  128. package/src/objects/LOD.js +1 -1
  129. package/src/objects/Sprite.js +2 -2
  130. package/src/renderers/WebGLRenderer.js +1 -10
  131. package/src/renderers/common/Attributes.js +1 -1
  132. package/src/renderers/common/Backend.js +19 -1
  133. package/src/renderers/common/Bindings.js +2 -0
  134. package/src/renderers/common/ChainMap.js +1 -1
  135. package/src/renderers/common/DataMap.js +1 -1
  136. package/src/renderers/common/Pipelines.js +1 -1
  137. package/src/renderers/common/RenderContext.js +2 -2
  138. package/src/renderers/common/RenderObject.js +14 -2
  139. package/src/renderers/common/Renderer.js +39 -19
  140. package/src/renderers/common/SampledTexture.js +1 -1
  141. package/src/renderers/common/Sampler.js +25 -13
  142. package/src/renderers/common/Textures.js +34 -12
  143. package/src/renderers/common/TimestampQueryPool.js +3 -3
  144. package/src/renderers/common/XRManager.js +35 -19
  145. package/src/renderers/common/nodes/NodeBuilderState.js +1 -1
  146. package/src/renderers/common/nodes/NodeLibrary.js +5 -5
  147. package/src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl.js +1 -1
  148. package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl.js +1 -1
  149. package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_vertex.glsl.js +1 -1
  150. package/src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl.js +1 -1
  151. package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +7 -15
  152. package/src/renderers/shaders/ShaderLib/depth.glsl.js +1 -1
  153. package/src/renderers/webgl/WebGLProgram.js +4 -4
  154. package/src/renderers/webgl/WebGLShadowMap.js +1 -1
  155. package/src/renderers/webgl/WebGLTextures.js +1 -0
  156. package/src/renderers/webgl/WebGLUtils.js +3 -2
  157. package/src/renderers/webgl-fallback/WebGLBackend.js +186 -135
  158. package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +110 -17
  159. package/src/renderers/webgl-fallback/utils/WebGLState.js +1 -1
  160. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +52 -3
  161. package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +9 -10
  162. package/src/renderers/webgl-fallback/utils/WebGLUtils.js +3 -2
  163. package/src/renderers/webgpu/WebGPUBackend.js +35 -31
  164. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +124 -34
  165. package/src/renderers/webgpu/utils/WebGPUConstants.js +2 -2
  166. package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +9 -18
  167. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +114 -25
  168. package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +3 -3
  169. package/src/renderers/webxr/WebXRManager.js +39 -24
  170. package/src/textures/ExternalTexture.js +15 -4
  171. package/src/textures/Source.js +1 -1
  172. package/src/textures/VideoTexture.js +0 -3
  173. package/examples/jsm/loaders/RGBMLoader.js +0 -1148
@@ -13,7 +13,8 @@ import {
13
13
  RGBAFormat, RGBFormat, RedFormat, RGFormat, RGBA_S3TC_DXT1_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT5_Format, UnsignedByteType, FloatType, HalfFloatType, SRGBTransfer, DepthFormat, DepthStencilFormat,
14
14
  RGBA_ASTC_4x4_Format, RGBA_ASTC_5x4_Format, RGBA_ASTC_5x5_Format, RGBA_ASTC_6x5_Format, RGBA_ASTC_6x6_Format, RGBA_ASTC_8x5_Format, RGBA_ASTC_8x6_Format, RGBA_ASTC_8x8_Format, RGBA_ASTC_10x5_Format,
15
15
  RGBA_ASTC_10x6_Format, RGBA_ASTC_10x8_Format, RGBA_ASTC_10x10_Format, RGBA_ASTC_12x10_Format, RGBA_ASTC_12x12_Format, UnsignedIntType, UnsignedShortType, UnsignedInt248Type, UnsignedInt5999Type,
16
- NeverCompare, AlwaysCompare, LessCompare, LessEqualCompare, EqualCompare, GreaterEqualCompare, GreaterCompare, NotEqualCompare, IntType, RedIntegerFormat, RGIntegerFormat, RGBAIntegerFormat
16
+ NeverCompare, AlwaysCompare, LessCompare, LessEqualCompare, EqualCompare, GreaterEqualCompare, GreaterCompare, NotEqualCompare, IntType, RedIntegerFormat, RGIntegerFormat, RGBAIntegerFormat,
17
+ UnsignedInt101111Type, RGBA_BPTC_Format, RGB_ETC1_Format, RGB_S3TC_DXT1_Format, RED_RGTC1_Format, SIGNED_RED_RGTC1_Format, RED_GREEN_RGTC2_Format, SIGNED_RED_GREEN_RGTC2_Format
17
18
  } from '../../../constants.js';
18
19
  import { CubeTexture } from '../../../textures/CubeTexture.js';
19
20
  import { DepthTexture } from '../../../textures/DepthTexture.js';
@@ -186,6 +187,15 @@ class WebGPUTextureUtils {
186
187
 
187
188
  }
188
189
 
190
+ if ( texture.isExternalTexture ) {
191
+
192
+ textureData.texture = texture.sourceTexture;
193
+ textureData.initialized = true;
194
+
195
+ return;
196
+
197
+ }
198
+
189
199
  if ( options.needsMipmaps === undefined ) options.needsMipmaps = false;
190
200
  if ( options.levels === undefined ) options.levels = 1;
191
201
  if ( options.depth === undefined ) options.depth = 1;
@@ -221,7 +231,7 @@ class WebGPUTextureUtils {
221
231
 
222
232
  }
223
233
 
224
- if ( texture.isCompressedTexture !== true && texture.isCompressedArrayTexture !== true ) {
234
+ if ( texture.isCompressedTexture !== true && texture.isCompressedArrayTexture !== true && format !== GPUTextureFormat.RGB9E5UFloat ) {
225
235
 
226
236
  usage |= GPUTextureUsage.RENDER_ATTACHMENT;
227
237
 
@@ -266,6 +276,7 @@ class WebGPUTextureUtils {
266
276
 
267
277
  msaaTextureDescriptorGPU.label = msaaTextureDescriptorGPU.label + '-msaa';
268
278
  msaaTextureDescriptorGPU.sampleCount = samples;
279
+ msaaTextureDescriptorGPU.mipLevelCount = 1; // See https://www.w3.org/TR/webgpu/#texture-creation
269
280
 
270
281
  textureData.msaaTexture = backend.device.createTexture( msaaTextureDescriptorGPU );
271
282
 
@@ -432,6 +443,7 @@ class WebGPUTextureUtils {
432
443
  updateTexture( texture, options ) {
433
444
 
434
445
  const textureData = this.backend.get( texture );
446
+ const mipmaps = texture.mipmaps;
435
447
 
436
448
  const { textureDescriptorGPU } = textureData;
437
449
 
@@ -442,7 +454,22 @@ class WebGPUTextureUtils {
442
454
 
443
455
  if ( texture.isDataTexture ) {
444
456
 
445
- this._copyBufferToTexture( options.image, textureData.texture, textureDescriptorGPU, 0, texture.flipY );
457
+ if ( mipmaps.length > 0 ) {
458
+
459
+ for ( let i = 0, il = mipmaps.length; i < il; i ++ ) {
460
+
461
+ const mipmap = mipmaps[ i ];
462
+
463
+ this._copyBufferToTexture( mipmap, textureData.texture, textureDescriptorGPU, 0, texture.flipY, 0, i );
464
+
465
+ }
466
+
467
+
468
+ } else {
469
+
470
+ this._copyBufferToTexture( options.image, textureData.texture, textureDescriptorGPU, 0, texture.flipY );
471
+
472
+ }
446
473
 
447
474
  } else if ( texture.isArrayTexture || texture.isDataArrayTexture || texture.isData3DTexture ) {
448
475
 
@@ -458,11 +485,26 @@ class WebGPUTextureUtils {
458
485
 
459
486
  } else if ( texture.isCubeTexture ) {
460
487
 
461
- this._copyCubeMapToTexture( options.images, textureData.texture, textureDescriptorGPU, texture.flipY, texture.premultiplyAlpha );
488
+ this._copyCubeMapToTexture( texture, textureData.texture, textureDescriptorGPU );
462
489
 
463
490
  } else {
464
491
 
465
- this._copyImageToTexture( options.image, textureData.texture, textureDescriptorGPU, 0, texture.flipY, texture.premultiplyAlpha );
492
+ if ( mipmaps.length > 0 ) {
493
+
494
+ for ( let i = 0, il = mipmaps.length; i < il; i ++ ) {
495
+
496
+ const mipmap = mipmaps[ i ];
497
+
498
+ this._copyImageToTexture( mipmap, textureData.texture, textureDescriptorGPU, 0, texture.flipY, texture.premultiplyAlpha, i );
499
+
500
+ }
501
+
502
+
503
+ } else {
504
+
505
+ this._copyImageToTexture( options.image, textureData.texture, textureDescriptorGPU, 0, texture.flipY, texture.premultiplyAlpha );
506
+
507
+ }
466
508
 
467
509
  }
468
510
 
@@ -470,8 +512,6 @@ class WebGPUTextureUtils {
470
512
 
471
513
  textureData.version = texture.version;
472
514
 
473
- if ( texture.onUpdate ) texture.onUpdate( texture );
474
-
475
515
  }
476
516
 
477
517
  /**
@@ -500,7 +540,7 @@ class WebGPUTextureUtils {
500
540
 
501
541
  const readBuffer = device.createBuffer(
502
542
  {
503
- size: width * height * bytesPerTexel,
543
+ size: ( ( height - 1 ) * bytesPerRow ) + ( width * bytesPerTexel ), // see https://github.com/mrdoob/three.js/issues/31658#issuecomment-3229442010
504
544
  usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ
505
545
  }
506
546
  );
@@ -593,27 +633,46 @@ class WebGPUTextureUtils {
593
633
  * Uploads cube texture image data to the GPU memory.
594
634
  *
595
635
  * @private
596
- * @param {Array} images - The cube image data.
636
+ * @param {CubeTexture} texture - The cube texture.
597
637
  * @param {GPUTexture} textureGPU - The GPU texture.
598
638
  * @param {Object} textureDescriptorGPU - The GPU texture descriptor.
599
- * @param {boolean} flipY - Whether to flip texture data along their vertical axis or not.
600
- * @param {boolean} premultiplyAlpha - Whether the texture should have its RGB channels premultiplied by the alpha channel or not.
601
639
  */
602
- _copyCubeMapToTexture( images, textureGPU, textureDescriptorGPU, flipY, premultiplyAlpha ) {
640
+ _copyCubeMapToTexture( texture, textureGPU, textureDescriptorGPU ) {
641
+
642
+ const images = texture.images;
643
+ const mipmaps = texture.mipmaps;
603
644
 
604
645
  for ( let i = 0; i < 6; i ++ ) {
605
646
 
606
647
  const image = images[ i ];
607
648
 
608
- const flipIndex = flipY === true ? _flipMap[ i ] : i;
649
+ const flipIndex = texture.flipY === true ? _flipMap[ i ] : i;
609
650
 
610
651
  if ( image.isDataTexture ) {
611
652
 
612
- this._copyBufferToTexture( image.image, textureGPU, textureDescriptorGPU, flipIndex, flipY );
653
+ this._copyBufferToTexture( image.image, textureGPU, textureDescriptorGPU, flipIndex, texture.flipY );
613
654
 
614
655
  } else {
615
656
 
616
- this._copyImageToTexture( image, textureGPU, textureDescriptorGPU, flipIndex, flipY, premultiplyAlpha );
657
+ this._copyImageToTexture( image, textureGPU, textureDescriptorGPU, flipIndex, texture.flipY, texture.premultiplyAlpha );
658
+
659
+ }
660
+
661
+ for ( let j = 0; j < mipmaps.length; j ++ ) {
662
+
663
+ const mipmap = mipmaps[ j ];
664
+ const image = mipmap.images[ i ];
665
+
666
+ if ( image.isDataTexture ) {
667
+
668
+ this._copyBufferToTexture( image.image, textureGPU, textureDescriptorGPU, flipIndex, texture.flipY, 0, j + 1 );
669
+
670
+ } else {
671
+
672
+ this._copyImageToTexture( image, textureGPU, textureDescriptorGPU, flipIndex, texture.flipY, texture.premultiplyAlpha, j + 1 );
673
+
674
+ }
675
+
617
676
 
618
677
  }
619
678
 
@@ -631,23 +690,27 @@ class WebGPUTextureUtils {
631
690
  * @param {number} originDepth - The origin depth.
632
691
  * @param {boolean} flipY - Whether to flip texture data along their vertical axis or not.
633
692
  * @param {boolean} premultiplyAlpha - Whether the texture should have its RGB channels premultiplied by the alpha channel or not.
693
+ * @param {number} [mipLevel=0] - The mip level where the data should be copied to.
634
694
  */
635
- _copyImageToTexture( image, textureGPU, textureDescriptorGPU, originDepth, flipY, premultiplyAlpha ) {
695
+ _copyImageToTexture( image, textureGPU, textureDescriptorGPU, originDepth, flipY, premultiplyAlpha, mipLevel = 0 ) {
636
696
 
637
697
  const device = this.backend.device;
638
698
 
699
+ const width = ( mipLevel > 0 ) ? image.width : textureDescriptorGPU.size.width;
700
+ const height = ( mipLevel > 0 ) ? image.height : textureDescriptorGPU.size.height;
701
+
639
702
  device.queue.copyExternalImageToTexture(
640
703
  {
641
704
  source: image,
642
705
  flipY: flipY
643
706
  }, {
644
707
  texture: textureGPU,
645
- mipLevel: 0,
708
+ mipLevel: mipLevel,
646
709
  origin: { x: 0, y: 0, z: originDepth },
647
710
  premultipliedAlpha: premultiplyAlpha
648
711
  }, {
649
- width: textureDescriptorGPU.size.width,
650
- height: textureDescriptorGPU.size.height,
712
+ width: width,
713
+ height: height,
651
714
  depthOrArrayLayers: 1
652
715
  }
653
716
  );
@@ -711,9 +774,10 @@ class WebGPUTextureUtils {
711
774
  * @param {Object} textureDescriptorGPU - The GPU texture descriptor.
712
775
  * @param {number} originDepth - The origin depth.
713
776
  * @param {boolean} flipY - Whether to flip texture data along their vertical axis or not.
714
- * @param {number} [depth=0] - TODO.
777
+ * @param {number} [depth=0] - The depth offset when copying array or 3D texture data.
778
+ * @param {number} [mipLevel=0] - The mip level where the data should be copied to.
715
779
  */
716
- _copyBufferToTexture( image, textureGPU, textureDescriptorGPU, originDepth, flipY, depth = 0 ) {
780
+ _copyBufferToTexture( image, textureGPU, textureDescriptorGPU, originDepth, flipY, depth = 0, mipLevel = 0 ) {
717
781
 
718
782
  // @TODO: Consider to use GPUCommandEncoder.copyBufferToTexture()
719
783
  // @TODO: Consider to support valid buffer layouts with other formats like RGB
@@ -728,7 +792,7 @@ class WebGPUTextureUtils {
728
792
  device.queue.writeTexture(
729
793
  {
730
794
  texture: textureGPU,
731
- mipLevel: 0,
795
+ mipLevel: mipLevel,
732
796
  origin: { x: 0, y: 0, z: originDepth }
733
797
  },
734
798
  data,
@@ -976,7 +1040,7 @@ class WebGPUTextureUtils {
976
1040
  if ( format === GPUTextureFormat.RG8Snorm ) return Int8Array;
977
1041
  if ( format === GPUTextureFormat.RGBA8Uint ) return Uint8Array;
978
1042
  if ( format === GPUTextureFormat.RGBA8Sint ) return Int8Array;
979
- if ( format === GPUTextureFormat.RGBA8Unorm ) return Uint8Array;
1043
+ if ( format === GPUTextureFormat.RGBA8Unorm || format === GPUTextureFormat.RGBA8UnormSRGB ) return Uint8Array;
980
1044
  if ( format === GPUTextureFormat.RGBA8Snorm ) return Int8Array;
981
1045
 
982
1046
 
@@ -1001,8 +1065,7 @@ class WebGPUTextureUtils {
1001
1065
  if ( format === GPUTextureFormat.RGBA32Sint ) return Int32Array;
1002
1066
  if ( format === GPUTextureFormat.RGBA32Float ) return Float32Array;
1003
1067
 
1004
- if ( format === GPUTextureFormat.BGRA8Unorm ) return Uint8Array;
1005
- if ( format === GPUTextureFormat.BGRA8UnormSRGB ) return Uint8Array;
1068
+ if ( format === GPUTextureFormat.BGRA8Unorm || format === GPUTextureFormat.BGRA8UnormSRGB ) return Uint8Array;
1006
1069
  if ( format === GPUTextureFormat.RGB10A2Unorm ) return Uint32Array;
1007
1070
  if ( format === GPUTextureFormat.RGB9E5UFloat ) return Uint32Array;
1008
1071
  if ( format === GPUTextureFormat.RG11B10UFloat ) return Uint32Array;
@@ -1062,6 +1125,7 @@ export function getFormat( texture, device = null ) {
1062
1125
 
1063
1126
  switch ( format ) {
1064
1127
 
1128
+ case RGB_S3TC_DXT1_Format:
1065
1129
  case RGBA_S3TC_DXT1_Format:
1066
1130
  formatGPU = ( transfer === SRGBTransfer ) ? GPUTextureFormat.BC1RGBAUnormSRGB : GPUTextureFormat.BC1RGBAUnorm;
1067
1131
  break;
@@ -1074,7 +1138,28 @@ export function getFormat( texture, device = null ) {
1074
1138
  formatGPU = ( transfer === SRGBTransfer ) ? GPUTextureFormat.BC3RGBAUnormSRGB : GPUTextureFormat.BC3RGBAUnorm;
1075
1139
  break;
1076
1140
 
1141
+ case RED_RGTC1_Format:
1142
+ formatGPU = GPUTextureFormat.BC4RUnorm;
1143
+ break;
1144
+
1145
+ case SIGNED_RED_RGTC1_Format:
1146
+ formatGPU = GPUTextureFormat.BC4RSnorm;
1147
+ break;
1148
+
1149
+ case RED_GREEN_RGTC2_Format:
1150
+ formatGPU = GPUTextureFormat.BC5RGUnorm;
1151
+ break;
1152
+
1153
+ case SIGNED_RED_GREEN_RGTC2_Format:
1154
+ formatGPU = GPUTextureFormat.BC5RGSnorm;
1155
+ break;
1156
+
1157
+ case RGBA_BPTC_Format:
1158
+ formatGPU = ( transfer === SRGBTransfer ) ? GPUTextureFormat.BC7RGBAUnormSRGB : GPUTextureFormat.BC7RGBAUnorm;
1159
+ break;
1160
+
1077
1161
  case RGB_ETC2_Format:
1162
+ case RGB_ETC1_Format:
1078
1163
  formatGPU = ( transfer === SRGBTransfer ) ? GPUTextureFormat.ETC2RGB8UnormSRGB : GPUTextureFormat.ETC2RGB8Unorm;
1079
1164
  break;
1080
1165
 
@@ -1201,6 +1286,10 @@ export function getFormat( texture, device = null ) {
1201
1286
  formatGPU = GPUTextureFormat.RGB9E5UFloat;
1202
1287
  break;
1203
1288
 
1289
+ case UnsignedInt101111Type:
1290
+ formatGPU = GPUTextureFormat.RG11B10UFloat;
1291
+ break;
1292
+
1204
1293
  default:
1205
1294
  console.error( 'WebGPURenderer: Unsupported texture type with RGBFormat.', type );
1206
1295
 
@@ -46,10 +46,10 @@ class WebGPUTimestampQueryPool extends TimestampQueryPool {
46
46
  /**
47
47
  * Allocates a pair of queries for a given render context.
48
48
  *
49
- * @param {Object} renderContext - The render context to allocate queries for.
49
+ * @param {string} uid - A unique identifier for the render context.
50
50
  * @returns {?number} The base offset for the allocated queries, or null if allocation failed.
51
51
  */
52
- allocateQueriesForContext( renderContext ) {
52
+ allocateQueriesForContext( uid ) {
53
53
 
54
54
  if ( ! this.trackTimestamp || this.isDisposed ) return null;
55
55
 
@@ -63,7 +63,7 @@ class WebGPUTimestampQueryPool extends TimestampQueryPool {
63
63
  const baseOffset = this.currentQueryIndex;
64
64
  this.currentQueryIndex += 2;
65
65
 
66
- this.queryOffsets.set( renderContext.id, baseOffset );
66
+ this.queryOffsets.set( uid, baseOffset );
67
67
  return baseOffset;
68
68
 
69
69
  }
@@ -52,6 +52,8 @@ class WebXRManager extends EventDispatcher {
52
52
  let glBaseLayer = null;
53
53
  let xrFrame = null;
54
54
 
55
+ const supportsGlBinding = typeof XRWebGLBinding !== 'undefined';
56
+
55
57
  const depthSensing = new WebXRDepthSensing();
56
58
  const cameraAccessTextures = {};
57
59
  const attributes = gl.getContextAttributes();
@@ -329,6 +331,9 @@ class WebXRManager extends EventDispatcher {
329
331
  /**
330
332
  * Returns the current base layer.
331
333
  *
334
+ * This is an `XRProjectionLayer` when the targeted XR device supports the
335
+ * WebXR Layers API, or an `XRWebGLLayer` otherwise.
336
+ *
332
337
  * @return {?(XRWebGLLayer|XRProjectionLayer)} The XR base layer.
333
338
  */
334
339
  this.getBaseLayer = function () {
@@ -340,10 +345,19 @@ class WebXRManager extends EventDispatcher {
340
345
  /**
341
346
  * Returns the current XR binding.
342
347
  *
343
- * @return {?XRWebGLBinding} The XR binding.
348
+ * Creates a new binding if needed and the browser is
349
+ * capable of doing so.
350
+ *
351
+ * @return {?XRWebGLBinding} The XR binding. Returns `null` if one cannot be created.
344
352
  */
345
353
  this.getBinding = function () {
346
354
 
355
+ if ( glBinding === null && supportsGlBinding ) {
356
+
357
+ glBinding = new XRWebGLBinding( session, gl );
358
+
359
+ }
360
+
347
361
  return glBinding;
348
362
 
349
363
  };
@@ -405,17 +419,12 @@ class WebXRManager extends EventDispatcher {
405
419
  currentPixelRatio = renderer.getPixelRatio();
406
420
  renderer.getSize( currentSize );
407
421
 
408
- if ( typeof XRWebGLBinding !== 'undefined' ) {
409
-
410
- glBinding = new XRWebGLBinding( session, gl );
411
-
412
- }
413
422
 
414
423
  // Check that the browser implements the necessary APIs to use an
415
424
  // XRProjectionLayer rather than an XRWebGLLayer
416
- const useLayers = glBinding !== null && 'createProjectionLayer' in XRWebGLBinding.prototype;
425
+ const supportsLayers = supportsGlBinding && 'createProjectionLayer' in XRWebGLBinding.prototype;
417
426
 
418
- if ( ! useLayers ) {
427
+ if ( ! supportsLayers ) {
419
428
 
420
429
  const layerInit = {
421
430
  antialias: attributes.antialias,
@@ -466,6 +475,8 @@ class WebXRManager extends EventDispatcher {
466
475
  scaleFactor: framebufferScaleFactor
467
476
  };
468
477
 
478
+ glBinding = this.getBinding();
479
+
469
480
  glProjLayer = glBinding.createProjectionLayer( projectionlayerInit );
470
481
 
471
482
  session.updateRenderState( { layers: [ glProjLayer ] } );
@@ -525,6 +536,8 @@ class WebXRManager extends EventDispatcher {
525
536
  /**
526
537
  * Returns the current depth texture computed via depth sensing.
527
538
  *
539
+ * See {@link WebXRDepthSensing#getDepthTexture}.
540
+ *
528
541
  * @return {?Texture} The depth texture.
529
542
  */
530
543
  this.getDepthTexture = function () {
@@ -695,7 +708,7 @@ class WebXRManager extends EventDispatcher {
695
708
 
696
709
  /**
697
710
  * Updates the state of the XR camera. Use this method on app level if you
698
- * set cameraAutoUpdate` to `false`. The method requires the non-XR
711
+ * set `cameraAutoUpdate` to `false`. The method requires the non-XR
699
712
  * camera of the scene as a parameter. The passed in camera's transformation
700
713
  * is automatically adjusted to the position of the XR camera when calling
701
714
  * this method.
@@ -872,6 +885,8 @@ class WebXRManager extends EventDispatcher {
872
885
  /**
873
886
  * Returns the depth sensing mesh.
874
887
  *
888
+ * See {@link WebXRDepthSensing#getMesh}.
889
+ *
875
890
  * @return {Mesh} The depth sensing mesh.
876
891
  */
877
892
  this.getDepthSensingMesh = function () {
@@ -992,7 +1007,9 @@ class WebXRManager extends EventDispatcher {
992
1007
  enabledFeatures.includes( 'depth-sensing' ) &&
993
1008
  session.depthUsage == 'gpu-optimized';
994
1009
 
995
- if ( gpuDepthSensingEnabled && glBinding ) {
1010
+ if ( gpuDepthSensingEnabled && supportsGlBinding ) {
1011
+
1012
+ glBinding = scope.getBinding();
996
1013
 
997
1014
  const depthData = glBinding.getDepthInformation( views[ 0 ] );
998
1015
 
@@ -1007,32 +1024,30 @@ class WebXRManager extends EventDispatcher {
1007
1024
  const cameraAccessEnabled = enabledFeatures &&
1008
1025
  enabledFeatures.includes( 'camera-access' );
1009
1026
 
1010
- if ( cameraAccessEnabled ) {
1027
+ if ( cameraAccessEnabled && supportsGlBinding ) {
1011
1028
 
1012
1029
  renderer.state.unbindTexture();
1013
1030
 
1014
- if ( glBinding ) {
1015
-
1016
- for ( let i = 0; i < views.length; i ++ ) {
1031
+ glBinding = scope.getBinding();
1017
1032
 
1018
- const camera = views[ i ].camera;
1033
+ for ( let i = 0; i < views.length; i ++ ) {
1019
1034
 
1020
- if ( camera ) {
1035
+ const camera = views[ i ].camera;
1021
1036
 
1022
- let cameraTex = cameraAccessTextures[ camera ];
1037
+ if ( camera ) {
1023
1038
 
1024
- if ( ! cameraTex ) {
1039
+ let cameraTex = cameraAccessTextures[ camera ];
1025
1040
 
1026
- cameraTex = new ExternalTexture();
1027
- cameraAccessTextures[ camera ] = cameraTex;
1041
+ if ( ! cameraTex ) {
1028
1042
 
1029
- }
1030
-
1031
- const glTexture = glBinding.getCameraImage( camera );
1032
- cameraTex.sourceTexture = glTexture;
1043
+ cameraTex = new ExternalTexture();
1044
+ cameraAccessTextures[ camera ] = cameraTex;
1033
1045
 
1034
1046
  }
1035
1047
 
1048
+ const glTexture = glBinding.getCameraImage( camera );
1049
+ cameraTex.sourceTexture = glTexture;
1050
+
1036
1051
  }
1037
1052
 
1038
1053
  }
@@ -1,12 +1,13 @@
1
1
  import { Texture } from './Texture.js';
2
2
 
3
3
  /**
4
- * Represents a texture created externally from the renderer context.
4
+ * Represents a texture created externally with the same renderer context.
5
5
  *
6
6
  * This may be a texture from a protected media stream, device camera feed,
7
7
  * or other data feeds like a depth sensor.
8
8
  *
9
- * Note that this class is only supported in {@link WebGLRenderer} right now.
9
+ * Note that this class is only supported in {@link WebGLRenderer}, and in
10
+ * the {@link WebGPURenderer} WebGPU backend.
10
11
  *
11
12
  * @augments Texture
12
13
  */
@@ -15,7 +16,7 @@ class ExternalTexture extends Texture {
15
16
  /**
16
17
  * Creates a new raw texture.
17
18
  *
18
- * @param {?WebGLTexture} [sourceTexture=null] - The external texture.
19
+ * @param {?(WebGLTexture|GPUTexture)} [sourceTexture=null] - The external texture.
19
20
  */
20
21
  constructor( sourceTexture = null ) {
21
22
 
@@ -24,7 +25,7 @@ class ExternalTexture extends Texture {
24
25
  /**
25
26
  * The external source texture.
26
27
  *
27
- * @type {?WebGLTexture}
28
+ * @type {?(WebGLTexture|GPUTexture)}
28
29
  * @default null
29
30
  */
30
31
  this.sourceTexture = sourceTexture;
@@ -40,6 +41,16 @@ class ExternalTexture extends Texture {
40
41
 
41
42
  }
42
43
 
44
+ copy( source ) {
45
+
46
+ super.copy( source );
47
+
48
+ this.sourceTexture = source.sourceTexture;
49
+
50
+ return this;
51
+
52
+ }
53
+
43
54
  }
44
55
 
45
56
  export { ExternalTexture };
@@ -83,7 +83,7 @@ class Source {
83
83
 
84
84
  const data = this.data;
85
85
 
86
- if ( data instanceof HTMLVideoElement ) {
86
+ if ( ( typeof HTMLVideoElement !== 'undefined' ) && ( data instanceof HTMLVideoElement ) ) {
87
87
 
88
88
  target.set( data.videoWidth, data.videoHeight, 0 );
89
89
 
@@ -108,9 +108,6 @@ class VideoTexture extends Texture {
108
108
 
109
109
  }
110
110
 
111
- /**
112
- * @override
113
- */
114
111
  dispose() {
115
112
 
116
113
  if ( this._requestVideoFrameCallbackId !== 0 ) {