super-three 0.162.0 → 0.164.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 (187) hide show
  1. package/build/three.cjs +847 -1226
  2. package/build/three.module.js +846 -1225
  3. package/build/three.module.min.js +2 -2
  4. package/examples/jsm/animation/CCDIKSolver.js +4 -2
  5. package/examples/jsm/controls/TransformControls.js +3 -3
  6. package/examples/jsm/exporters/GLTFExporter.js +66 -5
  7. package/examples/jsm/exporters/USDZExporter.js +22 -1
  8. package/examples/jsm/geometries/TextGeometry.js +10 -2
  9. package/examples/jsm/interactive/HTMLMesh.js +7 -9
  10. package/examples/jsm/libs/draco/README.md +2 -2
  11. package/examples/jsm/libs/fflate.module.js +694 -496
  12. package/examples/jsm/lines/LineMaterial.js +0 -2
  13. package/examples/jsm/loaders/3MFLoader.js +2 -0
  14. package/examples/jsm/loaders/EXRLoader.js +351 -97
  15. package/examples/jsm/loaders/FBXLoader.js +1 -1
  16. package/examples/jsm/loaders/GLTFLoader.js +59 -0
  17. package/examples/jsm/loaders/KTX2Loader.js +3 -10
  18. package/examples/jsm/loaders/LUT3dlLoader.js +0 -15
  19. package/examples/jsm/loaders/LUTCubeLoader.js +0 -14
  20. package/examples/jsm/loaders/LUTImageLoader.js +0 -14
  21. package/examples/jsm/loaders/RGBMLoader.js +16 -0
  22. package/examples/jsm/loaders/VRMLLoader.js +1 -1
  23. package/examples/jsm/loaders/lwo/IFFParser.js +8 -5
  24. package/examples/jsm/materials/MeshGouraudMaterial.js +7 -1
  25. package/examples/jsm/math/Octree.js +26 -20
  26. package/examples/jsm/misc/GPUComputationRenderer.js +0 -6
  27. package/examples/jsm/nodes/Nodes.js +10 -4
  28. package/examples/jsm/nodes/accessors/AccessorsUtils.js +16 -1
  29. package/examples/jsm/nodes/accessors/BatchNode.js +78 -0
  30. package/examples/jsm/nodes/accessors/ClippingNode.js +3 -2
  31. package/examples/jsm/nodes/accessors/InstanceNode.js +25 -2
  32. package/examples/jsm/nodes/accessors/MaterialNode.js +107 -3
  33. package/examples/jsm/nodes/accessors/MaterialReferenceNode.js +1 -1
  34. package/examples/jsm/nodes/accessors/MorphNode.js +13 -3
  35. package/examples/jsm/nodes/accessors/NormalNode.js +12 -2
  36. package/examples/jsm/nodes/accessors/ReferenceNode.js +1 -1
  37. package/examples/jsm/nodes/accessors/RendererReferenceNode.js +29 -0
  38. package/examples/jsm/nodes/accessors/StorageBufferNode.js +9 -0
  39. package/examples/jsm/nodes/accessors/TextureNode.js +51 -10
  40. package/examples/jsm/nodes/accessors/TextureSizeNode.js +1 -1
  41. package/examples/jsm/nodes/code/FunctionNode.js +0 -8
  42. package/examples/jsm/nodes/core/Node.js +63 -4
  43. package/examples/jsm/nodes/core/NodeBuilder.js +26 -25
  44. package/examples/jsm/nodes/core/NodeFrame.js +10 -10
  45. package/examples/jsm/nodes/core/NodeUtils.js +2 -2
  46. package/examples/jsm/nodes/core/OutputStructNode.js +2 -1
  47. package/examples/jsm/nodes/core/PropertyNode.js +10 -0
  48. package/examples/jsm/nodes/core/UniformNode.js +20 -0
  49. package/examples/jsm/nodes/display/BumpMapNode.js +7 -26
  50. package/examples/jsm/nodes/display/FrontFacingNode.js +13 -0
  51. package/examples/jsm/nodes/display/PassNode.js +17 -1
  52. package/examples/jsm/nodes/display/ToneMappingNode.js +8 -4
  53. package/examples/jsm/nodes/display/ViewportDepthNode.js +1 -1
  54. package/examples/jsm/nodes/display/ViewportNode.js +4 -2
  55. package/examples/jsm/nodes/display/ViewportSharedTextureNode.js +6 -0
  56. package/examples/jsm/nodes/display/ViewportTextureNode.js +4 -1
  57. package/examples/jsm/nodes/fog/FogExp2Node.js +4 -5
  58. package/examples/jsm/nodes/fog/FogNode.js +13 -3
  59. package/examples/jsm/nodes/fog/FogRangeNode.js +4 -3
  60. package/examples/jsm/nodes/functions/BSDF/BRDF_GGX.js +26 -7
  61. package/examples/jsm/nodes/functions/BSDF/D_GGX_Anisotropic.js +28 -0
  62. package/examples/jsm/nodes/functions/BSDF/V_GGX_SmithCorrelated.js +1 -3
  63. package/examples/jsm/nodes/functions/BSDF/V_GGX_SmithCorrelated_Anisotropic.js +29 -0
  64. package/examples/jsm/nodes/functions/PhongLightingModel.js +1 -1
  65. package/examples/jsm/nodes/functions/PhysicalLightingModel.js +164 -10
  66. package/examples/jsm/nodes/functions/ShadowMaskModel.js +31 -0
  67. package/examples/jsm/nodes/lighting/AnalyticLightNode.js +19 -5
  68. package/examples/jsm/nodes/lighting/DirectionalLightNode.js +2 -1
  69. package/examples/jsm/nodes/lighting/EnvironmentNode.js +22 -70
  70. package/examples/jsm/nodes/lighting/IrradianceNode.js +24 -0
  71. package/examples/jsm/nodes/lighting/LightsNode.js +11 -1
  72. package/examples/jsm/nodes/lighting/PointLightNode.js +2 -1
  73. package/examples/jsm/nodes/lighting/SpotLightNode.js +2 -1
  74. package/examples/jsm/nodes/materials/Line2NodeMaterial.js +10 -6
  75. package/examples/jsm/nodes/materials/Materials.js +1 -0
  76. package/examples/jsm/nodes/materials/MeshNormalNodeMaterial.js +0 -2
  77. package/examples/jsm/nodes/materials/MeshPhongNodeMaterial.js +2 -2
  78. package/examples/jsm/nodes/materials/MeshPhysicalNodeMaterial.js +76 -5
  79. package/examples/jsm/nodes/materials/MeshStandardNodeMaterial.js +11 -4
  80. package/examples/jsm/nodes/materials/NodeMaterial.js +55 -43
  81. package/examples/jsm/nodes/materials/ShadowNodeMaterial.js +34 -0
  82. package/examples/jsm/nodes/pmrem/PMREMNode.js +193 -0
  83. package/examples/jsm/nodes/pmrem/PMREMUtils.js +288 -0
  84. package/examples/jsm/nodes/shadernode/ShaderNode.js +3 -9
  85. package/examples/jsm/nodes/utils/EquirectUVNode.js +1 -1
  86. package/examples/jsm/objects/QuadMesh.js +7 -23
  87. package/examples/jsm/physics/JoltPhysics.js +281 -0
  88. package/examples/jsm/physics/RapierPhysics.js +4 -4
  89. package/examples/jsm/postprocessing/GlitchPass.js +0 -3
  90. package/examples/jsm/postprocessing/LUTPass.js +5 -71
  91. package/examples/jsm/postprocessing/RenderTransitionPass.js +193 -0
  92. package/examples/jsm/postprocessing/SAOPass.js +0 -1
  93. package/examples/jsm/postprocessing/SSAOPass.js +0 -3
  94. package/examples/jsm/renderers/common/Animation.js +3 -0
  95. package/examples/jsm/renderers/common/Background.js +8 -8
  96. package/examples/jsm/renderers/common/ClippingContext.js +1 -1
  97. package/examples/jsm/renderers/common/Info.js +11 -19
  98. package/examples/jsm/renderers/common/PostProcessing.js +12 -4
  99. package/examples/jsm/renderers/common/RenderContext.js +1 -1
  100. package/examples/jsm/renderers/common/RenderList.js +1 -1
  101. package/examples/jsm/renderers/common/RenderObject.js +47 -5
  102. package/examples/jsm/renderers/common/RenderObjects.js +1 -1
  103. package/examples/jsm/renderers/common/Renderer.js +153 -21
  104. package/examples/jsm/renderers/common/Textures.js +1 -1
  105. package/examples/jsm/renderers/common/extras/PMREMGenerator.js +773 -0
  106. package/examples/jsm/renderers/common/nodes/Nodes.js +34 -63
  107. package/examples/jsm/renderers/webgl/WebGLBackend.js +146 -36
  108. package/examples/jsm/renderers/webgl/WebGLBufferRenderer.js +145 -0
  109. package/examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js +9 -3
  110. package/examples/jsm/renderers/webgl/utils/WebGLAttributeUtils.js +1 -1
  111. package/examples/jsm/renderers/webgl/utils/WebGLConstants.js +1 -0
  112. package/examples/jsm/renderers/webgl/utils/WebGLTextureUtils.js +64 -7
  113. package/examples/jsm/renderers/webgl/utils/WebGLUtils.js +6 -23
  114. package/examples/jsm/renderers/webgpu/WebGPUBackend.js +77 -60
  115. package/examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js +21 -4
  116. package/examples/jsm/renderers/webgpu/utils/WebGPUAttributeUtils.js +29 -1
  117. package/examples/jsm/renderers/webgpu/utils/WebGPUBindingUtils.js +18 -4
  118. package/examples/jsm/renderers/webgpu/utils/WebGPUTextureUtils.js +92 -18
  119. package/examples/jsm/transpiler/GLSLDecoder.js +1 -1
  120. package/examples/jsm/transpiler/ShaderToyDecoder.js +1 -1
  121. package/examples/jsm/utils/GPUStatsPanel.js +10 -45
  122. package/examples/jsm/utils/SceneUtils.js +60 -1
  123. package/examples/jsm/utils/TextureUtils.js +1 -1
  124. package/examples/jsm/webxr/OculusHandModel.js +3 -2
  125. package/examples/jsm/webxr/XRHandModelFactory.js +4 -2
  126. package/package.json +1 -1
  127. package/src/Three.js +0 -1
  128. package/src/animation/AnimationClip.js +1 -1
  129. package/src/constants.js +3 -3
  130. package/src/core/Object3D.js +10 -7
  131. package/src/core/RenderTarget.js +8 -0
  132. package/src/extras/PMREMGenerator.js +21 -11
  133. package/src/loaders/FileLoader.js +1 -1
  134. package/src/loaders/MaterialLoader.js +1 -0
  135. package/src/loaders/ObjectLoader.js +2 -0
  136. package/src/materials/Material.js +2 -0
  137. package/src/materials/MeshPhysicalMaterial.js +20 -0
  138. package/src/materials/ShaderMaterial.js +0 -4
  139. package/src/math/Spherical.js +4 -5
  140. package/src/objects/BatchedMesh.js +27 -3
  141. package/src/objects/InstancedMesh.js +10 -0
  142. package/src/objects/Line.js +66 -43
  143. package/src/renderers/WebGLRenderer.js +130 -158
  144. package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +6 -0
  145. package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +1 -0
  146. package/src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl.js +2 -2
  147. package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl.js +1 -1
  148. package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_vertex.glsl.js +2 -10
  149. package/src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl.js +2 -16
  150. package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +32 -22
  151. package/src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl.js +17 -9
  152. package/src/renderers/shaders/ShaderChunk/transmission_fragment.glsl.js +1 -1
  153. package/src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js +47 -13
  154. package/src/renderers/shaders/ShaderChunk.js +0 -2
  155. package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +4 -0
  156. package/src/renderers/shaders/ShaderLib.js +2 -1
  157. package/src/renderers/shaders/UniformsUtils.js +10 -1
  158. package/src/renderers/webgl/WebGLAttributes.js +6 -33
  159. package/src/renderers/webgl/WebGLBackground.js +18 -3
  160. package/src/renderers/webgl/WebGLBindingStates.js +14 -51
  161. package/src/renderers/webgl/WebGLBufferRenderer.js +35 -21
  162. package/src/renderers/webgl/WebGLCapabilities.js +35 -13
  163. package/src/renderers/webgl/WebGLCubeUVMaps.js +10 -6
  164. package/src/renderers/webgl/WebGLExtensions.js +4 -19
  165. package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +35 -21
  166. package/src/renderers/webgl/WebGLLights.js +6 -32
  167. package/src/renderers/webgl/WebGLMaterials.js +8 -3
  168. package/src/renderers/webgl/WebGLMorphtargets.js +79 -217
  169. package/src/renderers/webgl/WebGLProgram.js +21 -52
  170. package/src/renderers/webgl/WebGLPrograms.js +24 -31
  171. package/src/renderers/webgl/WebGLRenderStates.js +13 -7
  172. package/src/renderers/webgl/WebGLShadowMap.js +25 -25
  173. package/src/renderers/webgl/WebGLState.js +15 -59
  174. package/src/renderers/webgl/WebGLTextures.js +138 -292
  175. package/src/renderers/webgl/WebGLUniformsGroups.js +1 -1
  176. package/src/renderers/webgl/WebGLUtils.js +9 -78
  177. package/src/renderers/webxr/WebXRDepthSensing.js +2 -3
  178. package/src/renderers/webxr/WebXRManager.js +4 -6
  179. package/src/scenes/Scene.js +7 -1
  180. package/src/textures/Texture.js +11 -1
  181. package/examples/jsm/nodes/utils/SpecularMIPLevelNode.js +0 -37
  182. package/examples/jsm/renderers/webgl-legacy/nodes/GLSL1NodeBuilder.js +0 -320
  183. package/examples/jsm/renderers/webgl-legacy/nodes/SlotNode.js +0 -26
  184. package/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodeBuilder.js +0 -794
  185. package/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodes.js +0 -51
  186. package/src/renderers/WebGL1Renderer.js +0 -7
  187. package/src/renderers/shaders/ShaderChunk/lightmap_fragment.glsl.js +0 -10
