@plastic-software/three 0.178.0 → 0.179.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 (141) hide show
  1. package/README.md +1 -1
  2. package/build/three.cjs +856 -196
  3. package/build/three.core.js +647 -123
  4. package/build/three.core.min.js +1 -1
  5. package/build/three.module.js +211 -76
  6. package/build/three.module.min.js +1 -1
  7. package/build/three.tsl.js +70 -21
  8. package/build/three.tsl.min.js +1 -1
  9. package/build/three.webgpu.js +1796 -557
  10. package/build/three.webgpu.min.js +1 -1
  11. package/build/three.webgpu.nodes.js +1754 -557
  12. package/build/three.webgpu.nodes.min.js +1 -1
  13. package/examples/jsm/Addons.js +1 -2
  14. package/examples/jsm/capabilities/WebGPU.js +1 -1
  15. package/examples/jsm/csm/CSMShadowNode.js +4 -4
  16. package/examples/jsm/environments/RoomEnvironment.js +8 -3
  17. package/examples/jsm/exporters/USDZExporter.js +676 -299
  18. package/examples/jsm/geometries/RoundedBoxGeometry.js +47 -8
  19. package/examples/jsm/interactive/HTMLMesh.js +5 -3
  20. package/examples/jsm/libs/meshopt_decoder.module.js +75 -58
  21. package/examples/jsm/lights/LightProbeGenerator.js +14 -3
  22. package/examples/jsm/loaders/EXRLoader.js +210 -22
  23. package/examples/jsm/loaders/FBXLoader.js +1 -1
  24. package/examples/jsm/loaders/MaterialXLoader.js +212 -30
  25. package/examples/jsm/loaders/TTFLoader.js +13 -1
  26. package/examples/jsm/loaders/USDLoader.js +219 -0
  27. package/examples/jsm/loaders/USDZLoader.js +4 -892
  28. package/examples/jsm/loaders/usd/USDAParser.js +741 -0
  29. package/examples/jsm/loaders/usd/USDCParser.js +17 -0
  30. package/examples/jsm/objects/LensflareMesh.js +3 -3
  31. package/examples/jsm/objects/SkyMesh.js +2 -2
  32. package/examples/jsm/physics/RapierPhysics.js +14 -5
  33. package/examples/jsm/postprocessing/GTAOPass.js +10 -9
  34. package/examples/jsm/postprocessing/OutlinePass.js +17 -17
  35. package/examples/jsm/postprocessing/SSAOPass.js +10 -9
  36. package/examples/jsm/shaders/UnpackDepthRGBAShader.js +11 -2
  37. package/examples/jsm/transpiler/GLSLDecoder.js +2 -2
  38. package/examples/jsm/tsl/display/BloomNode.js +8 -7
  39. package/examples/jsm/tsl/display/GaussianBlurNode.js +6 -8
  40. package/examples/jsm/tsl/display/{TRAAPassNode.js → TRAANode.js} +181 -172
  41. package/examples/jsm/tsl/lighting/TiledLightsNode.js +1 -1
  42. package/package.json +1 -1
  43. package/src/Three.Core.js +1 -0
  44. package/src/Three.TSL.js +69 -20
  45. package/src/animation/KeyframeTrack.js +1 -1
  46. package/src/animation/tracks/BooleanKeyframeTrack.js +1 -1
  47. package/src/animation/tracks/StringKeyframeTrack.js +1 -1
  48. package/src/cameras/Camera.js +14 -0
  49. package/src/cameras/OrthographicCamera.js +1 -1
  50. package/src/cameras/PerspectiveCamera.js +1 -1
  51. package/src/constants.js +1 -1
  52. package/{examples/jsm/misc → src/core}/Timer.js +4 -42
  53. package/src/extras/PMREMGenerator.js +11 -0
  54. package/src/helpers/CameraHelper.js +41 -11
  55. package/src/helpers/SkeletonHelper.js +35 -6
  56. package/src/lights/LightShadow.js +21 -8
  57. package/src/lights/PointLightShadow.js +1 -1
  58. package/src/loaders/FileLoader.js +25 -2
  59. package/src/loaders/ImageBitmapLoader.js +23 -0
  60. package/src/loaders/Loader.js +14 -0
  61. package/src/loaders/LoadingManager.js +23 -0
  62. package/src/materials/MeshBasicMaterial.js +1 -1
  63. package/src/materials/nodes/Line2NodeMaterial.js +0 -8
  64. package/src/materials/nodes/NodeMaterial.js +1 -1
  65. package/src/materials/nodes/PointsNodeMaterial.js +5 -0
  66. package/src/materials/nodes/manager/NodeMaterialObserver.js +87 -2
  67. package/src/math/Frustum.js +19 -8
  68. package/src/math/FrustumArray.js +10 -5
  69. package/src/math/Line3.js +129 -2
  70. package/src/math/Matrix4.js +48 -27
  71. package/src/math/Spherical.js +2 -2
  72. package/src/nodes/Nodes.js +1 -0
  73. package/src/nodes/TSL.js +1 -0
  74. package/src/nodes/accessors/Camera.js +12 -12
  75. package/src/nodes/accessors/Normal.js +11 -11
  76. package/src/nodes/accessors/ReferenceNode.js +18 -3
  77. package/src/nodes/accessors/SceneNode.js +1 -1
  78. package/src/nodes/accessors/StorageTextureNode.js +1 -1
  79. package/src/nodes/accessors/TextureNode.js +12 -0
  80. package/src/nodes/core/ArrayNode.js +12 -0
  81. package/src/nodes/core/AssignNode.js +3 -0
  82. package/src/nodes/core/ContextNode.js +20 -1
  83. package/src/nodes/core/Node.js +14 -2
  84. package/src/nodes/core/NodeBuilder.js +25 -20
  85. package/src/nodes/core/NodeUtils.js +4 -1
  86. package/src/nodes/core/StackNode.js +42 -0
  87. package/src/nodes/core/UniformNode.js +63 -5
  88. package/src/nodes/core/VarNode.js +91 -2
  89. package/src/nodes/display/PassNode.js +148 -2
  90. package/src/nodes/display/ViewportTextureNode.js +67 -7
  91. package/src/nodes/functions/PhysicalLightingModel.js +2 -2
  92. package/src/nodes/gpgpu/AtomicFunctionNode.js +1 -1
  93. package/src/nodes/gpgpu/ComputeNode.js +67 -23
  94. package/src/nodes/gpgpu/WorkgroupInfoNode.js +28 -3
  95. package/src/nodes/lighting/ProjectorLightNode.js +19 -6
  96. package/src/nodes/lighting/ShadowFilterNode.js +1 -1
  97. package/src/nodes/materialx/MaterialXNodes.js +131 -2
  98. package/src/nodes/materialx/lib/mx_noise.js +165 -1
  99. package/src/nodes/math/ConditionalNode.js +1 -1
  100. package/src/nodes/math/MathNode.js +78 -54
  101. package/src/nodes/math/OperatorNode.js +22 -22
  102. package/src/nodes/tsl/TSLCore.js +64 -9
  103. package/src/nodes/utils/DebugNode.js +1 -1
  104. package/src/nodes/utils/EventNode.js +83 -0
  105. package/src/nodes/utils/RTTNode.js +9 -0
  106. package/src/objects/BatchedMesh.js +4 -2
  107. package/src/renderers/WebGLRenderer.js +21 -22
  108. package/src/renderers/common/Bindings.js +19 -18
  109. package/src/renderers/common/Color4.js +2 -2
  110. package/src/renderers/common/PostProcessing.js +60 -5
  111. package/src/renderers/common/Renderer.js +18 -15
  112. package/src/renderers/common/SampledTexture.js +3 -71
  113. package/src/renderers/common/Sampler.js +79 -0
  114. package/src/renderers/common/Storage3DTexture.js +21 -0
  115. package/src/renderers/common/StorageArrayTexture.js +21 -0
  116. package/src/renderers/common/StorageTexture.js +19 -0
  117. package/src/renderers/common/Textures.js +19 -3
  118. package/src/renderers/common/XRManager.js +26 -8
  119. package/src/renderers/common/nodes/NodeSampledTexture.js +0 -12
  120. package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +20 -2
  121. package/src/renderers/shaders/ShaderLib/depth.glsl.js +11 -2
  122. package/src/renderers/webgl/WebGLCapabilities.js +2 -2
  123. package/src/renderers/webgl/WebGLMaterials.js +6 -6
  124. package/src/renderers/webgl/WebGLProgram.js +22 -16
  125. package/src/renderers/webgl/WebGLPrograms.js +4 -4
  126. package/src/renderers/webgl/WebGLShadowMap.js +11 -1
  127. package/src/renderers/webgl/WebGLTextures.js +19 -7
  128. package/src/renderers/webgl-fallback/WebGLBackend.js +22 -12
  129. package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +2 -2
  130. package/src/renderers/webgpu/WebGPUBackend.js +54 -15
  131. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +53 -73
  132. package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +35 -31
  133. package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +1 -1
  134. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +11 -64
  135. package/src/renderers/webgpu/utils/WebGPUUtils.js +2 -17
  136. package/src/renderers/webxr/WebXRDepthSensing.js +6 -10
  137. package/src/renderers/webxr/WebXRManager.js +68 -8
  138. package/src/textures/ExternalTexture.js +45 -0
  139. package/src/textures/FramebufferTexture.js +2 -2
  140. package/src/textures/Source.js +11 -1
  141. package/src/textures/VideoTexture.js +30 -2
