Skip to content

PhysicalLightingModel: Cleanup evalIridescence #29702

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions src/nodes/functions/PhysicalLightingModel.js
Original file line number Diff line number Diff line change
@@ -74,7 +74,7 @@ const getTransmissionSample = /*@__PURE__*/ Fn( ( [ fragCoord, roughness, ior ]
const transmissionSample = singleViewportMipTexture.uv( fragCoord );
//const transmissionSample = viewportMipTexture( fragCoord );

const lod = log2( float( screenSize.x ) ).mul( applyIorToRoughness( roughness, ior ) );
const lod = log2( screenSize.x ).mul( applyIorToRoughness( roughness, ior ) );

return textureBicubic( transmissionSample, lod );

@@ -233,15 +233,16 @@ const evalIridescence = /*@__PURE__*/ Fn( ( { outsideIOR, eta2, cosTheta1, thinF
// Force iridescenceIOR -> outsideIOR when thinFilmThickness -> 0.0
const iridescenceIOR = mix( outsideIOR, eta2, smoothstep( 0.0, 0.03, thinFilmThickness ) );
// Evaluate the cosTheta on the base layer (Snell law)
const sinTheta2Sq = outsideIOR.div( iridescenceIOR ).pow2().mul( float( 1 ).sub( cosTheta1.pow2() ) );
const sinTheta2Sq = outsideIOR.div( iridescenceIOR ).pow2().mul( cosTheta1.pow2().oneMinus() );

// Handle TIR:
const cosTheta2Sq = float( 1 ).sub( sinTheta2Sq );
/*if ( cosTheta2Sq < 0.0 ) {
const cosTheta2Sq = sinTheta2Sq.oneMinus();

return vec3( 1.0 );
If( cosTheta2Sq.lessThan( 0 ), () => {

}*/
return vec3( 1.0 );

} );

const cosTheta2 = cosTheta2Sq.sqrt();

@@ -274,17 +275,18 @@ const evalIridescence = /*@__PURE__*/ Fn( ( { outsideIOR, eta2, cosTheta1, thinF

// Reflectance term for m = 0 (DC term amplitude)
const C0 = R12.add( Rs );
let I = C0;
const I = C0.toVar();

// Reflectance term for m > 0 (pairs of diracs)
let Cm = Rs.sub( T121 );
for ( let m = 1; m <= 2; ++ m ) {
const Cm = Rs.sub( T121 ).toVar();

Loop( { start: 1, end: 2, condition: '<=', name: 'm' }, ( { m } ) => {

Cm = Cm.mul( r123 );
Cm.mulAssign( r123 );
const Sm = evalSensitivity( float( m ).mul( OPD ), float( m ).mul( phi ) ).mul( 2.0 );
I = I.add( Cm.mul( Sm ) );
I.addAssign( Cm.mul( Sm ) );

}
} );

// Since out of gamut colors might be produced, negative color values are clamped to 0.
return I.max( vec3( 0.0 ) );