From cd6fef4ec130461ba91c40d9fe623d2eca2fe8bc Mon Sep 17 00:00:00 2001 From: aardgoose Date: Wed, 21 Aug 2024 11:39:07 +0100 Subject: [PATCH 1/3] isolate --- src/core/RenderTarget.js | 6 ++++++ src/nodes/display/AfterImageNode.js | 1 + src/nodes/display/BloomNode.js | 2 ++ src/nodes/display/GaussianBlurNode.js | 12 ++++++------ src/renderers/common/RenderContexts.js | 2 ++ 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/core/RenderTarget.js b/src/core/RenderTarget.js index ab1c352b7733ff..b8422782bc7c44 100644 --- a/src/core/RenderTarget.js +++ b/src/core/RenderTarget.js @@ -4,6 +4,8 @@ import { LinearFilter } from '../constants.js'; import { Vector4 } from '../math/Vector4.js'; import { Source } from '../textures/Source.js'; +let _RenderTargetId = 0; + /* In options, we can specify: * Texture parameters for an auto-generated target texture @@ -26,6 +28,8 @@ class RenderTarget extends EventDispatcher { this.viewport = new Vector4( 0, 0, width, height ); + Object.defineProperty( this, 'id', { value: _RenderTargetId ++ } ); + const image = { width: width, height: height, depth: 1 }; options = Object.assign( { @@ -67,6 +71,8 @@ class RenderTarget extends EventDispatcher { this.samples = options.samples; + this.isolate = false; + } get texture() { diff --git a/src/nodes/display/AfterImageNode.js b/src/nodes/display/AfterImageNode.js index 3ed4bca762c846..49720994fcdba7 100644 --- a/src/nodes/display/AfterImageNode.js +++ b/src/nodes/display/AfterImageNode.js @@ -27,6 +27,7 @@ class AfterImageNode extends TempNode { this._compRT = new RenderTarget(); this._compRT.texture.name = 'AfterImageNode.comp'; + this._compRT.isolate = true; this._oldRT = new RenderTarget(); this._oldRT.texture.name = 'AfterImageNode.old'; diff --git a/src/nodes/display/BloomNode.js b/src/nodes/display/BloomNode.js index 9b54ecaf869626..2453c09bfe2ac5 100644 --- a/src/nodes/display/BloomNode.js +++ b/src/nodes/display/BloomNode.js @@ -57,6 +57,7 @@ class BloomNode extends TempNode { renderTargetHorizontal.texture.name = 'UnrealBloomPass.h' + i; renderTargetHorizontal.texture.generateMipmaps = false; + renderTargetHorizontal.isolate = true; this._renderTargetsHorizontal.push( renderTargetHorizontal ); @@ -64,6 +65,7 @@ class BloomNode extends TempNode { renderTargetVertical.texture.name = 'UnrealBloomPass.v' + i; renderTargetVertical.texture.generateMipmaps = false; + renderTargetVertical.isolate = true; this._renderTargetsVertical.push( renderTargetVertical ); diff --git a/src/nodes/display/GaussianBlurNode.js b/src/nodes/display/GaussianBlurNode.js index 797734a3e1caa8..5e156168225387 100644 --- a/src/nodes/display/GaussianBlurNode.js +++ b/src/nodes/display/GaussianBlurNode.js @@ -13,8 +13,7 @@ import { RenderTarget } from '../../core/RenderTarget.js'; // WebGPU: The use of a single QuadMesh for both gaussian blur passes results in a single RenderObject with a SampledTexture binding that // alternates between source textures and triggers creation of new BindGroups and BindGroupLayouts every frame. -const _quadMesh1 = /*@__PURE__*/ new QuadMesh(); -const _quadMesh2 = /*@__PURE__*/ new QuadMesh(); +const _quadMesh = /*@__PURE__*/ new QuadMesh(); class GaussianBlurNode extends TempNode { @@ -34,6 +33,8 @@ class GaussianBlurNode extends TempNode { this._verticalRT = new RenderTarget(); this._verticalRT.texture.name = 'GaussianBlurNode.vertical'; + this._verticalRT.isolate = true; + this._textureNode = passTexture( this, this._verticalRT.texture ); this.updateBeforeType = NodeUpdateType.RENDER; @@ -65,8 +66,7 @@ class GaussianBlurNode extends TempNode { const currentTexture = textureNode.value; - _quadMesh1.material = this._material; - _quadMesh2.material = this._material; + _quadMesh.material = this._material; this.setSize( map.image.width, map.image.height ); @@ -85,7 +85,7 @@ class GaussianBlurNode extends TempNode { this._passDirection.value.set( 1, 0 ); - _quadMesh1.render( renderer ); + _quadMesh.render( renderer ); // vertical @@ -94,7 +94,7 @@ class GaussianBlurNode extends TempNode { this._passDirection.value.set( 0, 1 ); - _quadMesh2.render( renderer ); + _quadMesh.render( renderer ); // restore diff --git a/src/renderers/common/RenderContexts.js b/src/renderers/common/RenderContexts.js index cdbfc8c26d8100..435908f366b11c 100644 --- a/src/renderers/common/RenderContexts.js +++ b/src/renderers/common/RenderContexts.js @@ -26,6 +26,8 @@ class RenderContexts { attachmentState = `${ count }:${ format }:${ renderTarget.samples }:${ renderTarget.depthBuffer }:${ renderTarget.stencilBuffer }`; + if ( renderTarget.isolate === true ) attachmentState += `:${ renderTarget.id }`; + } const chainMap = this.getChainMap( attachmentState ); From 67487c7aa4a0cdaa4b23179b909e681eaab342f6 Mon Sep 17 00:00:00 2001 From: aardgoose Date: Wed, 21 Aug 2024 14:50:34 +0100 Subject: [PATCH 2/3] include PMREMGenerator --- src/renderers/common/extras/PMREMGenerator.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/renderers/common/extras/PMREMGenerator.js b/src/renderers/common/extras/PMREMGenerator.js index d57b31fdeff59a..1db1b776743f1d 100644 --- a/src/renderers/common/extras/PMREMGenerator.js +++ b/src/renderers/common/extras/PMREMGenerator.js @@ -692,6 +692,7 @@ function _createRenderTarget( width, height, params ) { cubeUVRenderTarget.texture.name = 'PMREM.cubeUv'; cubeUVRenderTarget.texture.isPMREMTexture = true; cubeUVRenderTarget.scissorTest = true; + cubeUVRenderTarget.isolate = true; return cubeUVRenderTarget; } From 924f4d922c3ce1f286998d19072cd30260710233 Mon Sep 17 00:00:00 2001 From: aardgoose Date: Wed, 21 Aug 2024 14:53:56 +0100 Subject: [PATCH 3/3] remove redundant comment --- src/nodes/display/GaussianBlurNode.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/nodes/display/GaussianBlurNode.js b/src/nodes/display/GaussianBlurNode.js index 5e156168225387..4a058794c86f45 100644 --- a/src/nodes/display/GaussianBlurNode.js +++ b/src/nodes/display/GaussianBlurNode.js @@ -10,9 +10,6 @@ import QuadMesh from '../../renderers/common/QuadMesh.js'; import { Vector2 } from '../../math/Vector2.js'; import { RenderTarget } from '../../core/RenderTarget.js'; -// WebGPU: The use of a single QuadMesh for both gaussian blur passes results in a single RenderObject with a SampledTexture binding that -// alternates between source textures and triggers creation of new BindGroups and BindGroupLayouts every frame. - const _quadMesh = /*@__PURE__*/ new QuadMesh(); class GaussianBlurNode extends TempNode {