|
1 | 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, output, mrt, textureLoad, screenCoordinate } from 'three/tsl'; |
| 2 | +import { add, float, If, Loop, int, Fn, min, max, clamp, nodeObject, texture, uniform, uv, vec2, vec4, luminance } from 'three/tsl'; |
3 | 3 |
|
4 | 4 | const _quadMesh = /*@__PURE__*/ new QuadMesh(); |
5 | 5 | const _size = /*@__PURE__*/ new Vector2(); |
@@ -105,15 +105,6 @@ class TRAAPassNode extends PassNode { |
105 | 105 | */ |
106 | 106 | this._historyRenderTarget = null; |
107 | 107 |
|
108 | | - /** |
109 | | - * The MRT for the transfer step. |
110 | | - * |
111 | | - * @private |
112 | | - * @type {?MRTNode} |
113 | | - * @default null |
114 | | - */ |
115 | | - this._transferMRT = null; |
116 | | - |
117 | 108 | /** |
118 | 109 | * Material used for the resolve step. |
119 | 110 | * |
@@ -213,21 +204,29 @@ class TRAAPassNode extends PassNode { |
213 | 204 |
|
214 | 205 | // configure velocity |
215 | 206 |
|
216 | | - const currentMRT = this.getMRT(); |
217 | | - const velocityOutput = currentMRT.get( 'velocity' ); |
| 207 | + const mrt = this.getMRT(); |
| 208 | + const velocityOutput = mrt.get( 'velocity' ); |
| 209 | + |
| 210 | + if ( velocityOutput !== undefined ) { |
218 | 211 |
|
219 | | - velocityOutput.setProjectionMatrix( this._originalProjectionMatrix ); |
| 212 | + velocityOutput.setProjectionMatrix( this._originalProjectionMatrix ); |
| 213 | + |
| 214 | + } else { |
| 215 | + |
| 216 | + throw new Error( 'THREE:TRAAPassNode: Missing velocity output in MRT configuration.' ); |
| 217 | + |
| 218 | + } |
220 | 219 |
|
221 | 220 | // render sample |
222 | 221 |
|
223 | | - renderer.setMRT( currentMRT ); |
| 222 | + renderer.setMRT( mrt ); |
224 | 223 |
|
225 | 224 | renderer.setClearColor( this.clearColor, this.clearAlpha ); |
226 | 225 | renderer.setRenderTarget( this._sampleRenderTarget ); |
227 | 226 | renderer.render( scene, camera ); |
228 | 227 |
|
229 | 228 | renderer.setRenderTarget( null ); |
230 | | - renderer.setMRT( this._transferMRT ); |
| 229 | + renderer.setMRT( null ); |
231 | 230 |
|
232 | 231 | // every time when the dimensions change we need fresh history data. Copy the sample |
233 | 232 | // into the history and final render target (no AA happens at that point). |
@@ -313,49 +312,19 @@ class TRAAPassNode extends PassNode { |
313 | 312 | this._sampleRenderTarget.texture.minFiler = NearestFilter; |
314 | 313 | this._sampleRenderTarget.texture.magFilter = NearestFilter; |
315 | 314 |
|
316 | | - const currentMRT = this.getMRT(); |
317 | | - |
318 | | - if ( currentMRT === null ) { |
319 | | - |
320 | | - throw new Error( 'THREE:TRAAPassNode: Missing MRT configuration.' ); |
| 315 | + const velocityTarget = this._sampleRenderTarget.texture.clone(); |
| 316 | + velocityTarget.isRenderTargetTexture = true; |
| 317 | + velocityTarget.name = 'velocity'; |
321 | 318 |
|
322 | | - } else if ( currentMRT.has( 'velocity' ) === false ) { |
323 | | - |
324 | | - throw new Error( 'THREE:TRAAPassNode: Missing velocity output in MRT configuration.' ); |
325 | | - |
326 | | - } |
327 | | - |
328 | | - this._texturesIndex = currentMRT.getIndexes( this.renderTarget ); |
329 | | - |
330 | | - const transferNodes = {}; |
331 | | - |
332 | | - for ( const name in this._texturesIndex ) { |
333 | | - |
334 | | - if ( name === 'output' ) { |
335 | | - |
336 | | - transferNodes[ name ] = output; |
337 | | - |
338 | | - } else { |
339 | | - |
340 | | - const index = this._texturesIndex[ name ]; |
341 | | - |
342 | | - transferNodes[ name ] = textureLoad( this._sampleRenderTarget.textures[ index ], screenCoordinate ); |
343 | | - |
344 | | - } |
345 | | - |
346 | | - } |
347 | | - |
348 | | - this._transferMRT = mrt( transferNodes ); |
| 319 | + this._sampleRenderTarget.textures.push( velocityTarget ); // for MRT |
349 | 320 |
|
350 | 321 | } |
351 | 322 |
|
352 | 323 | // textures |
353 | 324 |
|
354 | | - const velocityIndex = this._texturesIndex[ 'velocity' ]; |
355 | | - |
356 | 325 | const historyTexture = texture( this._historyRenderTarget.texture ); |
357 | 326 | const sampleTexture = texture( this._sampleRenderTarget.textures[ 0 ] ); |
358 | | - const velocityTexture = texture( this._sampleRenderTarget.textures[ velocityIndex ] ); |
| 327 | + const velocityTexture = texture( this._sampleRenderTarget.textures[ 1 ] ); |
359 | 328 | const depthTexture = texture( this._sampleRenderTarget.depthTexture ); |
360 | 329 |
|
361 | 330 | const resolve = Fn( () => { |
@@ -426,7 +395,7 @@ class TRAAPassNode extends PassNode { |
426 | 395 |
|
427 | 396 | // materials |
428 | 397 |
|
429 | | - this._resolveMaterial.colorNode = resolve(); |
| 398 | + this._resolveMaterial.fragmentNode = resolve(); |
430 | 399 |
|
431 | 400 | return super.setup( builder ); |
432 | 401 |
|
|
0 commit comments