From 5e3abedaed83803a21010a1f61af566896f19bd5 Mon Sep 17 00:00:00 2001 From: sunag Date: Wed, 23 Oct 2024 13:44:15 -0300 Subject: [PATCH] fix buffer resize when transmission is used --- .../nodes/manager/NodeMaterialObserver.js | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/materials/nodes/manager/NodeMaterialObserver.js b/src/materials/nodes/manager/NodeMaterialObserver.js index 2cfe054b2c1a84..a714aefb37b52a 100644 --- a/src/materials/nodes/manager/NodeMaterialObserver.js +++ b/src/materials/nodes/manager/NodeMaterialObserver.js @@ -1,3 +1,5 @@ +import { Vector2 } from '../../../math/Vector2.js'; + const refreshUniforms = [ 'alphaMap', 'alphaTest', @@ -51,6 +53,8 @@ const refreshUniforms = [ 'transmissionMap' ]; +const _vector2 = /*@__PURE__*/ new Vector2(); + class NodeMaterialObserver { constructor( builder ) { @@ -115,6 +119,15 @@ class NodeMaterialObserver { } + if ( data.material.transmission > 0 ) { + + const bufferSize = this._getFrameBufferSize( renderObject ); + + data.bufferWidth = bufferSize.x; + data.bufferHeight = bufferSize.y; + + } + this.renderObjects.set( renderObject, data ); } @@ -193,6 +206,25 @@ class NodeMaterialObserver { } + _getFrameBufferSize( renderObject ) { + + const renderer = renderObject.renderer; + const renderTarget = renderer.getRenderTarget(); + + if ( renderTarget ) { + + _vector2.set( renderTarget.width, renderTarget.height ); + + } else { + + renderer.getDrawingBufferSize( _vector2 ); + + } + + return _vector2; + + } + equals( renderObject ) { const { object, material, geometry } = renderObject; @@ -249,6 +281,21 @@ class NodeMaterialObserver { } + if ( materialData.transmission > 0 ) { + + const bufferSize = this._getFrameBufferSize( renderObject ); + + if ( renderObjectData.bufferWidth !== bufferSize.x || renderObjectData.bufferHeight !== bufferSize.y ) { + + renderObjectData.bufferWidth = bufferSize.x; + renderObjectData.bufferHeight = bufferSize.y; + + return false; + + } + + } + // geometry const storedGeometryData = renderObjectData.geometry;