Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 0 additions & 15 deletions src/nodes/core/NodeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import { getCurrentStack, setCurrentStack } from '../tsl/TSLBase.js';
import CubeRenderTarget from '../../renderers/common/CubeRenderTarget.js';
import ChainMap from '../../renderers/common/ChainMap.js';

import PMREMGenerator from '../../renderers/common/extras/PMREMGenerator.js';

import BindGroup from '../../renderers/common/BindGroup.js';

import { REVISION, IntType, UnsignedIntType, LinearFilter, LinearMipmapNearestFilter, NearestMipmapLinearFilter, LinearMipmapLinearFilter } from '../../constants.js';
Expand Down Expand Up @@ -472,19 +470,6 @@ class NodeBuilder {

}

/**
* Factory method for creating an instance of {@link PMREMGenerator}.
*
* @return {PMREMGenerator} The PMREM generator.
*/
createPMREMGenerator() {

// TODO: Move Materials.js to outside of the Nodes.js in order to remove this function and improve tree-shaking support

return new PMREMGenerator( this.renderer );

}

/**
* Whether the given node is included in the internal array of nodes or not.
*
Expand Down
34 changes: 24 additions & 10 deletions src/nodes/pmrem/PMREMNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

import { WebGLCoordinateSystem } from '../../constants.js';
import { Texture } from '../../textures/Texture.js';

let _generator = null;
import { PMREMGenerator } from '../../renderers/common/extras/PMREMGenerator.js';

const _cache = new WeakMap();

Expand Down Expand Up @@ -36,9 +35,10 @@
*
* @private
* @param {Texture} texture - The texture to create the PMREM for.
* @param {PMREMGenerator} generator - The PMREM generator.
* @return {Texture} The PMREM.
*/
function _getPMREMFromTexture( texture ) {
function _getPMREMFromTexture( texture, generator ) {

let cacheTexture = _cache.get( texture );

Expand All @@ -52,7 +52,7 @@

if ( isCubeMapReady( image ) ) {

cacheTexture = _generator.fromCubemap( texture, cacheTexture );
cacheTexture = generator.fromCubemap( texture, cacheTexture );

} else {

Expand All @@ -65,7 +65,7 @@

if ( isEquirectangularMapReady( image ) ) {

cacheTexture = _generator.fromEquirectangular( texture, cacheTexture );
cacheTexture = generator.fromEquirectangular( texture, cacheTexture );

} else {

Expand Down Expand Up @@ -190,6 +190,14 @@
*/
this._maxMip = uniform( 0 );

/**
* A reference to a PMREM generator that can be globally used for generating PMREMs.
*
* @type {?PMREMGenerator}
* @default null
*/
this._generator = null;

/**
* The `updateBeforeType` is set to `NodeUpdateType.RENDER`.
*
Expand Down Expand Up @@ -249,7 +257,7 @@

} else {

pmrem = _getPMREMFromTexture( texture );
pmrem = _getPMREMFromTexture( texture, this._generator );

}

Expand All @@ -267,14 +275,12 @@

setup( builder ) {

if ( _generator === null ) {
if ( this._pmremGenerator === null ) {

_generator = builder.createPMREMGenerator();
this._pmremGenerator = new PMREMGenerator( builder.renderer );

}

//

this.updateBefore( builder );

//
Expand Down Expand Up @@ -315,6 +321,14 @@

}

dispose() {

super.dispose();

if ( this._generator !== null ) this._generator.dispose();

}

}

export default PMREMNode;
Expand Down
Loading