Skip to content

Commit 78bec7a

Browse files
authored
Merge pull request #536 from gkjohnson/fresnel-fix
revert some fresnel changes
2 parents e496fd9 + 8c8eedc commit 78bec7a

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

src/shader/bsdf/bsdfSampling.glsl.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,10 @@ export const bsdfSamplingGLSL = /* glsl */`
9494
9595
// TODO: subsurface approx?
9696
97-
float F = evaluateFresnelWeight( dot( wo, wh ), surf.eta, surf.f0 );
97+
// float F = evaluateFresnelWeight( dot( wo, wh ), surf.eta, surf.f0 );
98+
float F = disneyFresnel( wo, wi, wh, surf.f0, surf.eta, surf.metalness );
9899
color = ( 1.0 - F ) * transFactor * metalFactor * wi.z * surf.color * ( retro + lambert ) / PI;
100+
99101
return wi.z / PI;
100102
101103
}
@@ -206,7 +208,8 @@ export const bsdfSamplingGLSL = /* glsl */`
206208
color = surf.transmission * surf.color;
207209
208210
// PDF
209-
float F = evaluateFresnelWeight( dot( wo, wh ), surf.eta, surf.f0 );
211+
// float F = evaluateFresnelWeight( dot( wo, wh ), surf.eta, surf.f0 );
212+
float F = disneyFresnel( wo, wi, wh, surf.f0, surf.eta, surf.metalness );
210213
if ( F >= 1.0 ) {
211214
212215
return 0.0;
@@ -297,7 +300,8 @@ export const bsdfSamplingGLSL = /* glsl */`
297300
298301
float metalness = surf.metalness;
299302
float transmission = surf.transmission;
300-
float fEstimate = evaluateFresnelWeight( dot( wo, wh ), surf.eta, surf.f0 );
303+
// float fEstimate = evaluateFresnelWeight( dot( wo, wh ), surf.eta, surf.f0 );
304+
float fEstimate = disneyFresnel( wo, wi, wh, surf.f0, surf.eta, surf.metalness );
301305
302306
float transSpecularProb = mix( max( 0.25, fEstimate ), 1.0, metalness );
303307
float diffSpecularProb = 0.5 + 0.5 * metalness;

src/shader/common/fresnel.glsl.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,30 +69,36 @@ export const fresnelGLSL = /* glsl */`
6969
7070
}
7171
72-
float evaluateFresnelWeight( float cosTheta, float eta, float f0 ) {
72+
// TODO: disney fresnel was removed and replaced with this fresnel function to better align with
73+
// the glTF but is causing blown out pixels. Should be revisited
74+
// float evaluateFresnelWeight( float cosTheta, float eta, float f0 ) {
7375
74-
if ( totalInternalReflection( cosTheta, eta ) ) {
76+
// if ( totalInternalReflection( cosTheta, eta ) ) {
7577
76-
return 1.0;
78+
// return 1.0;
7779
78-
}
80+
// }
7981
80-
return schlickFresnel( cosTheta, f0 );
82+
// return schlickFresnel( cosTheta, f0 );
8183
82-
}
84+
// }
8385
84-
/*
8586
// https://schuttejoe.github.io/post/disneybsdf/
8687
float disneyFresnel( vec3 wo, vec3 wi, vec3 wh, float f0, float eta, float metalness ) {
8788
8889
float dotHV = dot( wo, wh );
89-
float dotHL = dot( wi, wh );
90+
if ( totalInternalReflection( dotHV, eta ) ) {
9091
92+
return 1.0;
93+
94+
}
95+
96+
float dotHL = dot( wi, wh );
9197
float dielectricFresnel = dielectricFresnel( abs( dotHV ), eta );
9298
float metallicFresnel = schlickFresnel( dotHL, f0 );
9399
94100
return mix( dielectricFresnel, metallicFresnel, metalness );
95101
96102
}
97-
*/
103+
98104
`;

0 commit comments

Comments
 (0)