@plastic-software/three 0.178.0 → 0.180.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 (245) hide show
  1. package/README.md +1 -1
  2. package/build/three.cjs +950 -230
  3. package/build/three.core.js +754 -138
  4. package/build/three.core.min.js +1 -1
  5. package/build/three.module.js +197 -96
  6. package/build/three.module.min.js +1 -1
  7. package/build/three.tsl.js +99 -25
  8. package/build/three.tsl.min.js +1 -1
  9. package/build/three.webgpu.js +4586 -1499
  10. package/build/three.webgpu.min.js +1 -1
  11. package/build/three.webgpu.nodes.js +4544 -1499
  12. package/build/three.webgpu.nodes.min.js +1 -1
  13. package/examples/jsm/Addons.js +2 -3
  14. package/examples/jsm/capabilities/WebGPU.js +1 -1
  15. package/examples/jsm/controls/ArcballControls.js +7 -7
  16. package/examples/jsm/controls/DragControls.js +6 -56
  17. package/examples/jsm/controls/FirstPersonControls.js +2 -2
  18. package/examples/jsm/controls/PointerLockControls.js +0 -8
  19. package/examples/jsm/csm/CSMShadowNode.js +4 -4
  20. package/examples/jsm/environments/RoomEnvironment.js +8 -3
  21. package/examples/jsm/exporters/GLTFExporter.js +30 -22
  22. package/examples/jsm/exporters/KTX2Exporter.js +4 -2
  23. package/examples/jsm/exporters/PLYExporter.js +1 -1
  24. package/examples/jsm/exporters/USDZExporter.js +676 -299
  25. package/examples/jsm/geometries/RoundedBoxGeometry.js +47 -8
  26. package/examples/jsm/interactive/HTMLMesh.js +5 -3
  27. package/examples/jsm/libs/ktx-parse.module.js +1 -1
  28. package/examples/jsm/libs/meshopt_decoder.module.js +75 -58
  29. package/examples/jsm/lights/LightProbeGenerator.js +14 -3
  30. package/examples/jsm/lines/Line2.js +3 -3
  31. package/examples/jsm/lines/LineGeometry.js +1 -1
  32. package/examples/jsm/lines/LineSegments2.js +2 -2
  33. package/examples/jsm/lines/Wireframe.js +2 -2
  34. package/examples/jsm/lines/WireframeGeometry2.js +1 -1
  35. package/examples/jsm/lines/webgpu/LineSegments2.js +1 -1
  36. package/examples/jsm/lines/webgpu/Wireframe.js +1 -1
  37. package/examples/jsm/loaders/ColladaLoader.js +1 -1
  38. package/examples/jsm/loaders/EXRLoader.js +210 -22
  39. package/examples/jsm/loaders/FBXLoader.js +1 -1
  40. package/examples/jsm/loaders/GLTFLoader.js +9 -5
  41. package/examples/jsm/loaders/HDRCubeTextureLoader.js +5 -5
  42. package/examples/jsm/loaders/HDRLoader.js +486 -0
  43. package/examples/jsm/loaders/KTX2Loader.js +112 -32
  44. package/examples/jsm/loaders/MaterialXLoader.js +212 -30
  45. package/examples/jsm/loaders/RGBELoader.js +7 -473
  46. package/examples/jsm/loaders/TTFLoader.js +13 -1
  47. package/examples/jsm/loaders/USDLoader.js +219 -0
  48. package/examples/jsm/loaders/USDZLoader.js +4 -892
  49. package/examples/jsm/loaders/UltraHDRLoader.js +1 -1
  50. package/examples/jsm/loaders/lwo/IFFParser.js +1 -1
  51. package/examples/jsm/loaders/usd/USDAParser.js +741 -0
  52. package/examples/jsm/loaders/usd/USDCParser.js +17 -0
  53. package/examples/jsm/materials/WoodNodeMaterial.js +533 -0
  54. package/examples/jsm/math/ColorSpaces.js +19 -1
  55. package/examples/jsm/math/ConvexHull.js +2 -2
  56. package/examples/jsm/math/Lut.js +2 -2
  57. package/examples/jsm/misc/MD2CharacterComplex.js +1 -1
  58. package/examples/jsm/misc/ProgressiveLightMap.js +1 -1
  59. package/examples/jsm/misc/Volume.js +1 -1
  60. package/examples/jsm/objects/LensflareMesh.js +3 -3
  61. package/examples/jsm/objects/SkyMesh.js +2 -2
  62. package/examples/jsm/physics/RapierPhysics.js +14 -5
  63. package/examples/jsm/postprocessing/GTAOPass.js +10 -9
  64. package/examples/jsm/postprocessing/OutlinePass.js +17 -17
  65. package/examples/jsm/postprocessing/SSAOPass.js +10 -9
  66. package/examples/jsm/postprocessing/SSRPass.js +37 -8
  67. package/examples/jsm/shaders/UnpackDepthRGBAShader.js +11 -2
  68. package/examples/jsm/transpiler/GLSLDecoder.js +23 -20
  69. package/examples/jsm/transpiler/TSLEncoder.js +2 -10
  70. package/examples/jsm/transpiler/WGSLEncoder.js +24 -0
  71. package/examples/jsm/tsl/display/AnamorphicNode.js +27 -4
  72. package/examples/jsm/tsl/display/BloomNode.js +7 -6
  73. package/examples/jsm/tsl/display/ChromaticAberrationNode.js +2 -1
  74. package/examples/jsm/tsl/display/DepthOfFieldNode.js +439 -90
  75. package/examples/jsm/tsl/display/GTAONode.js +8 -0
  76. package/examples/jsm/tsl/display/GaussianBlurNode.js +51 -41
  77. package/examples/jsm/tsl/display/OutlineNode.js +2 -2
  78. package/examples/jsm/tsl/display/SSRNode.js +180 -65
  79. package/examples/jsm/tsl/display/{TRAAPassNode.js → TRAANode.js} +181 -172
  80. package/examples/jsm/tsl/display/boxBlur.js +64 -0
  81. package/examples/jsm/tsl/display/hashBlur.js +15 -18
  82. package/examples/jsm/tsl/lighting/TiledLightsNode.js +1 -1
  83. package/examples/jsm/utils/BufferGeometryUtils.js +1 -1
  84. package/examples/jsm/utils/ShadowMapViewerGPU.js +12 -5
  85. package/examples/jsm/webxr/OculusHandModel.js +1 -1
  86. package/package.json +1 -1
  87. package/src/Three.Core.js +2 -0
  88. package/src/Three.TSL.js +98 -24
  89. package/src/animation/AnimationClip.js +17 -2
  90. package/src/animation/KeyframeTrack.js +1 -1
  91. package/src/animation/tracks/BooleanKeyframeTrack.js +1 -1
  92. package/src/animation/tracks/StringKeyframeTrack.js +1 -1
  93. package/src/cameras/Camera.js +14 -0
  94. package/src/cameras/OrthographicCamera.js +1 -1
  95. package/src/cameras/PerspectiveCamera.js +1 -1
  96. package/src/constants.js +11 -3
  97. package/src/core/BufferGeometry.js +2 -2
  98. package/{examples/jsm/misc → src/core}/Timer.js +4 -42
  99. package/src/extras/PMREMGenerator.js +11 -0
  100. package/src/extras/TextureUtils.js +2 -1
  101. package/src/extras/lib/earcut.js +1 -1
  102. package/src/helpers/CameraHelper.js +41 -11
  103. package/src/helpers/SkeletonHelper.js +35 -6
  104. package/src/lights/LightShadow.js +21 -8
  105. package/src/lights/PointLightShadow.js +1 -1
  106. package/src/lights/webgpu/ProjectorLight.js +1 -1
  107. package/src/loaders/FileLoader.js +25 -2
  108. package/src/loaders/ImageBitmapLoader.js +23 -0
  109. package/src/loaders/Loader.js +14 -0
  110. package/src/loaders/LoadingManager.js +23 -0
  111. package/src/materials/Material.js +12 -0
  112. package/src/materials/MeshBasicMaterial.js +1 -1
  113. package/src/materials/MeshDistanceMaterial.js +1 -1
  114. package/src/materials/nodes/Line2NodeMaterial.js +0 -8
  115. package/src/materials/nodes/NodeMaterial.js +1 -1
  116. package/src/materials/nodes/PointsNodeMaterial.js +86 -28
  117. package/src/materials/nodes/SpriteNodeMaterial.js +3 -15
  118. package/src/materials/nodes/manager/NodeMaterialObserver.js +87 -2
  119. package/src/math/ColorManagement.js +7 -1
  120. package/src/math/Frustum.js +19 -8
  121. package/src/math/FrustumArray.js +10 -5
  122. package/src/math/Line3.js +129 -2
  123. package/src/math/Matrix4.js +48 -27
  124. package/src/math/Spherical.js +2 -2
  125. package/src/nodes/Nodes.js +4 -0
  126. package/src/nodes/TSL.js +4 -0
  127. package/src/nodes/accessors/BufferNode.js +1 -1
  128. package/src/nodes/accessors/Camera.js +142 -16
  129. package/src/nodes/accessors/ClippingNode.js +6 -5
  130. package/src/nodes/accessors/CubeTextureNode.js +2 -2
  131. package/src/nodes/accessors/InstanceNode.js +3 -1
  132. package/src/nodes/accessors/Normal.js +11 -11
  133. package/src/nodes/accessors/Object3DNode.js +1 -1
  134. package/src/nodes/accessors/ReferenceBaseNode.js +1 -1
  135. package/src/nodes/accessors/ReferenceNode.js +19 -4
  136. package/src/nodes/accessors/SceneNode.js +1 -1
  137. package/src/nodes/accessors/StorageTextureNode.js +1 -1
  138. package/src/nodes/accessors/Texture3DNode.js +13 -0
  139. package/src/nodes/accessors/TextureNode.js +83 -19
  140. package/src/nodes/code/FunctionCallNode.js +19 -0
  141. package/src/nodes/code/FunctionNode.js +23 -0
  142. package/src/nodes/core/ArrayNode.js +12 -0
  143. package/src/nodes/core/AssignNode.js +6 -2
  144. package/src/nodes/core/ContextNode.js +44 -1
  145. package/src/nodes/core/Node.js +30 -22
  146. package/src/nodes/core/NodeBuilder.js +71 -32
  147. package/src/nodes/core/NodeFrame.js +1 -1
  148. package/src/nodes/core/NodeUniform.js +1 -1
  149. package/src/nodes/core/NodeUtils.js +5 -3
  150. package/src/nodes/core/StackNode.js +71 -4
  151. package/src/nodes/core/StructNode.js +5 -5
  152. package/src/nodes/core/StructTypeNode.js +1 -0
  153. package/src/nodes/core/SubBuildNode.js +2 -2
  154. package/src/nodes/core/UniformNode.js +79 -14
  155. package/src/nodes/core/VarNode.js +83 -15
  156. package/src/nodes/display/FrontFacingNode.js +4 -8
  157. package/src/nodes/display/PassNode.js +148 -2
  158. package/src/nodes/display/ScreenNode.js +42 -13
  159. package/src/nodes/display/ViewportDepthTextureNode.js +16 -4
  160. package/src/nodes/display/ViewportSharedTextureNode.js +12 -0
  161. package/src/nodes/display/ViewportTextureNode.js +94 -4
  162. package/src/nodes/functions/PhysicalLightingModel.js +2 -2
  163. package/src/nodes/gpgpu/AtomicFunctionNode.js +1 -1
  164. package/src/nodes/gpgpu/ComputeNode.js +67 -23
  165. package/src/nodes/gpgpu/SubgroupFunctionNode.js +430 -0
  166. package/src/nodes/gpgpu/WorkgroupInfoNode.js +28 -3
  167. package/src/nodes/lighting/LightsNode.js +1 -1
  168. package/src/nodes/lighting/ProjectorLightNode.js +19 -6
  169. package/src/nodes/lighting/ShadowFilterNode.js +1 -1
  170. package/src/nodes/materialx/MaterialXNodes.js +131 -2
  171. package/src/nodes/materialx/lib/mx_noise.js +165 -1
  172. package/src/nodes/math/BitcastNode.js +156 -0
  173. package/src/nodes/math/ConditionalNode.js +19 -3
  174. package/src/nodes/math/MathNode.js +72 -60
  175. package/src/nodes/math/OperatorNode.js +26 -25
  176. package/src/nodes/tsl/TSLCore.js +477 -142
  177. package/src/nodes/utils/DebugNode.js +1 -1
  178. package/src/nodes/utils/EventNode.js +83 -0
  179. package/src/nodes/utils/JoinNode.js +3 -1
  180. package/src/nodes/utils/MemberNode.js +58 -7
  181. package/src/nodes/utils/RTTNode.js +10 -1
  182. package/src/nodes/utils/ReflectorNode.js +51 -7
  183. package/src/nodes/utils/SampleNode.js +12 -2
  184. package/src/nodes/utils/SplitNode.js +11 -0
  185. package/src/nodes/utils/Timer.js +0 -47
  186. package/src/objects/BatchedMesh.js +6 -4
  187. package/src/objects/LOD.js +1 -1
  188. package/src/objects/Sprite.js +2 -2
  189. package/src/renderers/WebGLRenderer.js +21 -31
  190. package/src/renderers/common/Attributes.js +1 -1
  191. package/src/renderers/common/Backend.js +19 -1
  192. package/src/renderers/common/Bindings.js +21 -18
  193. package/src/renderers/common/ChainMap.js +1 -1
  194. package/src/renderers/common/Color4.js +2 -2
  195. package/src/renderers/common/DataMap.js +1 -1
  196. package/src/renderers/common/Pipelines.js +1 -1
  197. package/src/renderers/common/PostProcessing.js +60 -5
  198. package/src/renderers/common/RenderContext.js +2 -2
  199. package/src/renderers/common/RenderObject.js +14 -2
  200. package/src/renderers/common/Renderer.js +55 -32
  201. package/src/renderers/common/SampledTexture.js +4 -72
  202. package/src/renderers/common/Sampler.js +91 -0
  203. package/src/renderers/common/Storage3DTexture.js +21 -0
  204. package/src/renderers/common/StorageArrayTexture.js +21 -0
  205. package/src/renderers/common/StorageTexture.js +19 -0
  206. package/src/renderers/common/Textures.js +52 -14
  207. package/src/renderers/common/TimestampQueryPool.js +3 -3
  208. package/src/renderers/common/XRManager.js +51 -17
  209. package/src/renderers/common/nodes/NodeBuilderState.js +1 -1
  210. package/src/renderers/common/nodes/NodeLibrary.js +5 -5
  211. package/src/renderers/common/nodes/NodeSampledTexture.js +0 -12
  212. package/src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl.js +1 -1
  213. package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl.js +1 -1
  214. package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_vertex.glsl.js +1 -1
  215. package/src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl.js +1 -1
  216. package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +21 -11
  217. package/src/renderers/shaders/ShaderLib/depth.glsl.js +11 -2
  218. package/src/renderers/webgl/WebGLCapabilities.js +2 -2
  219. package/src/renderers/webgl/WebGLMaterials.js +6 -6
  220. package/src/renderers/webgl/WebGLProgram.js +24 -18
  221. package/src/renderers/webgl/WebGLPrograms.js +4 -4
  222. package/src/renderers/webgl/WebGLShadowMap.js +11 -1
  223. package/src/renderers/webgl/WebGLTextures.js +20 -7
  224. package/src/renderers/webgl/WebGLUtils.js +3 -2
  225. package/src/renderers/webgl-fallback/WebGLBackend.js +207 -146
  226. package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +112 -19
  227. package/src/renderers/webgl-fallback/utils/WebGLState.js +1 -1
  228. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +52 -3
  229. package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +9 -10
  230. package/src/renderers/webgl-fallback/utils/WebGLUtils.js +3 -2
  231. package/src/renderers/webgpu/WebGPUBackend.js +87 -44
  232. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +169 -99
  233. package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +35 -31
  234. package/src/renderers/webgpu/utils/WebGPUConstants.js +2 -2
  235. package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +10 -19
  236. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +120 -84
  237. package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +3 -3
  238. package/src/renderers/webgpu/utils/WebGPUUtils.js +2 -17
  239. package/src/renderers/webxr/WebXRDepthSensing.js +6 -10
  240. package/src/renderers/webxr/WebXRManager.js +86 -11
  241. package/src/textures/ExternalTexture.js +56 -0
  242. package/src/textures/FramebufferTexture.js +2 -2
  243. package/src/textures/Source.js +12 -2
  244. package/src/textures/VideoTexture.js +27 -2
  245. package/examples/jsm/loaders/RGBMLoader.js +0 -1148
