diff --git a/examples/jsm/csm/CSMShader.js b/examples/jsm/csm/CSMShader.js index c1f228177b0d46..546c2fa9e63cc8 100644 --- a/examples/jsm/csm/CSMShader.js +++ b/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 ) diff --git a/examples/jsm/materials/MeshGouraudMaterial.js b/examples/jsm/materials/MeshGouraudMaterial.js index b565bc0c29665b..b30f8697940ce3 100644 --- a/examples/jsm/materials/MeshGouraudMaterial.js +++ b/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 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/shaders/ShaderChunk/lights_pars_begin.glsl.js b/src/renderers/shaders/ShaderChunk/lights_pars_begin.glsl.js index 36624fe26ac927..0c7c2487468d2b 100644 --- a/src/renderers/shaders/ShaderChunk/lights_pars_begin.glsl.js +++ b/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 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..48436354ea6e0e 100644 --- a/src/renderers/webgl/WebGLProgram.js +++ b/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' : '', 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 );