Browse Source

fixed clear color

Emmett Lalish 5 years ago
parent
commit
1a75457088

+ 17 - 3
examples/js/pmrem/PMREMGenerator.js

@@ -241,12 +241,28 @@ THREE.PMREMGenerator = ( function () {
 		var gammaOutput = _renderer.gammaOutput;
 		var toneMapping = _renderer.toneMapping;
 		var toneMappingExposure = _renderer.toneMappingExposure;
+		var clearColor = _renderer.getClearColor();
+		var clearAlpha = _renderer.getClearAlpha();
 
 		_renderer.toneMapping = THREE.LinearToneMapping;
 		_renderer.toneMappingExposure = 1.0;
 		_renderer.gammaOutput = false;
 		scene.scale.z *= - 1;
 
+		var background = scene.background;
+		if ( background && background.isColor ) {
+
+			background.convertSRGBToLinear();
+			// Convert linear to RGBE
+			var maxComponent = Math.max( background.r, background.g, background.b );
+			var fExp = Math.min( Math.max( Math.ceil( Math.log2( maxComponent ) ), - 128.0 ), 127.0 );
+			background = background.multiplyScalar( Math.pow( 2.0, - fExp ) );
+			var alpha = ( fExp + 128.0 ) / 255.0;
+			_renderer.setClearColor( background, alpha );
+			scene.background = null;
+
+		}
+
 		_renderer.setRenderTarget( cubeUVRenderTarget );
 		for ( var i = 0; i < 6; i ++ ) {
 
@@ -276,6 +292,7 @@ THREE.PMREMGenerator = ( function () {
 		_renderer.toneMapping = toneMapping;
 		_renderer.toneMappingExposure = toneMappingExposure;
 		_renderer.gammaOutput = gammaOutput;
+		_renderer.setClearColor( clearColor, clearAlpha );
 		scene.scale.z *= - 1;
 
 	}
@@ -600,9 +617,6 @@ uniform samplerCube envMap;
 
 ${_getEncodings()}
 
-#define RECIPROCAL_PI 0.31830988618
-#define RECIPROCAL_PI2 0.15915494
-
 void main() {
 	gl_FragColor = vec4(0.0);
 	gl_FragColor.rgb = envMapTexelToLinear(textureCube(envMap, vOutputDirection)).rgb;

+ 17 - 3
examples/jsm/pmrem/PMREMGenerator.js

@@ -267,12 +267,28 @@ var PMREMGenerator = ( function () {
 		var gammaOutput = _renderer.gammaOutput;
 		var toneMapping = _renderer.toneMapping;
 		var toneMappingExposure = _renderer.toneMappingExposure;
+		var clearColor = _renderer.getClearColor();
+		var clearAlpha = _renderer.getClearAlpha();
 
 		_renderer.toneMapping = LinearToneMapping;
 		_renderer.toneMappingExposure = 1.0;
 		_renderer.gammaOutput = false;
 		scene.scale.z *= - 1;
 
+		var background = scene.background;
+		if ( background && background.isColor ) {
+
+			background.convertSRGBToLinear();
+			// Convert linear to RGBE
+			var maxComponent = Math.max( background.r, background.g, background.b );
+			var fExp = Math.min( Math.max( Math.ceil( Math.log2( maxComponent ) ), - 128.0 ), 127.0 );
+			background = background.multiplyScalar( Math.pow( 2.0, - fExp ) );
+			var alpha = ( fExp + 128.0 ) / 255.0;
+			_renderer.setClearColor( background, alpha );
+			scene.background = null;
+
+		}
+
 		_renderer.setRenderTarget( cubeUVRenderTarget );
 		for ( var i = 0; i < 6; i ++ ) {
 
@@ -302,6 +318,7 @@ var PMREMGenerator = ( function () {
 		_renderer.toneMapping = toneMapping;
 		_renderer.toneMappingExposure = toneMappingExposure;
 		_renderer.gammaOutput = gammaOutput;
+		_renderer.setClearColor( clearColor, clearAlpha );
 		scene.scale.z *= - 1;
 
 	}
@@ -626,9 +643,6 @@ uniform samplerCube envMap;
 
 ${_getEncodings()}
 
-#define RECIPROCAL_PI 0.31830988618
-#define RECIPROCAL_PI2 0.15915494
-
 void main() {
 	gl_FragColor = vec4(0.0);
 	gl_FragColor.rgb = envMapTexelToLinear(textureCube(envMap, vOutputDirection)).rgb;

+ 1 - 1
examples/webgl_furnace_test.html

@@ -117,7 +117,7 @@
 					var pmremGenerator = new PMREMGenerator( renderer );
 					radianceMap = pmremGenerator.fromScene( envScene ).texture;
 
-					scene.background = envScene.background;
+					scene.background = radianceMap;
 
 					resolve();