@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,5 +1,5 @@
1
- import { Color, Vector2, NearestFilter, Matrix4, RendererUtils, PassNode, QuadMesh, NodeMaterial } from 'three/webgpu';
2
- import { add, float, If, Loop, int, Fn, min, max, clamp, nodeObject, texture, uniform, uv, vec2, vec4, luminance } from 'three/tsl';
1
+ import { HalfFloatType, Vector2, RenderTarget, RendererUtils, QuadMesh, NodeMaterial, TempNode, NodeUpdateType, Matrix4 } from 'three/webgpu';
2
+ import { add, float, If, Loop, int, Fn, min, max, clamp, nodeObject, texture, uniform, uv, vec2, vec4, luminance, convertToTexture, passTexture, velocity } from 'three/tsl';
3
3
 
4
4
  const _quadMesh = /*@__PURE__*/ new QuadMesh();
5
5
  const _size = /*@__PURE__*/ new Vector2();
@@ -8,34 +8,34 @@ let _rendererState;
8
8
 
9
9
 
10
10
  /**
11
- * A special render pass node that renders the scene with TRAA (Temporal Reprojection Anti-Aliasing).
12
- *
13
- * Note: The current implementation does not yet support MRT setups.
11
+ * A special node that applies TRAA (Temporal Reprojection Anti-Aliasing).
14
12
  *
15
13
  * References:
16
14
  * - {@link https://alextardif.com/TAA.html}
17
15
  * - {@link https://www.elopezr.com/temporal-aa-and-the-quest-for-the-holy-trail/}
18
16
  *
19
- * @augments PassNode
20
- * @three_import import { traaPass } from 'three/addons/tsl/display/TRAAPassNode.js';
17
+ * @augments TempNode
18
+ * @three_import import { traa } from 'three/addons/tsl/display/TRAANode.js';
21
19
  */
