diff --git a/src/renderers/common/extras/PMREMGenerator.js b/src/renderers/common/extras/PMREMGenerator.js index 84f37c57ada02e..41cd23a9d4f9d2 100644 --- a/src/renderers/common/extras/PMREMGenerator.js +++ b/src/renderers/common/extras/PMREMGenerator.js @@ -4,7 +4,7 @@ import { equirectUV } from '../../../nodes/utils/EquirectUVNode.js'; import { userData } from '../../../nodes/accessors/UserDataNode.js'; import { texture } from '../../../nodes/accessors/TextureNode.js'; import { cubeTexture } from '../../../nodes/accessors/CubeTextureNode.js'; -import { float, vec3, Fn } from '../../../nodes/tsl/TSLBase.js'; +import { float, vec3 } from '../../../nodes/tsl/TSLBase.js'; import { uv } from '../../../nodes/accessors/UV.js'; import { attribute } from '../../../nodes/core/AttributeNode.js'; @@ -519,7 +519,7 @@ class PMREMGenerator { const blurMesh = this._lodMeshes[ lodOut ]; blurMesh.material = blurMaterial; - blurMesh.userData = this._setUniformsBlur( targetIn, lodIn, sigmaRadians, direction, poleAxis ); + blurMesh.userData = this._getUserDataBlur( targetIn, lodIn, sigmaRadians, direction, poleAxis ); targetIn.texture.frame = ( targetIn.texture.frame || 0 ) + 1; @@ -537,19 +537,22 @@ class PMREMGenerator { } - _setUniformsBlur( targetIn, lodIn, sigmaRadians, direction, poleAxis ) { + _getUserDataBlur( targetIn, lodIn, sigmaRadians, direction, poleAxis ) { - if ( direction !== 'latitudinal' && direction !== 'longitudinal' ) { + const cacheKey = `${ direction }-${ lodIn }`; - console.error( 'blur direction must be either latitudinal or longitudinal!' ); + const u = this._userData[ cacheKey ]; - } + if ( u !== undefined ) return u; - const cacheKey = `${ direction }-${ lodIn }`; - const u = this._userData[ cacheKey ]; + // populate data for this pass - if ( u !== undefined ) return u; + if ( direction !== 'latitudinal' && direction !== 'longitudinal' ) { + + console.error( 'blur direction must be either latitudinal or longitudinal!' ); + + } const { _lodMax } = this; @@ -569,7 +572,8 @@ class PMREMGenerator { } - const weights = new Array( MAX_SAMPLES ).fill( 0 ) + const weights = new Array( MAX_SAMPLES ).fill( 0 ); + let sum = 0; for ( let i = 0; i < MAX_SAMPLES; ++ i ) { @@ -596,7 +600,7 @@ class PMREMGenerator { } - const blurUniforms = { + const userData = { latitudinal: direction === 'latitudinal' ? 1 : 0, weights, poleAxis, @@ -607,9 +611,9 @@ class PMREMGenerator { mipInt: _lodMax - lodIn }; - this._userData[ cacheKey ] = blurUniforms; + this._userData[ cacheKey ] = userData; - return blurUniforms; + return userData; }