I am following the "Ray Tracing - the Rest of your Life" book by Peter Shirley and I am facing some troubles in the implementation of Monte Carlo importance sampling, and Direct light sampling.
Monte Carlo theory is clear to me. During the implementation, the way rays are scattered does not actually change and remains random. What changes looks to be the contribution of each ray.
So my first question is:
Do I understand this correctly? Rays, after hitting a surface, are still scattered randomly, but the value of the color is adjusted based on the probability of that direction?
For those familiar with the book
When the author implements the Direct light sampling, he modifies the function color(), while we previously modified scatter() and scattering_pdf(). This way, scatter() and scattering_pdf() are sampling based on a specific pdf - proportional to cos(theta) - while color() introduces a new pdf related to the direction of the light. It is not clear to me how these two things coexist, and if I am supposed to disregard the previous changes to scatter() and scattering_pdf().