Przeglądaj źródła

Core: Remove artist-friendly factor of PI from LightMap shader (#23613)

* Remove artist-friendly factor of PI from LightMap shader

* Modified WebGLMaterials signature
WestLangley 3 lat temu
rodzic
commit
f74105c727

+ 1 - 1
src/renderers/WebGLRenderer.js

@@ -308,7 +308,7 @@ function WebGLRenderer( parameters = {} ) {
 		morphtargets = new WebGLMorphtargets( _gl, capabilities, textures );
 		clipping = new WebGLClipping( properties );
 		programCache = new WebGLPrograms( _this, cubemaps, cubeuvmaps, extensions, capabilities, bindingStates, clipping );
-		materials = new WebGLMaterials( properties );
+		materials = new WebGLMaterials( _this, properties );
 		renderLists = new WebGLRenderLists();
 		renderStates = new WebGLRenderStates( extensions, capabilities );
 		background = new WebGLBackground( _this, cubemaps, state, objects, _alpha, _premultipliedAlpha );

+ 0 - 6
src/renderers/shaders/ShaderChunk/lightmap_fragment.glsl.js

@@ -4,12 +4,6 @@ export default /* glsl */`
 	vec4 lightMapTexel = texture2D( lightMap, vUv2 );
 	vec3 lightMapIrradiance = lightMapTexel.rgb * lightMapIntensity;
 
-	#ifndef PHYSICALLY_CORRECT_LIGHTS
-
-		lightMapIrradiance *= PI;
-
-	#endif
-
 	reflectedLight.indirectDiffuse += lightMapIrradiance;
 
 #endif

+ 0 - 6
src/renderers/shaders/ShaderChunk/lights_fragment_maps.glsl.js

@@ -6,12 +6,6 @@ export default /* glsl */`
 		vec4 lightMapTexel = texture2D( lightMap, vUv2 );
 		vec3 lightMapIrradiance = lightMapTexel.rgb * lightMapIntensity;
 
-		#ifndef PHYSICALLY_CORRECT_LIGHTS
-
-			lightMapIrradiance *= PI;
-
-		#endif
-
 		irradiance += lightMapIrradiance;
 
 	#endif

+ 2 - 2
src/renderers/shaders/ShaderLib/meshbasic.glsl.js

@@ -87,8 +87,8 @@ void main() {
 	// accumulation (baked indirect lighting only)
 	#ifdef USE_LIGHTMAP
 
-		vec4 lightMapTexel= texture2D( lightMap, vUv2 );
-		reflectedLight.indirectDiffuse += lightMapTexel.rgb * lightMapIntensity;
+		vec4 lightMapTexel = texture2D( lightMap, vUv2 );
+		reflectedLight.indirectDiffuse += lightMapTexel.rgb * lightMapIntensity * RECIPROCAL_PI;
 
 	#else
 

+ 6 - 2
src/renderers/webgl/WebGLMaterials.js

@@ -1,6 +1,6 @@
 import { BackSide } from '../../constants.js';
 
-function WebGLMaterials( properties ) {
+function WebGLMaterials( renderer, properties ) {
 
 	function refreshFogUniforms( uniforms, fog ) {
 
@@ -162,7 +162,11 @@ function WebGLMaterials( properties ) {
 		if ( material.lightMap ) {
 
 			uniforms.lightMap.value = material.lightMap;
-			uniforms.lightMapIntensity.value = material.lightMapIntensity;
+
+			// artist-friendly light intensity scaling factor
+			const scaleFactor = ( renderer.physicallyCorrectLights !== true ) ? Math.PI : 1;
+
+			uniforms.lightMapIntensity.value = material.lightMapIntensity * scaleFactor;
 
 		}