@plastic-software/three 0.183.4 → 0.184.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 (277) hide show
  1. package/build/three.cjs +773 -286
  2. package/build/three.core.js +372 -110
  3. package/build/three.core.min.js +1 -1
  4. package/build/three.module.js +426 -180
  5. package/build/three.module.min.js +1 -1
  6. package/build/three.tsl.js +7 -1
  7. package/build/three.tsl.min.js +1 -1
  8. package/build/three.webgpu.js +2979 -1281
  9. package/build/three.webgpu.min.js +1 -1
  10. package/build/three.webgpu.nodes.js +2942 -1281
  11. package/build/three.webgpu.nodes.min.js +1 -1
  12. package/examples/jsm/Addons.js +11 -0
  13. package/examples/jsm/animation/CCDIKSolver.js +5 -1
  14. package/examples/jsm/controls/ArcballControls.js +4 -1
  15. package/examples/jsm/controls/DragControls.js +2 -2
  16. package/examples/jsm/controls/FirstPersonControls.js +58 -54
  17. package/examples/jsm/controls/FlyControls.js +4 -0
  18. package/examples/jsm/controls/OrbitControls.js +2 -2
  19. package/examples/jsm/controls/TrackballControls.js +2 -2
  20. package/examples/jsm/controls/TransformControls.js +34 -2
  21. package/examples/jsm/csm/CSMShadowNode.js +6 -2
  22. package/examples/jsm/exporters/GLTFExporter.js +21 -5
  23. package/examples/jsm/geometries/TextGeometry.js +18 -0
  24. package/examples/jsm/helpers/LightProbeGridHelper.js +221 -0
  25. package/examples/jsm/inspector/Extension.js +13 -0
  26. package/examples/jsm/inspector/Inspector.js +169 -114
  27. package/examples/jsm/inspector/RendererInspector.js +2 -2
  28. package/examples/jsm/inspector/extensions/extensions.json +6 -0
  29. package/examples/jsm/inspector/extensions/tsl-graph/TSLGraphEditor.js +916 -0
  30. package/examples/jsm/inspector/extensions/tsl-graph/TSLGraphLoader.js +281 -0
  31. package/examples/jsm/inspector/tabs/Memory.js +128 -0
  32. package/examples/jsm/inspector/tabs/Parameters.js +34 -2
  33. package/examples/jsm/inspector/tabs/Performance.js +2 -2
  34. package/examples/jsm/inspector/tabs/Settings.js +264 -0
  35. package/examples/jsm/inspector/tabs/Timeline.js +1611 -0
  36. package/examples/jsm/inspector/tabs/Viewer.js +105 -3
  37. package/examples/jsm/inspector/ui/Graph.js +2 -2
  38. package/examples/jsm/inspector/ui/List.js +1 -1
  39. package/examples/jsm/inspector/ui/Profiler.js +273 -176
  40. package/examples/jsm/inspector/ui/Style.js +64 -10
  41. package/examples/jsm/inspector/ui/Tab.js +39 -7
  42. package/examples/jsm/inspector/ui/Values.js +39 -2
  43. package/examples/jsm/inspector/ui/utils.js +13 -0
  44. package/examples/jsm/interaction/InteractionManager.js +226 -0
  45. package/examples/jsm/libs/meshopt_decoder.module.js +8 -8
  46. package/examples/jsm/lighting/DynamicLighting.js +82 -0
  47. package/examples/jsm/lighting/LightProbeGrid.js +651 -0
  48. package/examples/jsm/lines/LineMaterial.js +1 -1
  49. package/examples/jsm/loaders/EXRLoader.js +682 -43
  50. package/examples/jsm/loaders/FBXLoader.js +233 -33
  51. package/examples/jsm/loaders/GLTFLoader.js +24 -7
  52. package/examples/jsm/loaders/HDRLoader.js +1 -1
  53. package/examples/jsm/loaders/KTX2Loader.js +8 -2
  54. package/examples/jsm/loaders/LDrawLoader.js +39 -47
  55. package/examples/jsm/loaders/SVGLoader.js +1 -1
  56. package/examples/jsm/loaders/VTKLoader.js +5 -1
  57. package/examples/jsm/loaders/collada/ColladaComposer.js +101 -7
  58. package/examples/jsm/loaders/collada/ColladaParser.js +19 -4
  59. package/examples/jsm/loaders/usd/USDAParser.js +6 -0
  60. package/examples/jsm/loaders/usd/USDCParser.js +26 -0
  61. package/examples/jsm/loaders/usd/USDComposer.js +656 -103
  62. package/examples/jsm/misc/GPUComputationRenderer.js +2 -0
  63. package/examples/jsm/misc/RollerCoaster.js +42 -4
  64. package/examples/jsm/modifiers/TessellateModifier.js +1 -1
  65. package/examples/jsm/objects/Reflector.js +73 -25
  66. package/examples/jsm/objects/Sky.js +14 -2
  67. package/examples/jsm/objects/SkyMesh.js +23 -6
  68. package/examples/jsm/renderers/Projector.js +18 -38
  69. package/examples/jsm/renderers/SVGRenderer.js +6 -25
  70. package/examples/jsm/transpiler/GLSLDecoder.js +2 -2
  71. package/examples/jsm/tsl/WebGLNodesHandler.js +605 -0
  72. package/examples/jsm/tsl/display/AfterImageNode.js +10 -0
  73. package/examples/jsm/tsl/display/AnamorphicNode.js +11 -0
  74. package/examples/jsm/tsl/display/BilateralBlurNode.js +10 -0
  75. package/examples/jsm/tsl/display/ChromaticAberrationNode.js +3 -36
  76. package/examples/jsm/tsl/display/FSR1Node.js +477 -0
  77. package/examples/jsm/tsl/display/GTAONode.js +2 -1
  78. package/examples/jsm/tsl/display/GaussianBlurNode.js +10 -0
  79. package/examples/jsm/tsl/display/GodraysNode.js +2 -11
  80. package/examples/jsm/tsl/display/OutlineNode.js +66 -16
  81. package/examples/jsm/tsl/display/SSGINode.js +0 -4
  82. package/examples/jsm/tsl/display/SharpenNode.js +283 -0
  83. package/examples/jsm/tsl/display/TAAUNode.js +835 -0
  84. package/examples/jsm/tsl/display/TRAANode.js +48 -7
  85. package/examples/jsm/tsl/lighting/DynamicLightsNode.js +300 -0
  86. package/examples/jsm/tsl/lighting/data/AmbientLightDataNode.js +61 -0
  87. package/examples/jsm/tsl/lighting/data/DirectionalLightDataNode.js +111 -0
  88. package/examples/jsm/tsl/lighting/data/HemisphereLightDataNode.js +99 -0
  89. package/examples/jsm/tsl/lighting/data/PointLightDataNode.js +134 -0
  90. package/examples/jsm/tsl/lighting/data/SpotLightDataNode.js +161 -0
  91. package/examples/jsm/tsl/math/Bayer.js +13 -2
  92. package/examples/jsm/utils/BufferGeometryUtils.js +2 -3
  93. package/examples/jsm/utils/ColorUtils.js +76 -0
  94. package/examples/jsm/utils/SkeletonUtils.js +14 -8
  95. package/examples/jsm/webxr/XRHandMeshModel.js +36 -10
  96. package/examples/jsm/webxr/XRHandModelFactory.js +2 -1
  97. package/package.json +4 -4
  98. package/src/Three.Core.js +1 -0
  99. package/src/Three.TSL.js +6 -0
  100. package/src/Three.WebGPU.Nodes.js +3 -0
  101. package/src/Three.WebGPU.js +6 -0
  102. package/src/animation/AnimationAction.js +11 -1
  103. package/src/audio/AudioContext.js +2 -2
  104. package/src/constants.js +1 -1
  105. package/src/core/BufferAttribute.js +13 -1
  106. package/src/core/Clock.js +1 -1
  107. package/src/core/Object3D.js +1 -5
  108. package/src/core/RenderTarget.js +1 -0
  109. package/src/extras/curves/CatmullRomCurve3.js +3 -2
  110. package/src/loaders/AudioLoader.js +11 -1
  111. package/src/loaders/DataTextureLoader.js +6 -4
  112. package/src/loaders/FileLoader.js +1 -2
  113. package/src/loaders/ImageBitmapLoader.js +4 -6
  114. package/src/loaders/MaterialLoader.js +1 -1
  115. package/src/loaders/ObjectLoader.js +25 -4
  116. package/src/loaders/nodes/NodeObjectLoader.js +18 -0
  117. package/src/materials/MeshToonMaterial.js +1 -1
  118. package/src/materials/nodes/Line2NodeMaterial.js +27 -0
  119. package/src/materials/nodes/NodeMaterial.js +0 -27
  120. package/src/materials/nodes/manager/NodeMaterialObserver.js +188 -89
  121. package/src/math/Line3.js +3 -0
  122. package/src/math/Matrix2.js +13 -9
  123. package/src/math/Matrix3.js +13 -9
  124. package/src/math/Matrix4.js +13 -9
  125. package/src/math/Plane.js +4 -3
  126. package/src/math/Triangle.js +1 -1
  127. package/src/math/Vector2.js +11 -7
  128. package/src/math/Vector3.js +12 -8
  129. package/src/math/Vector4.js +13 -9
  130. package/src/nodes/Nodes.js +0 -1
  131. package/src/nodes/TSL.js +1 -1
  132. package/src/nodes/accessors/BufferAttributeNode.js +9 -3
  133. package/src/nodes/accessors/CubeTextureNode.js +7 -1
  134. package/src/nodes/accessors/MaterialProperties.js +2 -5
  135. package/src/nodes/accessors/Object3DNode.js +1 -1
  136. package/src/nodes/accessors/ReferenceBaseNode.js +2 -2
  137. package/src/nodes/accessors/ReferenceNode.js +4 -4
  138. package/src/nodes/accessors/SceneProperties.js +2 -8
  139. package/src/nodes/accessors/StorageBufferNode.js +10 -4
  140. package/src/nodes/accessors/StorageTextureNode.js +4 -9
  141. package/src/nodes/accessors/TextureNode.js +10 -2
  142. package/src/nodes/accessors/UniformArrayNode.js +2 -2
  143. package/src/nodes/code/FunctionCallNode.js +1 -1
  144. package/src/nodes/code/FunctionNode.js +1 -1
  145. package/src/nodes/core/ArrayNode.js +1 -1
  146. package/src/nodes/core/AssignNode.js +1 -1
  147. package/src/nodes/core/AttributeNode.js +1 -1
  148. package/src/nodes/core/BypassNode.js +1 -1
  149. package/src/nodes/core/ContextNode.js +1 -1
  150. package/src/nodes/core/IndexNode.js +2 -1
  151. package/src/nodes/core/InputNode.js +1 -1
  152. package/src/nodes/core/InspectorNode.js +1 -1
  153. package/src/nodes/core/IsolateNode.js +1 -1
  154. package/src/nodes/core/Node.js +83 -12
  155. package/src/nodes/core/NodeBuilder.js +117 -16
  156. package/src/nodes/core/NodeUtils.js +1 -1
  157. package/src/nodes/core/OutputStructNode.js +1 -1
  158. package/src/nodes/core/ParameterNode.js +1 -1
  159. package/src/nodes/core/StackNode.js +1 -1
  160. package/src/nodes/core/StructNode.js +1 -1
  161. package/src/nodes/core/StructTypeNode.js +1 -1
  162. package/src/nodes/core/SubBuildNode.js +1 -1
  163. package/src/nodes/core/UniformGroupNode.js +36 -6
  164. package/src/nodes/core/VarNode.js +1 -1
  165. package/src/nodes/core/VaryingNode.js +1 -1
  166. package/src/nodes/display/NormalMapNode.js +2 -2
  167. package/src/nodes/display/PassNode.js +27 -7
  168. package/src/nodes/display/RenderOutputNode.js +4 -4
  169. package/src/nodes/display/ScreenNode.js +1 -1
  170. package/src/nodes/display/ViewportDepthTextureNode.js +11 -15
  171. package/src/nodes/display/ViewportTextureNode.js +18 -7
  172. package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated_Anisotropic.js +2 -2
  173. package/src/nodes/geometry/RangeNode.js +1 -1
  174. package/src/nodes/gpgpu/AtomicFunctionNode.js +1 -1
  175. package/src/nodes/gpgpu/BarrierNode.js +9 -0
  176. package/src/nodes/gpgpu/ComputeBuiltinNode.js +1 -1
  177. package/src/nodes/gpgpu/ComputeNode.js +69 -44
  178. package/src/nodes/gpgpu/SubgroupFunctionNode.js +1 -1
  179. package/src/nodes/lighting/LightsNode.js +6 -27
  180. package/src/nodes/lighting/ShadowNode.js +24 -2
  181. package/src/nodes/math/BitcastNode.js +1 -1
  182. package/src/nodes/math/ConditionalNode.js +1 -1
  183. package/src/nodes/math/MathNode.js +73 -1
  184. package/src/nodes/math/OperatorNode.js +1 -1
  185. package/src/nodes/math/PackFloatNode.js +1 -1
  186. package/src/nodes/math/UnpackFloatNode.js +1 -1
  187. package/src/nodes/tsl/TSLBase.js +1 -1
  188. package/src/nodes/tsl/TSLCore.js +21 -3
  189. package/src/nodes/utils/ArrayElementNode.js +1 -1
  190. package/src/nodes/utils/ConvertNode.js +1 -1
  191. package/src/nodes/utils/DebugNode.js +1 -1
  192. package/src/nodes/utils/EventNode.js +30 -0
  193. package/src/nodes/utils/FlipNode.js +1 -1
  194. package/src/nodes/utils/FunctionOverloadingNode.js +1 -1
  195. package/src/nodes/utils/JoinNode.js +1 -1
  196. package/src/nodes/utils/MemberNode.js +1 -1
  197. package/src/nodes/utils/Remap.js +48 -0
  198. package/src/nodes/utils/RotateNode.js +1 -1
  199. package/src/nodes/utils/SetNode.js +1 -1
  200. package/src/nodes/utils/SplitNode.js +1 -1
  201. package/src/objects/BatchedMesh.js +17 -2
  202. package/src/objects/InstancedMesh.js +19 -3
  203. package/src/objects/SkinnedMesh.js +26 -9
  204. package/src/renderers/WebGLRenderer.js +147 -48
  205. package/src/renderers/common/Animation.js +3 -3
  206. package/src/renderers/common/Attributes.js +15 -1
  207. package/src/renderers/common/Backend.js +0 -8
  208. package/src/renderers/common/Background.js +2 -2
  209. package/src/renderers/common/BindGroup.js +1 -8
  210. package/src/renderers/common/Bindings.js +2 -2
  211. package/src/renderers/common/ComputePipeline.js +1 -1
  212. package/src/renderers/common/CubeRenderTarget.js +1 -1
  213. package/src/renderers/common/Info.js +333 -4
  214. package/src/renderers/common/InspectorBase.js +6 -1
  215. package/src/renderers/common/Pipelines.js +36 -3
  216. package/src/renderers/common/ReadbackBuffer.js +78 -0
  217. package/src/renderers/common/RenderBundle.js +3 -1
  218. package/src/renderers/common/RenderBundles.js +5 -2
  219. package/src/renderers/common/RenderObject.js +2 -2
  220. package/src/renderers/common/RenderObjects.js +3 -3
  221. package/src/renderers/common/RenderPipeline.js +35 -6
  222. package/src/renderers/common/Renderer.js +232 -53
  223. package/src/renderers/common/Textures.js +72 -3
  224. package/src/renderers/common/UniformsGroup.js +1 -1
  225. package/src/renderers/common/XRManager.js +34 -27
  226. package/src/renderers/common/extras/PMREMGenerator.js +23 -15
  227. package/src/renderers/common/nodes/NodeBuilderState.js +1 -1
  228. package/src/renderers/common/nodes/NodeManager.js +230 -99
  229. package/src/renderers/shaders/ShaderChunk/envmap_common_pars_fragment.glsl.js +0 -1
  230. package/src/renderers/shaders/ShaderChunk/envmap_fragment.glsl.js +1 -1
  231. package/src/renderers/shaders/ShaderChunk/lightprobes_pars_fragment.glsl.js +80 -0
  232. package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +8 -0
  233. package/src/renderers/shaders/ShaderChunk/lights_pars_begin.glsl.js +2 -0
  234. package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +1 -3
  235. package/src/renderers/shaders/ShaderChunk/normal_fragment_maps.glsl.js +7 -0
  236. package/src/renderers/shaders/ShaderChunk/premultiplied_alpha_fragment.glsl.js +0 -1
  237. package/src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl.js +12 -2
  238. package/src/renderers/shaders/ShaderChunk.js +2 -0
  239. package/src/renderers/shaders/ShaderLib/backgroundCube.glsl.js +1 -2
  240. package/src/renderers/shaders/ShaderLib.js +0 -1
  241. package/src/renderers/shaders/UniformsLib.js +7 -2
  242. package/src/renderers/shaders/UniformsUtils.js +27 -5
  243. package/src/renderers/webgl/WebGLAnimation.js +2 -1
  244. package/src/renderers/webgl/WebGLBackground.js +13 -13
  245. package/src/renderers/webgl/WebGLBufferRenderer.js +0 -32
  246. package/src/renderers/webgl/WebGLCapabilities.js +6 -0
  247. package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +0 -32
  248. package/src/renderers/webgl/WebGLMaterials.js +12 -13
  249. package/src/renderers/webgl/WebGLOutput.js +4 -1
  250. package/src/renderers/webgl/WebGLProgram.js +4 -0
  251. package/src/renderers/webgl/WebGLPrograms.js +19 -3
  252. package/src/renderers/webgl/WebGLRenderStates.js +13 -2
  253. package/src/renderers/webgl/WebGLState.js +43 -0
  254. package/src/renderers/webgl/WebGLTextures.js +129 -26
  255. package/src/renderers/webgl/WebGLUniformsGroups.js +19 -0
  256. package/src/renderers/webgl-fallback/WebGLBackend.js +106 -65
  257. package/src/renderers/webgl-fallback/WebGLBufferRenderer.js +0 -41
  258. package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +29 -51
  259. package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +53 -19
  260. package/src/renderers/webgl-fallback/utils/WebGLCapabilities.js +25 -0
  261. package/src/renderers/webgl-fallback/utils/WebGLState.js +42 -1
  262. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +63 -50
  263. package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +1 -1
  264. package/src/renderers/webgpu/WebGPUBackend.js +160 -146
  265. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +55 -33
  266. package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +103 -17
  267. package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +1 -1
  268. package/src/renderers/webgpu/utils/WebGPUCapabilities.js +48 -0
  269. package/src/renderers/webgpu/utils/WebGPUConstants.js +8 -0
  270. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +91 -17
  271. package/src/renderers/webgpu/utils/WebGPUUtils.js +18 -2
  272. package/src/renderers/webxr/WebXRController.js +12 -0
  273. package/src/textures/HTMLTexture.js +74 -0
  274. package/src/textures/Source.js +1 -1
  275. package/src/textures/Texture.js +13 -2
  276. package/src/utils.js +23 -1
  277. package/src/nodes/utils/RemapNode.js +0 -125
