2
0
Эх сурвалжийг харах

Merge pull request #18218 from mrdoob/environment

Implemented Scene.environment
Mr.doob 5 жил өмнө
parent
commit
d1d0f4aee4

+ 1 - 1
examples/webgl_loader_gltf.html

@@ -51,6 +51,7 @@
 						pmremGenerator.dispose();
 
 						scene.background = envMap;
+						scene.environment = envMap;
 
 						// model
 
@@ -63,7 +64,6 @@
 
 								if ( child.isMesh ) {
 
-									child.material.envMap = envMap;
 									roughnessMipmapper.generateMipmaps( child.material );
 
 								}

+ 12 - 21
examples/webgl_materials_car.html

@@ -39,7 +39,7 @@
 			import { RGBELoader } from './jsm/loaders/RGBELoader.js';
 
 			var camera, scene, renderer;
-			var stats, carModel, materialsLib, envMap;
+			var stats, carModel, materialsLib;
 
 			var bodyMatSelect = document.getElementById( 'body-mat' );
 			var rimMatSelect = document.getElementById( 'rim-mat' );
@@ -67,10 +67,11 @@
 					.setPath( 'textures/hdr/' )
 					.load( 'quarry_01_1k.hdr', function ( texture ) {
 
-						envMap = pmremGenerator.fromEquirectangular( texture ).texture;
+						var envMap = pmremGenerator.fromEquirectangular( texture ).texture;
 						pmremGenerator.dispose();
 
 						scene.background = envMap;
+						scene.environment = envMap;
 
 						//
 
@@ -126,16 +127,6 @@
 
 					carModel = gltf.scene.children[ 0 ];
 
-					carModel.traverse( function ( child ) {
-
-						if ( child.isMesh ) {
-
-							child.material.envMap = envMap;
-
-						}
-
-					} );
-
 					// shadow
 					var texture = new THREE.TextureLoader().load( 'models/gltf/ferrari_ao.png' );
 					var shadow = new THREE.Mesh(
@@ -185,22 +176,22 @@
 					main: [
 
 						new THREE.MeshStandardMaterial( {
-							color: 0xff4400, envMap: envMap, metalness: 1.0, roughness: 0.2, name: 'orange'
+							color: 0xff4400, metalness: 1.0, roughness: 0.2, name: 'orange'
 						} ),
 						new THREE.MeshStandardMaterial( {
-							color: 0x001166, envMap: envMap, metalness: 1.0, roughness: 0.2, name: 'blue'
+							color: 0x001166, metalness: 1.0, roughness: 0.2, name: 'blue'
 						} ),
 						new THREE.MeshStandardMaterial( {
-							color: 0x990000, envMap: envMap, metalness: 1.0, roughness: 0.2, name: 'red'
+							color: 0x990000, metalness: 1.0, roughness: 0.2, name: 'red'
 						} ),
 						new THREE.MeshStandardMaterial( {
-							color: 0x000000, envMap: envMap, metalness: 1.0, roughness: 0.4, name: 'black'
+							color: 0x000000, metalness: 1.0, roughness: 0.4, name: 'black'
 						} ),
 						new THREE.MeshStandardMaterial( {
-							color: 0xffffff, envMap: envMap, metalness: 0.1, roughness: 0.2, name: 'white'
+							color: 0xffffff, metalness: 0.1, roughness: 0.2, name: 'white'
 						} ),
 						new THREE.MeshStandardMaterial( {
-							color: 0xffffff, envMap: envMap, metalness: 1.0, roughness: 0.2, name: 'metallic'
+							color: 0xffffff, metalness: 1.0, roughness: 0.2, name: 'metallic'
 						} ),
 
 					],
@@ -208,13 +199,13 @@
 					glass: [
 
 						new THREE.MeshPhysicalMaterial( {
-							color: 0xffffff, envMap: envMap, metalness: 1, roughness: 0, transparency: 1.0, transparent: true, name: 'clear'
+							color: 0xffffff, metalness: 1, roughness: 0, transparency: 1.0, transparent: true, name: 'clear'
 						} ),
 						new THREE.MeshPhysicalMaterial( {
-							color: 0x000000, envMap: envMap, metalness: 1, roughness: 0, transparency: 0.7, transparent: true, name: 'smoked'
+							color: 0x000000, metalness: 1, roughness: 0, transparency: 0.7, transparent: true, name: 'smoked'
 						} ),
 						new THREE.MeshPhysicalMaterial( {
-							color: 0x001133, envMap: envMap, metalness: 1, roughness: 0, transparency: 0.7, transparent: true, name: 'blue'
+							color: 0x001133, metalness: 1, roughness: 0, transparency: 0.7, transparent: true, name: 'blue'
 						} ),
 
 					],

+ 189 - 193
examples/webgl_materials_physical_clearcoat.html

@@ -1,248 +1,244 @@
 <!DOCTYPE html>
 <html lang="en">
+	<head>
+		<title>three.js webgl - materials - clearcoat</title>
+		<meta charset="utf-8">
+		<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
+		<link type="text/css" rel="stylesheet" href="main.css">
+	</head>
+	<body>
+		<div id="info">
+			<a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> webgl - materials - clearcoat
+		</div>
 
-<head>
-	<title>three.js webgl - materials - clearcoat</title>
-	<meta charset="utf-8">
-	<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
-	<link type="text/css" rel="stylesheet" href="main.css">
-</head>
+		<script type="module">
 
-<body>
-	<div id="info">
-		<a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> webgl - materials - clearcoat
-	</div>
+			import * as THREE from '../build/three.module.js';
 
-	<script type="module">
+			import Stats from './jsm/libs/stats.module.js';
 
-		import * as THREE from '../build/three.module.js';
+			import { OrbitControls } from './jsm/controls/OrbitControls.js';
+			import { HDRCubeTextureLoader } from './jsm/loaders/HDRCubeTextureLoader.js';
 
-		import Stats from './jsm/libs/stats.module.js';
+			var container, stats;
 
-		import { OrbitControls } from './jsm/controls/OrbitControls.js';
-		import { RGBELoader } from './jsm/loaders/RGBELoader.js';
+			var camera, scene, renderer;
 
-		var container, stats;
+			var particleLight;
+			var group;
 
-		var camera, scene, renderer;
+			init();
+			animate();
 
-		var particleLight;
-		var group;
+			function init() {
 
-		init();
-		animate();
+				container = document.createElement( 'div' );
+				document.body.appendChild( container );
 
-		function init() {
+				camera = new THREE.PerspectiveCamera( 27, window.innerWidth / window.innerHeight, 1, 10000 );
+				camera.position.z = 1000;
 
-			container = document.createElement( 'div' );
-			document.body.appendChild( container );
+				scene = new THREE.Scene();
 
-			camera = new THREE.PerspectiveCamera( 27, window.innerWidth / window.innerHeight, 1, 10000 );
-			camera.position.z = 1000;
+				group = new THREE.Group();
+				scene.add( group );
 
-			scene = new THREE.Scene();
-
-			group = new THREE.Group();
-			scene.add( group );
-
-			new RGBELoader()
+				new HDRCubeTextureLoader()
 					.setDataType( THREE.UnsignedByteType )
-					.setPath( 'textures/equirectangular/' )
-					.load( 'pedestrian_overpass_1k.hdr', function ( hdrEquirect ) {
-
-						var hdrCubeRenderTarget = pmremGenerator.fromEquirectangular( hdrEquirect );
-						hdrEquirect.dispose();
-						pmremGenerator.dispose();
-
-						var geometry = new THREE.SphereBufferGeometry( 80, 64, 32 );
-
-						var textureLoader = new THREE.TextureLoader();
-
-						var diffuse = textureLoader.load( "textures/carbon/Carbon.png" );
-						diffuse.encoding = THREE.sRGBEncoding;
-						diffuse.wrapS = THREE.RepeatWrapping;
-						diffuse.wrapT = THREE.RepeatWrapping;
-						diffuse.repeat.x = 10;
-						diffuse.repeat.y = 10;
-
-						var normalMap = textureLoader.load( "textures/carbon/Carbon_Normal.png" );
-						normalMap.wrapS = THREE.RepeatWrapping;
-						normalMap.wrapT = THREE.RepeatWrapping;
-
-						var normalMap2 = textureLoader.load( "textures/water/Water_1_M_Normal.jpg" );
-
-						var normalMap3 = textureLoader.load( "textures/flakes.png" );
-						normalMap3.wrapS = THREE.RepeatWrapping;
-						normalMap3.wrapT = THREE.RepeatWrapping;
-						normalMap3.repeat.x = 10;
-						normalMap3.repeat.y = 10;
-						normalMap3.anisotropy = 16;
-
-						var normalMap4 = textureLoader.load( "textures/golfball.jpg" );
-
-						var clearcoatNormaMap = textureLoader.load( "textures/pbr/Scratched_gold/Scratched_gold_01_1K_Normal.png" );
-
-						// car paint
-
-						var material = new THREE.MeshPhysicalMaterial( {
-							clearcoat: 1.0,
-							clearcoatRoughness: 0.1,
-							metalness: 0.9,
-							roughness: 0.5,
-							color: 0x0000ff,
-							envMap: hdrCubeRenderTarget.texture,
-							normalMap: normalMap3,
-							normalScale: new THREE.Vector2( 0.1, 0.1 )
-						} );
-
-						var mesh = new THREE.Mesh( geometry, material );
-						mesh.position.x = - 100;
-						mesh.position.y = 100;
-						group.add( mesh );
-
-						// fibers
-
-						var material = new THREE.MeshPhysicalMaterial( {
-							clearcoat: 1.0,
-							clearcoatRoughness: 0.1,
-							envMap: hdrCubeRenderTarget.texture,
-							map: diffuse,
-							normalMap: normalMap
-						} );
-						var mesh = new THREE.Mesh( geometry, material );
-						mesh.position.x = 100;
-						mesh.position.y = 100;
-						group.add( mesh );
-
-						// golf
-
-						var material = new THREE.MeshPhysicalMaterial( {
-							metalness: 0.0,
-							roughness: 0.1,
-							clearcoat: 1.0,
-							normalMap: normalMap4,
-							envMap: hdrCubeRenderTarget.texture,
-							clearcoatNormalMap: clearcoatNormaMap,
-							clearcoatNormalScale: new THREE.Vector2( 2.0, 2.0 )
-						} );
-						var mesh = new THREE.Mesh( geometry, material );
-						mesh.position.x = - 100;
-						mesh.position.y = - 100;
-						group.add( mesh );
-
-						// clearcoat + normalmap
-
-						var material = new THREE.MeshPhysicalMaterial( {
-							clearcoat: 1.0,
-							metalness: 1.0,
-							color: 0xff0000,
-							envMap: hdrCubeRenderTarget.texture,
-							normalMap: normalMap2,
-							normalScale: new THREE.Vector2( 0.15, 0.15 ),
-							clearcoatNormalMap: clearcoatNormaMap,
-							clearcoatNormalScale: new THREE.Vector2( 2.0, 2.0 )
-						} );
-						var mesh = new THREE.Mesh( geometry, material );
-						mesh.position.x = 100;
-						mesh.position.y = - 100;
-						group.add( mesh );
-
-						//
-
-						scene.background = hdrCubeRenderTarget.texture;
-
-					}
-
+					.setPath( 'textures/cube/pisaHDR/' )
+					.load( [ 'px.hdr', 'nx.hdr', 'py.hdr', 'ny.hdr', 'pz.hdr', 'nz.hdr' ],
+						function ( hdrCubeMap ) {
+
+							var hdrCubeRenderTarget = pmremGenerator.fromCubemap( hdrCubeMap );
+							hdrCubeMap.dispose();
+							pmremGenerator.dispose();
+
+							var geometry = new THREE.SphereBufferGeometry( 80, 64, 32 );
+
+							var textureLoader = new THREE.TextureLoader();
+
+							var diffuse = textureLoader.load( "textures/carbon/Carbon.png" );
+							diffuse.encoding = THREE.sRGBEncoding;
+							diffuse.wrapS = THREE.RepeatWrapping;
+							diffuse.wrapT = THREE.RepeatWrapping;
+							diffuse.repeat.x = 10;
+							diffuse.repeat.y = 10;
+
+							var normalMap = textureLoader.load( "textures/carbon/Carbon_Normal.png" );
+							normalMap.wrapS = THREE.RepeatWrapping;
+							normalMap.wrapT = THREE.RepeatWrapping;
+
+							var normalMap2 = textureLoader.load( "textures/water/Water_1_M_Normal.jpg" );
+
+							var normalMap3 = textureLoader.load( "textures/flakes.png" );
+							normalMap3.wrapS = THREE.RepeatWrapping;
+							normalMap3.wrapT = THREE.RepeatWrapping;
+							normalMap3.repeat.x = 10;
+							normalMap3.repeat.y = 10;
+							normalMap3.anisotropy = 16;
+
+							var normalMap4 = textureLoader.load( "textures/golfball.jpg" );
+
+							var clearcoatNormaMap = textureLoader.load( "textures/pbr/Scratched_gold/Scratched_gold_01_1K_Normal.png" );
+
+							// car paint
+
+							var material = new THREE.MeshPhysicalMaterial( {
+								clearcoat: 1.0,
+								clearcoatRoughness: 0.1,
+								metalness: 0.9,
+								roughness: 0.5,
+								color: 0x0000ff,
+								normalMap: normalMap3,
+								normalScale: new THREE.Vector2( 0.15, 0.15 )
+							} );
+
+							var mesh = new THREE.Mesh( geometry, material );
+							mesh.position.x = - 100;
+							mesh.position.y = 100;
+							group.add( mesh );
+
+							// fibers
+
+							var material = new THREE.MeshPhysicalMaterial( {
+								roughness: 0.5,
+								clearcoat: 1.0,
+								clearcoatRoughness: 0.1,
+								map: diffuse,
+								normalMap: normalMap
+							} );
+							var mesh = new THREE.Mesh( geometry, material );
+							mesh.position.x = 100;
+							mesh.position.y = 100;
+							group.add( mesh );
+
+							// golf
+
+							var material = new THREE.MeshPhysicalMaterial( {
+								metalness: 0.0,
+								roughness: 0.1,
+								clearcoat: 1.0,
+								normalMap: normalMap4,
+								clearcoatNormalMap: clearcoatNormaMap,
+								clearcoatNormalScale: new THREE.Vector2( 2.0, 2.0 )
+							} );
+							var mesh = new THREE.Mesh( geometry, material );
+							mesh.position.x = - 100;
+							mesh.position.y = - 100;
+							group.add( mesh );
+
+							// clearcoat + normalmap
+
+							var material = new THREE.MeshPhysicalMaterial( {
+								clearcoat: 1.0,
+								metalness: 1.0,
+								color: 0xff0000,
+								normalMap: normalMap2,
+								normalScale: new THREE.Vector2( 0.15, 0.15 ),
+								clearcoatNormalMap: clearcoatNormaMap,
+								clearcoatNormalScale: new THREE.Vector2( 2.0, 2.0 )
+							} );
+							var mesh = new THREE.Mesh( geometry, material );
+							mesh.position.x = 100;
+							mesh.position.y = - 100;
+							group.add( mesh );
+
+							//
+
+							scene.background = hdrCubeRenderTarget.texture;
+							scene.environment = hdrCubeRenderTarget.texture;
+
+						}
+
+					);
+
+				// LIGHTS
+
+				particleLight = new THREE.Mesh(
+					new THREE.SphereBufferGeometry( 4, 8, 8 ),
+					new THREE.MeshBasicMaterial( { color: 0xffffff } )
 				);
+				scene.add( particleLight );
 
-			// LIGHTS
+				particleLight.add( new THREE.PointLight( 0xffffff, 1 ) );
 
-			particleLight = new THREE.Mesh(
-				new THREE.SphereBufferGeometry( 4, 8, 8 ),
-				new THREE.MeshBasicMaterial( { color: 0xffffff } )
-			);
-			scene.add( particleLight );
+				renderer = new THREE.WebGLRenderer();
+				renderer.setPixelRatio( window.devicePixelRatio );
+				renderer.setSize( window.innerWidth, window.innerHeight );
+				container.appendChild( renderer.domElement );
 
-			particleLight.add( new THREE.PointLight( 0xffffff, 1 ) );
+				//
 
-			renderer = new THREE.WebGLRenderer();
-			renderer.setPixelRatio( window.devicePixelRatio );
-			renderer.setSize( window.innerWidth, window.innerHeight );
-			container.appendChild( renderer.domElement );
+				renderer.toneMapping = THREE.ACESFilmicToneMapping;
+				renderer.toneMappingExposure = 1;
 
-			//
+				//
 
-			renderer.toneMapping = THREE.ACESFilmicToneMapping;
-			renderer.toneMappingExposure = 1;
+				renderer.outputEncoding = THREE.sRGBEncoding;
 
-			//
+				//
 
-			renderer.outputEncoding = THREE.sRGBEncoding;
+				var pmremGenerator = new THREE.PMREMGenerator( renderer );
+				pmremGenerator.compileEquirectangularShader();
 
-			//
+				//
 
-			var pmremGenerator = new THREE.PMREMGenerator( renderer );
-			pmremGenerator.compileEquirectangularShader();
+				stats = new Stats();
+				container.appendChild( stats.dom );
 
-			//
+				// EVENTS
 
-			stats = new Stats();
-			container.appendChild( stats.dom );
+				new OrbitControls( camera, renderer.domElement );
 
-			// EVENTS
+				window.addEventListener( 'resize', onWindowResize, false );
 
-			var controls = new OrbitControls( camera, renderer.domElement );
+			}
 
-			window.addEventListener( 'resize', onWindowResize, false );
+			//
 
-		}
+			function onWindowResize() {
 
-		//
+				var width = window.innerWidth;
+				var height = window.innerHeight;
 
-		function onWindowResize() {
+				camera.aspect = width / height;
+				camera.updateProjectionMatrix();
 
-			var width = window.innerWidth;
-			var height = window.innerHeight;
+				renderer.setSize( width, height );
 
-			camera.aspect = width / height;
-			camera.updateProjectionMatrix();
+			}
 
-			renderer.setSize( width, height );
+			//
 
-		}
+			function animate() {
 
-		//
+				requestAnimationFrame( animate );
 
-		function animate() {
+				render();
 
-			requestAnimationFrame( animate );
+				stats.update();
 
-			render();
+			}
 
-			stats.update();
+			function render() {
 
-		}
+				var timer = Date.now() * 0.00025;
 
-		function render() {
+				particleLight.position.x = Math.sin( timer * 7 ) * 300;
+				particleLight.position.y = Math.cos( timer * 5 ) * 400;
+				particleLight.position.z = Math.cos( timer * 3 ) * 300;
 
-			var timer = Date.now() * 0.00025;
+				for ( var i = 0; i < group.children.length; i ++ ) {
 
-			particleLight.position.x = Math.sin( timer * 7 ) * 300;
-			particleLight.position.y = Math.cos( timer * 5 ) * 400;
-			particleLight.position.z = Math.cos( timer * 3 ) * 300;
+					var child = group.children[ i ];
+					child.rotation.y += 0.005;
 
-			for ( var i = 0; i < group.children.length; i ++ ) {
+				}
 
-				var child = group.children[ i ];
-				child.rotation.y += 0.005;
+				renderer.render( scene, camera );
 
 			}
 
-			renderer.render( scene, camera );
-
-		}
-
-
-	</script>
-</body>
+		</script>
+	</body>
 </html>

+ 2 - 3
examples/webgl_materials_standard.html

@@ -87,7 +87,7 @@
 
 						group.traverse( function ( child ) {
 
-							if ( child instanceof THREE.Mesh ) {
+							if ( child.isMesh ) {
 
 								child.material = material;
 
@@ -110,9 +110,8 @@
 						hdrEquirect.dispose();
 						pmremGenerator.dispose();
 
-						material.envMap = hdrCubeRenderTarget.texture;
-
 						scene.background = hdrCubeRenderTarget.texture;
+						scene.environment = hdrCubeRenderTarget.texture;
 
 					} );
 

+ 4 - 3
examples/webgl_tonemapping.html

@@ -136,8 +136,9 @@
 					.setPath( 'textures/equirectangular/' )
 					.load( 'pedestrian_overpass_1k.hdr', function ( hdrEquirect ) {
 
-						standardMaterial.envMap = pmremGenerator.fromEquirectangular( hdrEquirect ).texture;
-						standardMaterial.needsUpdate = true;
+						scene.environment = pmremGenerator.fromEquirectangular( hdrEquirect ).texture;
+
+						standardMaterial.needsUpdate = true; // TODO(mrdoob) Should WebGLRenderer handle this?
 
 						hdrEquirect.dispose();
 						pmremGenerator.dispose();
@@ -179,7 +180,7 @@
 				stats = new Stats();
 				container.appendChild( stats.dom );
 
-				var controls = new OrbitControls( camera, renderer.domElement );
+				new OrbitControls( camera, renderer.domElement );
 
 				window.addEventListener( 'resize', onWindowResize, false );
 

+ 34 - 25
src/renderers/WebGLRenderer.js

@@ -25,6 +25,7 @@ import { cloneUniforms } from './shaders/UniformsUtils.js';
 import { Vector2 } from '../math/Vector2.js';
 import { Vector3 } from '../math/Vector3.js';
 import { Vector4 } from '../math/Vector4.js';
+import { Scene } from '../scenes/Scene.js';
 import { WebGLAnimation } from './webgl/WebGLAnimation.js';
 import { WebGLAttributes } from './webgl/WebGLAttributes.js';
 import { WebGLBackground } from './webgl/WebGLBackground.js';
@@ -719,11 +720,15 @@ function WebGLRenderer( parameters ) {
 
 	};
 
-	this.renderBufferDirect = function ( camera, fog, geometry, material, object, group ) {
+	var tempScene = new Scene();
+
+	this.renderBufferDirect = function ( camera, scene, geometry, material, object, group ) {
+
+		if ( scene === null ) scene = tempScene; // renderBufferDirect second parameter used to be fog (could be null)
 
 		var frontFaceCW = ( object.isMesh && object.matrixWorld.determinant() < 0 );
 
-		var program = setProgram( camera, fog, material, object );
+		var program = setProgram( camera, scene, material, object );
 
 		state.setMaterial( material, frontFaceCW );
 
@@ -1053,13 +1058,13 @@ function WebGLRenderer( parameters ) {
 
 					for ( var i = 0; i < object.material.length; i ++ ) {
 
-						initMaterial( object.material[ i ], scene.fog, object );
+						initMaterial( object.material[ i ], scene, object );
 
 					}
 
 				} else {
 
-					initMaterial( object.material, scene.fog, object );
+					initMaterial( object.material, scene, object );
 
 				}
 
@@ -1456,7 +1461,7 @@ function WebGLRenderer( parameters ) {
 
 		if ( object.isImmediateRenderObject ) {
 
-			var program = setProgram( camera, scene.fog, material, object );
+			var program = setProgram( camera, scene, material, object );
 
 			state.setMaterial( material );
 
@@ -1468,7 +1473,7 @@ function WebGLRenderer( parameters ) {
 
 		} else {
 
-			_this.renderBufferDirect( camera, scene.fog, geometry, material, object, group );
+			_this.renderBufferDirect( camera, scene, geometry, material, object, group );
 
 		}
 
@@ -1477,7 +1482,7 @@ function WebGLRenderer( parameters ) {
 
 	}
 
-	function initMaterial( material, fog, object ) {
+	function initMaterial( material, scene, object ) {
 
 		var materialProperties = properties.get( material );
 
@@ -1487,7 +1492,7 @@ function WebGLRenderer( parameters ) {
 		var lightsStateVersion = lights.state.version;
 
 		var parameters = programCache.getParameters(
-			material, lights.state, shadowsArray, fog, _clipping.numPlanes, _clipping.numIntersection, object );
+			material, lights.state, shadowsArray, scene, _clipping.numPlanes, _clipping.numIntersection, object );
 
 		var programCacheKey = programCache.getProgramCacheKey( material, parameters );
 
@@ -1605,7 +1610,7 @@ function WebGLRenderer( parameters ) {
 
 		}
 
-		materialProperties.fog = fog;
+		materialProperties.fog = scene.fog;
 
 		// store the light setup it was created for
 
@@ -1642,10 +1647,13 @@ function WebGLRenderer( parameters ) {
 
 	}
 
-	function setProgram( camera, fog, material, object ) {
+	function setProgram( camera, scene, material, object ) {
 
 		textures.resetTextureUnits();
 
+		var fog = scene.fog;
+		var environment = material.isMeshStandardMaterial ? scene.environment : null;
+
 		var materialProperties = properties.get( material );
 		var lights = currentRenderState.state.lights;
 
@@ -1698,7 +1706,7 @@ function WebGLRenderer( parameters ) {
 
 		if ( material.version !== materialProperties.__version ) {
 
-			initMaterial( material, fog, object );
+			initMaterial( material, scene, object );
 			materialProperties.__version = material.version;
 
 		}
@@ -1923,22 +1931,21 @@ function WebGLRenderer( parameters ) {
 
 			} else if ( material.isMeshStandardMaterial ) {
 
-				refreshUniformsCommon( m_uniforms, material );
+				refreshUniformsCommon( m_uniforms, material, environment );
 
 				if ( material.isMeshPhysicalMaterial ) {
 
-					refreshUniformsPhysical( m_uniforms, material );
+					refreshUniformsPhysical( m_uniforms, material, environment );
 
 				} else {
 
-					refreshUniformsStandard( m_uniforms, material );
+					refreshUniformsStandard( m_uniforms, material, environment );
 
 				}
 
 			} else if ( material.isMeshMatcapMaterial ) {
 
 				refreshUniformsCommon( m_uniforms, material );
-
 				refreshUniformsMatcap( m_uniforms, material );
 
 			} else if ( material.isMeshDepthMaterial ) {
@@ -2031,7 +2038,7 @@ function WebGLRenderer( parameters ) {
 
 	// Uniforms (refresh uniforms objects)
 
-	function refreshUniformsCommon( uniforms, material ) {
+	function refreshUniformsCommon( uniforms, material, environment ) {
 
 		uniforms.opacity.value = material.opacity;
 
@@ -2065,20 +2072,22 @@ function WebGLRenderer( parameters ) {
 
 		}
 
-		if ( material.envMap ) {
+		var envMap = material.envMap || environment;
+
+		if ( envMap ) {
 
-			uniforms.envMap.value = material.envMap;
+			uniforms.envMap.value = envMap;
 
 			// don't flip CubeTexture envMaps, flip everything else:
 			//  WebGLRenderTargetCube will be flipped for backwards compatibility
 			//  WebGLRenderTargetCube.texture will be flipped because it's a Texture and NOT a CubeTexture
 			// this check must be handled differently, or removed entirely, if WebGLRenderTargetCube uses a CubeTexture in the future
-			uniforms.flipEnvMap.value = material.envMap.isCubeTexture ? - 1 : 1;
+			uniforms.flipEnvMap.value = envMap.isCubeTexture ? - 1 : 1;
 
 			uniforms.reflectivity.value = material.reflectivity;
 			uniforms.refractionRatio.value = material.refractionRatio;
 
-			uniforms.maxMipLevel.value = properties.get( material.envMap ).__maxMipLevel;
+			uniforms.maxMipLevel.value = properties.get( envMap ).__maxMipLevel;
 
 		}
 
@@ -2419,7 +2428,7 @@ function WebGLRenderer( parameters ) {
 
 	}
 
-	function refreshUniformsStandard( uniforms, material ) {
+	function refreshUniformsStandard( uniforms, material, environment ) {
 
 		uniforms.roughness.value = material.roughness;
 		uniforms.metalness.value = material.metalness;
@@ -2466,7 +2475,7 @@ function WebGLRenderer( parameters ) {
 
 		}
 
-		if ( material.envMap ) {
+		if ( material.envMap || environment ) {
 
 			//uniforms.envMap.value = material.envMap; // part of uniforms common
 			uniforms.envMapIntensity.value = material.envMapIntensity;
@@ -2475,9 +2484,9 @@ function WebGLRenderer( parameters ) {
 
 	}
 
-	function refreshUniformsPhysical( uniforms, material ) {
+	function refreshUniformsPhysical( uniforms, material, environment ) {
 
-		refreshUniformsStandard( uniforms, material );
+		refreshUniformsStandard( uniforms, material, environment );
 
 		uniforms.reflectivity.value = material.reflectivity; // also part of uniforms common
 
@@ -2609,7 +2618,7 @@ function WebGLRenderer( parameters ) {
 
 	function materialNeedsLights( material ) {
 
-		return material.isMeshLambertMaterial || material.isMeshToonMaterial || material.isMeshPhongMaterial ||
+		return material.isMeshLambertMaterial || material.isMeshToonMaterial || material.isMeshPhongMaterial ||
 			material.isMeshStandardMaterial || material.isShadowMaterial ||
 			( material.isShaderMaterial && material.lights === true );
 

+ 10 - 5
src/renderers/webgl/WebGLPrograms.js

@@ -110,7 +110,12 @@ function WebGLPrograms( renderer, extensions, capabilities ) {
 
 	}
 
-	this.getParameters = function ( material, lights, shadows, fog, nClipPlanes, nClipIntersection, object ) {
+	this.getParameters = function ( material, lights, shadows, scene, nClipPlanes, nClipIntersection, object ) {
+
+		var fog = scene.fog;
+		var environment = material.isMeshStandardMaterial ? scene.environment : null;
+
+		var envMap = material.envMap || environment;
 
 		var shaderID = shaderIDs[ material.type ];
 
@@ -151,10 +156,10 @@ function WebGLPrograms( renderer, extensions, capabilities ) {
 			mapEncoding: getTextureEncodingFromMap( material.map ),
 			matcap: !! material.matcap,
 			matcapEncoding: getTextureEncodingFromMap( material.matcap ),
-			envMap: !! material.envMap,
-			envMapMode: material.envMap && material.envMap.mapping,
-			envMapEncoding: getTextureEncodingFromMap( material.envMap ),
-			envMapCubeUV: ( !! material.envMap ) && ( ( material.envMap.mapping === CubeUVReflectionMapping ) || ( material.envMap.mapping === CubeUVRefractionMapping ) ),
+			envMap: !! envMap,
+			envMapMode: envMap && envMap.mapping,
+			envMapEncoding: getTextureEncodingFromMap( envMap ),
+			envMapCubeUV: ( !! envMap ) && ( ( envMap.mapping === CubeUVReflectionMapping ) || ( envMap.mapping === CubeUVRefractionMapping ) ),
 			lightMap: !! material.lightMap,
 			lightMapEncoding: getTextureEncodingFromMap( material.lightMap ),
 			aoMap: !! material.aoMap,

+ 1 - 0
src/scenes/Scene.d.ts

@@ -25,6 +25,7 @@ export class Scene extends Object3D {
 	overrideMaterial: Material | null;
 	autoUpdate: boolean;
 	background: null | Color | Texture;
+	environment: null | Texture;
 
 	toJSON( meta?: any ): any;
 	dispose(): void;

+ 5 - 0
src/scenes/Scene.js

@@ -11,7 +11,9 @@ function Scene() {
 	this.type = 'Scene';
 
 	this.background = null;
+	this.environment = null;
 	this.fog = null;
+
 	this.overrideMaterial = null;
 
 	this.autoUpdate = true; // checked by the renderer
@@ -35,7 +37,9 @@ Scene.prototype = Object.assign( Object.create( Object3D.prototype ), {
 		Object3D.prototype.copy.call( this, source, recursive );
 
 		if ( source.background !== null ) this.background = source.background.clone();
+		if ( source.environment !== null ) this.environment = source.environment.clone();
 		if ( source.fog !== null ) this.fog = source.fog.clone();
+
 		if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
 
 		this.autoUpdate = source.autoUpdate;
@@ -50,6 +54,7 @@ Scene.prototype = Object.assign( Object.create( Object3D.prototype ), {
 		var data = Object3D.prototype.toJSON.call( this, meta );
 
 		if ( this.background !== null ) data.object.background = this.background.toJSON( meta );
+		if ( this.environment !== null ) data.object.environment = this.environment.toJSON( meta );
 		if ( this.fog !== null ) data.object.fog = this.fog.toJSON();
 
 		return data;