Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NodeMaterialObserver: Fix buffer resize when transmission is used #29735

Merged
merged 1 commit into from
Oct 23, 2024
Merged
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
47 changes: 47 additions & 0 deletions src/materials/nodes/manager/NodeMaterialObserver.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Vector2 } from '../../../math/Vector2.js';

const refreshUniforms = [
'alphaMap',
'alphaTest',
Expand Down Expand Up @@ -51,6 +53,8 @@ const refreshUniforms = [
'transmissionMap'
];

const _vector2 = /*@__PURE__*/ new Vector2();

class NodeMaterialObserver {

constructor( builder ) {
Expand Down Expand Up @@ -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 );

}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down