@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
@@ -32,6 +32,15 @@ class Sampler extends Binding {
32
32
  */
33
33
  this.version = texture ? texture.version : 0;
34
34
 
35
+ /**
36
+ * The binding's generation which is an additional version
37
+ * qualifier.
38
+ *
39
+ * @type {?number}
40
+ * @default null
41
+ */
42
+ this.generation = null;
43
+
35
44
  /**
36
45
  * This flag can be used for type testing.
37
46
  *
@@ -43,6 +52,88 @@ class Sampler extends Binding {
43
52
 
44
53
  }
45
54
 
55
+ /**
56
+ * Sets the texture of this sampler.
57
+ * @param {?Texture} value - The texture to set.
58
+ */
59
+ set texture( value ) {
60
+
61
+ if ( this._texture === value ) return;
62
+
63
+ const onDispose = () => {
64
+
65
+ this._texture = null;
66
+ this.generation = null;
67
+ this.version = 0;
68
+
69
+ };
70
+
71
+ if ( this._texture ) {
72
+
73
+ this._texture.removeEventListener( 'dispose', onDispose );
74
+
75
+ }
76
+
77
+ this._texture = value;
78
+
79
+ this.generation = null;
80
+ this.version = 0;
81
+
82
+ if ( this._texture ) {
83
+
84
+ this._texture.addEventListener( 'dispose', onDispose );
85
+
86
+ }
87
+
88
+ }
89
+
90
+ /**
91
+ * Gets the texture of this sampler.
92
+ * @return {?Texture} The texture.
93
+ */
94
+ get texture() {
95
+
96
+ return this._texture;
97
+
98
+ }
99
+
100
+ /**
101
+ * Updates the binding.
102
+ *
103
+ * @return {boolean} Whether the texture has been updated and must be
104
+ * uploaded to the GPU.
105
+ */
106
+ update() {
107
+
108
+ const { texture, version } = this;
109
+
110
+ if ( version !== texture.version ) {
111
+
112
+ this.version = texture.version;
113
+
114
+ return true;
115
+
116
+ }
117
+
118
+ return false;
119
+
120
+ }
121
+
122
+
123
+ clone() {
124
+
125
+ const clonedSampler = super.clone();
126
+
127
+ // fix dispose handler for cloned instances
128
+ // TODO: Find better solution, see #31747
129
+
130
+ clonedSampler._texture = null;
131
+ clonedSampler.texture = this.texture;
132
+
133
+ return clonedSampler;
134
+
135
+ }
136
+
46
137
  }
47
138
 
48
139
  export default Sampler;
@@ -74,6 +74,27 @@ class Storage3DTexture extends Texture {
74
74
 
75
75
  }
76
76
 
77
+ /**
78
+ * Sets the size of the storage 3d texture.
79
+ *
80
+ * @param {number} width - The new width of the storage texture.
81
+ * @param {number} height - The new height of the storage texture.
82
+ * @param {number} depth - The new depth of the storage texture.
83
+ */
84
+ setSize( width, height, depth ) {
85
+
86
+ if ( this.image.width !== width || this.image.height !== height || this.image.depth !== depth ) {
87
+
88
+ this.image.width = width;
89
+ this.image.height = height;
90
+ this.image.depth = depth;
91
+
92
+ this.dispose();
93
+
94
+ }
95
+
96
+ }
97
+
77
98
  }
78
99
 
79
100
  export default Storage3DTexture;
@@ -58,6 +58,27 @@ class StorageArrayTexture extends Texture {
58
58
 
59
59
  }
60
60
 
61
+ /**
62
+ * Sets the size of the storage array texture.
63
+ *
64
+ * @param {number} width - The new width of the storage texture.
65
+ * @param {number} height - The new height of the storage texture.
66
+ * @param {number} depth - The new depth of the storage texture.
67
+ */
68
+ setSize( width, height, depth ) {
69
+
70
+ if ( this.image.width !== width || this.image.height !== height || this.image.depth !== depth ) {
71
+
72
+ this.image.width = width;
73
+ this.image.height = height;
74
+ this.image.depth = depth;
75
+
76
+ this.dispose();
77
+
78
+ }
79
+
80
+ }
81
+
61
82
  }
62
83
 
63
84
  export default StorageArrayTexture;
@@ -54,6 +54,25 @@ class StorageTexture extends Texture {
54
54
 
55
55
  }
56
56
 
