Skip to content

Commit

Permalink
Merge pull request #536 from gkjohnson/fresnel-fix
Browse files Browse the repository at this point in the history
revert some fresnel changes
  • Loading branch information
gkjohnson authored Feb 13, 2024
2 parents e496fd9 + 8c8eedc commit 78bec7a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
10 changes: 7 additions & 3 deletions src/shader/bsdf/bsdfSampling.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,10 @@ export const bsdfSamplingGLSL = /* glsl */`
// TODO: subsurface approx?
float F = evaluateFresnelWeight( dot( wo, wh ), surf.eta, surf.f0 );
// float F = evaluateFresnelWeight( dot( wo, wh ), surf.eta, surf.f0 );
float F = disneyFresnel( wo, wi, wh, surf.f0, surf.eta, surf.metalness );
color = ( 1.0 - F ) * transFactor * metalFactor * wi.z * surf.color * ( retro + lambert ) / PI;
return wi.z / PI;
}
Expand Down Expand Up @@ -206,7 +208,8 @@ export const bsdfSamplingGLSL = /* glsl */`
color = surf.transmission * surf.color;
// PDF
float F = evaluateFresnelWeight( dot( wo, wh ), surf.eta, surf.f0 );
// float F = evaluateFresnelWeight( dot( wo, wh ), surf.eta, surf.f0 );
float F = disneyFresnel( wo, wi, wh, surf.f0, surf.eta, surf.metalness );
if ( F >= 1.0 ) {
return 0.0;
Expand Down Expand Up @@ -297,7 +300,8 @@ export const bsdfSamplingGLSL = /* glsl */`
float metalness = surf.metalness;
float transmission = surf.transmission;
float fEstimate = evaluateFresnelWeight( dot( wo, wh ), surf.eta, surf.f0 );
// float fEstimate = evaluateFresnelWeight( dot( wo, wh ), surf.eta, surf.f0 );
float fEstimate = disneyFresnel( wo, wi, wh, surf.f0, surf.eta, surf.metalness );
float transSpecularProb = mix( max( 0.25, fEstimate ), 1.0, metalness );
float diffSpecularProb = 0.5 + 0.5 * metalness;
Expand Down
24 changes: 15 additions & 9 deletions src/shader/common/fresnel.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,30 +69,36 @@ export const fresnelGLSL = /* glsl */`
}
float evaluateFresnelWeight( float cosTheta, float eta, float f0 ) {
// TODO: disney fresnel was removed and replaced with this fresnel function to better align with
// the glTF but is causing blown out pixels. Should be revisited
// float evaluateFresnelWeight( float cosTheta, float eta, float f0 ) {
if ( totalInternalReflection( cosTheta, eta ) ) {
// if ( totalInternalReflection( cosTheta, eta ) ) {
return 1.0;
// return 1.0;
}
// }
return schlickFresnel( cosTheta, f0 );
// return schlickFresnel( cosTheta, f0 );
}
// }
/*
// https://schuttejoe.github.io/post/disneybsdf/
float disneyFresnel( vec3 wo, vec3 wi, vec3 wh, float f0, float eta, float metalness ) {
float dotHV = dot( wo, wh );
float dotHL = dot( wi, wh );
if ( totalInternalReflection( dotHV, eta ) ) {
return 1.0;
}
float dotHL = dot( wi, wh );
float dielectricFresnel = dielectricFresnel( abs( dotHV ), eta );
float metallicFresnel = schlickFresnel( dotHL, f0 );
return mix( dielectricFresnel, metallicFresnel, metalness );
}
*/
`;

0 comments on commit 78bec7a

Please sign in to comment.