@@ -198,7 +198,7 @@ class WebGPUTextureUtils {
198
198
 
199
199
  let textureGPU;
200
200
 
201
- const format = getFormat( texture );
201
+ const format = getFormat( texture, this.backend.device );
202
202
 
203
203
  if ( texture.isCubeTexture ) {
204
204
 
@@ -463,12 +463,12 @@ class WebGPUTextureUtils {
463
463
  if ( stencil ) {
464
464
 
465
465
  format = DepthStencilFormat;
466
- type = UnsignedInt248Type;
466
+ type = backend.renderer.reversedDepthBuffer === true ? FloatType : UnsignedInt248Type;
467
467
 
468
468
  } else if ( depth ) {
469
469
 
470
470
  format = DepthFormat;
471
- type = UnsignedIntType;
471
+ type = backend.renderer.reversedDepthBuffer === true ? FloatType : UnsignedIntType;
472
472
 
473
473
  }
474
474
 
@@ -538,9 +538,23 @@ class WebGPUTextureUtils {
538
538
 
539
539
  } else if ( texture.isArrayTexture || texture.isDataArrayTexture || texture.isData3DTexture ) {
540
540
 
541
- for ( let i = 0; i < options.image.depth; i ++ ) {
541
+ if ( texture.layerUpdates && texture.layerUpdates.size > 0 ) {
542
542
 
543
- this._copyBufferToTexture( options.image, textureData.texture, textureDescriptorGPU, i, texture.flipY, i );
543
+ for ( const layerIndex of texture.layerUpdates ) {
544
+
545
+ this._copyBufferToTexture( options.image, textureData.texture, textureDescriptorGPU, layerIndex, texture.flipY, layerIndex );
546
+
547
+ }
548
+
549
+ texture.clearLayerUpdates();
550
+
551
+ } else {
552
+
553
+ for ( let i = 0; i < options.image.depth; i ++ ) {
554
+
555
+ this._copyBufferToTexture( options.image, textureData.texture, textureDescriptorGPU, i, texture.flipY, i );
556
+
557
+ }
544
558
 
545
559
  }
546
560
 
@@ -552,6 +566,37 @@ class WebGPUTextureUtils {
552
566
 
553
567
  this._copyCubeMapToTexture( texture, textureData.texture, textureDescriptorGPU );
554
568
 
569
+ } else if ( texture.isHTMLTexture ) {
570
+
571
+ const device = this.backend.device;
572
+ const canvas = this.backend.renderer.domElement;
573
+ const image = texture.image;
574
+
575
+ if ( typeof device.queue.copyElementImageToTexture !== 'function' ) return;
576
+
577
+ // Skip the first frame — the element needs a paint record first.
578
+ if ( ! textureData.hasPaintCallback ) {
579
+
580
+ textureData.hasPaintCallback = true;
581
+ canvas.requestPaint();
582
+ return;
583
+
584
+ }
585
+
586
+ const width = textureDescriptorGPU.size.width;
587
+ const height = textureDescriptorGPU.size.height;
588
+
589
+ device.queue.copyElementImageToTexture(
590
+ image, width, height,
591
+ { texture: textureData.texture }
592
+ );
593
+
594
+ if ( texture.flipY ) {
595
+
596
+ this._flipY( textureData.texture, textureDescriptorGPU );
597
+
598
+ }
599
+
555
600
  } else {
556
601
 
557
602
  if ( mipmaps.length > 0 ) {
@@ -634,7 +679,9 @@ class WebGPUTextureUtils {
634
679
 
635
680
  await readBuffer.mapAsync( GPUMapMode.READ );
636
681
 
637
- const buffer = readBuffer.getMappedRange();
682
+ const buffer = readBuffer.getMappedRange().slice();
683
+
684
+ readBuffer.destroy();
638
685
 
639
686
  return new typedArrayType( buffer );
640
687
 
@@ -1059,7 +1106,9 @@ class WebGPUTextureUtils {
1059
1106
  format === GPUTextureFormat.RG8Unorm ||
1060
1107
  format === GPUTextureFormat.RG8Snorm ||
1061
1108
  format === GPUTextureFormat.RG8Uint ||
1062
- format === GPUTextureFormat.RG8Sint ) return 2;
1109
+ format === GPUTextureFormat.RG8Sint ||
1110
+ format === GPUTextureFormat.R16Unorm ||
1111
+ format === GPUTextureFormat.R16Snorm ) return 2;
1063
1112
 
1064
1113
  // 32-bit formats
1065
1114
  if ( format === GPUTextureFormat.R32Uint ||
@@ -1075,6 +1124,8 @@ class WebGPUTextureUtils {
1075
1124
  format === GPUTextureFormat.RGBA8Sint ||
1076
1125
  format === GPUTextureFormat.BGRA8Unorm ||
1077
1126
  format === GPUTextureFormat.BGRA8UnormSRGB ||
1127
+ format === GPUTextureFormat.RG16Unorm ||
1128
+ format === GPUTextureFormat.RG16Snorm ||
1078
1129
  // Packed 32-bit formats
1079
1130
  format === GPUTextureFormat.RGB9E5UFloat ||
1080
1131
  format === GPUTextureFormat.RGB10A2Unorm ||
@@ -1090,7 +1141,9 @@ class WebGPUTextureUtils {
1090
1141
  format === GPUTextureFormat.RG32Float ||
1091
1142
  format === GPUTextureFormat.RGBA16Uint ||
1092
1143
  format === GPUTextureFormat.RGBA16Sint ||
1093
- format === GPUTextureFormat.RGBA16Float ) return 8;
1144
+ format === GPUTextureFormat.RGBA16Float ||
1145
+ format === GPUTextureFormat.RGBA16Unorm ||
1146
+ format === GPUTextureFormat.RGBA16Snorm ) return 8;
1094
1147
 
1095
1148
  // 128-bit formats
1096
1149
  if ( format === GPUTextureFormat.RGBA32Uint ||
@@ -1133,6 +1186,12 @@ class WebGPUTextureUtils {
1133
1186
  if ( format === GPUTextureFormat.RG16Float ) return Uint16Array;
1134
1187
  if ( format === GPUTextureFormat.RGBA16Float ) return Uint16Array;
1135
1188
 
1189
+ if ( format === GPUTextureFormat.R16Unorm ) return Uint16Array;
1190
+ if ( format === GPUTextureFormat.R16Snorm ) return Int16Array;
1191
+ if ( format === GPUTextureFormat.RG16Unorm ) return Uint16Array;
1192
+ if ( format === GPUTextureFormat.RG16Snorm ) return Int16Array;
1193
+ if ( format === GPUTextureFormat.RGBA16Unorm ) return Uint16Array;
1194
+ if ( format === GPUTextureFormat.RGBA16Snorm ) return Int16Array;
1136
1195
 
1137
1196
  if ( format === GPUTextureFormat.R32Uint ) return Uint32Array;
1138
1197
  if ( format === GPUTextureFormat.R32Sint ) return Int32Array;
@@ -1187,19 +1246,33 @@ class WebGPUTextureUtils {
1187
1246
  * Returns the GPU format for the given texture.
1188
1247
  *
1189
1248
  * @param {Texture} texture - The texture.
1190
- * @param {?GPUDevice} [device=null] - The GPU device which is used for feature detection.
1191
- * It is not necessary to apply the device for most formats.
1249
+ * @param {GPUDevice} [device] - The GPU device which is used for feature detection.
1192
1250
  * @return {string} The GPU format.
1193
1251
  */
1194
- export function getFormat( texture, device = null ) {
1252
+ export function getFormat( texture, device ) {
1195
1253
 
1196
1254
  const format = texture.format;
1197
1255
  const type = texture.type;
1256
+ const normalized = texture.normalized;
1198
1257
  const colorSpace = texture.colorSpace;
1199
1258
  const transfer = ColorManagement.getTransfer( colorSpace );
1200
1259
 
1201
1260
  let formatGPU;
1202
1261
 
1262
+ let textureFormatsTier1 = false;
1263
+
1264
+ if ( normalized ) {
1265
+
1266
+ textureFormatsTier1 = device.features.has( GPUFeatureName.TextureFormatsTier1 );
1267
+
1268
+ if ( textureFormatsTier1 === false ) {
1269
+
1270
+ warn( 'WebGPURenderer: Unable to use normalized textures without texture-formats-tier1 feature.' );
1271
+
1272
+ }
1273
+
1274
+ }
1275
+
1203
1276
  if ( texture.isCompressedTexture === true || texture.isCompressedArrayTexture === true ) {
1204
1277
 
1205
1278
  switch ( format ) {
@@ -1340,12 +1413,13 @@ export function getFormat( texture, device = null ) {
1340
1413
  break;
1341
1414
 
1342
1415
  case ShortType:
1343
- formatGPU = GPUTextureFormat.RGBA16Sint;
1416
+ formatGPU = textureFormatsTier1 ? GPUTextureFormat.RGBA16Snorm : GPUTextureFormat.RGBA16Sint;
1344
1417
  break;
1345
1418
 
1346
1419
  case UnsignedShortType:
1347
- formatGPU = GPUTextureFormat.RGBA16Uint;
1420
+ formatGPU = textureFormatsTier1 ? GPUTextureFormat.RGBA16Unorm : GPUTextureFormat.RGBA16Uint;
1348
1421
  break;
1422
+
1349
1423
  case UnsignedIntType:
1350
1424
  formatGPU = GPUTextureFormat.RGBA32Uint;
1351
1425
  break;
@@ -1401,11 +1475,11 @@ export function getFormat( texture, device = null ) {
1401
1475
  break;
1402
1476
 
1403
1477
  case ShortType:
1404
- formatGPU = GPUTextureFormat.R16Sint;
1478
+ formatGPU = textureFormatsTier1 ? GPUTextureFormat.R16Snorm : GPUTextureFormat.R16Sint;
1405
1479
  break;
1406
1480
 
1407
1481
  case UnsignedShortType:
1408
- formatGPU = GPUTextureFormat.R16Uint;
1482
+ formatGPU = textureFormatsTier1 ? GPUTextureFormat.R16Unorm : GPUTextureFormat.R16Uint;
1409
1483
  break;
1410
1484
 
1411
1485
  case UnsignedIntType:
@@ -1444,11 +1518,11 @@ export function getFormat( texture, device = null ) {
1444
1518
  break;
1445
1519
 
1446
1520
  case ShortType:
1447
- formatGPU = GPUTextureFormat.RG16Sint;
1521
+ formatGPU = textureFormatsTier1 ? GPUTextureFormat.RG16Snorm : GPUTextureFormat.RG16Sint;
1448
1522
  break;
1449
1523
 
1450
1524
  case UnsignedShortType:
1451
- formatGPU = GPUTextureFormat.RG16Uint;
1525
+ formatGPU = textureFormatsTier1 ? GPUTextureFormat.RG16Unorm : GPUTextureFormat.RG16Uint;
1452
1526
  break;
1453
1527
 
1454
1528
  case UnsignedIntType:
@@ -42,11 +42,27 @@ class WebGPUUtils {
42
42
 
43
43
  } else if ( renderContext.stencil ) {
44
44
 
45
- format = GPUTextureFormat.Depth24PlusStencil8;
45
+ if ( this.backend.renderer.reversedDepthBuffer === true ) {
46
+
47
+ format = GPUTextureFormat.Depth32FloatStencil8;
48
+
49
+ } else {
50
+
51
+ format = GPUTextureFormat.Depth24PlusStencil8;
52
+
53
+ }
46
54
 
47
55
  } else {
48
56
 
49
- format = GPUTextureFormat.Depth24Plus;
57
+ if ( this.backend.renderer.reversedDepthBuffer === true ) {
58
+
59
+ format = GPUTextureFormat.Depth32Float;
60
+
61
+ } else {
62
+
63
+ format = GPUTextureFormat.Depth24Plus;
64
+
65
+ }
50
66
 
51
67
  }
52
68
 
@@ -109,6 +109,7 @@ class WebXRController {
109
109
  this._grip.linearVelocity = new Vector3();
110
110
  this._grip.hasAngularVelocity = false;
111
111
  this._grip.angularVelocity = new Vector3();
112
+ this._grip.eventsEnabled = false;
112
113
 
113
114
  }
114
115
 
@@ -321,6 +322,17 @@ class WebXRController {
321
322
 
322
323
  }
323
324
 
325
+ // grip update event if enabled
326
+ if ( grip.eventsEnabled ) {
327
+
328
+ grip.dispatchEvent( {
329
+ type: 'gripUpdated',
330
+ data: inputSource,
331
+ target: this
332
+ } );
333
+
334
+ }
335
+
324
336
  }
325
337
 
326
338
  }
@@ -0,0 +1,74 @@
1
+ import { Texture } from './Texture.js';
2
+
3
+ /**
4
+ * Creates a texture from an HTML element.
5
+ *
6
+ * This is almost the same as the base texture class, except that it sets {@link Texture#needsUpdate}
7
+ * to `true` immediately and listens for the parent canvas's paint events to trigger updates.
8
+ *
9
+ * @augments Texture
10
+ */
11
+ class HTMLTexture extends Texture {
12
+
13
+ /**
14
+ * Constructs a new texture.
15
+ *
16
+ * @param {HTMLElement} [element] - The HTML element.
17
+ * @param {number} [mapping=Texture.DEFAULT_MAPPING] - The texture mapping.
18
+ * @param {number} [wrapS=ClampToEdgeWrapping] - The wrapS value.
19
+ * @param {number} [wrapT=ClampToEdgeWrapping] - The wrapT value.
20
+ * @param {number} [magFilter=LinearFilter] - The mag filter value.
21
+ * @param {number} [minFilter=LinearMipmapLinearFilter] - The min filter value.
22
+ * @param {number} [format=RGBAFormat] - The texture format.
23
+ * @param {number} [type=UnsignedByteType] - The texture type.
24
+ * @param {number} [anisotropy=Texture.DEFAULT_ANISOTROPY] - The anisotropy value.
25
+ */
26
+ constructor( element, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
27
+
28
+ super( element, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
29
+
30
+ /**
31
+ * This flag can be used for type testing.
32
+ *
33
+ * @type {boolean}
34
+ * @readonly
35
+ * @default true
36
+ */
37
+ this.isHTMLTexture = true;
38
+ this.generateMipmaps = false;
39
+
40
+ this.needsUpdate = true;
41
+
42
+ const parent = element ? element.parentNode : null;
43
+
44
+ if ( parent !== null && 'requestPaint' in parent ) {
45
+
46
+ parent.onpaint = () => {
47
+
48
+ this.needsUpdate = true;
49
+
50
+ };
51
+
52
+ parent.requestPaint();
53
+
54
+ }
55
+
56
+ }
57
+
58
+ dispose() {
59
+
60
+ const parent = this.image ? this.image.parentNode : null;
61
+
62
+ if ( parent !== null && 'onpaint' in parent ) {
63
+
64
+ parent.onpaint = null;
65
+
66
+ }
67
+
68
+ super.dispose();
69
+
70
+ }
71
+
72
+ }
73
+
74
+ export { HTMLTexture };
@@ -90,7 +90,7 @@ class Source {
90
90
 
91
91
  } else if ( ( typeof VideoFrame !== 'undefined' ) && ( data instanceof VideoFrame ) ) {
92
92
 
93
- target.set( data.displayHeight, data.displayWidth, 0 );
93
+ target.set( data.displayWidth, data.displayHeight, 0 );
94
94
 
95
95
  } else if ( data !== null ) {
96
96
 
@@ -368,6 +368,15 @@ class Texture extends EventDispatcher {
368
368
  */
369
369
  this.pmremVersion = 0;
370
370
 
371
+ /**
372
+ * Whether the texture should use one of the 16 bit integer formats which are normalized
373
+ * to [0, 1] or [-1, 1] (depending on signed/unsigned) when sampled.
374
+ *
375
+ * @type {boolean}
376
+ * @default false
377
+ */
378
+ this.normalized = false;
379
+
371
380
  }
372
381
 
373
382
  /**
@@ -408,14 +417,14 @@ class Texture extends EventDispatcher {
408
417
 
409
418
  }
410
419
 
411
- set image( value = null ) {
420
+ set image( value ) {
412
421
 
413
422
  this.source.data = value;
414
423
 
415
424
  }
416
425
 
417
426
  /**
418
- * Updates the texture transformation matrix from the from the properties {@link Texture#offset},
427
+ * Updates the texture transformation matrix from the properties {@link Texture#offset},
419
428
  * {@link Texture#repeat}, {@link Texture#rotation}, and {@link Texture#center}.
420
429
  */
421
430
  updateMatrix() {
@@ -483,6 +492,7 @@ class Texture extends EventDispatcher {
483
492
  this.format = source.format;
484
493
  this.internalFormat = source.internalFormat;
485
494
  this.type = source.type;
495
+ this.normalized = source.normalized;
486
496
 
487
497
  this.offset.copy( source.offset );
488
498
  this.repeat.copy( source.repeat );
@@ -601,6 +611,7 @@ class Texture extends EventDispatcher {
601
611
  format: this.format,
602
612
  internalFormat: this.internalFormat,
603
613
  type: this.type,
614
+ normalized: this.normalized,
604
615
  colorSpace: this.colorSpace,
605
616
 
606
617
  minFilter: this.minFilter,
package/src/utils.js CHANGED
@@ -347,6 +347,28 @@ function warnOnce( ...params ) {
347
347
 
348
348
  }
349
349
 
350
+ /**
351
+ * Yields execution to the main thread to allow rendering and other tasks.
352
+ * Uses scheduler.yield() when available (Chrome 115+), falls back to requestAnimationFrame.
353
+ *
354
+ * @return {Promise<void>}
355
+ */
356
+ function yieldToMain() {
357
+
358
+ if ( typeof self !== 'undefined' && typeof self.scheduler !== 'undefined' && typeof self.scheduler.yield !== 'undefined' ) {
359
+
360
+ return self.scheduler.yield();
361
+
362
+ }
363
+
364
+ return new Promise( resolve => {
365
+
366
+ requestAnimationFrame( resolve );
367
+
368
+ } );
369
+
370
+ }
371
+
350
372
  /**
351
373
  * Asynchronously probes for WebGL sync object completion.
352
374
  *
@@ -468,4 +490,4 @@ const ReversedDepthFuncs = {
468
490
  [ GreaterEqualDepth ]: LessEqualDepth,
469
491
  };
470
492
 
471
- export { arrayMin, arrayMax, arrayNeedsUint32, getTypedArray, createElementNS, createCanvasElement, setConsoleFunction, getConsoleFunction, log, warn, error, warnOnce, probeAsync, toNormalizedProjectionMatrix, toReversedProjectionMatrix, isTypedArray, ReversedDepthFuncs };
493
+ export { arrayMin, arrayMax, arrayNeedsUint32, getTypedArray, createElementNS, createCanvasElement, setConsoleFunction, getConsoleFunction, log, warn, error, warnOnce, probeAsync, yieldToMain, toNormalizedProjectionMatrix, toReversedProjectionMatrix, isTypedArray, ReversedDepthFuncs };
@@ -1,125 +0,0 @@
1
- import Node from '../core/Node.js';
2
- import { float, addMethodChaining, nodeProxy } from '../tsl/TSLCore.js';
3
-
4
- /**
5
- * This node allows to remap a node value from one range into another. E.g a value of
6
- * `0.4` in the range `[ 0.3, 0.5 ]` should be remapped into the normalized range `[ 0, 1 ]`.
7
- * `RemapNode` takes care of that and converts the original value of `0.4` to `0.5`.
8
- *
9
- * @augments Node
10
- */
11
- class RemapNode extends Node {
12
-
13
- static get type() {
14
-
15
- return 'RemapNode';
16
-
17
- }
18
-
19
- /**
20
- * Constructs a new remap node.
21
- *
22
- * @param {Node} node - The node that should be remapped.
23
- * @param {Node} inLowNode - The source or current lower bound of the range.
24
- * @param {Node} inHighNode - The source or current upper bound of the range.
25
- * @param {Node} [outLowNode=float(0)] - The target lower bound of the range.
26
- * @param {Node} [outHighNode=float(1)] - The target upper bound of the range.
27
- */
28
- constructor( node, inLowNode, inHighNode, outLowNode = float( 0 ), outHighNode = float( 1 ) ) {
29
-
30
- super();
31
-
32
- /**
33
- * The node that should be remapped.
34
- *
35
- * @type {Node}
36
- */
37
- this.node = node;
38
-
39
- /**
40
- * The source or current lower bound of the range.
41
- *
42
- * @type {Node}
43
- */
44
- this.inLowNode = inLowNode;
45
-
46
- /**
47
- * The source or current upper bound of the range.
48
- *
49
- * @type {Node}
50
- */
51
- this.inHighNode = inHighNode;
52
-
53
- /**
54
- * The target lower bound of the range.
55
- *
56
- * @type {Node}
57
- * @default float(0)
58
- */
59
- this.outLowNode = outLowNode;
60
-
61
- /**
62
- * The target upper bound of the range.
63
- *
64
- * @type {Node}
65
- * @default float(1)
66
- */
67
- this.outHighNode = outHighNode;
68
-
69
- /**
70
- * Whether the node value should be clamped before
71
- * remapping it to the target range.
72
- *
73
- * @type {boolean}
74
- * @default true
75
- */
76
- this.doClamp = true;
77
-
78
- }
79
-
80
- setup() {
81
-
82
- const { node, inLowNode, inHighNode, outLowNode, outHighNode, doClamp } = this;
83
-
84
- let t = node.sub( inLowNode ).div( inHighNode.sub( inLowNode ) );
85
-
86
- if ( doClamp === true ) t = t.clamp();
87
-
88
- return t.mul( outHighNode.sub( outLowNode ) ).add( outLowNode );
89
-
90
- }
91
-
92
- }
93
-
94
- export default RemapNode;
95
-
96
- /**
97
- * TSL function for creating a remap node.
98
- *
99
- * @tsl
100
- * @function
101
- * @param {Node} node - The node that should be remapped.
102
- * @param {Node} inLowNode - The source or current lower bound of the range.
103
- * @param {Node} inHighNode - The source or current upper bound of the range.
104
- * @param {?Node} [outLowNode=float(0)] - The target lower bound of the range.
105
- * @param {?Node} [outHighNode=float(1)] - The target upper bound of the range.
106
- * @returns {RemapNode}
107
- */
108
- export const remap = /*@__PURE__*/ nodeProxy( RemapNode, null, null, { doClamp: false } ).setParameterLength( 3, 5 );
109
-
110
- /**
111
- * TSL function for creating a remap node, but with enabled clamping.
112
- *
113
- * @tsl
114
- * @function
115
- * @param {Node} node - The node that should be remapped.
116
- * @param {Node} inLowNode - The source or current lower bound of the range.
117
- * @param {Node} inHighNode - The source or current upper bound of the range.
118
- * @param {?Node} [outLowNode=float(0)] - The target lower bound of the range.
119
- * @param {?Node} [outHighNode=float(1)] - The target upper bound of the range.
120
- * @returns {RemapNode}
121
- */
122
- export const remapClamp = /*@__PURE__*/ nodeProxy( RemapNode ).setParameterLength( 3, 5 );
123
-
124
- addMethodChaining( 'remap', remap );
125
- addMethodChaining( 'remapClamp', remapClamp );