Browse Source

PMREMGenerator: More clean up.

Mr.doob 3 years ago
parent
commit
1db78b84b0
1 changed files with 26 additions and 23 deletions
  1. 26 23
      src/extras/PMREMGenerator.js

+ 26 - 23
src/extras/PMREMGenerator.js

@@ -86,8 +86,8 @@ class PMREMGenerator {
 		this._sigmas = [];
 		this._sigmas = [];
 
 
 		this._blurMaterial = null;
 		this._blurMaterial = null;
-		this._equirectShader = null;
-		this._cubemapShader = null;
+		this._cubemapMaterial = null;
+		this._equirectMaterial = null;
 
 
 		this._compileMaterial( this._blurMaterial );
 		this._compileMaterial( this._blurMaterial );
 
 
@@ -105,10 +105,12 @@ class PMREMGenerator {
 		_oldTarget = this._renderer.getRenderTarget();
 		_oldTarget = this._renderer.getRenderTarget();
 
 
 		this._setSize( 256 );
 		this._setSize( 256 );
+
 		const cubeUVRenderTarget = this._allocateTargets();
 		const cubeUVRenderTarget = this._allocateTargets();
 		cubeUVRenderTarget.depthBuffer = true;
 		cubeUVRenderTarget.depthBuffer = true;
 
 
 		this._sceneToCubeUV( scene, near, far, cubeUVRenderTarget );
 		this._sceneToCubeUV( scene, near, far, cubeUVRenderTarget );
+
 		if ( sigma > 0 ) {
 		if ( sigma > 0 ) {
 
 
 			this._blur( cubeUVRenderTarget, 0, 0, sigma );
 			this._blur( cubeUVRenderTarget, 0, 0, sigma );
@@ -150,10 +152,10 @@ class PMREMGenerator {
 	 */
 	 */
 	compileCubemapShader() {
 	compileCubemapShader() {
 
 
-		if ( this._cubemapShader === null ) {
+		if ( this._cubemapMaterial === null ) {
 
 
-			this._cubemapShader = _getCubemapShader();
-			this._compileMaterial( this._cubemapShader );
+			this._cubemapMaterial = _getCubemapMaterial();
+			this._compileMaterial( this._cubemapMaterial );
 
 
 		}
 		}
 
 
@@ -165,10 +167,10 @@ class PMREMGenerator {
 	 */
 	 */
 	compileEquirectangularShader() {
 	compileEquirectangularShader() {
 
 
-		if ( this._equirectShader === null ) {
+		if ( this._equirectMaterial === null ) {
 
 
-			this._equirectShader = _getEquirectMaterial();
-			this._compileMaterial( this._equirectShader );
+			this._equirectMaterial = _getEquirectMaterial();
+			this._compileMaterial( this._equirectMaterial );
 
 
 		}
 		}
 
 
@@ -183,8 +185,8 @@ class PMREMGenerator {
 
 
 		this._dispose();
 		this._dispose();
 
 
-		if ( this._cubemapShader !== null ) this._cubemapShader.dispose();
-		if ( this._equirectShader !== null ) this._equirectShader.dispose();
+		if ( this._cubemapMaterial !== null ) this._cubemapMaterial.dispose();
+		if ( this._equirectMaterial !== null ) this._equirectMaterial.dispose();
 
 
 	}
 	}
 
 
@@ -232,6 +234,7 @@ class PMREMGenerator {
 		}
 		}
 
 
 		_oldTarget = this._renderer.getRenderTarget();
 		_oldTarget = this._renderer.getRenderTarget();
+
 		const cubeUVRenderTarget = renderTarget || this._allocateTargets();
 		const cubeUVRenderTarget = renderTarget || this._allocateTargets();
 		this._textureToCubeUV( texture, cubeUVRenderTarget );
 		this._textureToCubeUV( texture, cubeUVRenderTarget );
 		this._applyPMREM( cubeUVRenderTarget );
 		this._applyPMREM( cubeUVRenderTarget );
@@ -334,6 +337,7 @@ class PMREMGenerator {
 		for ( let i = 0; i < 6; i ++ ) {
 		for ( let i = 0; i < 6; i ++ ) {
 
 
 			const col = i % 3;
 			const col = i % 3;
+
 			if ( col === 0 ) {
 			if ( col === 0 ) {
 
 
 				cubeCamera.up.set( 0, upSign[ i ], 0 );
 				cubeCamera.up.set( 0, upSign[ i ], 0 );
@@ -352,7 +356,9 @@ class PMREMGenerator {
 			}
 			}
 
 
 			const size = this._cubeSize;
 			const size = this._cubeSize;
+
 			_setViewport( cubeUVRenderTarget, col * size, i > 2 ? size : 0, size, size );
 			_setViewport( cubeUVRenderTarget, col * size, i > 2 ? size : 0, size, size );
+
 			renderer.setRenderTarget( cubeUVRenderTarget );
 			renderer.setRenderTarget( cubeUVRenderTarget );
 
 
 			if ( useSolidColor ) {
 			if ( useSolidColor ) {
@@ -382,25 +388,25 @@ class PMREMGenerator {
 
 
 		if ( isCubeTexture ) {
 		if ( isCubeTexture ) {
 
 
-			if ( this._cubemapShader === null ) {
+			if ( this._cubemapMaterial === null ) {
 
 
-				this._cubemapShader = _getCubemapShader();
+				this._cubemapMaterial = _getCubemapMaterial();
 
 
 			}
 			}
 
 
-			this._cubemapShader.uniforms.flipEnvMap.value = ( texture.isRenderTargetTexture === false ) ? - 1 : 1;
+			this._cubemapMaterial.uniforms.flipEnvMap.value = ( texture.isRenderTargetTexture === false ) ? - 1 : 1;
 
 
 		} else {
 		} else {
 
 
-			if ( this._equirectShader === null ) {
+			if ( this._equirectMaterial === null ) {
 
 
-				this._equirectShader = _getEquirectMaterial();
+				this._equirectMaterial = _getEquirectMaterial();
 
 
 			}
 			}
 
 
 		}
 		}
 
 
-		const material = isCubeTexture ? this._cubemapShader : this._equirectShader;
+		const material = isCubeTexture ? this._cubemapMaterial : this._equirectMaterial;
 		const mesh = new Mesh( this._lodPlanes[ 0 ], material );
 		const mesh = new Mesh( this._lodPlanes[ 0 ], material );
 
 
 		const uniforms = material.uniforms;
 		const uniforms = material.uniforms;
@@ -408,6 +414,7 @@ class PMREMGenerator {
 		uniforms[ 'envMap' ].value = texture;
 		uniforms[ 'envMap' ].value = texture;
 
 
 		const size = this._cubeSize;
 		const size = this._cubeSize;
+
 		_setViewport( cubeUVRenderTarget, 0, 0, 3 * size, 2 * size );
 		_setViewport( cubeUVRenderTarget, 0, 0, 3 * size, 2 * size );
 
 
 		renderer.setRenderTarget( cubeUVRenderTarget );
 		renderer.setRenderTarget( cubeUVRenderTarget );
@@ -751,7 +758,7 @@ function _getBlurShader( lodMax, width, height ) {
 
 
 function _getEquirectMaterial() {
 function _getEquirectMaterial() {
 
 
-	const shaderMaterial = new ShaderMaterial( {
+	return new ShaderMaterial( {
 
 
 		name: 'EquirectangularToCubeUV',
 		name: 'EquirectangularToCubeUV',
 
 
@@ -788,13 +795,11 @@ function _getEquirectMaterial() {
 
 
 	} );
 	} );
 
 
-	return shaderMaterial;
-
 }
 }
 
 
-function _getCubemapShader() {
+function _getCubemapMaterial() {
 
 
-	const shaderMaterial = new ShaderMaterial( {
+	return new ShaderMaterial( {
 
 
 		name: 'CubemapToCubeUV',
 		name: 'CubemapToCubeUV',
 
 
@@ -829,8 +834,6 @@ function _getCubemapShader() {
 
 
 	} );
 	} );
 
 
-	return shaderMaterial;
-
 }
 }
 
 
 function _getCommonVertexShader() {
 function _getCommonVertexShader() {