Skip to content

Commit

Permalink
Clamp roughness in sheen closure to avoid NaNs
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Kulla <ckulla@gmail.com>
  • Loading branch information
fpsunflower committed Jun 21, 2024
1 parent 8a4baa6 commit f72ac64
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/testrender/shading.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1460,7 +1460,7 @@ struct ZeltnerBurleySheen final : public BSDF, MxSheenParams {

Color3 get_albedo(const Vec3& wo) const override
{
const float NdotV = clamp(N.dot(wo), 0.0f, 1.0f);
const float NdotV = clamp(N.dot(wo), 1e-5f, 1.0f);
return Color3(fetch_ltc(NdotV).z);
}

Expand Down Expand Up @@ -1529,7 +1529,7 @@ struct ZeltnerBurleySheen final : public BSDF, MxSheenParams {
// for the implementation in MaterialX:
// https://github.com/AcademySoftwareFoundation/MaterialX/blob/main/libraries/pbrlib/genglsl/lib/mx_microfacet_sheen.glsl
const float x = NdotV;
const float y = roughness;
const float y = std::max(roughness, 1e-3f);
const float A = ((2.58126f * x + 0.813703f * y) * y)
/ (1.0f + 0.310327f * x * x + 2.60994f * x * y);
const float B = sqrtf(1.0f - x) * (y - 1.0f) * y * y * y
Expand All @@ -1546,6 +1546,9 @@ struct ZeltnerBurleySheen final : public BSDF, MxSheenParams {
float q = (x - m) * invs;
const float inv_sqrt2pi = 0.39894228040143f;
float R = expf(-0.5f * q * q) * invs * inv_sqrt2pi + o;
assert(isfinite(A));
assert(isfinite(B));
assert(isfinite(R));
return Vec3(A, B, R);
}
};
Expand Down

0 comments on commit f72ac64

Please sign in to comment.