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

Question about HomogeneousMedium::Sample implementation #159

Closed Immocat closed 6 years ago

Immocat commented 6 years ago

I'm a little bit confused by the implementation of HomogeneousMedium::Sample.

Around line 57, homogeneous.cpp(Also at Page 894 in pbrt3 book)

Float dist = -std::log(1 - sampler.Get1D()) / sigma_t[channel];
Float t = std::min(dist * ray.d.Length(), ray.tMax);

As far as I know, the dist is the sampled distance over [0,+inf). For rays ( o + d t ), `dist == t ray.d.Length(), andt = dist / ray.d.Length()`.

Why the code is dist * ray.d.Length()? Maybe I misunderstand something, or it is a bug here.

mmp commented 6 years ago

Thanks!