Skip to content

Commit d293a0f

Browse files
authored
PMREMGenerator: Don't pollute node material scope. (#30324)
1 parent 782b621 commit d293a0f

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/renderers/common/extras/PMREMGenerator.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,18 @@ const _axisDirections = [
6969
/*@__PURE__*/ new Vector3( 1, 1, 1 )
7070
];
7171

72-
//
72+
// maps blur materials to their uniforms dictionary
73+
74+
const _uniformsMap = new WeakMap();
7375

7476
// WebGPU Face indices
7577
const _faceLib = [
7678
3, 1, 5,
7779
0, 4, 2
7880
];
7981

80-
const direction = getDirection( uv(), attribute( 'faceIndex' ) ).normalize();
81-
const outputDirection = vec3( direction.x, direction.y, direction.z );
82+
const _direction = /*@__PURE__*/ getDirection( uv(), attribute( 'faceIndex' ) ).normalize();
83+
const _outputDirection = /*@__PURE__*/ vec3( _direction.x, _direction.y, _direction.z );
8284

8385
/**
8486
* This class generates a Prefiltered, Mipmapped Radiance Environment Map
@@ -667,7 +669,7 @@ class PMREMGenerator {
667669
const blurMesh = this._lodMeshes[ lodOut ];
668670
blurMesh.material = blurMaterial;
669671

670-
const blurUniforms = blurMaterial.uniforms;
672+
const blurUniforms = _uniformsMap.get( blurMaterial );
671673

672674
const pixels = this._sizeLods[ lodIn ] - 1;
673675
const radiansPerPixel = isFinite( sigmaRadians ) ? Math.PI / ( 2 * pixels ) : 2 * Math.PI / ( 2 * MAX_SAMPLES - 1 );
@@ -871,7 +873,7 @@ function _getBlurShader( lodMax, width, height ) {
871873
latitudinal,
872874
weights,
873875
poleAxis,
874-
outputDirection,
876+
outputDirection: _outputDirection,
875877
dTheta,
876878
samples,
877879
envMap,
@@ -882,17 +884,18 @@ function _getBlurShader( lodMax, width, height ) {
882884
};
883885

884886
const material = _getMaterial( 'blur' );
885-
material.uniforms = materialUniforms; // TODO: Move to outside of the material
886887
material.fragmentNode = blur( { ...materialUniforms, latitudinal: latitudinal.equal( 1 ) } );
887888

889+
_uniformsMap.set( material, materialUniforms );
890+
888891
return material;
889892

890893
}
891894

892895
function _getCubemapMaterial( envTexture ) {
893896

894897
const material = _getMaterial( 'cubemap' );
895-
material.fragmentNode = cubeTexture( envTexture, outputDirection );
898+
material.fragmentNode = cubeTexture( envTexture, _outputDirection );
896899

897900
return material;
898901

@@ -901,7 +904,7 @@ function _getCubemapMaterial( envTexture ) {
901904
function _getEquirectMaterial( envTexture ) {
902905

903906
const material = _getMaterial( 'equirect' );
904-
material.fragmentNode = texture( envTexture, equirectUV( outputDirection ), 0 );
907+
material.fragmentNode = texture( envTexture, equirectUV( _outputDirection ), 0 );
905908

906909
return material;
907910

0 commit comments

Comments
 (0)