Browse Source

WebGLRenderer: Remove deprecated WebGLRenderer.useLegacyLights (#28482)

* remove legacy lights support

* fix example

---------

Co-authored-by: aardgoose <[email protected]>
aardgoose 1 year ago
parent
commit
629f8a068d

+ 1 - 5
examples/jsm/environments/RoomEnvironment.js

@@ -24,11 +24,7 @@ class RoomEnvironment extends Scene {
 		const roomMaterial = new MeshStandardMaterial( { side: BackSide } );
 		const roomMaterial = new MeshStandardMaterial( { side: BackSide } );
 		const boxMaterial = new MeshStandardMaterial();
 		const boxMaterial = new MeshStandardMaterial();
 
 
-		let intensity = 5;
-
-		if ( renderer !== null && renderer._useLegacyLights === false ) intensity = 900;
-
-		const mainLight = new PointLight( 0xffffff, intensity, 28, 2 );
+		const mainLight = new PointLight( 0xffffff, 900, 28, 2 );
 		mainLight.position.set( 0.418, 16.199, 0.300 );
 		mainLight.position.set( 0.418, 16.199, 0.300 );
 		this.add( mainLight );
 		this.add( mainLight );
 
 

+ 2 - 20
src/renderers/WebGLRenderer.js

@@ -145,10 +145,6 @@ class WebGLRenderer {
 
 
 		this._outputColorSpace = SRGBColorSpace;
 		this._outputColorSpace = SRGBColorSpace;
 
 
-		// physical lights
-
-		this._useLegacyLights = false;
-
 		// tone mapping
 		// tone mapping
 
 
 		this.toneMapping = NoToneMapping;
 		this.toneMapping = NoToneMapping;
@@ -955,7 +951,7 @@ class WebGLRenderer {
 
 
 			}
 			}
 
 
-			currentRenderState.setupLights( _this._useLegacyLights );
+			currentRenderState.setupLights();
 
 
 			// Only initialize materials in the new scene, not the targetScene.
 			// Only initialize materials in the new scene, not the targetScene.
 
 
@@ -1183,7 +1179,7 @@ class WebGLRenderer {
 			const opaqueObjects = currentRenderList.opaque;
 			const opaqueObjects = currentRenderList.opaque;
 			const transmissiveObjects = currentRenderList.transmissive;
 			const transmissiveObjects = currentRenderList.transmissive;
 
 
-			currentRenderState.setupLights( _this._useLegacyLights );
+			currentRenderState.setupLights();
 
 
 			if ( camera.isArrayCamera ) {
 			if ( camera.isArrayCamera ) {
 
 
@@ -2788,20 +2784,6 @@ class WebGLRenderer {
 
 
 	}
 	}
 
 
-	get useLegacyLights() { // @deprecated, r155
-
-		console.warn( 'THREE.WebGLRenderer: The property .useLegacyLights has been deprecated. Migrate your lighting according to the following guide: https://discourse.threejs.org/t/updates-to-lighting-in-three-js-r155/53733.' );
-		return this._useLegacyLights;
-
-	}
-
-	set useLegacyLights( value ) { // @deprecated, r155
-
-		console.warn( 'THREE.WebGLRenderer: The property .useLegacyLights has been deprecated. Migrate your lighting according to the following guide: https://discourse.threejs.org/t/updates-to-lighting-in-three-js-r155/53733.' );
-		this._useLegacyLights = value;
-
-	}
-
 }
 }
 
 
 
 

+ 8 - 22
src/renderers/shaders/ShaderChunk/lights_pars_begin.glsl.js

@@ -55,32 +55,18 @@ vec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {
 
 
 float getDistanceAttenuation( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {
 float getDistanceAttenuation( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {
 
 
-	#if defined ( LEGACY_LIGHTS )
+	// based upon Frostbite 3 Moving to Physically-based Rendering
+	// page 32, equation 26: E[window1]
+	// https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
+	float distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );
 
 
-		if ( cutoffDistance > 0.0 && decayExponent > 0.0 ) {
+	if ( cutoffDistance > 0.0 ) {
 
 
-			return pow( saturate( - lightDistance / cutoffDistance + 1.0 ), decayExponent );
+		distanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );
 
 
-		}
-
-		return 1.0;
-
-	#else
-
-		// based upon Frostbite 3 Moving to Physically-based Rendering
-		// page 32, equation 26: E[window1]
-		// https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
-		float distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );
-
-		if ( cutoffDistance > 0.0 ) {
-
-			distanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );
-
-		}
-
-		return distanceFalloff;
+	}
 
 
-	#endif
+	return distanceFalloff;
 
 
 }
 }
 
 

+ 9 - 12
src/renderers/webgl/WebGLLights.js

@@ -205,7 +205,7 @@ function WebGLLights( extensions ) {
 	const matrix4 = new Matrix4();
 	const matrix4 = new Matrix4();
 	const matrix42 = new Matrix4();
 	const matrix42 = new Matrix4();
 
 
-	function setup( lights, useLegacyLights ) {
+	function setup( lights ) {
 
 
 		let r = 0, g = 0, b = 0;
 		let r = 0, g = 0, b = 0;
 
 
@@ -228,9 +228,6 @@ function WebGLLights( extensions ) {
 		// ordering : [shadow casting + map texturing, map texturing, shadow casting, none ]
 		// ordering : [shadow casting + map texturing, map texturing, shadow casting, none ]
 		lights.sort( shadowCastingAndTexturingLightsFirst );
 		lights.sort( shadowCastingAndTexturingLightsFirst );
 
 
-		// artist-friendly light intensity scaling factor
-		const scaleFactor = ( useLegacyLights === true ) ? Math.PI : 1;
-
 		for ( let i = 0, l = lights.length; i < l; i ++ ) {
 		for ( let i = 0, l = lights.length; i < l; i ++ ) {
 
 
 			const light = lights[ i ];
 			const light = lights[ i ];
@@ -243,9 +240,9 @@ function WebGLLights( extensions ) {
 
 
 			if ( light.isAmbientLight ) {
 			if ( light.isAmbientLight ) {
 
 
-				r += color.r * intensity * scaleFactor;
-				g += color.g * intensity * scaleFactor;
-				b += color.b * intensity * scaleFactor;
+				r += color.r * intensity;
+				g += color.g * intensity;
+				b += color.b * intensity;
 
 
 			} else if ( light.isLightProbe ) {
 			} else if ( light.isLightProbe ) {
 
 
@@ -261,7 +258,7 @@ function WebGLLights( extensions ) {
 
 
 				const uniforms = cache.get( light );
 				const uniforms = cache.get( light );
 
 
-				uniforms.color.copy( light.color ).multiplyScalar( light.intensity * scaleFactor );
+				uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
 
 
 				if ( light.castShadow ) {
 				if ( light.castShadow ) {
 
 
@@ -292,7 +289,7 @@ function WebGLLights( extensions ) {
 
 
 				uniforms.position.setFromMatrixPosition( light.matrixWorld );
 				uniforms.position.setFromMatrixPosition( light.matrixWorld );
 
 
-				uniforms.color.copy( color ).multiplyScalar( intensity * scaleFactor );
+				uniforms.color.copy( color ).multiplyScalar( intensity );
 				uniforms.distance = distance;
 				uniforms.distance = distance;
 
 
 				uniforms.coneCos = Math.cos( light.angle );
 				uniforms.coneCos = Math.cos( light.angle );
@@ -353,7 +350,7 @@ function WebGLLights( extensions ) {
 
 
 				const uniforms = cache.get( light );
 				const uniforms = cache.get( light );
 
 
-				uniforms.color.copy( light.color ).multiplyScalar( light.intensity * scaleFactor );
+				uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
 				uniforms.distance = light.distance;
 				uniforms.distance = light.distance;
 				uniforms.decay = light.decay;
 				uniforms.decay = light.decay;
 
 
@@ -386,8 +383,8 @@ function WebGLLights( extensions ) {
 
 
 				const uniforms = cache.get( light );
 				const uniforms = cache.get( light );
 
 
-				uniforms.skyColor.copy( light.color ).multiplyScalar( intensity * scaleFactor );
-				uniforms.groundColor.copy( light.groundColor ).multiplyScalar( intensity * scaleFactor );
+				uniforms.skyColor.copy( light.color ).multiplyScalar( intensity );
+				uniforms.groundColor.copy( light.groundColor ).multiplyScalar( intensity );
 
 
 				state.hemi[ hemiLength ] = uniforms;
 				state.hemi[ hemiLength ] = uniforms;
 
 

+ 1 - 5
src/renderers/webgl/WebGLMaterials.js

@@ -249,11 +249,7 @@ function WebGLMaterials( renderer, properties ) {
 		if ( material.lightMap ) {
 		if ( material.lightMap ) {
 
 
 			uniforms.lightMap.value = material.lightMap;
 			uniforms.lightMap.value = material.lightMap;
-
-			// artist-friendly light intensity scaling factor
-			const scaleFactor = ( renderer._useLegacyLights === true ) ? Math.PI : 1;
-
-			uniforms.lightMapIntensity.value = material.lightMapIntensity * scaleFactor;
+			uniforms.lightMapIntensity.value = material.lightMapIntensity;
 
 
 			refreshTransformUniform( material.lightMap, uniforms.lightMapTransform );
 			refreshTransformUniform( material.lightMap, uniforms.lightMapTransform );
 
 

+ 0 - 4
src/renderers/webgl/WebGLProgram.js

@@ -631,8 +631,6 @@ function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) {
 
 
 			parameters.numLightProbes > 0 ? '#define USE_LIGHT_PROBES' : '',
 			parameters.numLightProbes > 0 ? '#define USE_LIGHT_PROBES' : '',
 
 
-			parameters.useLegacyLights ? '#define LEGACY_LIGHTS' : '',
-
 			parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
 			parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
 
 
 			'uniform mat4 modelMatrix;',
 			'uniform mat4 modelMatrix;',
@@ -796,8 +794,6 @@ function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) {
 
 
 			parameters.numLightProbes > 0 ? '#define USE_LIGHT_PROBES' : '',
 			parameters.numLightProbes > 0 ? '#define USE_LIGHT_PROBES' : '',
 
 
-			parameters.useLegacyLights ? '#define LEGACY_LIGHTS' : '',
-
 			parameters.decodeVideoTexture ? '#define DECODE_VIDEO_TEXTURE' : '',
 			parameters.decodeVideoTexture ? '#define DECODE_VIDEO_TEXTURE' : '',
 
 
 			parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
 			parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',

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

@@ -337,7 +337,6 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
 			shadowMapType: renderer.shadowMap.type,
 			shadowMapType: renderer.shadowMap.type,
 
 
 			toneMapping: toneMapping,
 			toneMapping: toneMapping,
-			useLegacyLights: renderer._useLegacyLights,
 
 
 			decodeVideoTexture: HAS_MAP && ( material.map.isVideoTexture === true ) && ( ColorManagement.getTransfer( material.map.colorSpace ) === SRGBTransfer ),
 			decodeVideoTexture: HAS_MAP && ( material.map.isVideoTexture === true ) && ( ColorManagement.getTransfer( material.map.colorSpace ) === SRGBTransfer ),
 
 
@@ -537,28 +536,26 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
 			_programLayers.enable( 8 );
 			_programLayers.enable( 8 );
 		if ( parameters.shadowMapEnabled )
 		if ( parameters.shadowMapEnabled )
 			_programLayers.enable( 9 );
 			_programLayers.enable( 9 );
-		if ( parameters.useLegacyLights )
-			_programLayers.enable( 10 );
 		if ( parameters.doubleSided )
 		if ( parameters.doubleSided )
-			_programLayers.enable( 11 );
+			_programLayers.enable( 10 );
 		if ( parameters.flipSided )
 		if ( parameters.flipSided )
-			_programLayers.enable( 12 );
+			_programLayers.enable( 11 );
 		if ( parameters.useDepthPacking )
 		if ( parameters.useDepthPacking )
-			_programLayers.enable( 13 );
+			_programLayers.enable( 12 );
 		if ( parameters.dithering )
 		if ( parameters.dithering )
-			_programLayers.enable( 14 );
+			_programLayers.enable( 13 );
 		if ( parameters.transmission )
 		if ( parameters.transmission )
-			_programLayers.enable( 15 );
+			_programLayers.enable( 14 );
 		if ( parameters.sheen )
 		if ( parameters.sheen )
-			_programLayers.enable( 16 );
+			_programLayers.enable( 15 );
 		if ( parameters.opaque )
 		if ( parameters.opaque )
-			_programLayers.enable( 17 );
+			_programLayers.enable( 16 );
 		if ( parameters.pointsUvs )
 		if ( parameters.pointsUvs )
-			_programLayers.enable( 18 );
+			_programLayers.enable( 17 );
 		if ( parameters.decodeVideoTexture )
 		if ( parameters.decodeVideoTexture )
-			_programLayers.enable( 19 );
+			_programLayers.enable( 18 );
 		if ( parameters.alphaToCoverage )
 		if ( parameters.alphaToCoverage )
-			_programLayers.enable( 20 );
+			_programLayers.enable( 19 );
 
 
 		array.push( _programLayers.mask );
 		array.push( _programLayers.mask );
 
 

+ 2 - 2
src/renderers/webgl/WebGLRenderStates.js

@@ -28,9 +28,9 @@ function WebGLRenderState( extensions ) {
 
 
 	}
 	}
 
 
-	function setupLights( useLegacyLights ) {
+	function setupLights() {
 
 
-		lights.setup( lightsArray, useLegacyLights );
+		lights.setup( lightsArray );
 
 
 	}
 	}