22
- class TRAAPassNode extends PassNode {
20
+ class TRAANode extends TempNode {
23
21
 
24
22
  static get type() {
25
23
 
26
- return 'TRAAPassNode';
24
+ return 'TRAANode';
27
25
 
28
26
  }
29
27
 
30
28
  /**
31
- * Constructs a new TRAA pass node.
29
+ * Constructs a new TRAA node.
32
30
  *
33
- * @param {Scene} scene - The scene to render.
34
- * @param {Camera} camera - The camera to render the scene with.
31
+ * @param {TextureNode} beautyNode - The texture node that represents the input of the effect.
32
+ * @param {TextureNode} depthNode - A node that represents the scene's depth.
33
+ * @param {TextureNode} velocityNode - A node that represents the scene's velocity.
34
+ * @param {Camera} camera - The camera the scene is rendered with.
35
35
  */
36
- constructor( scene, camera ) {
36
+ constructor( beautyNode, depthNode, velocityNode, camera ) {
37
37
 
38
- super( PassNode.COLOR, scene, camera );
38
+ super( 'vec4' );
39
39
 
40
40
  /**
41
41
  * This flag can be used for type testing.
@@ -44,40 +44,53 @@ class TRAAPassNode extends PassNode {
44
44
  * @readonly
45
45
  * @default true
46
46
  */
47
- this.isTRAAPassNode = true;
47
+ this.isTRAANode = true;
48
48
 
49
49
  /**
50
- * The clear color of the pass.
50
+ * The `updateBeforeType` is set to `NodeUpdateType.FRAME` since the node renders
51
+ * its effect once per frame in `updateBefore()`.
51
52
  *
52
- * @type {Color}
53
- * @default 0x000000
53
+ * @type {string}
54
+ * @default 'frame'
54
55
  */
55
- this.clearColor = new Color( 0x000000 );
56
+ this.updateBeforeType = NodeUpdateType.FRAME;
56
57
 
57
58
  /**
58
- * The clear alpha of the pass.
59
+ * The texture node that represents the input of the effect.
59
60
  *
60
- * @type {number}
61
- * @default 0
61
+ * @type {TextureNode}
62
62
  */
63
- this.clearAlpha = 0;
63
+ this.beautyNode = beautyNode;
64
64
 
65
65
  /**
66
- * The jitter index selects the current camera offset value.
66
+ * A node that represents the scene's velocity.
67
67
  *
68
- * @private
69
- * @type {number}
70
- * @default 0
68
+ * @type {TextureNode}
71
69
  */
72
- this._jitterIndex = 0;
70
+ this.depthNode = depthNode;
73
71
 
74
72
  /**
75
- * Used to save the original/unjittered projection matrix.
73
+ * A node that represents the scene's velocity.
74
+ *
75
+ * @type {TextureNode}
76
+ */
77
+ this.velocityNode = velocityNode;
78
+
79
+ /**
80
+ * The camera the scene is rendered with.
81
+ *
82
+ * @type {TextureNode}
83
+ */
84
+ this.camera = camera;
85
+
86
+ /**
87
+ * The jitter index selects the current camera offset value.
76
88
  *
77
89
  * @private
78
- * @type {Matrix4}
90
+ * @type {number}
91
+ * @default 0
79
92
  */
80
- this._originalProjectionMatrix = new Matrix4();
93
+ this._jitterIndex = 0;
81
94
 
82
95
  /**
83
96
  * A uniform node holding the inverse resolution value.
@@ -88,22 +101,22 @@ class TRAAPassNode extends PassNode {
88
101
  this._invSize = uniform( new Vector2() );
89
102
 
90
103
  /**
91
- * The render target that holds the current sample.
104
+ * The render target that represents the history of frame data.
92
105
  *
93
106
  * @private
94
107
  * @type {?RenderTarget}
95
- * @default null
96
108
  */
97
- this._sampleRenderTarget = null;
109
+ this._historyRenderTarget = new RenderTarget( 1, 1, { depthBuffer: false, type: HalfFloatType } );
110
+ this._historyRenderTarget.texture.name = 'TRAANode.history';
98
111
 
99
112
  /**
100
- * The render target that represents the history of frame data.
113
+ * The render target for the resolve.
101
114
  *
102
115
  * @private
103
116
  * @type {?RenderTarget}
104
- * @default null
105
117
  */
106
- this._historyRenderTarget = null;
118
+ this._resolveRenderTarget = new RenderTarget( 1, 1, { depthBuffer: false, type: HalfFloatType } );
119
+ this._resolveRenderTarget.texture.name = 'TRAANode.resolve';
107
120
 
108
121
  /**
109
122
  * Material used for the resolve step.
@@ -112,7 +125,41 @@ class TRAAPassNode extends PassNode {
112
125
  * @type {NodeMaterial}
113
126
  */
114
127
  this._resolveMaterial = new NodeMaterial();
115
- this._resolveMaterial.name = 'TRAA.Resolve';
128
+ this._resolveMaterial.name = 'TRAA.resolve';
129
+
130
+ /**
131
+ * The result of the effect is represented as a separate texture node.
132
+ *
133
+ * @private
134
+ * @type {PassTextureNode}
135
+ */
136
+ this._textureNode = passTexture( this, this._resolveRenderTarget.texture );
137
+
138
+ /**
139
+ * Used to save the original/unjittered projection matrix.
140
+ *
141
+ * @private
142
+ * @type {Matrix4}
143
+ */
144
+ this._originalProjectionMatrix = new Matrix4();
145
+
146
+ /**
147
+ * Sync the post processing stack with the TRAA node.
148
+ * @private
149
+ * @type {boolean}
150
+ */
151
+ this._needsPostProcessingSync = false;
152
+
153
+ }
154
+
155
+ /**
156
+ * Returns the result of the effect as a texture node.
157
+ *
158
+ * @return {PassTextureNode} A texture node that represents the result of the effect.
159
+ */
160
+ getTextureNode() {
161
+
162
+ return this._textureNode;
116
163
 
117
164
  }
118
165
 
@@ -121,78 +168,48 @@ class TRAAPassNode extends PassNode {
121
168
  *
122
169
  * @param {number} width - The width of the effect.
123
170
  * @param {number} height - The height of the effect.
124
- * @return {boolean} Whether the TRAA needs a restart or not. That is required after a resize since buffer data with different sizes can't be resolved.
125
171
  */
126
172
  setSize( width, height ) {
127
173
 
128
- super.setSize( width, height );
129
-
130
- let needsRestart = false;
131
-
132
- if ( this.renderTarget.width !== this._sampleRenderTarget.width || this.renderTarget.height !== this._sampleRenderTarget.height ) {
133
-
134
- this._sampleRenderTarget.setSize( this.renderTarget.width, this.renderTarget.height );
135
- this._historyRenderTarget.setSize( this.renderTarget.width, this.renderTarget.height );
136
-
137
- this._invSize.value.set( 1 / this.renderTarget.width, 1 / this.renderTarget.height );
138
-
139
- needsRestart = true;
140
-
141
- }
174
+ this._historyRenderTarget.setSize( width, height );
175
+ this._resolveRenderTarget.setSize( width, height );
142
176
 
143
- return needsRestart;
177
+ this._invSize.value.set( 1 / width, 1 / height );
144
178
 
145
179
  }
146
180
 
147
181
  /**
148
- * This method is used to render the effect once per frame.
182
+ * Defines the TRAA's current jitter as a view offset
183
+ * to the scene's camera.
149
184
  *
150
- * @param {NodeFrame} frame - The current node frame.
185
+ * @param {number} width - The width of the effect.
186
+ * @param {number} height - The height of the effect.
151
187
  */
152
- updateBefore( frame ) {
153
-
154
- const { renderer } = frame;
155
- const { scene, camera } = this;
156
-
157
- _rendererState = RendererUtils.resetRendererState( renderer, _rendererState );
158
-
159
- //
160
-
161
- this._pixelRatio = renderer.getPixelRatio();
162
- const size = renderer.getSize( _size );
163
-
164
- const needsRestart = this.setSize( size.width, size.height );
188
+ setViewOffset( width, height ) {
165
189
 
166
190
  // save original/unjittered projection matrix for velocity pass
167
191
 
168
- camera.updateProjectionMatrix();
169
- this._originalProjectionMatrix.copy( camera.projectionMatrix );
192
+ this.camera.updateProjectionMatrix();
193
+ this._originalProjectionMatrix.copy( this.camera.projectionMatrix );
170
194
 
171
- // camera configuration
195
+ velocity.setProjectionMatrix( this._originalProjectionMatrix );
172
196
 
173
- this._cameraNear.value = camera.near;
174
- this._cameraFar.value = camera.far;
175
-
176
- // configure jitter as view offset
197
+ //
177
198
 
178
199
  const viewOffset = {
179
200
 
180
- fullWidth: this.renderTarget.width,
181
- fullHeight: this.renderTarget.height,
201
+ fullWidth: width,
202
+ fullHeight: height,
182
203
  offsetX: 0,
183
204
  offsetY: 0,
184
- width: this.renderTarget.width,
185
- height: this.renderTarget.height
205
+ width: width,
206
+ height: height
186
207
 
187
208
  };
188
209
 
189
- const originalViewOffset = Object.assign( {}, camera.view );
190
-
191
- if ( originalViewOffset.enabled ) Object.assign( viewOffset, originalViewOffset );
192
-
193
210
  const jitterOffset = _JitterVectors[ this._jitterIndex ];
194
211
 
195
- camera.setViewOffset(
212
+ this.camera.setViewOffset(
196
213
 
197
214
  viewOffset.fullWidth, viewOffset.fullHeight,
198
215
 
@@ -202,95 +219,88 @@ class TRAAPassNode extends PassNode {
202
219
 
203
220
  );
204
221
 
205
- // configure velocity
206
-
207
- const mrt = this.getMRT();
208
- const velocityOutput = mrt.get( 'velocity' );
209
-
210
- if ( velocityOutput !== undefined ) {
211
-
212
- velocityOutput.setProjectionMatrix( this._originalProjectionMatrix );
213
-
214
- } else {
215
-
216
- throw new Error( 'THREE:TRAAPassNode: Missing velocity output in MRT configuration.' );
217
-
218
- }
219
-
220
- // render sample
222
+ }
221
223
 
222
- renderer.setMRT( mrt );
224
+ /**
225
+ * Clears the view offset from the scene's camera.
226
+ */
227
+ clearViewOffset() {
223
228
 
224
- renderer.setClearColor( this.clearColor, this.clearAlpha );
225
- renderer.setRenderTarget( this._sampleRenderTarget );
226
- renderer.render( scene, camera );
229
+ this.camera.clearViewOffset();
227
230
 
228
- renderer.setRenderTarget( null );
229
- renderer.setMRT( null );
231
+ velocity.setProjectionMatrix( null );
230
232
 
231
- // every time when the dimensions change we need fresh history data. Copy the sample
232
- // into the history and final render target (no AA happens at that point).
233
+ // update jitter index
233
234
 
234
- if ( needsRestart === true ) {
235
+ this._jitterIndex ++;
236
+ this._jitterIndex = this._jitterIndex % ( _JitterVectors.length - 1 );
235
237
 
236
- // bind and clear render target to make sure they are initialized after the resize which triggers a dispose()
238
+ }
237
239
 
238
- renderer.setRenderTarget( this._historyRenderTarget );
239
- renderer.clear();
240
+ /**
241
+ * This method is used to render the effect once per frame.
242
+ *
243
+ * @param {NodeFrame} frame - The current node frame.
244
+ */
245
+ updateBefore( frame ) {
240
246
 
241
- renderer.setRenderTarget( this.renderTarget );
242
- renderer.clear();
247
+ const { renderer } = frame;
243
248
 
244
- renderer.setRenderTarget( null );
249
+ // keep the TRAA in sync with the dimensions of the beauty node
245
250
 
246
- renderer.copyTextureToTexture( this._sampleRenderTarget.texture, this._historyRenderTarget.texture );
247
- renderer.copyTextureToTexture( this._sampleRenderTarget.texture, this.renderTarget.texture );
251
+ const beautyRenderTarget = ( this.beautyNode.isRTTNode ) ? this.beautyNode.renderTarget : this.beautyNode.passNode.renderTarget;
248
252
 
249
- } else {
253
+ const width = beautyRenderTarget.texture.width;
254
+ const height = beautyRenderTarget.texture.height;
250
255
 
251
- // resolve
256
+ //
252
257
 
253
- renderer.setRenderTarget( this.renderTarget );
254
- _quadMesh.material = this._resolveMaterial;
255
- _quadMesh.render( renderer );
256
- renderer.setRenderTarget( null );
258
+ if ( this._needsPostProcessingSync === true ) {
257
259
 
258
- // update history
260
+ this.setViewOffset( width, height );
259
261
 
260
- renderer.copyTextureToTexture( this.renderTarget.texture, this._historyRenderTarget.texture );
262
+ this._needsPostProcessingSync = false;
261
263
 
262
264
  }
263
265
 
264
- // copy depth
266
+ _rendererState = RendererUtils.resetRendererState( renderer, _rendererState );
267
+
268
+ //
265
269
 
266
- renderer.copyTextureToTexture( this._sampleRenderTarget.depthTexture, this.renderTarget.depthTexture );
270
+ const needsRestart = this._historyRenderTarget.width !== width || this._historyRenderTarget.height !== height;
271
+ this.setSize( width, height );
267
272
 
268
- // update jitter index
273
+ // every time when the dimensions change we need fresh history data
269
274
 
270
- this._jitterIndex ++;
271
- this._jitterIndex = this._jitterIndex % ( _JitterVectors.length - 1 );
275
+ if ( needsRestart === true ) {
272
276
 
273
- // restore
277
+ // bind and clear render target to make sure they are initialized after the resize which triggers a dispose()
274
278
 
275
- if ( originalViewOffset.enabled ) {
279
+ renderer.setRenderTarget( this._historyRenderTarget );
280
+ renderer.clear();
276
281
 
277
- camera.setViewOffset(
282
+ renderer.setRenderTarget( this._resolveRenderTarget );
283
+ renderer.clear();
278
284
 
279
- originalViewOffset.fullWidth, originalViewOffset.fullHeight,
285
+ // make sure to reset the history with the contents of the beauty buffer otherwise subsequent frames after the
286
+ // resize will fade from a darker color to the correct one because the history was cleared with black.
280
287
 
281
- originalViewOffset.offsetX, originalViewOffset.offsetY,
288
+ renderer.copyTextureToTexture( beautyRenderTarget.texture, this._historyRenderTarget.texture );
282
289
 
283
- originalViewOffset.width, originalViewOffset.height
290
+ }
284
291
 
285
- );
292
+ // resolve
286
293
 
287
- } else {
294
+ renderer.setRenderTarget( this._resolveRenderTarget );
295
+ _quadMesh.material = this._resolveMaterial;
296
+ _quadMesh.render( renderer );
297
+ renderer.setRenderTarget( null );
288
298
 
289
- camera.clearViewOffset();
299
+ // update history
290
300
 
291
- }
301
+ renderer.copyTextureToTexture( this._resolveRenderTarget.texture, this._historyRenderTarget.texture );
292
302
 
293
- velocityOutput.setProjectionMatrix( null );
303
+ // restore
294
304
 
295
305
  RendererUtils.restoreRendererState( renderer, _rendererState );
296
306
 
@@ -304,28 +314,31 @@ class TRAAPassNode extends PassNode {
304
314
  */
305
315
  setup( builder ) {
306
316
 
307
- if ( this._sampleRenderTarget === null ) {
317
+ const postProcessing = builder.context.postProcessing;
308
318
 
309
- this._sampleRenderTarget = this.renderTarget.clone();
310
- this._historyRenderTarget = this.renderTarget.clone();
319
+ if ( postProcessing ) {
311
320
 
312
- this._sampleRenderTarget.texture.minFiler = NearestFilter;
313
- this._sampleRenderTarget.texture.magFilter = NearestFilter;
321
+ this._needsPostProcessingSync = true;
314
322
 
315
- const velocityTarget = this._sampleRenderTarget.texture.clone();
316
- velocityTarget.isRenderTargetTexture = true;
317
- velocityTarget.name = 'velocity';
323
+ postProcessing.context.onBeforePostProcessing = () => {
318
324
 
319
- this._sampleRenderTarget.textures.push( velocityTarget ); // for MRT
325
+ const size = builder.renderer.getDrawingBufferSize( _size );
326
+ this.setViewOffset( size.width, size.height );
320
327
 
321
- }
328
+ };
322
329
 
323
- // textures
330
+ postProcessing.context.onAfterPostProcessing = () => {
331
+
332
+ this.clearViewOffset();
333
+
334
+ };
335
+
336
+ }
324
337
 
325
338
  const historyTexture = texture( this._historyRenderTarget.texture );
326
- const sampleTexture = texture( this._sampleRenderTarget.textures[ 0 ] );
327
- const velocityTexture = texture( this._sampleRenderTarget.textures[ 1 ] );
328
- const depthTexture = texture( this._sampleRenderTarget.depthTexture );
339
+ const sampleTexture = this.beautyNode;
340
+ const depthTexture = this.depthNode;
341
+ const velocityTexture = this.velocityNode;
329
342
 
330
343
  const resolve = Fn( () => {
331
344
 
@@ -395,9 +408,9 @@ class TRAAPassNode extends PassNode {
395
408
 
396
409
  // materials
397
410
 
398
- this._resolveMaterial.fragmentNode = resolve();
411
+ this._resolveMaterial.colorNode = resolve();
399
412
 
400
- return super.setup( builder );
413
+ return this._textureNode;
401
414
 
402
415
  }
403
416
 
@@ -407,14 +420,8 @@ class TRAAPassNode extends PassNode {
407
420
  */
408
421
  dispose() {
409
422
 
410
- super.dispose();
411
-
412
- if ( this._sampleRenderTarget !== null ) {
413
-
414
- this._sampleRenderTarget.dispose();
415
- this._historyRenderTarget.dispose();
416
-
417
- }
423
+ this._historyRenderTarget.dispose();
424
+ this._resolveRenderTarget.dispose();
418
425
 
419
426
  this._resolveMaterial.dispose();
420
427
 
@@ -422,7 +429,7 @@ class TRAAPassNode extends PassNode {
422
429
 
423
430
  }
424
431
 
425
- export default TRAAPassNode;
432
+ export default TRAANode;
426
433
 
427
434
  // These jitter vectors are specified in integers because it is easier.
428
435
  // I am assuming a [-8,8) integer grid, but it needs to be mapped onto [-0.5,0.5)
@@ -441,12 +448,14 @@ const _JitterVectors = [
441
448
  ];
442
449
 
443
450
  /**
444
- * TSL function for creating a TRAA pass node for Temporal Reprojection Anti-Aliasing.
451
+ * TSL function for creating a TRAA node for Temporal Reprojection Anti-Aliasing.
445
452
  *
446
453
  * @tsl
447
454
  * @function
448
- * @param {Scene} scene - The scene to render.
449
- * @param {Camera} camera - The camera to render the scene with.
450
- * @returns {TRAAPassNode}
455
+ * @param {TextureNode} beautyNode - The texture node that represents the input of the effect.
456
+ * @param {TextureNode} depthNode - A node that represents the scene's depth.
457
+ * @param {TextureNode} velocityNode - A node that represents the scene's velocity.
458
+ * @param {Camera} camera - The camera the scene is rendered with.
459
+ * @returns {TRAANode}
451
460
  */
452
- export const traaPass = ( scene, camera ) => nodeObject( new TRAAPassNode( scene, camera ) );
461
+ export const traa = ( beautyNode, depthNode, velocityNode, camera ) => nodeObject( new TRAANode( convertToTexture( beautyNode ), depthNode, velocityNode, camera ) );
@@ -322,7 +322,7 @@ class TiledLightsNode extends LightsNode {
322
322
  const lightsTexture = new DataTexture( lightsData, lightsData.length / 8, 2, RGBAFormat, FloatType );
323
323
 
324
324
  const lightIndexesArray = new Int32Array( count * 4 * 2 );
325
- const lightIndexes = attributeArray( lightIndexesArray, 'ivec4' ).label( 'lightIndexes' );
325
+ const lightIndexes = attributeArray( lightIndexesArray, 'ivec4' ).setName( 'lightIndexes' );
326
326
 
327
327
  // compute
328
328
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plastic-software/three",
3
- "version": "0.178.0",
3
+ "version": "0.179.0",
4
4
  "description": "JavaScript 3D library",
5
5
  "type": "module",
6
6
  "main": "./build/three.cjs",
package/src/Three.Core.js CHANGED
@@ -103,6 +103,7 @@ export { Raycaster } from './core/Raycaster.js';
103
103
  export { Layers } from './core/Layers.js';
104
104
  export { EventDispatcher } from './core/EventDispatcher.js';
105
105
  export { Clock } from './core/Clock.js';
106
+ export { Timer } from './core/Timer.js';
106
107
  export { QuaternionLinearInterpolant } from './math/interpolants/QuaternionLinearInterpolant.js';
107
108
  export { LinearInterpolant } from './math/interpolants/LinearInterpolant.js';
108
109
  export { DiscreteInterpolant } from './math/interpolants/DiscreteInterpolant.js';