Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions src/nodes/accessors/TextureNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ class TextureNode extends UniformNode {

const textureNode = this.clone();
textureNode.uvNode = nodeObject( uvNode );
textureNode.referenceNode = this.getSelf();
textureNode.referenceNode = this.getBase();

return nodeObject( textureNode );

Expand Down Expand Up @@ -576,7 +576,7 @@ class TextureNode extends UniformNode {

const textureNode = this.clone();
textureNode.biasNode = nodeObject( amountNode ).mul( maxMipLevel( textureNode ) );
textureNode.referenceNode = this.getSelf();
textureNode.referenceNode = this.getBase();

const map = textureNode.value;

Expand All @@ -602,7 +602,7 @@ class TextureNode extends UniformNode {

const textureNode = this.clone();
textureNode.levelNode = nodeObject( levelNode );
textureNode.referenceNode = this.getSelf();
textureNode.referenceNode = this.getBase();

return nodeObject( textureNode );

Expand Down Expand Up @@ -630,12 +630,22 @@ class TextureNode extends UniformNode {

const textureNode = this.clone();
textureNode.biasNode = nodeObject( biasNode );
textureNode.referenceNode = this.getSelf();
textureNode.referenceNode = this.getBase();

return nodeObject( textureNode );

}

/**
* Returns the base texture of this node.
* @return {TextureNode} The base texture node.
*/
getBase() {

return this.referenceNode ? this.referenceNode.getBase() : this.getSelf();

}

/**
* Samples the texture by executing a compare operation.
*
Expand All @@ -646,7 +656,7 @@ class TextureNode extends UniformNode {

const textureNode = this.clone();
textureNode.compareNode = nodeObject( compareNode );
textureNode.referenceNode = this.getSelf();
textureNode.referenceNode = this.getBase();

return nodeObject( textureNode );

Expand All @@ -663,7 +673,7 @@ class TextureNode extends UniformNode {

const textureNode = this.clone();
textureNode.gradNode = [ nodeObject( gradNodeX ), nodeObject( gradNodeY ) ];
textureNode.referenceNode = this.getSelf();
textureNode.referenceNode = this.getBase();

return nodeObject( textureNode );

Expand All @@ -679,7 +689,7 @@ class TextureNode extends UniformNode {

const textureNode = this.clone();
textureNode.depthNode = nodeObject( depthNode );
textureNode.referenceNode = this.getSelf();
textureNode.referenceNode = this.getBase();

return nodeObject( textureNode );

Expand Down Expand Up @@ -779,7 +789,7 @@ export const texture = ( value = EmptyTexture, uvNode = null, levelNode = null,
if ( value && value.isTextureNode === true ) {

textureNode = nodeObject( value.clone() );
textureNode.referenceNode = value.getSelf(); // Ensure the reference is set to the original node
textureNode.referenceNode = value.getBase(); // Ensure the reference is set to the original node

if ( uvNode !== null ) textureNode.uvNode = nodeObject( uvNode );
if ( levelNode !== null ) textureNode.levelNode = nodeObject( levelNode );
Expand Down
6 changes: 6 additions & 0 deletions src/nodes/display/ViewportSharedTextureNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ class ViewportSharedTextureNode extends ViewportTextureNode {

}

getFrameBufferTexture() {

return _sharedFramebuffer;

}

updateReference() {

return this;
Expand Down
41 changes: 31 additions & 10 deletions src/nodes/display/ViewportTextureNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,43 +80,66 @@ class ViewportTextureNode extends TextureNode {
this.isOutputTextureNode = true;

/**
* The `updateBeforeType` is set to `NodeUpdateType.RENDER` since the node renders the
* scene once per render in its {@link ViewportTextureNode#updateBefore} method.
* The `updateBeforeType` is set to `NodeUpdateType.FRAME` since the node renders the
* scene once per frame in its {@link ViewportTextureNode#updateBefore} method.
*
* @type {string}
* @default 'frame'
*/
this.updateBeforeType = NodeUpdateType.RENDER;
this.updateBeforeType = NodeUpdateType.FRAME;

/**
* The framebuffer texture for the current renderer context.
*
* @type {WeakMap<RenderTarget, FramebufferTexture>}
* @private
*/
this._textures = new WeakMap();
this._cacheTextures = new WeakMap();

}

getFrameBufferTexture( reference = null ) {

const defaultFramebuffer = this.referenceNode ? this.referenceNode.defaultFramebuffer : this.defaultFramebuffer;
let defaultFramebuffer;
let cacheTextures;

if ( this.referenceNode ) {

defaultFramebuffer = this.referenceNode.defaultFramebuffer;
cacheTextures = this.referenceNode._cacheTextures;

} else {

defaultFramebuffer = this.defaultFramebuffer;
cacheTextures = this._cacheTextures;

}

if ( reference === null ) {

return defaultFramebuffer;

}

if ( this._textures.has( reference ) === false ) {
if ( cacheTextures.has( reference ) === false ) {

const framebufferTexture = defaultFramebuffer.clone();

this._textures.set( reference, framebufferTexture );
cacheTextures.set( reference, framebufferTexture );

}

return this._textures.get( reference );
return cacheTextures.get( reference );

}

updateReference( frame ) {

const renderTarget = frame.renderer.getRenderTarget();

this.value = this.getFrameBufferTexture( renderTarget );

return this.value;

}

Expand Down Expand Up @@ -156,8 +179,6 @@ class ViewportTextureNode extends TextureNode {

framebufferTexture.generateMipmaps = currentGenerateMipmaps;

this.value = framebufferTexture;

}

clone() {
Expand Down
Loading