Skip to content

Commit

Permalink
Harmonize on VNDF sampling
Browse files Browse the repository at this point in the history
  • Loading branch information
jstone-lucasfilm committed Dec 26, 2023
1 parent 3f3f7aa commit 8b74333
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 18 deletions.
12 changes: 0 additions & 12 deletions libraries/pbrlib/genglsl/lib/mx_microfacet_specular.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,6 @@ float mx_ggx_NDF(vec3 H, vec2 alpha)
return 1.0 / (M_PI * alpha.x * alpha.y * mx_square(denom));
}

// https://media.disneyanimation.com/uploads/production/publication_asset/48/asset/s2012_pbs_disney_brdf_notes_v3.pdf
// Appendix B.2 Equation 15
vec3 mx_ggx_importance_sample_NDF(vec2 Xi, vec2 alpha)
{
float phi = 2.0 * M_PI * Xi.x;
float tanTheta = sqrt(Xi.y / (1.0 - Xi.y));
vec3 H = vec3(tanTheta * alpha.x * cos(phi),
tanTheta * alpha.y * sin(phi),
1.0);
return normalize(H);
}

// https://ggx-research.github.io/publication/2023/06/09/publication-ggx.html
vec3 mx_ggx_importance_sample_VNDF(vec2 Xi, vec3 V, vec2 alpha)
{
Expand Down
12 changes: 6 additions & 6 deletions libraries/pbrlib/genglsl/lib/mx_prefilter_environment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ vec3 mx_prefilter_environment()
// implemented prefiltering yet, so we use a high sample count.
int sampleCount = 1597; // Must be a Fibonacci number

vec3 lightInt = vec3(0.0, 0.0, 0.0);
float cbsdfInt = 0.0;
vec3 radiance = vec3(0.0, 0.0, 0.0);
float weight = 0.0;

for (int i = 0; i < sampleCount; ++i)
{
vec2 Xi = mx_spherical_fibonacci(i, sampleCount);

// Compute the half vector and incoming light direction.
vec3 H = mx_ggx_importance_sample_NDF(Xi, vec2(alpha, alpha));
vec3 H = mx_ggx_importance_sample_VNDF(Xi, vec3(0.0, 0.0, 1.0), vec2(alpha, alpha));
vec3 L = vec3(0.0, 0.0, -1.0) + 2.0 * H.z * H;

// Compute dot products for this sample.
Expand All @@ -87,9 +87,9 @@ vec3 mx_prefilter_environment()

// Add the radiance contribution of this sample.
vec3 sampleColor = mx_latlong_map_lookup(localToWorld * L, $envMatrix, 0, $envRadiance);
lightInt += G * sampleColor;
cbsdfInt += G;
radiance += G * sampleColor;
weight += G;
}

return lightInt / cbsdfInt;
return radiance / weight;
}

0 comments on commit 8b74333

Please sign in to comment.