From a481380b23acae8809be337ed73ede0f2839e76a Mon Sep 17 00:00:00 2001 From: Mugen87 Date: Fri, 15 Sep 2023 19:40:09 +0200 Subject: [PATCH] WebGLRenderer: Introduce USE_LIGHT_PROBES define. --- .../ShaderChunk/lights_fragment_begin.glsl.js | 6 +++++- src/renderers/webgl/WebGLLights.js | 17 ++++++++++++++--- src/renderers/webgl/WebGLProgram.js | 2 ++ src/renderers/webgl/WebGLPrograms.js | 3 +++ 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js b/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js index 6a5cbc1ca26334..ce50879412444a 100644 --- a/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +++ b/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 ) diff --git a/src/renderers/webgl/WebGLLights.js b/src/renderers/webgl/WebGLLights.js index de48b309fee46e..aff2d36aef7dc4 100644 --- a/src/renderers/webgl/WebGLLights.js +++ b/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 ++; } diff --git a/src/renderers/webgl/WebGLProgram.js b/src/renderers/webgl/WebGLProgram.js index 01614ad5a22079..1b4fe85830c822 100644 --- a/src/renderers/webgl/WebGLProgram.js +++ b/src/renderers/webgl/WebGLProgram.js @@ -788,6 +788,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' : '', diff --git a/src/renderers/webgl/WebGLPrograms.js b/src/renderers/webgl/WebGLPrograms.js index 3546ed5823243c..89208605a9d765 100644 --- a/src/renderers/webgl/WebGLPrograms.js +++ b/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 );