57
+ /**
58
+ * Sets the size of the storage texture.
59
+ *
60
+ * @param {number} width - The new width of the storage texture.
61
+ * @param {number} height - The new height of the storage texture.
62
+ */
63
+ setSize( width, height ) {
64
+
65
+ if ( this.image.width !== width || this.image.height !== height ) {
66
+
67
+ this.image.width = width;
68
+ this.image.height = height;
69
+
70
+ this.dispose();
71
+
72
+ }
73
+
74
+ }
75
+
57
76
  }
58
77
 
59
78
  export default StorageTexture;
@@ -2,7 +2,8 @@ import DataMap from './DataMap.js';
2
2
 
3
3
  import { Vector3 } from '../../math/Vector3.js';
4
4
  import { DepthTexture } from '../../textures/DepthTexture.js';
5
- import { DepthStencilFormat, DepthFormat, UnsignedIntType, UnsignedInt248Type, UnsignedByteType } from '../../constants.js';
5
+ import { DepthStencilFormat, DepthFormat, UnsignedIntType, UnsignedInt248Type, UnsignedByteType, SRGBTransfer } from '../../constants.js';
6
+ import { ColorManagement } from '../../math/ColorManagement.js';
6
7
 
7
8
  const _size = /*@__PURE__*/ new Vector3();
8
9
 
@@ -178,6 +179,7 @@ class Textures extends DataMap {
178
179
  }
179
180
 
180
181
  this.delete( renderTarget );
182
+ this.backend.delete( renderTarget );
181
183
 
182
184
  };
183
185
 
