pbr-book-website
pbr-book-website copied to clipboard
Code on the website that will lead to confusion
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
- PhaseHG function definition:
Float denom = 1 + g * g + 2 * g * cosTheta;, if no minus sign given,denomshould be1 + g * g - 2 * g * cosTheta. According to the ray direction convention in PBRT-v3, all 'incident ray' points outwards, thereforecosThetaRHS should have a minus sign. - The formula in that chapter, listed right above the code block.
- Actual experiments... Initially I implemented h-g sampling based on the code above, which costed me two days to debug my code. The following experiments are based on pbrt-v3, and the code doesn't have the problem mentioned above. You will notice that we can not really distinguish between these two the incorrect results, even though one exhibits forward scattering and the other is backward.
| correct g = 0.5 | correct g = -0.5 | incorrect g = 0.5 | incorrect g =-0.5 |
|---|---|---|---|
![]() |
![]() |
![]() |
![]() |
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.
Thanks. Looking forward to reading more new advanced topics in PBR-book.



