PhysicalLightingModel.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  1. import BRDF_Lambert from './BSDF/BRDF_Lambert.js';
  2. import BRDF_GGX from './BSDF/BRDF_GGX.js';
  3. import DFGApprox from './BSDF/DFGApprox.js';
  4. import EnvironmentBRDF from './BSDF/EnvironmentBRDF.js';
  5. import F_Schlick from './BSDF/F_Schlick.js';
  6. import Schlick_to_F0 from './BSDF/Schlick_to_F0.js';
  7. import BRDF_Sheen from './BSDF/BRDF_Sheen.js';
  8. import LightingModel from '../core/LightingModel.js';
  9. import { diffuseColor, specularColor, specularF90, roughness, clearcoat, clearcoatRoughness, sheen, sheenRoughness, iridescence, iridescenceIOR, iridescenceThickness, ior, thickness, transmission, attenuationDistance, attenuationColor } from '../core/PropertyNode.js';
  10. import { transformedNormalView, transformedClearcoatNormalView, transformedNormalWorld } from '../accessors/NormalNode.js';
  11. import { positionViewDirection, positionWorld } from '../accessors/PositionNode.js';
  12. import { tslFn, float, vec2, vec3, vec4, mat3, If } from '../shadernode/ShaderNode.js';
  13. import { cond } from '../math/CondNode.js';
  14. import { mix, normalize, refract, length, clamp, log2, log, exp, smoothstep } from '../math/MathNode.js';
  15. import { div } from '../math/OperatorNode.js';
  16. import { cameraPosition, cameraProjectionMatrix, cameraViewMatrix } from '../accessors/CameraNode.js';
  17. import { modelWorldMatrix } from '../accessors/ModelNode.js';
  18. import { viewportResolution } from '../display/ViewportNode.js';
  19. import { viewportMipTexture } from '../display/ViewportTextureNode.js';
  20. //
  21. // Transmission
  22. //
  23. const getVolumeTransmissionRay = tslFn( ( [ n, v, thickness, ior, modelMatrix ] ) => {
  24. // Direction of refracted light.
  25. const refractionVector = vec3( refract( v.negate(), normalize( n ), div( 1.0, ior ) ) );
  26. // Compute rotation-independant scaling of the model matrix.
  27. const modelScale = vec3(
  28. length( modelMatrix[ 0 ].xyz ),
  29. length( modelMatrix[ 1 ].xyz ),
  30. length( modelMatrix[ 2 ].xyz )
  31. );
  32. // The thickness is specified in local space.
  33. return normalize( refractionVector ).mul( thickness.mul( modelScale ) );
  34. } ).setLayout( {
  35. name: 'getVolumeTransmissionRay',
  36. type: 'vec3',
  37. inputs: [
  38. { name: 'n', type: 'vec3' },
  39. { name: 'v', type: 'vec3' },
  40. { name: 'thickness', type: 'float' },
  41. { name: 'ior', type: 'float' },
  42. { name: 'modelMatrix', type: 'mat4' }
  43. ]
  44. } );
  45. const applyIorToRoughness = tslFn( ( [ roughness, ior ] ) => {
  46. // Scale roughness with IOR so that an IOR of 1.0 results in no microfacet refraction and
  47. // an IOR of 1.5 results in the default amount of microfacet refraction.
  48. return roughness.mul( clamp( ior.mul( 2.0 ).sub( 2.0 ), 0.0, 1.0 ) );
  49. } ).setLayout( {
  50. name: 'applyIorToRoughness',
  51. type: 'float',
  52. inputs: [
  53. { name: 'roughness', type: 'float' },
  54. { name: 'ior', type: 'float' }
  55. ]
  56. } );
  57. const singleViewportMipTexture = viewportMipTexture();
  58. const getTransmissionSample = tslFn( ( [ fragCoord, roughness, ior ] ) => {
  59. const transmissionSample = singleViewportMipTexture.uv( fragCoord );
  60. //const transmissionSample = viewportMipTexture( fragCoord );
  61. const lod = log2( float( viewportResolution.x ) ).mul( applyIorToRoughness( roughness, ior ) );
  62. return transmissionSample.bicubic( lod );
  63. } );
  64. const volumeAttenuation = tslFn( ( [ transmissionDistance, attenuationColor, attenuationDistance ] ) => {
  65. If( attenuationDistance.notEqual( 0 ), () => {
  66. // Compute light attenuation using Beer's law.
  67. const attenuationCoefficient = log( attenuationColor ).negate().div( attenuationDistance );
  68. const transmittance = exp( attenuationCoefficient.negate().mul( transmissionDistance ) );
  69. return transmittance;
  70. } );
  71. // Attenuation distance is +∞, i.e. the transmitted color is not attenuated at all.
  72. return vec3( 1.0 );
  73. } ).setLayout( {
  74. name: 'volumeAttenuation',
  75. type: 'vec3',
  76. inputs: [
  77. { name: 'transmissionDistance', type: 'float' },
  78. { name: 'attenuationColor', type: 'vec3' },
  79. { name: 'attenuationDistance', type: 'float' }
  80. ]
  81. } );
  82. const getIBLVolumeRefraction = tslFn( ( [ n, v, roughness, diffuseColor, specularColor, specularF90, position, modelMatrix, viewMatrix, projMatrix, ior, thickness, attenuationColor, attenuationDistance ] ) => {
  83. const transmissionRay = getVolumeTransmissionRay( n, v, thickness, ior, modelMatrix );
  84. const refractedRayExit = position.add( transmissionRay );
  85. // Project refracted vector on the framebuffer, while mapping to normalized device coordinates.
  86. const ndcPos = projMatrix.mul( viewMatrix.mul( vec4( refractedRayExit, 1.0 ) ) );
  87. const refractionCoords = vec2( ndcPos.xy.div( ndcPos.w ) ).toVar();
  88. refractionCoords.addAssign( 1.0 );
  89. refractionCoords.divAssign( 2.0 );
  90. refractionCoords.assign( vec2( refractionCoords.x, refractionCoords.y.oneMinus() ) ); // webgpu
  91. // Sample framebuffer to get pixel the refracted ray hits.
  92. const transmittedLight = getTransmissionSample( refractionCoords, roughness, ior );
  93. const transmittance = diffuseColor.mul( volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance ) );
  94. const attenuatedColor = transmittance.rgb.mul( transmittedLight.rgb );
  95. const dotNV = n.dot( v ).clamp();
  96. // Get the specular component.
  97. const F = vec3( EnvironmentBRDF( { // n, v, specularColor, specularF90, roughness
  98. dotNV,
  99. specularColor,
  100. specularF90,
  101. roughness
  102. } ) );
  103. // As less light is transmitted, the opacity should be increased. This simple approximation does a decent job
  104. // of modulating a CSS background, and has no effect when the buffer is opaque, due to a solid object or clear color.
  105. const transmittanceFactor = transmittance.r.add( transmittance.g, transmittance.b ).div( 3.0 );
  106. return vec4( F.oneMinus().mul( attenuatedColor ), transmittedLight.a.oneMinus().mul( transmittanceFactor ).oneMinus() );
  107. } );
  108. //
  109. // Iridescence
  110. //
  111. // XYZ to linear-sRGB color space
  112. const XYZ_TO_REC709 = mat3(
  113. 3.2404542, - 0.9692660, 0.0556434,
  114. - 1.5371385, 1.8760108, - 0.2040259,
  115. - 0.4985314, 0.0415560, 1.0572252
  116. );
  117. // Assume air interface for top
  118. // Note: We don't handle the case fresnel0 == 1
  119. const Fresnel0ToIor = ( fresnel0 ) => {
  120. const sqrtF0 = fresnel0.sqrt();
  121. return vec3( 1.0 ).add( sqrtF0 ).div( vec3( 1.0 ).sub( sqrtF0 ) );
  122. };
  123. // ior is a value between 1.0 and 3.0. 1.0 is air interface
  124. const IorToFresnel0 = ( transmittedIor, incidentIor ) => {
  125. return transmittedIor.sub( incidentIor ).div( transmittedIor.add( incidentIor ) ).pow2();
  126. };
  127. // Fresnel equations for dielectric/dielectric interfaces.
  128. // Ref: https://belcour.github.io/blog/research/2017/05/01/brdf-thin-film.html
  129. // Evaluation XYZ sensitivity curves in Fourier space
  130. const evalSensitivity = ( OPD, shift ) => {
  131. const phase = OPD.mul( 2.0 * Math.PI * 1.0e-9 );
  132. const val = vec3( 5.4856e-13, 4.4201e-13, 5.2481e-13 );
  133. const pos = vec3( 1.6810e+06, 1.7953e+06, 2.2084e+06 );
  134. const VAR = vec3( 4.3278e+09, 9.3046e+09, 6.6121e+09 );
  135. const x = float( 9.7470e-14 * Math.sqrt( 2.0 * Math.PI * 4.5282e+09 ) ).mul( phase.mul( 2.2399e+06 ).add( shift.x ).cos() ).mul( phase.pow2().mul( - 4.5282e+09 ).exp() );
  136. let xyz = val.mul( VAR.mul( 2.0 * Math.PI ).sqrt() ).mul( pos.mul( phase ).add( shift ).cos() ).mul( phase.pow2().negate().mul( VAR ).exp() );
  137. xyz = vec3( xyz.x.add( x ), xyz.y, xyz.z ).div( 1.0685e-7 );
  138. const rgb = XYZ_TO_REC709.mul( xyz );
  139. return rgb;
  140. };
  141. const evalIridescence = tslFn( ( { outsideIOR, eta2, cosTheta1, thinFilmThickness, baseF0 } ) => {
  142. // Force iridescenceIOR -> outsideIOR when thinFilmThickness -> 0.0
  143. const iridescenceIOR = mix( outsideIOR, eta2, smoothstep( 0.0, 0.03, thinFilmThickness ) );
  144. // Evaluate the cosTheta on the base layer (Snell law)
  145. const sinTheta2Sq = outsideIOR.div( iridescenceIOR ).pow2().mul( float( 1 ).sub( cosTheta1.pow2() ) );
  146. // Handle TIR:
  147. const cosTheta2Sq = float( 1 ).sub( sinTheta2Sq );
  148. /*if ( cosTheta2Sq < 0.0 ) {
  149. return vec3( 1.0 );
  150. }*/
  151. const cosTheta2 = cosTheta2Sq.sqrt();
  152. // First interface
  153. const R0 = IorToFresnel0( iridescenceIOR, outsideIOR );
  154. const R12 = F_Schlick( { f0: R0, f90: 1.0, dotVH: cosTheta1 } );
  155. //const R21 = R12;
  156. const T121 = R12.oneMinus();
  157. const phi12 = iridescenceIOR.lessThan( outsideIOR ).cond( Math.PI, 0.0 );
  158. const phi21 = float( Math.PI ).sub( phi12 );
  159. // Second interface
  160. const baseIOR = Fresnel0ToIor( baseF0.clamp( 0.0, 0.9999 ) ); // guard against 1.0
  161. const R1 = IorToFresnel0( baseIOR, iridescenceIOR.vec3() );
  162. const R23 = F_Schlick( { f0: R1, f90: 1.0, dotVH: cosTheta2 } );
  163. const phi23 = vec3(
  164. baseIOR.x.lessThan( iridescenceIOR ).cond( Math.PI, 0.0 ),
  165. baseIOR.y.lessThan( iridescenceIOR ).cond( Math.PI, 0.0 ),
  166. baseIOR.z.lessThan( iridescenceIOR ).cond( Math.PI, 0.0 )
  167. );
  168. // Phase shift
  169. const OPD = iridescenceIOR.mul( thinFilmThickness, cosTheta2, 2.0 );
  170. const phi = vec3( phi21 ).add( phi23 );
  171. // Compound terms
  172. const R123 = R12.mul( R23 ).clamp( 1e-5, 0.9999 );
  173. const r123 = R123.sqrt();
  174. const Rs = T121.pow2().mul( R23 ).div( vec3( 1.0 ).sub( R123 ) );
  175. // Reflectance term for m = 0 (DC term amplitude)
  176. const C0 = R12.add( Rs );
  177. let I = C0;
  178. // Reflectance term for m > 0 (pairs of diracs)
  179. let Cm = Rs.sub( T121 );
  180. for ( let m = 1; m <= 2; ++ m ) {
  181. Cm = Cm.mul( r123 );
  182. const Sm = evalSensitivity( float( m ).mul( OPD ), float( m ).mul( phi ) ).mul( 2.0 );
  183. I = I.add( Cm.mul( Sm ) );
  184. }
  185. // Since out of gamut colors might be produced, negative color values are clamped to 0.
  186. return I.max( vec3( 0.0 ) );
  187. } ).setLayout( {
  188. name: 'evalIridescence',
  189. type: 'vec3',
  190. inputs: [
  191. { name: 'outsideIOR', type: 'float' },
  192. { name: 'eta2', type: 'float' },
  193. { name: 'cosTheta1', type: 'float' },
  194. { name: 'thinFilmThickness', type: 'float' },
  195. { name: 'baseF0', type: 'vec3' }
  196. ]
  197. } );
  198. //
  199. // Sheen
  200. //
  201. // This is a curve-fit approxmation to the "Charlie sheen" BRDF integrated over the hemisphere from
  202. // Estevez and Kulla 2017, "Production Friendly Microfacet Sheen BRDF". The analysis can be found
  203. // in the Sheen section of https://drive.google.com/file/d/1T0D1VSyR4AllqIJTQAraEIzjlb5h4FKH/view?usp=sharing
  204. const IBLSheenBRDF = tslFn( ( { normal, viewDir, roughness } ) => {
  205. const dotNV = normal.dot( viewDir ).saturate();
  206. const r2 = roughness.pow2();
  207. const a = cond(
  208. roughness.lessThan( 0.25 ),
  209. float( - 339.2 ).mul( r2 ).add( float( 161.4 ).mul( roughness ) ).sub( 25.9 ),
  210. float( - 8.48 ).mul( r2 ).add( float( 14.3 ).mul( roughness ) ).sub( 9.95 )
  211. );
  212. const b = cond(
  213. roughness.lessThan( 0.25 ),
  214. float( 44.0 ).mul( r2 ).sub( float( 23.7 ).mul( roughness ) ).add( 3.26 ),
  215. float( 1.97 ).mul( r2 ).sub( float( 3.27 ).mul( roughness ) ).add( 0.72 )
  216. );
  217. const DG = cond( roughness.lessThan( 0.25 ), 0.0, float( 0.1 ).mul( roughness ).sub( 0.025 ) ).add( a.mul( dotNV ).add( b ).exp() );
  218. return DG.mul( 1.0 / Math.PI ).saturate();
  219. } );
  220. const clearcoatF0 = vec3( 0.04 );
  221. const clearcoatF90 = vec3( 1 );
  222. //
  223. class PhysicalLightingModel extends LightingModel {
  224. constructor( clearcoat = false, sheen = false, iridescence = false, anisotropy = false, transmission = false ) {
  225. super();
  226. this.clearcoat = clearcoat;
  227. this.sheen = sheen;
  228. this.iridescence = iridescence;
  229. this.anisotropy = anisotropy;
  230. this.transmission = transmission;
  231. this.clearcoatRadiance = null;
  232. this.clearcoatSpecularDirect = null;
  233. this.clearcoatSpecularIndirect = null;
  234. this.sheenSpecularDirect = null;
  235. this.sheenSpecularIndirect = null;
  236. this.iridescenceFresnel = null;
  237. this.iridescenceF0 = null;
  238. }
  239. start( context ) {
  240. if ( this.clearcoat === true ) {
  241. this.clearcoatRadiance = vec3().temp( 'clearcoatRadiance' );
  242. this.clearcoatSpecularDirect = vec3().temp( 'clearcoatSpecularDirect' );
  243. this.clearcoatSpecularIndirect = vec3().temp( 'clearcoatSpecularIndirect' );
  244. }
  245. if ( this.sheen === true ) {
  246. this.sheenSpecularDirect = vec3().temp( 'sheenSpecularDirect' );
  247. this.sheenSpecularIndirect = vec3().temp( 'sheenSpecularIndirect' );
  248. }
  249. if ( this.iridescence === true ) {
  250. const dotNVi = transformedNormalView.dot( positionViewDirection ).clamp();
  251. this.iridescenceFresnel = evalIridescence( {
  252. outsideIOR: float( 1.0 ),
  253. eta2: iridescenceIOR,
  254. cosTheta1: dotNVi,
  255. thinFilmThickness: iridescenceThickness,
  256. baseF0: specularColor
  257. } );
  258. this.iridescenceF0 = Schlick_to_F0( { f: this.iridescenceFresnel, f90: 1.0, dotVH: dotNVi } );
  259. }
  260. if ( this.transmission === true ) {
  261. const position = positionWorld;
  262. const v = cameraPosition.sub( positionWorld ).normalize(); // TODO: Create Node for this, same issue in MaterialX
  263. const n = transformedNormalWorld;
  264. context.backdrop = getIBLVolumeRefraction(
  265. n,
  266. v,
  267. roughness,
  268. diffuseColor,
  269. specularColor,
  270. specularF90, // specularF90
  271. position, // positionWorld
  272. modelWorldMatrix, // modelMatrix
  273. cameraViewMatrix, // viewMatrix
  274. cameraProjectionMatrix, // projMatrix
  275. ior,
  276. thickness,
  277. attenuationColor,
  278. attenuationDistance
  279. );
  280. context.backdropAlpha = transmission;
  281. diffuseColor.a.mulAssign( mix( 1, context.backdrop.a, transmission ) );
  282. }
  283. }
  284. // Fdez-Agüera's "Multiple-Scattering Microfacet Model for Real-Time Image Based Lighting"
  285. // Approximates multiscattering in order to preserve energy.
  286. // http://www.jcgt.org/published/0008/01/03/
  287. computeMultiscattering( singleScatter, multiScatter, specularF90 ) {
  288. const dotNV = transformedNormalView.dot( positionViewDirection ).clamp(); // @ TODO: Move to core dotNV
  289. const fab = DFGApprox( { roughness, dotNV } );
  290. const Fr = this.iridescenceF0 ? iridescence.mix( specularColor, this.iridescenceF0 ) : specularColor;
  291. const FssEss = Fr.mul( fab.x ).add( specularF90.mul( fab.y ) );
  292. const Ess = fab.x.add( fab.y );
  293. const Ems = Ess.oneMinus();
  294. const Favg = specularColor.add( specularColor.oneMinus().mul( 0.047619 ) ); // 1/21
  295. const Fms = FssEss.mul( Favg ).div( Ems.mul( Favg ).oneMinus() );
  296. singleScatter.addAssign( FssEss );
  297. multiScatter.addAssign( Fms.mul( Ems ) );
  298. }
  299. direct( { lightDirection, lightColor, reflectedLight } ) {
  300. const dotNL = transformedNormalView.dot( lightDirection ).clamp();
  301. const irradiance = dotNL.mul( lightColor );
  302. if ( this.sheen === true ) {
  303. this.sheenSpecularDirect.addAssign( irradiance.mul( BRDF_Sheen( { lightDirection } ) ) );
  304. }
  305. if ( this.clearcoat === true ) {
  306. const dotNLcc = transformedClearcoatNormalView.dot( lightDirection ).clamp();
  307. const ccIrradiance = dotNLcc.mul( lightColor );
  308. this.clearcoatSpecularDirect.addAssign( ccIrradiance.mul( BRDF_GGX( { lightDirection, f0: clearcoatF0, f90: clearcoatF90, roughness: clearcoatRoughness, normalView: transformedClearcoatNormalView } ) ) );
  309. }
  310. reflectedLight.directDiffuse.addAssign( irradiance.mul( BRDF_Lambert( { diffuseColor: diffuseColor.rgb } ) ) );
  311. reflectedLight.directSpecular.addAssign( irradiance.mul( BRDF_GGX( { lightDirection, f0: specularColor, f90: 1, roughness, iridescence: this.iridescence, f: this.iridescenceFresnel, USE_IRIDESCENCE: this.iridescence, USE_ANISOTROPY: this.anisotropy } ) ) );
  312. }
  313. indirectDiffuse( { irradiance, reflectedLight } ) {
  314. reflectedLight.indirectDiffuse.addAssign( irradiance.mul( BRDF_Lambert( { diffuseColor } ) ) );
  315. }
  316. indirectSpecular( { radiance, iblIrradiance, reflectedLight } ) {
  317. if ( this.sheen === true ) {
  318. this.sheenSpecularIndirect.addAssign( iblIrradiance.mul(
  319. sheen,
  320. IBLSheenBRDF( {
  321. normal: transformedNormalView,
  322. viewDir: positionViewDirection,
  323. roughness: sheenRoughness
  324. } )
  325. ) );
  326. }
  327. if ( this.clearcoat === true ) {
  328. const dotNVcc = transformedClearcoatNormalView.dot( positionViewDirection ).clamp();
  329. const clearcoatEnv = EnvironmentBRDF( {
  330. dotNV: dotNVcc,
  331. specularColor: clearcoatF0,
  332. specularF90: clearcoatF90,
  333. roughness: clearcoatRoughness
  334. } );
  335. this.clearcoatSpecularIndirect.addAssign( this.clearcoatRadiance.mul( clearcoatEnv ) );
  336. }
  337. // Both indirect specular and indirect diffuse light accumulate here
  338. const singleScattering = vec3().temp( 'singleScattering' );
  339. const multiScattering = vec3().temp( 'multiScattering' );
  340. const cosineWeightedIrradiance = iblIrradiance.mul( 1 / Math.PI );
  341. this.computeMultiscattering( singleScattering, multiScattering, specularF90 );
  342. const totalScattering = singleScattering.add( multiScattering );
  343. const diffuse = diffuseColor.mul( totalScattering.r.max( totalScattering.g ).max( totalScattering.b ).oneMinus() );
  344. reflectedLight.indirectSpecular.addAssign( radiance.mul( singleScattering ) );
  345. reflectedLight.indirectSpecular.addAssign( multiScattering.mul( cosineWeightedIrradiance ) );
  346. reflectedLight.indirectDiffuse.addAssign( diffuse.mul( cosineWeightedIrradiance ) );
  347. }
  348. ambientOcclusion( { ambientOcclusion, reflectedLight } ) {
  349. const dotNV = transformedNormalView.dot( positionViewDirection ).clamp(); // @ TODO: Move to core dotNV
  350. const aoNV = dotNV.add( ambientOcclusion );
  351. const aoExp = roughness.mul( - 16.0 ).oneMinus().negate().exp2();
  352. const aoNode = ambientOcclusion.sub( aoNV.pow( aoExp ).oneMinus() ).clamp();
  353. if ( this.clearcoat === true ) {
  354. this.clearcoatSpecularIndirect.mulAssign( ambientOcclusion );
  355. }
  356. if ( this.sheen === true ) {
  357. this.sheenSpecularIndirect.mulAssign( ambientOcclusion );
  358. }
  359. reflectedLight.indirectDiffuse.mulAssign( ambientOcclusion );
  360. reflectedLight.indirectSpecular.mulAssign( aoNode );
  361. }
  362. finish( context ) {
  363. const { outgoingLight } = context;
  364. if ( this.clearcoat === true ) {
  365. const dotNVcc = transformedClearcoatNormalView.dot( positionViewDirection ).clamp();
  366. const Fcc = F_Schlick( {
  367. dotVH: dotNVcc,
  368. f0: clearcoatF0,
  369. f90: clearcoatF90
  370. } );
  371. const clearcoatLight = outgoingLight.mul( clearcoat.mul( Fcc ).oneMinus() ).add( this.clearcoatSpecularDirect.add( this.clearcoatSpecularIndirect ).mul( clearcoat ) );
  372. outgoingLight.assign( clearcoatLight );
  373. }
  374. if ( this.sheen === true ) {
  375. const sheenEnergyComp = sheen.r.max( sheen.g ).max( sheen.b ).mul( 0.157 ).oneMinus();
  376. const sheenLight = outgoingLight.mul( sheenEnergyComp ).add( this.sheenSpecularDirect, this.sheenSpecularIndirect );
  377. outgoingLight.assign( sheenLight );
  378. }
  379. }
  380. }
  381. export default PhysicalLightingModel;