@@ -143,6 +143,7 @@ class WebGLTextureUtils {
143
143
  if ( glType === gl.UNSIGNED_SHORT_5_6_5 ) internalFormat = gl.RGB565;
144
144
  if ( glType === gl.UNSIGNED_SHORT_5_5_5_1 ) internalFormat = gl.RGB5_A1;
145
145
  if ( glType === gl.UNSIGNED_SHORT_4_4_4_4 ) internalFormat = gl.RGB4;
146
+ if ( glType === gl.UNSIGNED_INT_5_9_9_9_REV ) internalFormat = gl.RGB9_E5;
146
147
 
147
148
  }
148
149
 
@@ -523,6 +524,48 @@ class WebGLTextureUtils {
523
524
 
524
525
  }
525
526
 
527
+ copyTextureToTexture( position, srcTexture, dstTexture, level = 0 ) {
528
+
529
+ const { gl, backend } = this;
530
+ const { state } = this.backend;
531
+
532
+ const width = srcTexture.image.width;
533
+ const height = srcTexture.image.height;
534
+ const { textureGPU: dstTextureGPU, glTextureType, glType, glFormat } = backend.get( dstTexture );
535
+
536
+ state.bindTexture( glTextureType, dstTextureGPU );
537
+
538
+ // As another texture upload may have changed pixelStorei
539
+ // parameters, make sure they are correct for the dstTexture
540
+ gl.pixelStorei( gl.UNPACK_FLIP_Y_WEBGL, dstTexture.flipY );
541
+ gl.pixelStorei( gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, dstTexture.premultiplyAlpha );
542
+ gl.pixelStorei( gl.UNPACK_ALIGNMENT, dstTexture.unpackAlignment );
543
+
544
+ if ( srcTexture.isDataTexture ) {
545
+
546
+ gl.texSubImage2D( gl.TEXTURE_2D, level, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data );
547
+
548
+ } else {
549
+
550
+ if ( srcTexture.isCompressedTexture ) {
551
+
552
+ gl.compressedTexSubImage2D( gl.TEXTURE_2D, level, position.x, position.y, srcTexture.mipmaps[ 0 ].width, srcTexture.mipmaps[ 0 ].height, glFormat, srcTexture.mipmaps[ 0 ].data );
553
+
554
+ } else {
555
+
556
+ gl.texSubImage2D( gl.TEXTURE_2D, level, position.x, position.y, glFormat, glType, srcTexture.image );
557
+
558
+ }
559
+
560
+ }
561
+
562
+ // Generate mipmaps only when copying level 0
563
+ if ( level === 0 && dstTexture.generateMipmaps ) gl.generateMipmap( gl.TEXTURE_2D );
564
+
565
+ state.unbindTexture();
566
+
567
+ }
568
+
526
569
  copyFramebufferToTexture( texture, renderContext ) {
527
570
 
528
571
  const { gl } = this;
@@ -533,20 +576,35 @@ class WebGLTextureUtils {
533
576
  const width = texture.image.width;
534
577
  const height = texture.image.height;
535
578
 
536
- if ( texture.isDepthTexture ) {
579
+ const requireDrawFrameBuffer = texture.isDepthTexture === true || ( renderContext.renderTarget && renderContext.renderTarget.samples > 0 );
580
+
581
+ if ( requireDrawFrameBuffer ) {
537
582
 
538
- let mask = gl.DEPTH_BUFFER_BIT;
583
+ let mask;
584
+ let attachment;
539
585
 
540
- if ( renderContext.stencil ) {
586
+ if ( texture.isDepthTexture === true ) {
541
587
 
542
- mask |= gl.STENCIL_BUFFER_BIT;
588
+ mask = gl.DEPTH_BUFFER_BIT;
589
+ attachment = gl.DEPTH_ATTACHMENT;
590
+
591
+ if ( renderContext.stencil ) {
592
+
593
+ mask |= gl.STENCIL_BUFFER_BIT;
594
+
595
+ }
596
+
597
+ } else {
598
+
599
+ mask = gl.COLOR_BUFFER_BIT;
600
+ attachment = gl.COLOR_ATTACHMENT0;
543
601
 
544
602
  }
545
603
 
546
604
  const fb = gl.createFramebuffer();
547
605
  state.bindFramebuffer( gl.DRAW_FRAMEBUFFER, fb );
548
606
 
549
- gl.framebufferTexture2D( gl.DRAW_FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.TEXTURE_2D, textureGPU, 0 );
607
+ gl.framebufferTexture2D( gl.DRAW_FRAMEBUFFER, attachment, gl.TEXTURE_2D, textureGPU, 0 );
550
608
 
551
609
  gl.blitFramebuffer( 0, 0, width, height, 0, 0, width, height, mask, gl.NEAREST );
552
610
 
@@ -583,7 +641,6 @@ class WebGLTextureUtils {
583
641
 
584
642
  if ( samples > 0 ) {
585
643
 
586
-
587
644
  if ( depthTexture && depthTexture.isDepthTexture ) {
588
645
 
589
646
  if ( depthTexture.type === gl.FLOAT ) {
@@ -649,7 +706,7 @@ class WebGLTextureUtils {
649
706
 
650
707
  await backend.utils._clientWaitAsync();
651
708
 
652
- const dstBuffer = new typedArrayType( elementCount );
709
+ const dstBuffer = new typedArrayType( byteLength / typedArrayType.BYTES_PER_ELEMENT );
653
710
 
654
711
  gl.bindBuffer( gl.PIXEL_PACK_BUFFER, buffer );
655
712
  gl.getBufferSubData( gl.PIXEL_PACK_BUFFER, 0, dstBuffer );
@@ -1,4 +1,4 @@
1
- import { 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, RGBA_ASTC_10x6_Format, RGBA_ASTC_10x8_Format, RGBA_ASTC_10x10_Format, RGBA_ASTC_12x10_Format, RGBA_ASTC_12x12_Format, RGB_ETC1_Format, RGB_ETC2_Format, RGBA_ETC2_EAC_Format, RGBA_PVRTC_2BPPV1_Format, RGBA_PVRTC_4BPPV1_Format, RGB_PVRTC_2BPPV1_Format, RGB_PVRTC_4BPPV1_Format, RGBA_S3TC_DXT5_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT1_Format, RGB_S3TC_DXT1_Format, DepthFormat, DepthStencilFormat, LuminanceAlphaFormat, LuminanceFormat, RedFormat, RGBAFormat, AlphaFormat, RedIntegerFormat, RGFormat, RGIntegerFormat, RGBAIntegerFormat, HalfFloatType, FloatType, UnsignedIntType, IntType, UnsignedShortType, ShortType, ByteType, UnsignedInt248Type, UnsignedShort5551Type, UnsignedShort4444Type, UnsignedByteType, RGBA_BPTC_Format, _SRGBAFormat, RED_RGTC1_Format, SIGNED_RED_RGTC1_Format, RED_GREEN_RGTC2_Format, SIGNED_RED_GREEN_RGTC2_Format, SRGBColorSpace, NoColorSpace } from 'three';
1
+ import { 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, RGBA_ASTC_10x6_Format, RGBA_ASTC_10x8_Format, RGBA_ASTC_10x10_Format, RGBA_ASTC_12x10_Format, RGBA_ASTC_12x12_Format, RGB_ETC1_Format, RGB_ETC2_Format, RGBA_ETC2_EAC_Format, RGBA_PVRTC_2BPPV1_Format, RGBA_PVRTC_4BPPV1_Format, RGB_PVRTC_2BPPV1_Format, RGB_PVRTC_4BPPV1_Format, RGBA_S3TC_DXT5_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT1_Format, RGB_S3TC_DXT1_Format, DepthFormat, DepthStencilFormat, LuminanceAlphaFormat, LuminanceFormat, RedFormat, RGBFormat, RGBAFormat, AlphaFormat, RedIntegerFormat, RGFormat, RGIntegerFormat, RGBAIntegerFormat, HalfFloatType, FloatType, UnsignedIntType, IntType, UnsignedShortType, ShortType, ByteType, UnsignedInt248Type, UnsignedInt5999Type, UnsignedShort5551Type, UnsignedShort4444Type, UnsignedByteType, RGBA_BPTC_Format, RED_RGTC1_Format, SIGNED_RED_RGTC1_Format, RED_GREEN_RGTC2_Format, SIGNED_RED_GREEN_RGTC2_Format, SRGBColorSpace, NoColorSpace } from 'three';
2
2
 
3
3
  class WebGLUtils {
4
4
 
@@ -20,6 +20,7 @@ class WebGLUtils {
20
20
  if ( p === UnsignedByteType ) return gl.UNSIGNED_BYTE;
21
21
  if ( p === UnsignedShort4444Type ) return gl.UNSIGNED_SHORT_4_4_4_4;
22
22
  if ( p === UnsignedShort5551Type ) return gl.UNSIGNED_SHORT_5_5_5_1;
23
+ if ( p === UnsignedInt5999Type ) return gl.UNSIGNED_INT_5_9_9_9_REV;
23
24
 
24
25
  if ( p === ByteType ) return gl.BYTE;
25
26
  if ( p === ShortType ) return gl.SHORT;
@@ -35,7 +36,7 @@ class WebGLUtils {
35
36
  }
36
37
 
37
38
  if ( p === AlphaFormat ) return gl.ALPHA;
38
- if ( p === gl.RGB ) return gl.RGB; // patch since legacy doesn't use RGBFormat for rendering but here it's needed for packing optimization
39
+ if ( p === RGBFormat ) return gl.RGB;
39
40
  if ( p === RGBAFormat ) return gl.RGBA;
40
41
  if ( p === LuminanceFormat ) return gl.LUMINANCE;
41
42
  if ( p === LuminanceAlphaFormat ) return gl.LUMINANCE_ALPHA;
@@ -113,33 +114,15 @@ class WebGLUtils {
113
114
 
114
115
  }
115
116
 
116
- // ETC1
117
+ // ETC
117
118
 
118
- if ( p === RGB_ETC1_Format ) {
119
-
120
- extension = extensions.get( 'WEBGL_compressed_texture_etc1' );
121
-
122
- if ( extension !== null ) {
123
-
124
- return extension.COMPRESSED_RGB_ETC1_WEBGL;
125
-
126
- } else {
127
-
128
- return null;
129
-
130
- }
131
-
132
- }
133
-
134
- // ETC2
135
-
136
- if ( p === RGB_ETC2_Format || p === RGBA_ETC2_EAC_Format ) {
119
+ if ( p === RGB_ETC1_Format || p === RGB_ETC2_Format || p === RGBA_ETC2_EAC_Format ) {
137
120
 
138
121
  extension = extensions.get( 'WEBGL_compressed_texture_etc' );
139
122
 
140
123
  if ( extension !== null ) {
141
124
 
142
- if ( p === RGB_ETC2_Format ) return ( colorSpace === SRGBColorSpace ) ? extension.COMPRESSED_SRGB8_ETC2 : extension.COMPRESSED_RGB8_ETC2;
125
+ if ( p === RGB_ETC1_Format || p === RGB_ETC2_Format ) return ( colorSpace === SRGBColorSpace ) ? extension.COMPRESSED_SRGB8_ETC2 : extension.COMPRESSED_RGB8_ETC2;
143
126
  if ( p === RGBA_ETC2_EAC_Format ) return ( colorSpace === SRGBColorSpace ) ? extension.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC : extension.COMPRESSED_RGBA8_ETC2_EAC;
144
127
 
145
128
  } else {
@@ -14,7 +14,6 @@ import WebGPUAttributeUtils from './utils/WebGPUAttributeUtils.js';
14
14
  import WebGPUBindingUtils from './utils/WebGPUBindingUtils.js';
15
15
  import WebGPUPipelineUtils from './utils/WebGPUPipelineUtils.js';
16
16
  import WebGPUTextureUtils from './utils/WebGPUTextureUtils.js';
17
- import WebGPU from '../../capabilities/WebGPU.js';
18
17
 
19
18
  //
20
19
 
@@ -45,7 +44,6 @@ class WebGPUBackend extends Backend {
45
44
 
46
45
  this.trackTimestamp = ( parameters.trackTimestamp === true );
47
46
 
48
- this.adapter = null;
49
47
  this.device = null;
50
48
  this.context = null;
51
49
  this.colorBuffer = null;
@@ -68,44 +66,55 @@ class WebGPUBackend extends Backend {
68
66
 
69
67
  const parameters = this.parameters;
70
68
 
71
- const adapterOptions = {
72
- powerPreference: parameters.powerPreference
73
- };
69
+ // create the device if it is not passed with parameters
70
+
71
+ let device;
74
72
 
75
- const adapter = await navigator.gpu.requestAdapter( adapterOptions );
73
+ if ( parameters.device === undefined ) {
76
74
 
77
- if ( adapter === null ) {
75
+ const adapterOptions = {
76
+ powerPreference: parameters.powerPreference
77
+ };
78
78
 
79
- throw new Error( 'WebGPUBackend: Unable to create WebGPU adapter.' );
79
+ const adapter = await navigator.gpu.requestAdapter( adapterOptions );
80
80
 
81
- }
81
+ if ( adapter === null ) {
82
+
83
+ throw new Error( 'WebGPUBackend: Unable to create WebGPU adapter.' );
84
+
85
+ }
82
86
 
83
- // feature support
87
+ // feature support
84
88
 
85
- const features = Object.values( GPUFeatureName );
89
+ const features = Object.values( GPUFeatureName );
86
90
 
87
- const supportedFeatures = [];
91
+ const supportedFeatures = [];
88
92
 
89
- for ( const name of features ) {
93
+ for ( const name of features ) {
90
94
 
91
- if ( adapter.features.has( name ) ) {
95
+ if ( adapter.features.has( name ) ) {
92
96
 
93
- supportedFeatures.push( name );
97
+ supportedFeatures.push( name );
98
+
99
+ }
94
100
 
95
101
  }
96
102
 
97
- }
103
+ const deviceDescriptor = {
104
+ requiredFeatures: supportedFeatures,
105
+ requiredLimits: parameters.requiredLimits
106
+ };
98
107
 
99
- const deviceDescriptor = {
100
- requiredFeatures: supportedFeatures,
101
- requiredLimits: parameters.requiredLimits
102
- };
108
+ device = await adapter.requestDevice( deviceDescriptor );
103
109
 
104
- const device = await adapter.requestDevice( deviceDescriptor );
110
+ } else {
111
+
112
+ device = parameters.device;
113
+
114
+ }
105
115
 
106
116
  const context = ( parameters.context !== undefined ) ? parameters.context : renderer.domElement.getContext( 'webgpu' );
107
117
 
108
- this.adapter = adapter;
109
118
  this.device = device;
110
119
  this.context = context;
111
120
 
@@ -871,7 +880,7 @@ class WebGPUBackend extends Backend {
871
880
 
872
881
  // draw
873
882
 
874
- const drawRange = geometry.drawRange;
883
+ const drawRange = renderObject.drawRange;
875
884
  const firstVertex = drawRange.start;
876
885
 
877
886
  const instanceCount = this.getInstanceCount( renderObject );
@@ -1049,9 +1058,11 @@ class WebGPUBackend extends Backend {
1049
1058
  beginningOfPassWriteIndex: 0, // Write timestamp in index 0 when pass begins.
1050
1059
  endOfPassWriteIndex: 1, // Write timestamp in index 1 when pass ends.
1051
1060
  };
1061
+
1052
1062
  Object.assign( descriptor, {
1053
1063
  timestampWrites,
1054
1064
  } );
1065
+
1055
1066
  renderContextData.timeStampQuerySet = timeStampQuerySet;
1056
1067
 
1057
1068
  }
@@ -1084,33 +1095,29 @@ class WebGPUBackend extends Backend {
1084
1095
 
1085
1096
  }
1086
1097
 
1087
- async resolveTimestampAsync( renderContext, type = 'render' ) {
1088
-
1089
- if ( ! this.hasFeature( GPUFeatureName.TimestampQuery ) || ! this.trackTimestamp ) return;
1090
-
1091
- const renderContextData = this.get( renderContext );
1092
-
1093
- // handle timestamp query results
1094
-
1098
+ async resolveTimestampAsync(renderContext, type = 'render') {
1099
+ if (!this.hasFeature(GPUFeatureName.TimestampQuery) || !this.trackTimestamp) return;
1100
+
1101
+ const renderContextData = this.get(renderContext);
1095
1102
  const { currentTimestampQueryBuffer } = renderContextData;
1096
-
1097
- if ( currentTimestampQueryBuffer ) {
1098
-
1099
- renderContextData.currentTimestampQueryBuffer = null;
1100
-
1101
- await currentTimestampQueryBuffer.mapAsync( GPUMapMode.READ );
1102
-
1103
- const times = new BigUint64Array( currentTimestampQueryBuffer.getMappedRange() );
1104
-
1105
- const duration = Number( times[ 1 ] - times[ 0 ] ) / 1000000;
1106
- // console.log( `Compute ${type} duration: ${Number( times[ 1 ] - times[ 0 ] ) / 1000000}ms` );
1107
- this.renderer.info.updateTimestamp( type, duration );
1108
-
1109
- currentTimestampQueryBuffer.unmap();
1110
-
1103
+
1104
+ if (currentTimestampQueryBuffer === undefined) return;
1105
+
1106
+ const buffer = currentTimestampQueryBuffer;
1107
+
1108
+ try {
1109
+ await buffer.mapAsync(GPUMapMode.READ);
1110
+ const times = new BigUint64Array(buffer.getMappedRange());
1111
+ const duration = Number(times[1] - times[0]) / 1000000;
1112
+ this.renderer.info.updateTimestamp(type, duration);
1113
+ } catch (error) {
1114
+ console.error(`Error mapping buffer: ${error}`);
1115
+ // Optionally handle the error, e.g., re-queue the buffer or skip it
1116
+ } finally {
1117
+ buffer.unmap();
1111
1118
  }
1112
-
1113
1119
  }
1120
+
1114
1121
 
1115
1122
  // node builder
1116
1123
 
@@ -1222,27 +1229,37 @@ class WebGPUBackend extends Backend {
1222
1229
 
1223
1230
  }
1224
1231
 
1225
- async hasFeatureAsync( name ) {
1226
-
1227
- const adapter = this.adapter || await WebGPU.getStaticAdapter();
1228
-
1229
- //
1232
+ hasFeature( name ) {
1230
1233
 
1231
- return adapter.features.has( name );
1234
+ return this.device.features.has( name );
1232
1235
 
1233
1236
  }
1234
1237
 
1235
- hasFeature( name ) {
1236
-
1237
- if ( ! this.adapter ) {
1238
+ copyTextureToTexture( position, srcTexture, dstTexture, level = 0 ) {
1238
1239
 
1239
- console.warn( 'WebGPUBackend: WebGPU adapter has not been initialized yet. Please use detectSupportAsync instead' );
1240
+ const encoder = this.device.createCommandEncoder( { label: 'copyTextureToTexture_' + srcTexture.id + '_' + dstTexture.id } );
1240
1241
 
1241
- return false;
1242
+ const sourceGPU = this.get( srcTexture ).texture;
1243
+ const destinationGPU = this.get( dstTexture ).texture;
1242
1244
 
1243
- }
1245
+ encoder.copyTextureToTexture(
1246
+ {
1247
+ texture: sourceGPU,
1248
+ mipLevel: level,
1249
+ origin: { x: 0, y: 0, z: 0 }
1250
+ },
1251
+ {
1252
+ texture: destinationGPU,
1253
+ mipLevel: level,
1254
+ origin: { x: position.x, y: position.y, z: position.z }
1255
+ },
1256
+ [
1257
+ srcTexture.image.width,
1258
+ srcTexture.image.height
1259
+ ]
1260
+ );
1244
1261
 
1245
- return this.adapter.features.has( name );
1262
+ this.device.queue.submit( [ encoder.finish() ] );
1246
1263
 
1247
1264
  }
1248
1265
 
@@ -228,7 +228,7 @@ class WGSLNodeBuilder extends NodeBuilder {
228
228
 
229
229
  isUnfilterable( texture ) {
230
230
 
231
- return texture.isDataTexture === true && texture.type === FloatType;
231
+ return this.getComponentTypeFromTexture( texture ) !== 'float' || ( texture.isDataTexture === true && texture.type === FloatType );
232
232
 
233
233
  }
234
234
 
@@ -254,6 +254,21 @@ class WGSLNodeBuilder extends NodeBuilder {
254
254
 
255
255
  }
256
256
 
257
+ generateTextureGrad( texture, textureProperty, uvSnippet, gradSnippet, depthSnippet, shaderStage = this.shaderStage ) {
258
+
259
+ if ( shaderStage === 'fragment' ) {
260
+
261
+ // TODO handle i32 or u32 --> uvSnippet, array_index: A, ddx, ddy
262
+ return `textureSampleGrad( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ gradSnippet[ 0 ] }, ${ gradSnippet[ 1 ] } )`;
263
+
264
+ } else {
265
+
266
+ console.error( `WebGPURenderer: THREE.TextureNode.gradient() does not support ${ shaderStage } shader.` );
267
+
268
+ }
269
+
270
+ }
271
+
257
272
  generateTextureCompare( texture, textureProperty, uvSnippet, compareSnippet, depthSnippet, shaderStage = this.shaderStage ) {
258
273
 
259
274
  if ( shaderStage === 'fragment' ) {
@@ -522,7 +537,7 @@ ${ flowData.code }
522
537
 
523
538
  getFragCoord() {
524
539
 
525
- return this.getBuiltin( 'position', 'fragCoord', 'vec4<f32>' ) + '.xy';
540
+ return this.getBuiltin( 'position', 'fragCoord', 'vec4<f32>' ) + '.xyz';
526
541
 
527
542
  }
528
543
 
@@ -759,11 +774,13 @@ ${ flowData.code }
759
774
 
760
775
  const format = getFormat( texture );
761
776
 
762
- textureType = 'texture_storage_2d<' + format + ', write>';
777
+ textureType = `texture_storage_2d<${ format }, write>`;
763
778
 
764
779
  } else {
765
780
 
766
- textureType = 'texture_2d<f32>';
781
+ const componentPrefix = this.getComponentTypeFromTexture( texture ).charAt( 0 );
782
+
783
+ textureType = `texture_2d<${ componentPrefix }32>`;
767
784
 
768
785
  }
769
786
 
@@ -17,7 +17,9 @@ const typedAttributeToVertexFormatPrefix = new Map( [
17
17
 
18
18
  const typeArraysToVertexFormatPrefixForItemSize1 = new Map( [
19
19
  [ Int32Array, 'sint32' ],
20
+ [ Int16Array, 'sint32' ], // patch for INT16
20
21
  [ Uint32Array, 'uint32' ],
22
+ [ Uint16Array, 'uint32' ], // patch for UINT16
21
23
  [ Float32Array, 'float32' ]
22
24
  ] );
23
25
 
@@ -44,9 +46,24 @@ class WebGPUAttributeUtils {
44
46
 
45
47
  let array = bufferAttribute.array;
46
48
 
49
+ // patch for INT16 and UINT16
50
+ if ( attribute.normalized === false && ( array.constructor === Int16Array || array.constructor === Uint16Array ) ) {
51
+
52
+ const tempArray = new Uint32Array( array.length );
53
+ for ( let i = 0; i < array.length; i ++ ) {
54
+
55
+ tempArray[ i ] = array[ i ];
56
+
57
+ }
58
+
59
+ array = tempArray;
60
+
61
+ }
62
+
63
+ bufferAttribute.array = array;
64
+
47
65
  if ( ( bufferAttribute.isStorageBufferAttribute || bufferAttribute.isStorageInstancedBufferAttribute ) && bufferAttribute.itemSize === 3 ) {
48
66
 
49
- bufferAttribute.itemSize = 4;
50
67
  array = new array.constructor( bufferAttribute.count * 4 );
51
68
 
52
69
  for ( let i = 0; i < bufferAttribute.count; i ++ ) {
@@ -55,6 +72,10 @@ class WebGPUAttributeUtils {
55
72
 
56
73
  }
57
74
 
75
+ // Update BufferAttribute
76
+ bufferAttribute.itemSize = 4;
77
+ bufferAttribute.array = array;
78
+
58
79
  }
59
80
 
60
81
  const size = array.byteLength + ( ( 4 - ( array.byteLength % 4 ) ) % 4 ); // ensure 4 byte alignment, see #20441
@@ -149,6 +170,13 @@ class WebGPUAttributeUtils {
149
170
 
150
171
  }
151
172
 
173
+ // patch for INT16 and UINT16
174
+ if ( geometryAttribute.normalized === false && ( geometryAttribute.array.constructor === Int16Array || geometryAttribute.array.constructor === Uint16Array ) ) {
175
+
176
+ arrayStride = 4;
177
+
178
+ }
179
+
152
180
  vertexBufferLayout = {
153
181
  arrayStride,
154
182
  attributes: [],
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  GPUTextureAspect, GPUTextureViewDimension, GPUBufferBindingType, GPUTextureSampleType
3
3
  } from './WebGPUConstants.js';
4
- import { FloatType } from 'three';
4
+ import { FloatType, IntType, UnsignedIntType } from 'three';
5
5
 
6
6
  class WebGPUBindingUtils {
7
7
 
@@ -73,11 +73,25 @@ class WebGPUBindingUtils {
73
73
 
74
74
  texture.sampleType = GPUTextureSampleType.Depth;
75
75
 
76
- } else if ( binding.texture.isDataTexture && binding.texture.type === FloatType ) {
76
+ } else if ( binding.texture.isDataTexture ) {
77
77
 
78
- // @TODO: Add support for this soon: backend.hasFeature( 'float32-filterable' )
78
+ const type = binding.texture.type;
79
79
 
80
- texture.sampleType = GPUTextureSampleType.UnfilterableFloat;
80
+ if ( type === IntType ) {
81
+
82
+ texture.sampleType = GPUTextureSampleType.SInt;
83
+
84
+ } else if ( type === UnsignedIntType ) {
85
+
86
+ texture.sampleType = GPUTextureSampleType.UInt;
87
+
88
+ } else if ( type === FloatType ) {
89
+
90
+ // @TODO: Add support for this soon: backend.hasFeature( 'float32-filterable' )
91
+
92
+ texture.sampleType = GPUTextureSampleType.UnfilterableFloat;
93
+
94
+ }
81
95
 
82
96
  }
83
97