Skip to content

Commit

Permalink
fix_DisneyClearcoat_bug v1 (mmp#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
Immocat authored and mmp committed Mar 5, 2018
1 parent 086165b commit 277d749
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/materials/disney.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,15 +266,15 @@ Spectrum DisneyClearcoat::f(const Vector3f &wo, const Vector3f &wi) const {
// Clearcoat has ior = 1.5 hardcoded -> F0 = 0.04. It then uses the
// GTR1 distribution, which has even fatter tails than Trowbridge-Reitz
// (which is GTR2).
Float Dr = GTR1(AbsCosTheta(wh), Lerp(gloss, .1, .001));
Float Dr = GTR1(AbsCosTheta(wh), gloss);
Float Fr = FrSchlick(.04, Dot(wo, wh));
// The geometric term always based on alpha = 0.25.
Float Gr =
smithG_GGX(AbsCosTheta(wo), .25) * smithG_GGX(AbsCosTheta(wi), .25);

// Ad-hoc 0.25 term to match Disney implementation (unpublished, via
// Brent Burley.)
return .25 * weight * Gr * Fr * Dr;
return .25 * weight * Gr * Fr * Dr / (AbsCosTheta(wo) * AbsCosTheta(wi));
}

Spectrum DisneyClearcoat::Sample_f(const Vector3f &wo, Vector3f *wi,
Expand All @@ -285,8 +285,7 @@ Spectrum DisneyClearcoat::Sample_f(const Vector3f &wo, Vector3f *wi,
// somewhere.
if (wo.z == 0) return 0.;

Float alpha = 0.25;
Float alpha2 = alpha * alpha;
Float alpha2 = gloss * gloss;
Float cosTheta = std::sqrt(
std::max(Float(0), (1 - std::pow(alpha2, 1 - u[0])) / (1 - alpha2)));
Float sinTheta = std::sqrt(std::max((Float)0, 1 - cosTheta * cosTheta));
Expand All @@ -312,8 +311,8 @@ Float DisneyClearcoat::Pdf(const Vector3f &wo, const Vector3f &wi) const {
// Thus, the final value of the PDF is just the value of the
// distribution for wh converted to a mesure with respect to the
// surface normal.
Float Dr = GTR1(AbsCosTheta(wh), Lerp(gloss, .1, .001));
return Dr / (4 * Dot(wo, wh));
Float Dr = GTR1(AbsCosTheta(wh), gloss);
return Dr * AbsCosTheta(wh) / (4 * Dot(wo, wh));
}

std::string DisneyClearcoat::ToString() const {
Expand Down Expand Up @@ -559,7 +558,7 @@ void DisneyMaterial::ComputeScatteringFunctions(SurfaceInteraction *si,
Float cc = clearcoat->Evaluate(*si);
if (cc > 0) {
si->bsdf->Add(ARENA_ALLOC(arena, DisneyClearcoat)(
cc, clearcoatGloss->Evaluate(*si)));
cc, Lerp(clearcoatGloss->Evaluate(*si), .1, .001)));
}

// BTDF
Expand Down

0 comments on commit 277d749

Please sign in to comment.