Skip to content

Commit

Permalink
PMREMGenerator: Don't pollute node material scope. (#30324)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mugen87 authored Jan 15, 2025
1 parent 782b621 commit d293a0f
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/renderers/common/extras/PMREMGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,18 @@ const _axisDirections = [
/*@__PURE__*/ new Vector3( 1, 1, 1 )
];

//
// maps blur materials to their uniforms dictionary

const _uniformsMap = new WeakMap();

// WebGPU Face indices
const _faceLib = [
3, 1, 5,
0, 4, 2
];

const direction = getDirection( uv(), attribute( 'faceIndex' ) ).normalize();
const outputDirection = vec3( direction.x, direction.y, direction.z );
const _direction = /*@__PURE__*/ getDirection( uv(), attribute( 'faceIndex' ) ).normalize();
const _outputDirection = /*@__PURE__*/ vec3( _direction.x, _direction.y, _direction.z );

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

const blurUniforms = blurMaterial.uniforms;
const blurUniforms = _uniformsMap.get( blurMaterial );

const pixels = this._sizeLods[ lodIn ] - 1;
const radiansPerPixel = isFinite( sigmaRadians ) ? Math.PI / ( 2 * pixels ) : 2 * Math.PI / ( 2 * MAX_SAMPLES - 1 );
Expand Down Expand Up @@ -871,7 +873,7 @@ function _getBlurShader( lodMax, width, height ) {
latitudinal,
weights,
poleAxis,
outputDirection,
outputDirection: _outputDirection,
dTheta,
samples,
envMap,
Expand All @@ -882,17 +884,18 @@ function _getBlurShader( lodMax, width, height ) {
};

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

_uniformsMap.set( material, materialUniforms );

return material;

}

function _getCubemapMaterial( envTexture ) {

const material = _getMaterial( 'cubemap' );
material.fragmentNode = cubeTexture( envTexture, outputDirection );
material.fragmentNode = cubeTexture( envTexture, _outputDirection );

return material;

Expand All @@ -901,7 +904,7 @@ function _getCubemapMaterial( envTexture ) {
function _getEquirectMaterial( envTexture ) {

const material = _getMaterial( 'equirect' );
material.fragmentNode = texture( envTexture, equirectUV( outputDirection ), 0 );
material.fragmentNode = texture( envTexture, equirectUV( _outputDirection ), 0 );

return material;

Expand Down

0 comments on commit d293a0f

Please sign in to comment.