@@ -1,6 +1,7 @@
1
1
  import NodeMaterial from '../../materials/nodes/NodeMaterial.js';
2
+ import { ColorManagement } from '../../math/ColorManagement.js';
2
3
  import { vec4, renderOutput } from '../../nodes/TSL.js';
3
- import { LinearSRGBColorSpace, NoToneMapping } from '../../constants.js';
4
+ import { NoToneMapping } from '../../constants.js';
4
5
  import QuadMesh from '../../renderers/common/QuadMesh.js';
5
6
 
6
7
  /**
@@ -82,6 +83,15 @@ class PostProcessing {
82
83
  */
83
84
  this._quadMesh = new QuadMesh( material );
84
85
 
86
+ /**
87
+ * The context of the post processing stack.
88
+ *
89
+ * @private
90
+ * @type {?Object}
91
+ * @default null
92
+ */
93
+ this._context = null;
94
+
85
95
  }
86
96
 
87
97
  /**
@@ -91,15 +101,17 @@ class PostProcessing {
91
101
  */
92
102
  render() {
93
103
 
104
+ const renderer = this.renderer;
105
+
94
106
  this._update();
95
107
 
96
- const renderer = this.renderer;
108
+ if ( this._context.onBeforePostProcessing !== null ) this._context.onBeforePostProcessing();
97
109
 
98
110
  const toneMapping = renderer.toneMapping;
99
111
  const outputColorSpace = renderer.outputColorSpace;
100
112
 
101
113
  renderer.toneMapping = NoToneMapping;
102
- renderer.outputColorSpace = LinearSRGBColorSpace;
114
+ renderer.outputColorSpace = ColorManagement.workingColorSpace;
103
115
 
104
116
  //
105
117
 
@@ -115,6 +127,20 @@ class PostProcessing {
115
127
  renderer.toneMapping = toneMapping;
116
128
  renderer.outputColorSpace = outputColorSpace;
117
129
 
130
+ if ( this._context.onAfterPostProcessing !== null ) this._context.onAfterPostProcessing();
131
+
132
+ }
133
+
134
+ /**
135
+ * Returns the current context of the post processing stack.
136
+ *
137
+ * @readonly
138
+ * @type {?Object}
139
+ */
140
+ get context() {
141
+
142
+ return this._context;
143
+
118
144
  }
119
145
 
120
146
  /**
@@ -140,7 +166,32 @@ class PostProcessing {
140
166
  const toneMapping = renderer.toneMapping;
141
167
  const outputColorSpace = renderer.outputColorSpace;
142
168
 
143
- this._quadMesh.material.fragmentNode = this.outputColorTransform === true ? renderOutput( this.outputNode, toneMapping, outputColorSpace ) : this.outputNode.context( { toneMapping, outputColorSpace } );
169
+ const context = {
170
+ postProcessing: this,
171
+ onBeforePostProcessing: null,
172
+ onAfterPostProcessing: null
173
+ };
174
+
175
+ let outputNode = this.outputNode;
176
+
177
+ if ( this.outputColorTransform === true ) {
178
+
179
+ outputNode = outputNode.context( context );
180
+
181
+ outputNode = renderOutput( outputNode, toneMapping, outputColorSpace );
182
+
183
+ } else {
184
+
185
+ context.toneMapping = toneMapping;
186
+ context.outputColorSpace = outputColorSpace;
187
+
188
+ outputNode = outputNode.context( context );
189
+
190
+ }
191
+
192
+ this._context = context;
193
+
194
+ this._quadMesh.material.fragmentNode = outputNode;
144
195
  this._quadMesh.material.needsUpdate = true;
145
196
 
146
197
  this.needsUpdate = false;
@@ -161,13 +212,15 @@ class PostProcessing {
161
212
 
162
213
  this._update();
163
214
 
215
+ if ( this._context.onBeforePostProcessing !== null ) this._context.onBeforePostProcessing();
216
+
164
217
  const renderer = this.renderer;
165
218
 
166
219
  const toneMapping = renderer.toneMapping;
167
220
  const outputColorSpace = renderer.outputColorSpace;
168
221
 
169
222
  renderer.toneMapping = NoToneMapping;
170
- renderer.outputColorSpace = LinearSRGBColorSpace;
223
+ renderer.outputColorSpace = ColorManagement.workingColorSpace;
171
224
 
172
225
  //
173
226
 
@@ -183,6 +236,8 @@ class PostProcessing {
183
236
  renderer.toneMapping = toneMapping;
184
237
  renderer.outputColorSpace = outputColorSpace;
185
238
 
239
+ if ( this._context.onAfterPostProcessing !== null ) this._context.onAfterPostProcessing();
240
+
186
241
  }
187
242
 
188
243
  }
@@ -21,13 +21,14 @@ import XRManager from './XRManager.js';
21
21
  import NodeMaterial from '../../materials/nodes/NodeMaterial.js';
22
22
 
23
23
  import { Scene } from '../../scenes/Scene.js';
24
+ import { ColorManagement } from '../../math/ColorManagement.js';
24
25
  import { Frustum } from '../../math/Frustum.js';
25
26
  import { FrustumArray } from '../../math/FrustumArray.js';
26
27
  import { Matrix4 } from '../../math/Matrix4.js';
27
28
  import { Vector2 } from '../../math/Vector2.js';
28
29
  import { Vector4 } from '../../math/Vector4.js';
29
30
  import { RenderTarget } from '../../core/RenderTarget.js';
30
- import { DoubleSide, BackSide, FrontSide, SRGBColorSpace, NoToneMapping, LinearFilter, LinearSRGBColorSpace, HalfFloatType, RGBAFormat, PCFShadowMap } from '../../constants.js';
31
+ import { DoubleSide, BackSide, FrontSide, SRGBColorSpace, NoToneMapping, LinearFilter, HalfFloatType, RGBAFormat, PCFShadowMap } from '../../constants.js';
31
32
 
32
33
  import { highpModelNormalViewMatrix, highpModelViewMatrix } from '../../nodes/accessors/ModelNode.js';
33
34
 
@@ -1210,7 +1211,7 @@ class Renderer {
1210
1211
  const { currentToneMapping, currentColorSpace } = this;
1211
1212
 
1212
1213
  const useToneMapping = currentToneMapping !== NoToneMapping;
1213
- const useColorSpace = currentColorSpace !== LinearSRGBColorSpace;
1214
+ const useColorSpace = currentColorSpace !== ColorManagement.workingColorSpace;
1214
1215
 
1215
1216
  if ( useToneMapping === false && useColorSpace === false ) return null;
1216
1217
 
@@ -1226,7 +1227,7 @@ class Renderer {
1226
1227
  stencilBuffer: stencil,
1227
1228
  type: this._colorBufferType,
1228
1229
  format: RGBAFormat,
1229
- colorSpace: LinearSRGBColorSpace,
1230
+ colorSpace: ColorManagement.workingColorSpace,
1230
1231
  generateMipmaps: false,
1231
1232
  minFilter: LinearFilter,
1232
1233
  magFilter: LinearFilter,
@@ -1412,7 +1413,7 @@ class Renderer {
1412
1413
  if ( ! camera.isArrayCamera ) {
1413
1414
 
1414
1415
  _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
1415
- frustum.setFromProjectionMatrix( _projScreenMatrix, coordinateSystem );
1416
+ frustum.setFromProjectionMatrix( _projScreenMatrix, camera.coordinateSystem, camera.reversedDepth );
1416
1417
 
1417
1418
  }
1418
1419
 
@@ -2130,8 +2131,8 @@ class Renderer {
2130
2131
  }
2131
2132
 
2132
2133
  /**
2133
- * The current output tone mapping of the renderer. When a render target is set,
2134
- * the output tone mapping is always `NoToneMapping`.
2134
+ * The current tone mapping of the renderer. When not producing screen output,
2135
+ * the tone mapping is always `NoToneMapping`.
2135
2136
  *
2136
2137
  * @type {number}
2137
2138
  */
@@ -2142,14 +2143,14 @@ class Renderer {
2142
2143
  }
2143
2144
 
2144
2145
  /**
2145
- * The current output color space of the renderer. When a render target is set,
2146
- * the output color space is always `LinearSRGBColorSpace`.
2146
+ * The current color space of the renderer. When not producing screen output,
2147
+ * the color space is always the working color space.
2147
2148
  *
2148
2149
  * @type {string}
2149
2150
  */
2150
2151
  get currentColorSpace() {
2151
2152
 
2152
- return this.isOutputTarget ? this.outputColorSpace : LinearSRGBColorSpace;
2153
+ return this.isOutputTarget ? this.outputColorSpace : ColorManagement.workingColorSpace;
2153
2154
 
2154
2155
  }
2155
2156
 
@@ -2308,9 +2309,10 @@ class Renderer {
2308
2309
  * if the renderer has been initialized.
2309
2310
  *
2310
2311
  * @param {Node|Array<Node>} computeNodes - The compute node(s).
2312
+ * @param {Array<number>|number} [dispatchSizeOrCount=null] - Array with [ x, y, z ] values for dispatch or a single number for the count.
2311
2313
  * @return {Promise|undefined} A Promise that resolve when the compute has finished. Only returned when the renderer has not been initialized.
2312
2314
  */
2313
- compute( computeNodes ) {
2315
+ compute( computeNodes, dispatchSizeOrCount = null ) {
2314
2316
 
2315
2317
  if ( this._isDeviceLost === true ) return;
2316
2318
 
@@ -2389,7 +2391,7 @@ class Renderer {
2389
2391
  const computeBindings = bindings.getForCompute( computeNode );
2390
2392
  const computePipeline = pipelines.getForCompute( computeNode, computeBindings );
2391
2393
 
2392
- backend.compute( computeNodes, computeNode, computeBindings, computePipeline );
2394
+ backend.compute( computeNodes, computeNode, computeBindings, computePipeline, dispatchSizeOrCount );
2393
2395
 
2394
2396
  }
2395
2397
 
@@ -2406,13 +2408,14 @@ class Renderer {
2406
2408
  *
2407
2409
  * @async
2408
2410
  * @param {Node|Array<Node>} computeNodes - The compute node(s).
2411
+ * @param {Array<number>|number} [dispatchSizeOrCount=null] - Array with [ x, y, z ] values for dispatch or a single number for the count.
2409
2412
  * @return {Promise} A Promise that resolve when the compute has finished.
2410
2413
  */
2411
- async computeAsync( computeNodes ) {
2414
+ async computeAsync( computeNodes, dispatchSizeOrCount = null ) {
2412
2415
 
2413
2416
  if ( this._initialized === false ) await this.init();
2414
2417
 
2415
- this.compute( computeNodes );
2418
+ this.compute( computeNodes, dispatchSizeOrCount );
2416
2419
 
2417
2420
  }
2418
2421
 
@@ -2961,7 +2964,7 @@ class Renderer {
2961
2964
  * @param {LightsNode} lightsNode - The current lights node.
2962
2965
  * @param {?{start: number, count: number}} group - Only relevant for objects using multiple materials. This represents a group entry from the respective `BufferGeometry`.
2963
2966
  * @param {ClippingContext} clippingContext - The clipping context.
2964
- * @param {?string} [passId=null] - An optional ID for identifying the pass.
2967
+ * @param {string} [passId] - An optional ID for identifying the pass.
2965
2968
  */
2966
2969
  _renderObjectDirect( object, material, scene, camera, lightsNode, group, clippingContext, passId ) {
2967
2970
 
@@ -3016,7 +3019,7 @@ class Renderer {
3016
3019
  * @param {LightsNode} lightsNode - The current lights node.
3017
3020
  * @param {?{start: number, count: number}} group - Only relevant for objects using multiple materials. This represents a group entry from the respective `BufferGeometry`.
3018
3021
  * @param {ClippingContext} clippingContext - The clipping context.
3019
- * @param {?string} [passId=null] - An optional ID for identifying the pass.
3022
+ * @param {string} [passId] - An optional ID for identifying the pass.
3020
3023
  */
3021
3024
  _createObjectPipeline( object, material, scene, camera, lightsNode, group, clippingContext, passId ) {
3022
3025
 
@@ -1,4 +1,4 @@
1
- import Binding from './Binding.js';
1
+ import Sampler from './Sampler.js';
2
2
 
3
3
  let _id = 0;
4
4
 
@@ -8,7 +8,7 @@ let _id = 0;
8
8
  * @private
9
9
  * @augments Binding
10
10
  */
11
- class SampledTexture extends Binding {
11
+ class SampledTexture extends Sampler {
12
12
 
13
13
  /**
14
14
  * Constructs a new sampled texture.
@@ -18,7 +18,7 @@ class SampledTexture extends Binding {
18
18
  */
19
19
  constructor( name, texture ) {
20
20
 
21
- super( name );
21
+ super( name, texture );
22
22
 
23
23
  /**
24
24
  * This identifier.
@@ -27,20 +27,6 @@ class SampledTexture extends Binding {
27
27
  */
28
28
  this.id = _id ++;
29
29
 
30
- /**
31
- * The texture this binding is referring to.
32
- *
33
- * @type {?Texture}
34
- */
35
- this.texture = texture;
36
-
37
- /**
38
- * The binding's version.
39
- *
40
- * @type {number}
41
- */
42
- this.version = texture ? texture.version : 0;
43
-
44
30
  /**
45
31
  * Whether the texture is a storage texture or not.
46
32
  *
@@ -49,15 +35,6 @@ class SampledTexture extends Binding {
49
35
  */
50
36
  this.store = false;
51
37
 
52
- /**
53
- * The binding's generation which is an additional version
54
- * qualifier.
55
- *
56
- * @type {?number}
57
- * @default null
58
- */
59
- this.generation = null;
60
-
61
38
  /**
62
39
  * This flag can be used for type testing.
63
40
  *
@@ -69,51 +46,6 @@ class SampledTexture extends Binding {
69
46
 
70
47
  }
71
48
 
72
- /**
73
- * Returns `true` whether this binding requires an update for the
74
- * given generation.
75
- *
76
- * @param {number} generation - The generation.
77
- * @return {boolean} Whether an update is required or not.
78
- */
79
- needsBindingsUpdate( generation ) {
80
-
81
- const { texture } = this;
82
-
83
- if ( generation !== this.generation ) {
84
-
85
- this.generation = generation;
86
-
87
- return true;
88
-
89
- }
90
-
91
- return texture.isVideoTexture;
92
-
93
- }
94
-
95
- /**
96
- * Updates the binding.
97
- *
98
- * @return {boolean} Whether the texture has been updated and must be
99
- * uploaded to the GPU.
100
- */
101
- update() {
102
-
103
- const { texture, version } = this;
104
-
105
- if ( version !== texture.version ) {
106
-
107
- this.version = texture.version;
108
-
109
- return true;
110
-
111
- }
112
-
113
- return false;
114
-
115
- }
116
-
117
49
  }
118
50
 
119
51
  /**
@@ -18,6 +18,17 @@ class Sampler extends Binding {
18
18
 
19
19
  super( name );
20
20
 
21
+ /**
22
+ * This function is called when the texture is disposed.
23
+ * @type {function}
24
+ * @private
25
+ */
26
+ this._onDisposeTexture = () => {
27
+
28
+ this.texture = null;
29
+
30
+ };
31
+
21
32
  /**
22
33
  * The texture the sampler is referring to.
23
34
  *
@@ -32,6 +43,15 @@ class Sampler extends Binding {
32
43
  */
33
44
  this.version = texture ? texture.version : 0;
34
45
 
46
+ /**
47
+ * The binding's generation which is an additional version
48
+ * qualifier.
49
+ *
50
+ * @type {?number}
51
+ * @default null
52
+ */
53
+ this.generation = null;
54
+
35
55
  /**
36
56
  * This flag can be used for type testing.
37
57
  *
@@ -43,6 +63,65 @@ class Sampler extends Binding {
43
63
 
44
64
  }
45
65
 
66
+ /**
67
+ * Sets the texture of this sampler.
68
+ * @param {?Texture} value - The texture to set.
69
+ */
70
+ set texture( value ) {
71
+
72
+ if ( this._texture === value ) return;
73
+
74
+ if ( this._texture ) {
75
+
76
+ this._texture.removeEventListener( 'dispose', this._onDisposeTexture );
77
+
78
+ }
79
+
80
+ this._texture = value;
81
+
82
+ this.generation = null;
83
+ this.version = 0;
84
+
85
+ if ( this._texture ) {
86
+
87
+ this._texture.addEventListener( 'dispose', this._onDisposeTexture );
88
+
89
+ }
90
+
91
+ }
92
+
93
+ /**
94
+ * Gets the texture of this sampler.
95
+ * @return {?Texture} The texture.
96
+ */
97
+ get texture() {
98
+
99
+ return this._texture;
100
+
101
+ }
102
+
103
+ /**
104
+ * Updates the binding.
105
+ *
106
+ * @return {boolean} Whether the texture has been updated and must be
107
+ * uploaded to the GPU.
108
+ */
109
+ update() {
110
+
111
+ const { texture, version } = this;
112
+
113
+ if ( version !== texture.version ) {
114
+
115
+ this.version = texture.version;
116
+
117
+ return true;
118
+
119
+ }
120
+
121
+ return false;
122
+
123
+ }
124
+
46
125
  }
47
126
 
48
127
  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;
@@ -366,9 +366,25 @@ class Textures extends DataMap {
366
366
 
367
367
  if ( image.image !== undefined ) image = image.image;
368
368
 
369
- target.width = image.width || 1;
370
- target.height = image.height || 1;
371
- target.depth = texture.isCubeTexture ? 6 : ( image.depth || 1 );
369
+ if ( image instanceof HTMLVideoElement ) {
370
+
371
+ target.width = image.videoWidth || 1;
372
+ target.height = image.videoHeight || 1;
373
+ target.depth = 1;
374
+
375
+ } else if ( image instanceof VideoFrame ) {
376
+
377
+ target.width = image.displayWidth || 1;
378
+ target.height = image.displayHeight || 1;
379
+ target.depth = 1;
380
+
381
+ } else {
382
+
383
+ target.width = image.width || 1;
384
+ target.height = image.height || 1;
385
+ target.depth = texture.isCubeTexture ? 6 : ( image.depth || 1 );
386
+
387
+ }
372
388
 
373
389
  } else {
374
390
 
@@ -171,6 +171,15 @@ class XRManager extends EventDispatcher {
171
171
  */
172
172
  this._supportsLayers = false;
173
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';
182
+
174
183
  this._frameBufferTargets = null;
175
184
 
176
185
  /**
@@ -357,7 +366,7 @@ class XRManager extends EventDispatcher {
357
366
  * @type {boolean}
358
367
  * @readonly
359
368
  */
360
- this._useLayers = ( typeof XRWebGLBinding !== 'undefined' && 'createProjectionLayer' in XRWebGLBinding.prototype ); // eslint-disable-line compat/compat
369
+ this._useLayers = ( this._supportsGlBinding && 'createProjectionLayer' in XRWebGLBinding.prototype ); // eslint-disable-line compat/compat
361
370
 
362
371
  /**
363
372
  * Whether the usage of multiview has been requested by the application or not.
@@ -915,9 +924,18 @@ class XRManager extends EventDispatcher {
915
924
 
916
925
  //
917
926
 
927
+ if ( this._supportsGlBinding ) {
928
+
929
+ const glBinding = new XRWebGLBinding( session, gl );
930
+ this._glBinding = glBinding;
931
+
932
+ }
933
+
934
+ //
935
+
918
936
  if ( this._useLayers === true ) {
919
937
 
920
- // default path using XRWebGLBinding/XRProjectionLayer
938
+ // default path using XRProjectionLayer
921
939
 
922
940
  let depthFormat = null;
923
941
  let depthType = null;
@@ -945,11 +963,9 @@ class XRManager extends EventDispatcher {
945
963
 
946
964
  }
947
965
 
948
- const glBinding = new XRWebGLBinding( session, gl );
949
- const glProjLayer = glBinding.createProjectionLayer( projectionlayerInit );
966
+ const glProjLayer = this._glBinding.createProjectionLayer( projectionlayerInit );
950
967
  const layersArray = [ glProjLayer ];
951
968
 
952
- this._glBinding = glBinding;
953
969
  this._glProjLayer = glProjLayer;
954
970
 
955
971
  renderer.setPixelRatio( 1 );
@@ -1095,9 +1111,11 @@ class XRManager extends EventDispatcher {
1095
1111
 
1096
1112
  }
1097
1113
 
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;
1114
+ // inherit camera layers and enable eye layers (1 = left, 2 = right)
1115
+ cameraXR.layers.mask = camera.layers.mask | 0b110;
1116
+ cameraL.layers.mask = cameraXR.layers.mask & 0b011;
1117
+ cameraR.layers.mask = cameraXR.layers.mask & 0b101;
1118
+
1101
1119
 
1102
1120
  const parent = camera.parent;
1103
1121
  const cameras = cameraXR.cameras;
@@ -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
  *
@@ -75,7 +75,17 @@ export default /* glsl */`
75
75
 
76
76
  float texture2DCompare( sampler2D depths, vec2 uv, float compare ) {
77
77
 
78
- return step( compare, unpackRGBAToDepth( texture2D( depths, uv ) ) );
78
+ float depth = unpackRGBAToDepth( texture2D( depths, uv ) );
79
+
80
+ #ifdef USE_REVERSEDEPTHBUF
81
+
82
+ return step( depth, compare );
83
+
84
+ #else
85
+
86
+ return step( compare, depth );
87
+
88
+ #endif
79
89
 
80
90
  }
81
91
 
@@ -91,7 +101,15 @@ export default /* glsl */`
91
101
 
92
102
  vec2 distribution = texture2DDistribution( shadow, uv );
93
103
 
94
- float hard_shadow = step( compare , distribution.x ); // Hard Shadow
104
+ #ifdef USE_REVERSEDEPTHBUF
105
+
106
+ float hard_shadow = step( distribution.x, compare ); // Hard Shadow
107
+
108
+ #else
109
+
110
+ float hard_shadow = step( compare , distribution.x ); // Hard Shadow
111
+
112
+ #endif
95
113
 
96
114
  if (hard_shadow != 1.0 ) {
97
115