Skip to content

Commit a1bad17

Browse files
authored
WebGPURenderer: Clearcoat and sheen is shadowed by ambient occlusion (#26957)
1 parent 0f964b7 commit a1bad17

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

examples/jsm/nodes/functions/PhysicalLightingModel.js

+26-10
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,10 @@ class PhysicalLightingModel extends LightingModel {
181181
this.iridescence = iridescence;
182182

183183
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;
186188
this.iridescenceFresnel = null;
187189
this.iridescenceF0 = null;
188190

@@ -193,13 +195,15 @@ class PhysicalLightingModel extends LightingModel {
193195
if ( this.clearcoat === true ) {
194196

195197
this.clearcoatRadiance = vec3().temp( 'clearcoatRadiance' );
196-
this.clearcoatSpecular = vec3().temp( 'clearcoatSpecular' );
198+
this.clearcoatSpecularDirect = vec3().temp( 'clearcoatSpecularDirect' );
199+
this.clearcoatSpecularIndirect = vec3().temp( 'clearcoatSpecularIndirect' );
197200

198201
}
199202

200203
if ( this.sheen === true ) {
201204

202-
this.sheenSpecular = vec3().temp( 'sheenSpecular' );
205+
this.sheenSpecularDirect = vec3().temp( 'sheenSpecularDirect' );
206+
this.sheenSpecularIndirect = vec3().temp( 'sheenSpecularIndirect' );
203207

204208
}
205209

@@ -253,7 +257,7 @@ class PhysicalLightingModel extends LightingModel {
253257

254258
if ( this.sheen === true ) {
255259

256-
this.sheenSpecular.addAssign( irradiance.mul( BRDF_Sheen( { lightDirection } ) ) );
260+
this.sheenSpecularDirect.addAssign( irradiance.mul( BRDF_Sheen( { lightDirection } ) ) );
257261

258262
}
259263

@@ -262,7 +266,7 @@ class PhysicalLightingModel extends LightingModel {
262266
const dotNLcc = transformedClearcoatNormalView.dot( lightDirection ).clamp();
263267
const ccIrradiance = dotNLcc.mul( lightColor );
264268

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 } ) ) );
266270

267271
}
268272

@@ -282,7 +286,7 @@ class PhysicalLightingModel extends LightingModel {
282286

283287
if ( this.sheen === true ) {
284288

285-
this.sheenSpecular.addAssign( iblIrradiance.mul(
289+
this.sheenSpecularIndirect.addAssign( iblIrradiance.mul(
286290
sheen,
287291
IBLSheenBRDF( {
288292
normal: transformedNormalView,
@@ -304,7 +308,7 @@ class PhysicalLightingModel extends LightingModel {
304308
roughness: clearcoatRoughness
305309
} );
306310

307-
this.clearcoatSpecular.addAssign( this.clearcoatRadiance.mul( clearcoatEnv ) );
311+
this.clearcoatSpecularIndirect.addAssign( this.clearcoatRadiance.mul( clearcoatEnv ) );
308312

309313
}
310314

@@ -336,6 +340,18 @@ class PhysicalLightingModel extends LightingModel {
336340

337341
const aoNode = ambientOcclusion.sub( aoNV.pow( aoExp ).oneMinus() ).clamp();
338342

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+
339355
reflectedLight.indirectDiffuse.mulAssign( ambientOcclusion );
340356
reflectedLight.indirectSpecular.mulAssign( aoNode );
341357

@@ -355,7 +371,7 @@ class PhysicalLightingModel extends LightingModel {
355371
f90: clearcoatF90
356372
} );
357373

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 );
359375

360376
outgoingLight.assign( clearcoatLight );
361377

@@ -364,7 +380,7 @@ class PhysicalLightingModel extends LightingModel {
364380
if ( this.sheen === true ) {
365381

366382
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 );
368384

369385
outgoingLight.assign( sheenLight );
370386

0 commit comments

Comments
 (0)