@@ -5,7 +5,7 @@ import {
5
5
  } from './WebGPUConstants.js';
6
6
 
7
7
  import {
8
- FrontSide, BackSide, DoubleSide,
8
+ BackSide, DoubleSide,
9
9
  NeverDepth, AlwaysDepth, LessDepth, LessEqualDepth, EqualDepth, GreaterEqualDepth, GreaterDepth, NotEqualDepth,
10
10
  NoBlending, NormalBlending, AdditiveBlending, SubtractiveBlending, MultiplyBlending, CustomBlending,
11
11
  ZeroFactor, OneFactor, SrcColorFactor, OneMinusSrcColorFactor, SrcAlphaFactor, OneMinusSrcAlphaFactor, DstColorFactor,
@@ -672,6 +672,8 @@ class WebGPUPipelineUtils {
672
672
  const descriptor = {};
673
673
  const utils = this.backend.utils;
674
674
 
675
+ //
676
+
675
677
  descriptor.topology = utils.getPrimitiveTopology( object, material );
676
678
 
677
679
  if ( geometry.index !== null && object.isLine === true && object.isLineSegments !== true ) {
@@ -680,28 +682,17 @@ class WebGPUPipelineUtils {
680
682
 
681
683
  }
682
684
 
683
- switch ( material.side ) {
685
+ //
684
686
 
685
- case FrontSide:
686
- descriptor.frontFace = GPUFrontFace.CCW;
687
- descriptor.cullMode = GPUCullMode.Back;
688
- break;
687
+ let flipSided = ( material.side === BackSide );
689
688
 
690
- case BackSide:
691
- descriptor.frontFace = GPUFrontFace.CCW;
692
- descriptor.cullMode = GPUCullMode.Front;
693
- break;
689
+ if ( object.isMesh && object.matrixWorld.determinant() < 0 ) flipSided = ! flipSided;
694
690
 
695
- case DoubleSide:
696
- descriptor.frontFace = GPUFrontFace.CCW;
697
- descriptor.cullMode = GPUCullMode.None;
698
- break;
691
+ descriptor.frontFace = ( flipSided === true ) ? GPUFrontFace.CW : GPUFrontFace.CCW;
699
692
 
700
- default:
701
- console.error( 'THREE.WebGPUPipelineUtils: Unknown material.side value.', material.side );
702
- break;
693
+ //
703
694
 
704
- }
695
+ descriptor.cullMode = ( material.side === DoubleSide ) ? GPUCullMode.None : GPUCullMode.Back;
705
696
 
706
697
  return descriptor;
707
698
 
@@ -712,7 +703,7 @@ class WebGPUPipelineUtils {
712
703
  *
713
704
  * @private
714
705
  * @param {Material} material - The material.
715
- * @return {string} The GPU color write mask.
706
+ * @return {number} The GPU color write mask.
716
707
  */
717
708
  _getColorWriteMask( material ) {
718
709
 
@@ -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';
@@ -159,10 +160,6 @@ class WebGPUTextureUtils {
159
160
 
160
161
  textureGPU = this._getDefaultCubeTextureGPU( format );
161
162
 
162
- } else if ( texture.isVideoTexture ) {
163
-
164
- this.backend.get( texture ).externalTexture = this._getDefaultVideoFrame();
165
-
166
163
  } else {
167
164
 
168
165
  textureGPU = this._getDefaultTextureGPU( format );
@@ -190,6 +187,15 @@ class WebGPUTextureUtils {
190
187
 
191
188
  }
192
189
 
190
+ if ( texture.isExternalTexture ) {
191
+
192
+ textureData.texture = texture.sourceTexture;
193
+ textureData.initialized = true;
194
+
195
+ return;
196
+
197
+ }
198
+
193
199
  if ( options.needsMipmaps === undefined ) options.needsMipmaps = false;
194
200
  if ( options.levels === undefined ) options.levels = 1;
195
201
  if ( options.depth === undefined ) options.depth = 1;
@@ -225,7 +231,7 @@ class WebGPUTextureUtils {
225
231
 
226
232
  }
227
233
 
228
- if ( texture.isCompressedTexture !== true && texture.isCompressedArrayTexture !== true ) {
234
+ if ( texture.isCompressedTexture !== true && texture.isCompressedArrayTexture !== true && format !== GPUTextureFormat.RGB9E5UFloat ) {
229
235
 
230
236
  usage |= GPUTextureUsage.RENDER_ATTACHMENT;
231
237
 
@@ -247,45 +253,30 @@ class WebGPUTextureUtils {
247
253
 
248
254
  // texture creation
249
255
 
250
- if ( texture.isVideoTexture ) {
251
-
252
- const video = texture.source.data;
253
- const videoFrame = new VideoFrame( video );
254
-
255
- textureDescriptorGPU.size.width = videoFrame.displayWidth;
256
- textureDescriptorGPU.size.height = videoFrame.displayHeight;
257
-
258
- videoFrame.close();
256
+ if ( format === undefined ) {
259
257
 
260
- textureData.externalTexture = video;
258
+ console.warn( 'WebGPURenderer: Texture format not supported.' );
261
259
 
262
- } else {
263
-
264
- if ( format === undefined ) {
265
-
266
- console.warn( 'WebGPURenderer: Texture format not supported.' );
267
-
268
- this.createDefaultTexture( texture );
269
- return;
270
-
271
- }
272
-
273
- if ( texture.isCubeTexture ) {
260
+ this.createDefaultTexture( texture );
261
+ return;
274
262
 
275
- textureDescriptorGPU.textureBindingViewDimension = GPUTextureViewDimension.Cube;
263
+ }
276
264
 
277
- }
265
+ if ( texture.isCubeTexture ) {
278
266
 
279
- textureData.texture = backend.device.createTexture( textureDescriptorGPU );
267
+ textureDescriptorGPU.textureBindingViewDimension = GPUTextureViewDimension.Cube;
280
268
 
281
269
  }
282
270
 
271
+ textureData.texture = backend.device.createTexture( textureDescriptorGPU );
272
+
283
273
  if ( isMSAA ) {
284
274
 
285
275
  const msaaTextureDescriptorGPU = Object.assign( {}, textureDescriptorGPU );
286
276
 
287
277
  msaaTextureDescriptorGPU.label = msaaTextureDescriptorGPU.label + '-msaa';
288
278
  msaaTextureDescriptorGPU.sampleCount = samples;
279
+ msaaTextureDescriptorGPU.mipLevelCount = 1; // See https://www.w3.org/TR/webgpu/#texture-creation
289
280
 
290
281
  textureData.msaaTexture = backend.device.createTexture( msaaTextureDescriptorGPU );
291
282
 
@@ -452,6 +443,7 @@ class WebGPUTextureUtils {
452
443
  updateTexture( texture, options ) {
453
444
 
454
445
  const textureData = this.backend.get( texture );
446
+ const mipmaps = texture.mipmaps;
455
447
 
456
448
  const { textureDescriptorGPU } = textureData;
457
449
 
@@ -462,7 +454,22 @@ class WebGPUTextureUtils {
462
454
 
463
455
  if ( texture.isDataTexture ) {
464
456
 
465
- 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
+ }
466
473
 
467
474
  } else if ( texture.isArrayTexture || texture.isDataArrayTexture || texture.isData3DTexture ) {
468
475
 
@@ -478,17 +485,26 @@ class WebGPUTextureUtils {
478
485
 
479
486
  } else if ( texture.isCubeTexture ) {
480
487
 
481
- this._copyCubeMapToTexture( options.images, textureData.texture, textureDescriptorGPU, texture.flipY, texture.premultiplyAlpha );
488
+ this._copyCubeMapToTexture( texture, textureData.texture, textureDescriptorGPU );
482
489
 
483
- } else if ( texture.isVideoTexture ) {
490
+ } else {
484
491
 
485
- const video = texture.source.data;
492
+ if ( mipmaps.length > 0 ) {
486
493
 
487
- textureData.externalTexture = video;
494
+ for ( let i = 0, il = mipmaps.length; i < il; i ++ ) {
488
495
 
489
- } else {
496
+ const mipmap = mipmaps[ i ];
497
+
498
+ this._copyImageToTexture( mipmap, textureData.texture, textureDescriptorGPU, 0, texture.flipY, texture.premultiplyAlpha, i );
499
+
500
+ }
490
501
 
491
- this._copyImageToTexture( options.image, textureData.texture, textureDescriptorGPU, 0, texture.flipY, texture.premultiplyAlpha );
502
+
503
+ } else {
504
+
505
+ this._copyImageToTexture( options.image, textureData.texture, textureDescriptorGPU, 0, texture.flipY, texture.premultiplyAlpha );
506
+
507
+ }
492
508
 
493
509
  }
494
510
 
@@ -496,8 +512,6 @@ class WebGPUTextureUtils {
496
512
 
497
513
  textureData.version = texture.version;
498
514
 
499
- if ( texture.onUpdate ) texture.onUpdate( texture );
500
-
501
515
  }
502
516
 
503
517
  /**
@@ -526,7 +540,7 @@ class WebGPUTextureUtils {
526
540
 
527
541
  const readBuffer = device.createBuffer(
528
542
  {
529
- size: width * height * bytesPerTexel,
543
+ size: ( ( height - 1 ) * bytesPerRow ) + ( width * bytesPerTexel ), // see https://github.com/mrdoob/three.js/issues/31658#issuecomment-3229442010
530
544
  usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ
531
545
  }
532
546
  );
@@ -616,57 +630,49 @@ class WebGPUTextureUtils {
616
630
  }
617
631
 
618
632
  /**
619
- * Returns the default video frame used as default data in context of video textures.
633
+ * Uploads cube texture image data to the GPU memory.
620
634
  *
621
635
  * @private
622
- * @return {VideoFrame} The video frame.
636
+ * @param {CubeTexture} texture - The cube texture.
637
+ * @param {GPUTexture} textureGPU - The GPU texture.
638
+ * @param {Object} textureDescriptorGPU - The GPU texture descriptor.
623
639
  */
624
- _getDefaultVideoFrame() {
640
+ _copyCubeMapToTexture( texture, textureGPU, textureDescriptorGPU ) {
625
641
 
626
- let defaultVideoFrame = this.defaultVideoFrame;
642
+ const images = texture.images;
643
+ const mipmaps = texture.mipmaps;
627
644
 
628
- if ( defaultVideoFrame === null ) {
645
+ for ( let i = 0; i < 6; i ++ ) {
629
646
 
630
- const init = {
631
- timestamp: 0,
632
- codedWidth: 1,
633
- codedHeight: 1,
634
- format: 'RGBA',
635
- };
647
+ const image = images[ i ];
636
648
 
637
- this.defaultVideoFrame = defaultVideoFrame = new VideoFrame( new Uint8Array( [ 0, 0, 0, 0xff ] ), init );
649
+ const flipIndex = texture.flipY === true ? _flipMap[ i ] : i;
638
650
 
639
- }
651
+ if ( image.isDataTexture ) {
640
652
 
641
- return defaultVideoFrame;
653
+ this._copyBufferToTexture( image.image, textureGPU, textureDescriptorGPU, flipIndex, texture.flipY );
642
654
 
643
- }
655
+ } else {
644
656
 
645
- /**
646
- * Uploads cube texture image data to the GPU memory.
647
- *
648
- * @private
649
- * @param {Array} images - The cube image data.
650
- * @param {GPUTexture} textureGPU - The GPU texture.
651
- * @param {Object} textureDescriptorGPU - The GPU texture descriptor.
652
- * @param {boolean} flipY - Whether to flip texture data along their vertical axis or not.
653
- * @param {boolean} premultiplyAlpha - Whether the texture should have its RGB channels premultiplied by the alpha channel or not.
654
- */
655
- _copyCubeMapToTexture( images, textureGPU, textureDescriptorGPU, flipY, premultiplyAlpha ) {
657
+ this._copyImageToTexture( image, textureGPU, textureDescriptorGPU, flipIndex, texture.flipY, texture.premultiplyAlpha );
656
658
 
657
- for ( let i = 0; i < 6; i ++ ) {
659
+ }
658
660
 
659
- const image = images[ i ];
661
+ for ( let j = 0; j < mipmaps.length; j ++ ) {
660
662
 
661
- const flipIndex = flipY === true ? _flipMap[ i ] : i;
663
+ const mipmap = mipmaps[ j ];
664
+ const image = mipmap.images[ i ];
662
665
 
663
- if ( image.isDataTexture ) {
666
+ if ( image.isDataTexture ) {
664
667
 
665
- this._copyBufferToTexture( image.image, textureGPU, textureDescriptorGPU, flipIndex, flipY );
668
+ this._copyBufferToTexture( image.image, textureGPU, textureDescriptorGPU, flipIndex, texture.flipY, 0, j + 1 );
666
669
 
667
- } else {
670
+ } else {
671
+
672
+ this._copyImageToTexture( image, textureGPU, textureDescriptorGPU, flipIndex, texture.flipY, texture.premultiplyAlpha, j + 1 );
673
+
674
+ }
668
675
 
669
- this._copyImageToTexture( image, textureGPU, textureDescriptorGPU, flipIndex, flipY, premultiplyAlpha );
670
676
 
671
677
  }
672
678
 
@@ -684,23 +690,27 @@ class WebGPUTextureUtils {
684
690
  * @param {number} originDepth - The origin depth.
685
691
  * @param {boolean} flipY - Whether to flip texture data along their vertical axis or not.
686
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.
687
694
  */
688
- _copyImageToTexture( image, textureGPU, textureDescriptorGPU, originDepth, flipY, premultiplyAlpha ) {
695
+ _copyImageToTexture( image, textureGPU, textureDescriptorGPU, originDepth, flipY, premultiplyAlpha, mipLevel = 0 ) {
689
696
 
690
697
  const device = this.backend.device;
691
698
 
699
+ const width = ( mipLevel > 0 ) ? image.width : textureDescriptorGPU.size.width;
700
+ const height = ( mipLevel > 0 ) ? image.height : textureDescriptorGPU.size.height;
701
+
692
702
  device.queue.copyExternalImageToTexture(
693
703
  {
694
704
  source: image,
695
705
  flipY: flipY
696
706
  }, {
697
707
  texture: textureGPU,
698
- mipLevel: 0,
708
+ mipLevel: mipLevel,
699
709
  origin: { x: 0, y: 0, z: originDepth },
700
710
  premultipliedAlpha: premultiplyAlpha
701
711
  }, {
702
- width: image.width,
703
- height: image.height,
712
+ width: width,
713
+ height: height,
704
714
  depthOrArrayLayers: 1
705
715
  }
706
716
  );
@@ -764,9 +774,10 @@ class WebGPUTextureUtils {
764
774
  * @param {Object} textureDescriptorGPU - The GPU texture descriptor.
765
775
  * @param {number} originDepth - The origin depth.
766
776
  * @param {boolean} flipY - Whether to flip texture data along their vertical axis or not.
767
- * @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.
768
779
  */
769
- _copyBufferToTexture( image, textureGPU, textureDescriptorGPU, originDepth, flipY, depth = 0 ) {
780
+ _copyBufferToTexture( image, textureGPU, textureDescriptorGPU, originDepth, flipY, depth = 0, mipLevel = 0 ) {
770
781
 
771
782
  // @TODO: Consider to use GPUCommandEncoder.copyBufferToTexture()
772
783
  // @TODO: Consider to support valid buffer layouts with other formats like RGB
@@ -781,7 +792,7 @@ class WebGPUTextureUtils {
781
792
  device.queue.writeTexture(
782
793
  {
783
794
  texture: textureGPU,
784
- mipLevel: 0,
795
+ mipLevel: mipLevel,
785
796
  origin: { x: 0, y: 0, z: originDepth }
786
797
  },
787
798
  data,
@@ -1029,7 +1040,7 @@ class WebGPUTextureUtils {
1029
1040
  if ( format === GPUTextureFormat.RG8Snorm ) return Int8Array;
1030
1041
  if ( format === GPUTextureFormat.RGBA8Uint ) return Uint8Array;
1031
1042
  if ( format === GPUTextureFormat.RGBA8Sint ) return Int8Array;
1032
- if ( format === GPUTextureFormat.RGBA8Unorm ) return Uint8Array;
1043
+ if ( format === GPUTextureFormat.RGBA8Unorm || format === GPUTextureFormat.RGBA8UnormSRGB ) return Uint8Array;
1033
1044
  if ( format === GPUTextureFormat.RGBA8Snorm ) return Int8Array;
1034
1045
 
1035
1046
 
@@ -1054,8 +1065,7 @@ class WebGPUTextureUtils {
1054
1065
  if ( format === GPUTextureFormat.RGBA32Sint ) return Int32Array;
1055
1066
  if ( format === GPUTextureFormat.RGBA32Float ) return Float32Array;
1056
1067
 
1057
- if ( format === GPUTextureFormat.BGRA8Unorm ) return Uint8Array;
1058
- if ( format === GPUTextureFormat.BGRA8UnormSRGB ) return Uint8Array;
1068
+ if ( format === GPUTextureFormat.BGRA8Unorm || format === GPUTextureFormat.BGRA8UnormSRGB ) return Uint8Array;
1059
1069
  if ( format === GPUTextureFormat.RGB10A2Unorm ) return Uint32Array;
1060
1070
  if ( format === GPUTextureFormat.RGB9E5UFloat ) return Uint32Array;
1061
1071
  if ( format === GPUTextureFormat.RG11B10UFloat ) return Uint32Array;
@@ -1115,6 +1125,7 @@ export function getFormat( texture, device = null ) {
1115
1125
 
1116
1126
  switch ( format ) {
1117
1127
 
1128
+ case RGB_S3TC_DXT1_Format:
1118
1129
  case RGBA_S3TC_DXT1_Format:
1119
1130
  formatGPU = ( transfer === SRGBTransfer ) ? GPUTextureFormat.BC1RGBAUnormSRGB : GPUTextureFormat.BC1RGBAUnorm;
1120
1131
  break;
@@ -1127,7 +1138,28 @@ export function getFormat( texture, device = null ) {
1127
1138
  formatGPU = ( transfer === SRGBTransfer ) ? GPUTextureFormat.BC3RGBAUnormSRGB : GPUTextureFormat.BC3RGBAUnorm;
1128
1139
  break;
1129
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
+
1130
1161
  case RGB_ETC2_Format:
1162
+ case RGB_ETC1_Format:
1131
1163
  formatGPU = ( transfer === SRGBTransfer ) ? GPUTextureFormat.ETC2RGB8UnormSRGB : GPUTextureFormat.ETC2RGB8Unorm;
1132
1164
  break;
1133
1165
 
@@ -1254,6 +1286,10 @@ export function getFormat( texture, device = null ) {
1254
1286
  formatGPU = GPUTextureFormat.RGB9E5UFloat;
1255
1287
  break;
1256
1288
 
1289
+ case UnsignedInt101111Type:
1290
+ formatGPU = GPUTextureFormat.RG11B10UFloat;
1291
+ break;
1292
+
1257
1293
  default:
1258
1294
  console.error( 'WebGPURenderer: Unsupported texture type with RGBFormat.', type );
1259
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
  }
@@ -161,29 +161,14 @@ class WebGPUUtils {
161
161
  /**
162
162
  * Returns a modified sample count from the given sample count value.
163
163
  *
164
- * That is required since WebGPU does not support arbitrary sample counts.
164
+ * That is required since WebGPU only supports either 1 or 4.
165
165
  *
166
166
  * @param {number} sampleCount - The input sample count.
167
167
  * @return {number} The (potentially updated) output sample count.
168
168
  */
169
169
  getSampleCount( sampleCount ) {
170
170
 
171
- let count = 1;
172
-
173
- if ( sampleCount > 1 ) {
174
-
175
- // WebGPU only supports power-of-two sample counts and 2 is not a valid value
176
- count = Math.pow( 2, Math.floor( Math.log2( sampleCount ) ) );
177
-
178
- if ( count === 2 ) {
179
-
180
- count = 4;
181
-
182
- }
183
-
184
- }
185
-
186
- return count;
171
+ return sampleCount >= 4 ? 4 : 1;
187
172
 
188
173
  }
189
174
 
@@ -1,7 +1,7 @@
1
1
  import { PlaneGeometry } from '../../geometries/PlaneGeometry.js';
2
2
  import { ShaderMaterial } from '../../materials/ShaderMaterial.js';
3
3
  import { Mesh } from '../../objects/Mesh.js';
4
- import { Texture } from '../../textures/Texture.js';
4
+ import { ExternalTexture } from '../../textures/ExternalTexture.js';
5
5
 
6
6
  const _occlusion_vertex = `
7
7
  void main() {
@@ -42,9 +42,9 @@ class WebXRDepthSensing {
42
42
  constructor() {
43
43
 
44
44
  /**
45
- * A texture representing the depth of the user's environment.
45
+ * An opaque texture representing the depth of the user's environment.
46
46
  *
47
- * @type {?Texture}
47
+ * @type {?ExternalTexture}
48
48
  */
49
49
  this.texture = null;
50
50
 
@@ -74,18 +74,14 @@ class WebXRDepthSensing {
74
74
  /**
75
75
  * Inits the depth sensing module
76
76
  *
77
- * @param {WebGLRenderer} renderer - The renderer.
78
77
  * @param {XRWebGLDepthInformation} depthData - The XR depth data.
79
78
  * @param {XRRenderState} renderState - The XR render state.
80
79
  */
81
- init( renderer, depthData, renderState ) {
80
+ init( depthData, renderState ) {
82
81
 
83
82
  if ( this.texture === null ) {
84
83
 
85
- const texture = new Texture();
86
-
87
- const texProps = renderer.properties.get( texture );
88
- texProps.__webglTexture = depthData.texture;
84
+ const texture = new ExternalTexture( depthData.texture );
89
85
 
90
86
  if ( ( depthData.depthNear !== renderState.depthNear ) || ( depthData.depthFar !== renderState.depthFar ) ) {
91
87
 
@@ -146,7 +142,7 @@ class WebXRDepthSensing {
146
142
  /**
147
143
  * Returns a texture representing the depth of the user's environment.
148
144
  *
149
- * @return {?Texture} The depth texture.
145
+ * @return {?ExternalTexture} The depth texture.
150
146
  */
151
147
  getDepthTexture() {
152
148