@@ -240,9 +242,15 @@ class Textures extends DataMap {
240
242
  options.needsMipmaps = this.needsMipmaps( texture );
241
243
  options.levels = options.needsMipmaps ? this.getMipLevels( texture, width, height ) : 1;
242
244
 
245
+ // TODO: Uniformly handle mipmap definitions
246
+ // Normal textures and compressed cube textures define base level + mips with their mipmap array
247
+ // Uncompressed cube textures use their mipmap array only for mips (no base level)
248
+
249
+ if ( texture.isCubeTexture && texture.mipmaps.length > 0 ) options.levels ++;
250
+
243
251
  //
244
252
 
245
- if ( isRenderTarget || texture.isStorageTexture === true ) {
253
+ if ( isRenderTarget || texture.isStorageTexture === true || texture.isExternalTexture === true ) {
246
254
 
247
255
  backend.createSampler( texture );
248
256
  backend.createTexture( texture, options );
@@ -300,6 +308,8 @@ class Textures extends DataMap {
300
308
 
301
309
  if ( options.needsMipmaps && texture.mipmaps.length === 0 ) backend.generateMipmaps( texture );
302
310
 
311
+ if ( texture.onUpdate ) texture.onUpdate( texture );
312
+
303
313
  }
304
314
 
305
315
  } else {
@@ -326,6 +336,14 @@ class Textures extends DataMap {
326
336
 
327
337
  this.info.memory.textures ++;
328
338
 
339
+ //
340
+
341
+ if ( texture.isVideoTexture && ColorManagement.getTransfer( texture.colorSpace ) !== SRGBTransfer ) {
342
+
343
+ console.warn( 'WebGPURenderer: Video textures must use a color space with a sRGB transfer function, e.g. SRGBColorSpace.' );
344
+
345
+ }
346
+
329
347
  // dispose
330
348
 
331
349
  const onDispose = () => {
@@ -366,9 +384,25 @@ class Textures extends DataMap {
366
384
 
367
385
  if ( image.image !== undefined ) image = image.image;
368
386
 
369
- target.width = image.width || 1;
370
- target.height = image.height || 1;
371
- target.depth = texture.isCubeTexture ? 6 : ( image.depth || 1 );
387
+ if ( ( typeof HTMLVideoElement !== 'undefined' ) && ( image instanceof HTMLVideoElement ) ) {
388
+
389
+ target.width = image.videoWidth || 1;
390
+ target.height = image.videoHeight || 1;
391
+ target.depth = 1;
392
+
393
+ } else if ( image instanceof VideoFrame ) {
394
+
395
+ target.width = image.displayWidth || 1;
396
+ target.height = image.displayHeight || 1;
397
+ target.depth = 1;
398
+
399
+ } else {
400
+
401
+ target.width = image.width || 1;
402
+ target.height = image.height || 1;
403
+ target.depth = texture.isCubeTexture ? 6 : ( image.depth || 1 );
404
+
405
+ }
372
406
 
373
407
  } else {
374
408
 
@@ -392,21 +426,25 @@ class Textures extends DataMap {
392
426
 
393
427
  let mipLevelCount;
394
428
 
395
- if ( texture.isCompressedTexture ) {
429
+ if ( texture.mipmaps.length > 0 ) {
430
+
431
+ mipLevelCount = texture.mipmaps.length;
396
432
 
397
- if ( texture.mipmaps ) {
433
+ } else {
398
434
 
399
- mipLevelCount = texture.mipmaps.length;
435
+ if ( texture.isCompressedTexture === true ) {
400
436
 
401
- } else {
437
+ // it is not possible to compute mipmaps for compressed textures. So
438
+ // when no mipmaps are defined in "texture.mipmaps", force a texture
439
+ // level of 1
402
440
 
403
441
  mipLevelCount = 1;
404
442
 
405
- }
443
+ } else {
406
444
 
407
- } else {
445
+ mipLevelCount = Math.floor( Math.log2( Math.max( width, height ) ) ) + 1;
408
446
 
409
- mipLevelCount = Math.floor( Math.log2( Math.max( width, height ) ) ) + 1;
447
+ }
410
448
 
411
449
  }
412
450
 
@@ -415,14 +453,14 @@ class Textures extends DataMap {
415
453
  }
416
454
 
417
455
  /**
418
- * Returns `true` if the given texture requires mipmaps.
456
+ * Returns `true` if the given texture makes use of mipmapping.
419
457
  *
420
458
  * @param {Texture} texture - The texture.
421
459
  * @return {boolean} Whether mipmaps are required or not.
422
460
  */
423
461
  needsMipmaps( texture ) {
424
462
 
425
- return texture.isCompressedTexture === true || texture.generateMipmaps;
463
+ return texture.generateMipmaps === true || texture.mipmaps.length > 0;
426
464
 
427
465
  }
428
466
 
@@ -70,13 +70,13 @@ class TimestampQueryPool {
70
70
  }
71
71
 
72
72
  /**
73
- * Allocate queries for a specific renderContext.
73
+ * Allocate queries for a specific uid.
74
74
  *
75
75
  * @abstract
76
- * @param {Object} renderContext - The render context to allocate queries for.
76
+ * @param {string} uid - A unique identifier for the render context.
77
77
  * @returns {?number}
78
78
  */
79
- allocateQueriesForContext( /* renderContext */ ) {}
79
+ allocateQueriesForContext( /* uid */ ) {}
80
80
 
81
81
  /**
82
82
  * Resolve all timestamps and return data (or process them).
@@ -164,12 +164,21 @@ class XRManager extends EventDispatcher {
164
164
  this._layers = [];
165
165
 
166
166
  /**
167
- * Whether the device has support for all layer types.
167
+ * Whether the XR session uses layers.
168
168
  *
169
169
  * @type {boolean}
170
170
  * @default false
171
171
  */
172
- this._supportsLayers = false;
172
+ this._sessionUsesLayers = false;
173
+
174
+ /**
175
+ * Whether the device supports binding gl objects.
176
+ *
177
+ * @private
178
+ * @type {boolean}
179
+ * @readonly
180
+ */
181
+ this._supportsGlBinding = typeof XRWebGLBinding !== 'undefined';
173
182
 
174
183
  this._frameBufferTargets = null;
175
184
 
@@ -351,13 +360,16 @@ class XRManager extends EventDispatcher {
351
360
  this._xrFrame = null;
352
361
 
353
362
  /**
354
- * Whether to use the WebXR Layers API or not.
363
+ * Whether the browser supports the APIs necessary to use XRProjectionLayers.
364
+ *
365
+ * Note: this does not represent XRSession explicitly requesting
366
+ * `'layers'` as a feature - see `_sessionUsesLayers` and #30112
355
367
  *
356
368
  * @private
357
369
  * @type {boolean}
358
370
  * @readonly
359
371
  */
360
- this._useLayers = ( typeof XRWebGLBinding !== 'undefined' && 'createProjectionLayer' in XRWebGLBinding.prototype ); // eslint-disable-line compat/compat
372
+ this._supportsLayers = ( this._supportsGlBinding && 'createProjectionLayer' in XRWebGLBinding.prototype ); // eslint-disable-line compat/compat
361
373
 
362
374
  /**
363
375
  * Whether the usage of multiview has been requested by the application or not.
@@ -578,6 +590,27 @@ class XRManager extends EventDispatcher {
578
590
 
579
591
  }
580
592
 
593
+
594
+ /**
595
+ * Returns the current XR binding.
596
+ *
597
+ * Creates a new binding if needed and the browser is
598
+ * capable of doing so.
599
+ *
600
+ * @return {?XRWebGLBinding} The XR binding. Returns `null` if one cannot be created.
601
+ */
602
+ getBinding() {
603
+
604
+ if ( this._glBinding === null && this._supportsGlBinding ) {
605
+
606
+ this._glBinding = new XRWebGLBinding( this._session, this._gl );
607
+
608
+ }
609
+
610
+ return this._glBinding;
611
+
612
+ }
613
+
581
614
  /**
582
615
  * Returns the current XR frame.
583
616
  *
@@ -808,7 +841,7 @@ class XRManager extends EventDispatcher {
808
841
  layer.renderTarget.isXRRenderTarget = this._session !== null;
809
842
  layer.renderTarget._hasExternalTextures = layer.renderTarget.isXRRenderTarget;
810
843
 
811
- if ( layer.renderTarget.isXRRenderTarget && this._supportsLayers ) {
844
+ if ( layer.renderTarget.isXRRenderTarget && this._sessionUsesLayers ) {
812
845
 
813
846
  layer.xrlayer.transform = new XRRigidTransform( layer.plane.getWorldPosition( translationObject ), layer.plane.getWorldQuaternion( quaternionObject ) );
814
847
 
@@ -915,9 +948,9 @@ class XRManager extends EventDispatcher {
915
948
 
916
949
  //
917
950
 
918
- if ( this._useLayers === true ) {
951
+ if ( this._supportsLayers === true ) {
919
952
 
920
- // default path using XRWebGLBinding/XRProjectionLayer
953
+ // default path using XRProjectionLayer
921
954
 
922
955
  let depthFormat = null;
923
956
  let depthType = null;
@@ -945,11 +978,10 @@ class XRManager extends EventDispatcher {
945
978
 
946
979
  }
947
980
 
948
- const glBinding = new XRWebGLBinding( session, gl );
949
- const glProjLayer = glBinding.createProjectionLayer( projectionlayerInit );
981
+ this._glBinding = this.getBinding();
982
+ const glProjLayer = this._glBinding.createProjectionLayer( projectionlayerInit );
950
983
  const layersArray = [ glProjLayer ];
951
984
 
952
- this._glBinding = glBinding;
953
985
  this._glProjLayer = glProjLayer;
954
986
 
955
987
  renderer.setPixelRatio( 1 );
@@ -977,11 +1009,11 @@ class XRManager extends EventDispatcher {
977
1009
  this._xrRenderTarget._hasExternalTextures = true;
978
1010
  this._xrRenderTarget.depth = this._useMultiview ? 2 : 1;
979
1011
 
980
- this._supportsLayers = session.enabledFeatures.includes( 'layers' );
1012
+ this._sessionUsesLayers = session.enabledFeatures.includes( 'layers' );
981
1013
 
982
1014
  this._referenceSpace = await session.requestReferenceSpace( this.getReferenceSpaceType() );
983
1015
 
984
- if ( this._supportsLayers ) {
1016
+ if ( this._sessionUsesLayers ) {
985
1017
 
986
1018
  // switch layers to native
987
1019
  for ( const layer of this._layers ) {
@@ -1095,9 +1127,11 @@ class XRManager extends EventDispatcher {
1095
1127
 
1096
1128
  }
1097
1129
 
1098
- cameraL.layers.mask = camera.layers.mask | 0b010;
1099
- cameraR.layers.mask = camera.layers.mask | 0b100;
1100
- cameraXR.layers.mask = cameraL.layers.mask | cameraR.layers.mask;
1130
+ // inherit camera layers and enable eye layers (1 = left, 2 = right)
1131
+ cameraXR.layers.mask = camera.layers.mask | 0b110;
1132
+ cameraL.layers.mask = cameraXR.layers.mask & 0b011;
1133
+ cameraR.layers.mask = cameraXR.layers.mask & 0b101;
1134
+
1101
1135
 
1102
1136
  const parent = camera.parent;
1103
1137
  const cameras = cameraXR.cameras;
@@ -1348,7 +1382,7 @@ function onSessionEnd() {
1348
1382
  this._xrRenderTarget = null;
1349
1383
 
1350
1384
  // switch layers back to emulated
1351
- if ( this._supportsLayers === true ) {
1385
+ if ( this._sessionUsesLayers === true ) {
1352
1386
 
1353
1387
  for ( const layer of this._layers ) {
1354
1388
 
@@ -1550,7 +1584,7 @@ function onAnimationFrame( time, frame ) {
1550
1584
 
1551
1585
  let viewport;
1552
1586
 
1553
- if ( this._useLayers === true ) {
1587
+ if ( this._supportsLayers === true ) {
1554
1588
 
1555
1589
  const glSubImage = this._glBinding.getViewSubImage( this._glProjLayer, view );
1556
1590
  viewport = glSubImage.viewport;
@@ -126,7 +126,7 @@ class NodeBuilderState {
126
126
 
127
127
  if ( shared !== true ) {
128
128
 
129
- const bindingsGroup = new BindGroup( instanceGroup.name, [], instanceGroup.index, instanceGroup );
129
+ const bindingsGroup = new BindGroup( instanceGroup.name, [], instanceGroup.index, instanceGroup.bindingsReference );
130
130
  bindings.push( bindingsGroup );
131
131
 
132
132
  for ( const instanceBinding of instanceGroup.bindings ) {
@@ -146,9 +146,9 @@ class NodeLibrary {
146
146
  /**
147
147
  * Adds a node class definition for the given type to the provided type library.
148
148
  *
149
- * @param {any} nodeClass - The node class definition.
149
+ * @param {Node.constructor} nodeClass - The node class definition.
150
150
  * @param {number|string} type - The object type.
151
- * @param {Map} library - The type library.
151
+ * @param {Map<number|string,Node.constructor>} library - The type library.
152
152
  */
153
153
  addType( nodeClass, type, library ) {
154
154
 
@@ -169,9 +169,9 @@ class NodeLibrary {
169
169
  /**
170
170
  * Adds a node class definition for the given class definition to the provided type library.
171
171
  *
172
- * @param {any} nodeClass - The node class definition.
173
- * @param {any} baseClass - The class definition.
174
- * @param {WeakMap} library - The type library.
172
+ * @param {Node.constructor} nodeClass - The node class definition.
173
+ * @param {Node.constructor} baseClass - The class definition.
174
+ * @param {WeakMap<Node.constructor, Node.constructor>} library - The type library.
175
175
  */
176
176
  addClass( nodeClass, baseClass, library ) {
177
177
 
@@ -45,18 +45,6 @@ class NodeSampledTexture extends SampledTexture {
45
45
 
46
46
  }
47
47
 
48
- /**
49
- * Overwrites the default to additionally check if the node value has changed.
50
- *
51
- * @param {number} generation - The generation.
52
- * @return {boolean} Whether an update is required or not.
53
- */
54
- needsBindingsUpdate( generation ) {
55
-
56
- return this.textureNode.value !== this.texture || super.needsBindingsUpdate( generation );
57
-
58
- }
59
-
60
48
  /**
61
49
  * Updates the binding.
62
50
  *
@@ -1,5 +1,5 @@
1
1
  export default /* glsl */`
2
- #if defined( USE_LOGDEPTHBUF )
2
+ #if defined( USE_LOGARITHMIC_DEPTH_BUFFER )
3
3
 
4
4
  // Doing a strict comparison with == 1.0 can cause noise artifacts
5
5
  // on some platforms. See issue #17623.
@@ -1,5 +1,5 @@
1
1
  export default /* glsl */`
2
- #if defined( USE_LOGDEPTHBUF )
2
+ #if defined( USE_LOGARITHMIC_DEPTH_BUFFER )
3
3
 
4
4
  uniform float logDepthBufFC;
5
5
  varying float vFragDepth;
@@ -1,5 +1,5 @@
1
1
  export default /* glsl */`
2
- #ifdef USE_LOGDEPTHBUF
2
+ #ifdef USE_LOGARITHMIC_DEPTH_BUFFER
3
3
 
4
4
  varying float vFragDepth;
5
5
  varying float vIsPerspective;
@@ -1,5 +1,5 @@
1
1
  export default /* glsl */`
2
- #ifdef USE_LOGDEPTHBUF
2
+ #ifdef USE_LOGARITHMIC_DEPTH_BUFFER
3
3
 
4
4
  vFragDepth = 1.0 + gl_Position.w;
5
5
  vIsPerspective = float( isPerspectiveMatrix( projectionMatrix ) );
@@ -65,17 +65,19 @@ export default /* glsl */`
65
65
 
66
66
  #endif
67
67
 
68
- /*
69
- #if NUM_RECT_AREA_LIGHTS > 0
68
+ float texture2DCompare( sampler2D depths, vec2 uv, float compare ) {
70
69
 
71
- // TODO (abelnation): create uniforms for area light shadows
70
+ float depth = unpackRGBAToDepth( texture2D( depths, uv ) );
72
71
 
73
- #endif
74
- */
72
+ #ifdef USE_REVERSED_DEPTH_BUFFER
75
73
 
76
- float texture2DCompare( sampler2D depths, vec2 uv, float compare ) {
74
+ return step( depth, compare );
77
75
 
78
- return step( compare, unpackRGBAToDepth( texture2D( depths, uv ) ) );
76
+ #else
77
+
78
+ return step( compare, depth );
79
+
80
+ #endif
79
81
 
80
82
  }
81
83
 
@@ -85,17 +87,25 @@ export default /* glsl */`
85
87
 
86
88
  }
87
89
 
88
- float VSMShadow (sampler2D shadow, vec2 uv, float compare ){
90
+ float VSMShadow( sampler2D shadow, vec2 uv, float compare ) {
89
91
 
90
92
  float occlusion = 1.0;
91
93
 
92
94
  vec2 distribution = texture2DDistribution( shadow, uv );
93
95
 
94
- float hard_shadow = step( compare , distribution.x ); // Hard Shadow
96
+ #ifdef USE_REVERSED_DEPTH_BUFFER
97
+
98
+ float hard_shadow = step( distribution.x, compare );
99
+
100
+ #else
101
+
102
+ float hard_shadow = step( compare, distribution.x );
103
+
104
+ #endif
95
105
 
96
- if (hard_shadow != 1.0 ) {
106
+ if ( hard_shadow != 1.0 ) {
97
107
 
98
- float distance = compare - distribution.x ;
108
+ float distance = compare - distribution.x;
99
109
  float variance = max( 0.00000, distribution.y * distribution.y );
100
110
  float softness_probability = variance / (variance + distance * distance ); // Chebeyshevs inequality
101
111
  softness_probability = clamp( ( softness_probability - 0.3 ) / ( 0.95 - 0.3 ), 0.0, 1.0 ); // 0.3 reduces light bleed
@@ -81,8 +81,17 @@ void main() {
81
81
 
82
82
  #include <logdepthbuf_fragment>
83
83
 
84
- // Higher precision equivalent of gl_FragCoord.z. This assumes depthRange has been left to its default values.
85
- float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;
84
+ // Higher precision equivalent of gl_FragCoord.z
85
+
86
+ #ifdef USE_REVERSED_DEPTH_BUFFER
87
+
88
+ float fragCoordZ = vHighPrecisionZW[ 0 ] / vHighPrecisionZW[ 1 ];
89
+
90
+ #else
91
+
92
+ float fragCoordZ = 0.5 * vHighPrecisionZW[ 0 ] / vHighPrecisionZW[ 1 ] + 0.5;
93
+
94
+ #endif
86
95
 
87
96
  #if DEPTH_PACKING == 3200
88
97
 
@@ -92,7 +92,7 @@ function WebGLCapabilities( gl, extensions, parameters, utils ) {
92
92
  }
93
93
 
94
94
  const logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
95
- const reverseDepthBuffer = parameters.reverseDepthBuffer === true && extensions.has( 'EXT_clip_control' );
95
+ const reversedDepthBuffer = parameters.reversedDepthBuffer === true && extensions.has( 'EXT_clip_control' );
96
96
 
97
97
  const maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
98
98
  const maxVertexTextures = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS );
@@ -120,7 +120,7 @@ function WebGLCapabilities( gl, extensions, parameters, utils ) {
120
120
 
121
121
  precision: precision,
122
122
  logarithmicDepthBuffer: logarithmicDepthBuffer,
123
- reverseDepthBuffer: reverseDepthBuffer,
123
+ reversedDepthBuffer: reversedDepthBuffer,
124
124
 
125
125
  maxTextures: maxTextures,
126
126
  maxVertexTextures: maxVertexTextures,