RayTracing / raytracing.github.io

Main Web Site (Online Books)
https://raytracing.github.io/
Creative Commons Zero v1.0 Universal
8.67k stars 852 forks source link

Book 1 - Importance sampling pdfs #924

Open webanck opened 3 years ago

webanck commented 3 years ago

Multiple strategies to sample a new bouncing direction are given in book 1. It is also said that the resulting renders differ, suggesting that's expected, but the it isn't. Indeed, by weighting the contribution of each ray by the pdf of the sampled direction, using any sampling strategy should result in the same [converged] renders, albeit yielding different convergence rates.

trevordblack commented 3 years ago

Yeah, this is just wrong. Sorry.

I'm not entirely certain what your argument is, but if my understanding of your statement is correct: "All 3 bouncing distributions will all converge to the same result (given enough samples)"

Can be fairly quickly disproved by racking up the spp into the 1000s.

You are correct that weighting by (any) pdf will converge on the correct answer. But the "correct" answer in this case differs for each strategy. Each of the three ray reflection algorithms represent fundamentally different diffuse materials. With fundamentally different reflection distributions.

Choosing a pdf wouldn't change what these strategies converge to, namely, fundamentally different reflection distributions.

From the rendering equation: image

f() of 8.1 is cos^2() f() of 8.5 is cos() f() of 8.6 is 1

Have I misunderstood you? I can reread through the text to see if a clarification edit is necessary

webanck commented 3 years ago

Thanks for your quick reply. My point was more a discussion/suggestion than an error, sorry about my late me from yesterday. To sum up: all implemented distributions could have been used to converge to the same render (if weighted).

As you pointed out, different f_r are implicitly defined by the sampling implementations of the book. Moreover, rereading section 8, it states that the "true" lambertian reflection material is obtained using the implementation of section 8.5, yielding f_r = cos.

So three different materials are implicitly implemented, starting by a tricky one. What about plotting explicitly the three materials distributions to show how different they are? And if speaking about the uniform distribution, what about pointing to a way to use it to implement any other material/bouncing distribution? It would even give a way to check strategies/implementations by comparing to a reference render.

In think that when implementing recursive bouncing for the first time, sampling a direction uniformly is one of the first things to try. Then, acknowledging that it doesn't yield lambertian reflectance without the cos. And then finding a way to correct this. But all that might be too much oriented towards Monte Carlo integration.

trevordblack commented 3 years ago

Ah, understood. Sorry I flattened your point.

When it comes it the first book, we try to avoid winking the user at content available later in the series, in this case PDFs. Just because so much of the first book is convenient shortcuts that if we stopped to sign post all of the simplifications, the book would be significantly denser. This is a balance (more or less information) that we're constantly refining.

states that the "true" lambertian reflection material is obtained using the implementation of section 8.5

This whole chapter is one that I'm so unsure about and wonder if we should just rewrite it and simplify to only including the cosine law lambert. It's kind of a lot. In backing up my argument above I dug through the literature and rediscovered that "Lambertian Diffuse" is frequently defined as uniform scattering above the horizon, which is just ridiculously confusing to the new person (this is just historically inaccurate, but is so pervasively mistaught that I'm not sure how to approach that one).

What about plotting explicitly the three materials distributions to show how different they are?

Hmmm. this is actually a fantastic idea. I'll noodle on if it's worth doing. The plot may get dropped into book 3. Not sure.

And if speaking about the uniform distribution, what about pointing to a way to use it to implement any other material/bouncing distribution

Not sure what you mean here.

In think that when implementing recursive bouncing for the first time, sampling a direction uniformly is one of the first things to try.

This is actually how I would rewrite the chapter. Start with the "naive" approach, and then correct toward cosine law. We start on cos^2 today (I literally cannot remember if it's cos^3 or cos^2) because that was the outcome of the algorithm in the initial version of the book, and so we say upfront that that way of doing it was wrong. With enough time past since the initial publication of v1, it might be worth rearranging them.

But all that might be too much oriented towards Monte Carlo integration.

I would frame the cosine law as more of a property of the material, the monte carlo justification can be fleshed out in the third book.

trevordblack commented 2 years ago

I'm going to rewrite book 1's diffuse chapter in line with your guidance above, ala #992

Regarding plotting the pdf curves in book 3, I might still do that, but we've so much still left to do in v4 that I'm punting this to the backlog

trevordblack commented 5 months ago

The diffuse chapter in book 1 was rewritten according to the above discussion.

The book 3 suggestions (pdf curves) is getting punted out of v4 and into backlog

hollasch commented 5 months ago

@trevordblack -- ok to close out this issue?

hollasch commented 1 month ago

@trevordblack — please review.