浏览代码

WebGLRenderer: Introduce USE_LIGHT_PROBES define. (#26768)

* WebGLRenderer: Introduce USE_LIGHT_PROBES define.

* Examples: Make use of USE_LIGHT_PROBES.

* Add light probe define to vertex shader

---------

Co-authored-by: WestLangley <[email protected]>
Michael Herzog 1 年之前
父节点
当前提交
5238faec76

+ 5 - 1
examples/jsm/csm/CSMShader.js

@@ -251,7 +251,11 @@ IncidentLight directLight;
 
 	vec3 irradiance = getAmbientLightIrradiance( ambientLightColor );
 
-	irradiance += getLightProbeIrradiance( lightProbe, geometry.normal );
+	#if defined( USE_LIGHT_PROBES )
+
+		irradiance += getLightProbeIrradiance( lightProbe, geometry.normal );
+
+	#endif
 
 	#if ( NUM_HEMI_LIGHTS > 0 )
 

+ 10 - 2
examples/jsm/materials/MeshGouraudMaterial.js

@@ -97,13 +97,21 @@ const GouraudShader = {
 
 			vIndirectFront += getAmbientLightIrradiance( ambientLightColor );
 
-			vIndirectFront += getLightProbeIrradiance( lightProbe, geometry.normal );
+			#if defined( USE_LIGHT_PROBES )
+
+				vIndirectFront += getLightProbeIrradiance( lightProbe, geometry.normal );
+
+			#endif
 
 			#ifdef DOUBLE_SIDED
 
 				vIndirectBack += getAmbientLightIrradiance( ambientLightColor );
 
-				vIndirectBack += getLightProbeIrradiance( lightProbe, backGeometry.normal );
+				#if defined( USE_LIGHT_PROBES )
+
+					vIndirectBack += getLightProbeIrradiance( lightProbe, backGeometry.normal );
+
+				#endif
 
 			#endif
 

+ 5 - 1
src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js

@@ -173,7 +173,11 @@ IncidentLight directLight;
 
 	vec3 irradiance = getAmbientLightIrradiance( ambientLightColor );
 
-	irradiance += getLightProbeIrradiance( lightProbe, geometry.normal );
+	#if defined( USE_LIGHT_PROBES )
+
+		irradiance += getLightProbeIrradiance( lightProbe, geometry.normal );
+
+	#endif
 
 	#if ( NUM_HEMI_LIGHTS > 0 )
 

+ 6 - 1
src/renderers/shaders/ShaderChunk/lights_pars_begin.glsl.js

@@ -1,7 +1,12 @@
 export default /* glsl */`
 uniform bool receiveShadow;
 uniform vec3 ambientLightColor;
-uniform vec3 lightProbe[ 9 ];
+
+#if defined( USE_LIGHT_PROBES )
+
+	uniform vec3 lightProbe[ 9 ];
+
+#endif
 
 // get the irradiance (radiance convolved with cosine lobe) at the point 'normal' on the unit sphere
 // source: https://graphics.stanford.edu/papers/envmap/envmap.pdf

+ 14 - 3
src/renderers/webgl/WebGLLights.js

@@ -170,7 +170,9 @@ function WebGLLights( extensions, capabilities ) {
 			numDirectionalShadows: - 1,
 			numPointShadows: - 1,
 			numSpotShadows: - 1,
-			numSpotMaps: - 1
+			numSpotMaps: - 1,
+
+			numLightProbes: - 1
 		},
 
 		ambient: [ 0, 0, 0 ],
@@ -192,7 +194,8 @@ function WebGLLights( extensions, capabilities ) {
 		pointShadowMap: [],
 		pointShadowMatrix: [],
 		hemi: [],
-		numSpotLightShadowsWithMaps: 0
+		numSpotLightShadowsWithMaps: 0,
+		numLightProbes: 0
 
 	};
 
@@ -220,6 +223,8 @@ function WebGLLights( extensions, capabilities ) {
 		let numSpotMaps = 0;
 		let numSpotShadowsWithMaps = 0;
 
+		let numLightProbes = 0;
+
 		// ordering : [shadow casting + map texturing, map texturing, shadow casting, none ]
 		lights.sort( shadowCastingAndTexturingLightsFirst );
 
@@ -250,6 +255,8 @@ function WebGLLights( extensions, capabilities ) {
 
 				}
 
+				numLightProbes ++;
+
 			} else if ( light.isDirectionalLight ) {
 
 				const uniforms = cache.get( light );
@@ -437,7 +444,8 @@ function WebGLLights( extensions, capabilities ) {
 			hash.numDirectionalShadows !== numDirectionalShadows ||
 			hash.numPointShadows !== numPointShadows ||
 			hash.numSpotShadows !== numSpotShadows ||
-			hash.numSpotMaps !== numSpotMaps ) {
+			hash.numSpotMaps !== numSpotMaps ||
+			hash.numLightProbes !== numLightProbes ) {
 
 			state.directional.length = directionalLength;
 			state.spot.length = spotLength;
@@ -456,6 +464,7 @@ function WebGLLights( extensions, capabilities ) {
 			state.spotLightMatrix.length = numSpotShadows + numSpotMaps - numSpotShadowsWithMaps;
 			state.spotLightMap.length = numSpotMaps;
 			state.numSpotLightShadowsWithMaps = numSpotShadowsWithMaps;
+			state.numLightProbes = numLightProbes;
 
 			hash.directionalLength = directionalLength;
 			hash.pointLength = pointLength;
@@ -468,6 +477,8 @@ function WebGLLights( extensions, capabilities ) {
 			hash.numSpotShadows = numSpotShadows;
 			hash.numSpotMaps = numSpotMaps;
 
+			hash.numLightProbes = numLightProbes;
+
 			state.version = nextVersion ++;
 
 		}

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

@@ -606,6 +606,8 @@ function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) {
 
 			parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
 
+			parameters.numLightProbes > 0 ? '#define USE_LIGHT_PROBES' : '',
+
 			parameters.useLegacyLights ? '#define LEGACY_LIGHTS' : '',
 
 			parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
@@ -788,6 +790,8 @@ function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) {
 
 			parameters.premultipliedAlpha ? '#define PREMULTIPLIED_ALPHA' : '',
 
+			parameters.numLightProbes > 0 ? '#define USE_LIGHT_PROBES' : '',
+
 			parameters.useLegacyLights ? '#define LEGACY_LIGHTS' : '',
 
 			parameters.decodeVideoTexture ? '#define DECODE_VIDEO_TEXTURE' : '',

+ 3 - 0
src/renderers/webgl/WebGLPrograms.js

@@ -325,6 +325,8 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
 			numSpotLightShadows: lights.spotShadowMap.length,
 			numSpotLightShadowsWithMaps: lights.numSpotLightShadowsWithMaps,
 
+			numLightProbes: lights.numLightProbes,
+
 			numClippingPlanes: clipping.numPlanes,
 			numClipIntersection: clipping.numIntersection,
 
@@ -449,6 +451,7 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
 		array.push( parameters.numPointLightShadows );
 		array.push( parameters.numSpotLightShadows );
 		array.push( parameters.numSpotLightShadowsWithMaps );
+		array.push( parameters.numLightProbes );
 		array.push( parameters.shadowMapType );
 		array.push( parameters.toneMapping );
 		array.push( parameters.numClippingPlanes );