Skip to content

Commit 5238fae

Browse files
Mugen87WestLangley
andauthored
WebGLRenderer: Introduce USE_LIGHT_PROBES define. (mrdoob#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]>
1 parent fbc28ae commit 5238fae

File tree

7 files changed

+47
-8
lines changed

7 files changed

+47
-8
lines changed

examples/jsm/csm/CSMShader.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,11 @@ IncidentLight directLight;
251251
252252
vec3 irradiance = getAmbientLightIrradiance( ambientLightColor );
253253
254-
irradiance += getLightProbeIrradiance( lightProbe, geometry.normal );
254+
#if defined( USE_LIGHT_PROBES )
255+
256+
irradiance += getLightProbeIrradiance( lightProbe, geometry.normal );
257+
258+
#endif
255259
256260
#if ( NUM_HEMI_LIGHTS > 0 )
257261

examples/jsm/materials/MeshGouraudMaterial.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,21 @@ const GouraudShader = {
9797
9898
vIndirectFront += getAmbientLightIrradiance( ambientLightColor );
9999
100-
vIndirectFront += getLightProbeIrradiance( lightProbe, geometry.normal );
100+
#if defined( USE_LIGHT_PROBES )
101+
102+
vIndirectFront += getLightProbeIrradiance( lightProbe, geometry.normal );
103+
104+
#endif
101105
102106
#ifdef DOUBLE_SIDED
103107
104108
vIndirectBack += getAmbientLightIrradiance( ambientLightColor );
105109
106-
vIndirectBack += getLightProbeIrradiance( lightProbe, backGeometry.normal );
110+
#if defined( USE_LIGHT_PROBES )
111+
112+
vIndirectBack += getLightProbeIrradiance( lightProbe, backGeometry.normal );
113+
114+
#endif
107115
108116
#endif
109117

src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,11 @@ IncidentLight directLight;
173173
174174
vec3 irradiance = getAmbientLightIrradiance( ambientLightColor );
175175
176-
irradiance += getLightProbeIrradiance( lightProbe, geometry.normal );
176+
#if defined( USE_LIGHT_PROBES )
177+
178+
irradiance += getLightProbeIrradiance( lightProbe, geometry.normal );
179+
180+
#endif
177181
178182
#if ( NUM_HEMI_LIGHTS > 0 )
179183

src/renderers/shaders/ShaderChunk/lights_pars_begin.glsl.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
export default /* glsl */`
22
uniform bool receiveShadow;
33
uniform vec3 ambientLightColor;
4-
uniform vec3 lightProbe[ 9 ];
4+
5+
#if defined( USE_LIGHT_PROBES )
6+
7+
uniform vec3 lightProbe[ 9 ];
8+
9+
#endif
510
611
// get the irradiance (radiance convolved with cosine lobe) at the point 'normal' on the unit sphere
712
// source: https://graphics.stanford.edu/papers/envmap/envmap.pdf

src/renderers/webgl/WebGLLights.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,9 @@ function WebGLLights( extensions, capabilities ) {
170170
numDirectionalShadows: - 1,
171171
numPointShadows: - 1,
172172
numSpotShadows: - 1,
173-
numSpotMaps: - 1
173+
numSpotMaps: - 1,
174+
175+
numLightProbes: - 1
174176
},
175177

176178
ambient: [ 0, 0, 0 ],
@@ -192,7 +194,8 @@ function WebGLLights( extensions, capabilities ) {
192194
pointShadowMap: [],
193195
pointShadowMatrix: [],
194196
hemi: [],
195-
numSpotLightShadowsWithMaps: 0
197+
numSpotLightShadowsWithMaps: 0,
198+
numLightProbes: 0
196199

197200
};
198201

@@ -220,6 +223,8 @@ function WebGLLights( extensions, capabilities ) {
220223
let numSpotMaps = 0;
221224
let numSpotShadowsWithMaps = 0;
222225

226+
let numLightProbes = 0;
227+
223228
// ordering : [shadow casting + map texturing, map texturing, shadow casting, none ]
224229
lights.sort( shadowCastingAndTexturingLightsFirst );
225230

@@ -250,6 +255,8 @@ function WebGLLights( extensions, capabilities ) {
250255

251256
}
252257

258+
numLightProbes ++;
259+
253260
} else if ( light.isDirectionalLight ) {
254261

255262
const uniforms = cache.get( light );
@@ -437,7 +444,8 @@ function WebGLLights( extensions, capabilities ) {
437444
hash.numDirectionalShadows !== numDirectionalShadows ||
438445
hash.numPointShadows !== numPointShadows ||
439446
hash.numSpotShadows !== numSpotShadows ||
440-
hash.numSpotMaps !== numSpotMaps ) {
447+
hash.numSpotMaps !== numSpotMaps ||
448+
hash.numLightProbes !== numLightProbes ) {
441449

442450
state.directional.length = directionalLength;
443451
state.spot.length = spotLength;
@@ -456,6 +464,7 @@ function WebGLLights( extensions, capabilities ) {
456464
state.spotLightMatrix.length = numSpotShadows + numSpotMaps - numSpotShadowsWithMaps;
457465
state.spotLightMap.length = numSpotMaps;
458466
state.numSpotLightShadowsWithMaps = numSpotShadowsWithMaps;
467+
state.numLightProbes = numLightProbes;
459468

460469
hash.directionalLength = directionalLength;
461470
hash.pointLength = pointLength;
@@ -468,6 +477,8 @@ function WebGLLights( extensions, capabilities ) {
468477
hash.numSpotShadows = numSpotShadows;
469478
hash.numSpotMaps = numSpotMaps;
470479

480+
hash.numLightProbes = numLightProbes;
481+
471482
state.version = nextVersion ++;
472483

473484
}

src/renderers/webgl/WebGLProgram.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,8 @@ function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) {
606606

607607
parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
608608

609+
parameters.numLightProbes > 0 ? '#define USE_LIGHT_PROBES' : '',
610+
609611
parameters.useLegacyLights ? '#define LEGACY_LIGHTS' : '',
610612

611613
parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
@@ -788,6 +790,8 @@ function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) {
788790

789791
parameters.premultipliedAlpha ? '#define PREMULTIPLIED_ALPHA' : '',
790792

793+
parameters.numLightProbes > 0 ? '#define USE_LIGHT_PROBES' : '',
794+
791795
parameters.useLegacyLights ? '#define LEGACY_LIGHTS' : '',
792796

793797
parameters.decodeVideoTexture ? '#define DECODE_VIDEO_TEXTURE' : '',

src/renderers/webgl/WebGLPrograms.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,8 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
325325
numSpotLightShadows: lights.spotShadowMap.length,
326326
numSpotLightShadowsWithMaps: lights.numSpotLightShadowsWithMaps,
327327

328+
numLightProbes: lights.numLightProbes,
329+
328330
numClippingPlanes: clipping.numPlanes,
329331
numClipIntersection: clipping.numIntersection,
330332

@@ -449,6 +451,7 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
449451
array.push( parameters.numPointLightShadows );
450452
array.push( parameters.numSpotLightShadows );
451453
array.push( parameters.numSpotLightShadowsWithMaps );
454+
array.push( parameters.numLightProbes );
452455
array.push( parameters.shadowMapType );
453456
array.push( parameters.toneMapping );
454457
array.push( parameters.numClippingPlanes );

0 commit comments

Comments
 (0)