mmp / pbr-book-website

Other
472 stars 64 forks source link

Code on the website that will lead to confusion #11

Open Enigmatisms opened 1 year ago

Enigmatisms commented 1 year ago

In chapter 15.2 - Sampling Volume Scattering, for H-G phase function sampling:

<<Compute  for Henyey–Greenstein sample>>= 
Float cosTheta;
if (std::abs(g) < 1e-3)
    cosTheta = 1 - 2 * u[0];
else {
    Float sqrTerm = (1 - g * g) /
                    (1 - g + 2 * g * u[0]);
    cosTheta = (1 + g * g - sqrTerm * sqrTerm) / (2 * g);                         // HERE
}

There should be a negative sign in front of cosTheta RHS.

The code block is not consistent with , and is not consistent with

correct g = 0.5 correct g = -0.5 incorrect g = 0.5 incorrect g =-0.5
cornell-correct-pos05 cornell-correct-neg05 cornell-pos05 cornell-neg05
mmp commented 1 year ago

Interesting; that code is correct in the pbrt-v3 source code but seems to be incorrect in the online text. I will look into what happened there. https://github.com/mmp/pbrt-v3/blob/aaa552a4b9cbf9dccb71450f47b268e0ed6370e2/src/core/medium.cpp#L194.

Sorry for any inconvenience.

Enigmatisms commented 1 year ago

Thanks. Looking forward to reading more new advanced topics in PBR-book.