mmp / pbrt-v3

Source code for pbrt, the renderer described in the third edition of "Physically Based Rendering: From Theory To Implementation", by Matt Pharr, Wenzel Jakob, and Greg Humphreys.
http://pbrt.org
BSD 2-Clause "Simplified" License
4.86k stars 1.18k forks source link

Schlick function in disney material maybe wrong #270

Open jxo opened 4 years ago

jxo commented 4 years ago
// The Schlick Fresnel approximation is:
//
// R = R(0) + (1 - R(0)) (1 - cos theta)^5,
//
// where R(0) is the reflectance at normal indicence.
inline Float SchlickWeight(Float cosTheta) {
    Float m = Clamp(1 - cosTheta, 0, 1);
    return (m * m) * (m * m) * m;
}

inline Float FrSchlick(Float R0, Float cosTheta) {
    return Lerp(SchlickWeight(cosTheta), R0, 1);
}

inline Spectrum FrSchlick(const Spectrum &R0, Float cosTheta) {
    return Lerp(SchlickWeight(cosTheta), R0, Spectrum(1.));
}

Lerp here is (1 - SchlickWeight(cosTheta)) R0 + SchlickWeight(cosTheta) not R0 + (1 - R0) SchlickWeight(cosTheta)

oceanusxiv commented 3 years ago

@jxo I think it's just the comment equation that is wrong, and the actual function implementation is still correct.

jxo commented 3 years ago

@eric1221bday see here, the comment equation is right. https://en.wikipedia.org/wiki/Schlick's_approximation Lerp definition: inline Float Lerp(Float t, Float v1, Float v2) { return (1 - t) v1 + t v2; } Lerp(R0, SchlickWeight(cosTheta), 1) may be right