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

Fix plastic fresnel #286

Closed kennyalive closed 4 years ago

mmp commented 4 years ago

Yep. (See also #210...) However, I think it's best to not fix this at this late point, in the interests of not causing renderings to change for existing scenes...

kennyalive commented 4 years ago

One interesting observation. There are pbrt projects files for which we still get correct result when using FresnelDielectric(1.5f, 1.f). This happens because of another bug which cancels out the effect of IOR typo. For example, dragon ply model in f9-3.pbrt has normals with outside direction, still we we have ReverseOrientation flag specified which forces the normals to point inside. Because of this cosThetaI in FrDielectric function is negative in most cases. Then we have this code snippet which checks for negative values:

    bool entering = cosThetaI > 0.f;
    if (!entering) {
        std::swap(etaI, etaT);
        cosThetaI = std::abs(cosThetaI);
    }

It swaps IORs assuming that we are inside the object and effectively we get FresnelDielectric(1.f, 1.5) fresnel configuration.