@@ -181,8 +181,10 @@ class PhysicalLightingModel extends LightingModel {
181
181
this . iridescence = iridescence ;
182
182
183
183
this . clearcoatRadiance = null ;
184
- this . clearcoatSpecular = null ;
185
- this . sheenSpecular = null ;
184
+ this . clearcoatSpecularDirect = null ;
185
+ this . clearcoatSpecularIndirect = null ;
186
+ this . sheenSpecularDirect = null ;
187
+ this . sheenSpecularIndirect = null ;
186
188
this . iridescenceFresnel = null ;
187
189
this . iridescenceF0 = null ;
188
190
@@ -193,13 +195,15 @@ class PhysicalLightingModel extends LightingModel {
193
195
if ( this . clearcoat === true ) {
194
196
195
197
this . clearcoatRadiance = vec3 ( ) . temp ( 'clearcoatRadiance' ) ;
196
- this . clearcoatSpecular = vec3 ( ) . temp ( 'clearcoatSpecular' ) ;
198
+ this . clearcoatSpecularDirect = vec3 ( ) . temp ( 'clearcoatSpecularDirect' ) ;
199
+ this . clearcoatSpecularIndirect = vec3 ( ) . temp ( 'clearcoatSpecularIndirect' ) ;
197
200
198
201
}
199
202
200
203
if ( this . sheen === true ) {
201
204
202
- this . sheenSpecular = vec3 ( ) . temp ( 'sheenSpecular' ) ;
205
+ this . sheenSpecularDirect = vec3 ( ) . temp ( 'sheenSpecularDirect' ) ;
206
+ this . sheenSpecularIndirect = vec3 ( ) . temp ( 'sheenSpecularIndirect' ) ;
203
207
204
208
}
205
209
@@ -253,7 +257,7 @@ class PhysicalLightingModel extends LightingModel {
253
257
254
258
if ( this . sheen === true ) {
255
259
256
- this . sheenSpecular . addAssign ( irradiance . mul ( BRDF_Sheen ( { lightDirection } ) ) ) ;
260
+ this . sheenSpecularDirect . addAssign ( irradiance . mul ( BRDF_Sheen ( { lightDirection } ) ) ) ;
257
261
258
262
}
259
263
@@ -262,7 +266,7 @@ class PhysicalLightingModel extends LightingModel {
262
266
const dotNLcc = transformedClearcoatNormalView . dot ( lightDirection ) . clamp ( ) ;
263
267
const ccIrradiance = dotNLcc . mul ( lightColor ) ;
264
268
265
- this . clearcoatSpecular . addAssign ( ccIrradiance . mul ( BRDF_GGX ( { lightDirection, f0 : clearcoatF0 , f90 : clearcoatF90 , roughness : clearcoatRoughness , normalView : transformedClearcoatNormalView } ) ) ) ;
269
+ this . clearcoatSpecularDirect . addAssign ( ccIrradiance . mul ( BRDF_GGX ( { lightDirection, f0 : clearcoatF0 , f90 : clearcoatF90 , roughness : clearcoatRoughness , normalView : transformedClearcoatNormalView } ) ) ) ;
266
270
267
271
}
268
272
@@ -282,7 +286,7 @@ class PhysicalLightingModel extends LightingModel {
282
286
283
287
if ( this . sheen === true ) {
284
288
285
- this . sheenSpecular . addAssign ( iblIrradiance . mul (
289
+ this . sheenSpecularIndirect . addAssign ( iblIrradiance . mul (
286
290
sheen ,
287
291
IBLSheenBRDF ( {
288
292
normal : transformedNormalView ,
@@ -304,7 +308,7 @@ class PhysicalLightingModel extends LightingModel {
304
308
roughness : clearcoatRoughness
305
309
} ) ;
306
310
307
- this . clearcoatSpecular . addAssign ( this . clearcoatRadiance . mul ( clearcoatEnv ) ) ;
311
+ this . clearcoatSpecularIndirect . addAssign ( this . clearcoatRadiance . mul ( clearcoatEnv ) ) ;
308
312
309
313
}
310
314
@@ -336,6 +340,18 @@ class PhysicalLightingModel extends LightingModel {
336
340
337
341
const aoNode = ambientOcclusion . sub ( aoNV . pow ( aoExp ) . oneMinus ( ) ) . clamp ( ) ;
338
342
343
+ if ( this . clearcoat === true ) {
344
+
345
+ this . clearcoatSpecularIndirect . mulAssign ( ambientOcclusion ) ;
346
+
347
+ }
348
+
349
+ if ( this . sheen === true ) {
350
+
351
+ this . sheenSpecularIndirect . mulAssign ( ambientOcclusion ) ;
352
+
353
+ }
354
+
339
355
reflectedLight . indirectDiffuse . mulAssign ( ambientOcclusion ) ;
340
356
reflectedLight . indirectSpecular . mulAssign ( aoNode ) ;
341
357
@@ -355,7 +371,7 @@ class PhysicalLightingModel extends LightingModel {
355
371
f90 : clearcoatF90
356
372
} ) ;
357
373
358
- const clearcoatLight = outgoingLight . mul ( clearcoat . mul ( Fcc ) . oneMinus ( ) ) . add ( this . clearcoatSpecular . mul ( clearcoat ) ) ;
374
+ const clearcoatLight = outgoingLight . mul ( clearcoat . mul ( Fcc ) . oneMinus ( ) ) . add ( this . clearcoatSpecularDirect , this . clearcoatSpecularIndirect ) . mul ( clearcoat ) ;
359
375
360
376
outgoingLight . assign ( clearcoatLight ) ;
361
377
@@ -364,7 +380,7 @@ class PhysicalLightingModel extends LightingModel {
364
380
if ( this . sheen === true ) {
365
381
366
382
const sheenEnergyComp = sheen . r . max ( sheen . g ) . max ( sheen . b ) . mul ( 0.157 ) . oneMinus ( ) ;
367
- const sheenLight = outgoingLight . mul ( sheenEnergyComp ) . add ( this . sheenSpecular ) ;
383
+ const sheenLight = outgoingLight . mul ( sheenEnergyComp ) . add ( this . sheenSpecularDirect , this . sheenSpecularIndirect ) ;
368
384
369
385
outgoingLight . assign ( sheenLight ) ;
370
386
0 commit comments