Skip to content

Commit df42a7d

Browse files
authored
TSL: Share context between RTT (#28811)
1 parent 4210ee8 commit df42a7d

File tree

3 files changed

+41
-5
lines changed

3 files changed

+41
-5
lines changed

src/nodes/core/NodeBuilder.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,17 @@ class NodeBuilder {
395395

396396
}
397397

398+
getSharedContext() {
399+
400+
const context = { ...this.context };
401+
402+
delete context.keywords;
403+
delete context.material;
404+
405+
return this.context;
406+
407+
}
408+
398409
setCache( cache ) {
399410

400411
this.cache = cache;

src/nodes/display/GaussianBlurNode.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ class GaussianBlurNode extends TempNode {
155155
//
156156

157157
const material = this._material || ( this._material = builder.createNodeMaterial() );
158-
material.fragmentNode = blur();
158+
material.fragmentNode = blur().context( builder.getSharedContext() );
159+
material.needsUpdate = true;
159160

160161
//
161162

src/nodes/utils/RTTNode.js

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { RenderTarget } from '../../core/RenderTarget.js';
1010
import { Vector2 } from '../../math/Vector2.js';
1111
import { HalfFloatType } from '../../constants.js';
1212

13-
const _quadMesh = new QuadMesh( new NodeMaterial() );
1413
const _size = new Vector2();
1514

1615
class RTTNode extends TextureNode {
@@ -32,6 +31,9 @@ class RTTNode extends TextureNode {
3231

3332
this.updateMap = new WeakMap();
3433

34+
this._rttNode = null;
35+
this._quadMesh = new QuadMesh( new NodeMaterial() );
36+
3537
this.updateBeforeType = NodeUpdateType.RENDER;
3638

3739
}
@@ -42,17 +44,37 @@ class RTTNode extends TextureNode {
4244

4345
}
4446

47+
setup( builder ) {
48+
49+
this._rttNode = this.node.context( builder.getSharedContext() );
50+
this._quadMesh.material.needsUpdate = true;
51+
52+
return super.setup( builder );
53+
54+
}
55+
4556
setSize( width, height ) {
4657

4758
this.width = width;
4859
this.height = height;
4960

50-
this.renderTarget.setSize( width, height );
61+
const effectiveWidth = width * this.pixelRatio;
62+
const effectiveHeight = height * this.pixelRatio;
63+
64+
this.renderTarget.setSize( effectiveWidth, effectiveHeight );
5165

5266
this.textureNeedsUpdate = true;
5367

5468
}
5569

70+
setPixelRatio( pixelRatio ) {
71+
72+
this.pixelRatio = pixelRatio;
73+
74+
this.setSize( this.width, this.height );
75+
76+
}
77+
5678
updateBefore( { renderer } ) {
5779

5880
if ( this.textureNeedsUpdate === false && this.autoUpdate === false ) return;
@@ -63,6 +85,8 @@ class RTTNode extends TextureNode {
6385

6486
if ( this.autoSize === true ) {
6587

88+
this.pixelRatio = renderer.getPixelRatio();
89+
6690
const size = renderer.getSize( _size );
6791

6892
this.setSize( size.width, size.height );
@@ -71,15 +95,15 @@ class RTTNode extends TextureNode {
7195

7296
//
7397

74-
_quadMesh.material.fragmentNode = this.node;
98+
this._quadMesh.material.fragmentNode = this._rttNode;
7599

76100
//
77101

78102
const currentRenderTarget = renderer.getRenderTarget();
79103

80104
renderer.setRenderTarget( this.renderTarget );
81105

82-
_quadMesh.render( renderer );
106+
this._quadMesh.render( renderer );
83107

84108
renderer.setRenderTarget( currentRenderTarget );
85109

0 commit comments

Comments
 (0)