-
Notifications
You must be signed in to change notification settings - Fork 904
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Book 3.6.2: Missing actual change to the probability function #1302
Comments
From (now closed #1272):
|
FWIW, I got different results between 6.1 and 6.2. This seems to make sense, actually. In 6.1 we multiply and divide by the same value of the PDF, which nullify each other. In 6.2 brighter rays are penalized less, relative to the darker ones since all are divided by the same amount. I think this sentence in 6.2:
goes against what was said earlier in the book. For example, when talking about directing rays towards the light in 3.3:
|
TLDR: The code from section 6.2 is not valid and causes the program to converge to a different solution, not one respecting the equation we are trying to solve. There needs to be a change to the scatter function alongside the change to the pdf function. If you enjoy the math down below I would be happy to write a PR adding some of it to the book To follow-up on the discussion, looking at the math more precisly: the code from section 6.2 should not converge to the same solution as the code of 6.1 and 6.2 does in fact execute a bad monte-carlo integration. When given an integral of a function In the above formula Combining the two formulas we should expect: Notice that the right side, looks almost exactly like what is given in the code of section 6.2. The bad new comes from the VERY important need for UNIFORM distribution of the sampled points over the domain, however in 6.2 This could already conclude this explanation, but I'll be a pain for a little longer. Some people might not be convinced with my explanation since I have gone from the uniform monte-carlo, obtained a formula very similar to the one in 6.2 then just pointed at the difference, although in 6.2 the change is justified as being for non-uniform monte-carlo. Let's just work this quickly, using the following change of variables (IDC, is, like in the book, the Inverse Cumulative Density Function of Plugging this change of variables into the initial integral gives: Then, applying the uniform monte-carlo to this second integral gives the following (once again, From this we can see that indeed, the numerator (the function to evaluate) should have the same input as the pdf. In 6.2 I'll conclude this overly long comment by a side-suggestion, I feel like adding some slightly stricter math (as I have written here) to the book, even as sidenotes or foot-chapters could go a long way to help some people (like me) consolidate their understanding of the material, and would helpmore people catch issues like this one in their own work. If you feel the same, I will open a new issue for this and start working on a PR. |
It's not very clearly explained IMO, but the pdf value you're multiplying by is the value from the ideal pdf you want to use for the surface, and the one you divide by is the value from the pdf you've actually used to generate the rays (which can e.g. be biased towards lights for importance sampling).
But in 6.2 as it stands at the time of writing (4.0.0-alpha.1 I believe) you're only changing the value you're dividing by to a uniform value, but still generating with the cosine distribution inside the material! So they don't match, and instead of correcting for the distribution being used it's actually altering it to a double cosine reflectance by accident.
The change you make in 6.3 to change to generate rays using a uniform hemisphere should be in 6.2 as well, to get the effect you're claiming of giving the same result but taking longer to converge (aka more noise).
Also, a lot of the code past this point is using the material function that returns a scatter ray in an out parameter but then throws that away and generates another one it actually uses immediately afterwards, which is inefficient
The text was updated successfully, but these errors were encountered: