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.89k stars 1.19k forks source link

problem about bump #261

Open shihaoL opened 4 years ago

shihaoL commented 4 years ago

According to the formula, dpdu is not a normalized vector, but si->shading.dpdu is normalized.

// Compute bump-mapped differential geometry
    Vector3f dpdu = si->shading.dpdu +
                    (uDisplace - displace) / du * Vector3f(si->shading.n) +
                    displace * Vector3f(si->shading.dndu);

    Vector3f dpdv = si->shading.dpdv +
                    (vDisplace - displace) / dv * Vector3f(si->shading.n) +
                    displace * Vector3f(si->shading.dndv);

This is a part of code in "Triangle::Intersect", ts and ss are normalized, the values are assigned to shading.dpdu and shading.dpdv.

        Vector3f ts = Cross(ss, ns);
        if (ts.LengthSquared() > 0.f) {
            ts = Normalize(ts);
            ss = Cross(ts, ns);
        } else
            CoordinateSystem((Vector3f)ns, &ss, &ts);
        isect->SetShadingGeometry(ss, ts, dndu, dndv, true);

Is the code wrong?

mmp commented 4 years ago

The code is indeed wrong. :-(. I'm going to defer fixing this until pbrt-v4, however, since doing so can cause rendered images to change significantly.